Esempio n. 1
0
        void LoginWebpageGetHandler(HttpRequestSignature signature, ref HttpListenerContext context)
        {
            string pageContent = "<html><head><title>Simian</title></head><body><br/><h1>Welcome to Simian</h1></body></html>";

            byte[] pageData = Encoding.UTF8.GetBytes(pageContent);
            context.Response.OutputStream.Write(pageData, 0, pageData.Length);
            context.Response.Close();
        }
Esempio n. 2
0
        void LoginLLSDPostHandler(HttpRequestSignature signature, ref HttpListenerContext context)
        {
            string body = String.Empty;

            using (StreamReader reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding))
            {
                body = reader.ReadToEnd();
            }

            Console.WriteLine(body);
        }
Esempio n. 3
0
        public void AddHandler(string method, string contentType, string path, bool exactPath, bool sendResponseAfterCallback, HttpRequestCallback callback)
        {
            HttpRequestSignature signature = new HttpRequestSignature(method, contentType, path, exactPath);
            HttpRequestHandler   handler   = new HttpRequestHandler(signature, callback, sendResponseAfterCallback);

            lock (m_handlersWriteLock)
            {
                HttpRequestHandler[] newHandlers = new HttpRequestHandler[m_requestHandlers.Length + 1];

                for (int i = 0; i < m_requestHandlers.Length; i++)
                {
                    newHandlers[i] = m_requestHandlers[i];
                }
                newHandlers[m_requestHandlers.Length] = handler;

                m_requestHandlers = newHandlers;
            }
        }
Esempio n. 4
0
        private void RequestReceivedHandler(object sender, RequestEventArgs e)
        {
            IHttpClientContext context = (IHttpClientContext)sender;
            IHttpRequest       request = e.Request;

            IHttpResponse response = request.CreateResponse(context);

            // Load cookies if they exist
            RequestCookies cookies = (request.Headers["cookie"] != null)
                ? new RequestCookies(request.Headers["cookie"])
                : new RequestCookies(String.Empty);

            request.SetCookies(cookies);

            // Create a request signature
            HttpRequestSignature signature = new HttpRequestSignature(request);

            // Look for a signature match in our handlers
            HttpRequestHandler foundHandler = null;

            for (int i = 0; i < m_requestHandlers.Length; i++)
            {
                HttpRequestHandler handler = m_requestHandlers[i];

                if (signature == handler.Signature)
                {
                    foundHandler = handler;
                    break;
                }
            }

            if (foundHandler != null)
            {
                FireRequestCallback(context, request, response, foundHandler);
            }
            else
            {
                FireRequestCallback(context, request, response, m_notFoundHandler);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="signature">Signature pattern for matching against incoming requests</param>
 /// <param name="callback">Callback for handling the request</param>
 /// <param name="sendResponseAfterCallback">If true, the IHttpResponse will be sent
 /// to the client after the callback completes. Otherwise, the connection will be left
 /// open and the user is responsible for closing the connection later</param>
 public HttpRequestHandler(HttpRequestSignature signature, HttpRequestCallback callback, bool sendResponseAfterCallback)
 {
     Signature = signature;
     Callback  = callback;
     SendResponseAfterCallback = sendResponseAfterCallback;
 }
Esempio n. 6
0
        void LoginXmlRpcPostHandler(HttpRequestSignature signature, ref HttpListenerContext context)
        {
            string
                firstName = String.Empty,
                lastName  = String.Empty,
                password  = String.Empty,
                start     = String.Empty,
                version   = String.Empty,
                channel   = String.Empty;

            try
            {
                // Parse the incoming XML
                XmlReader reader = XmlReader.Create(context.Request.InputStream);

                reader.ReadStartElement("methodCall");
                {
                    string methodName = reader.ReadElementContentAsString("methodName", String.Empty);

                    if (methodName == "login_to_simulator")
                    {
                        reader.ReadStartElement("params");
                        reader.ReadStartElement("param");
                        reader.ReadStartElement("value");
                        reader.ReadStartElement("struct");
                        {
                            while (reader.Name == "member")
                            {
                                reader.ReadStartElement("member");
                                {
                                    string name = reader.ReadElementContentAsString("name", String.Empty);

                                    reader.ReadStartElement("value");
                                    {
                                        switch (name)
                                        {
                                        case "first":
                                            firstName = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "last":
                                            lastName = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "passwd":
                                            password = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "start":
                                            start = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "version":
                                            version = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "channel":
                                            channel = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        default:
                                            if (reader.Name == "string")
                                            {
                                                Console.WriteLine(String.Format("Ignore login xml value: name={0}, value={1}", name, reader.ReadInnerXml()));
                                            }
                                            else
                                            {
                                                Console.WriteLine(String.Format("Unknown login xml: name={0}, value={1}", name, reader.ReadInnerXml()));
                                            }
                                            break;
                                        }
                                    }
                                    reader.ReadEndElement();
                                }
                                reader.ReadEndElement();
                            }
                        }
                        reader.ReadEndElement();
                        reader.ReadEndElement();
                        reader.ReadEndElement();
                        reader.ReadEndElement();
                    }
                }
                reader.ReadEndElement();
                reader.Close();

                LoginResponseData responseData = HandleLogin(firstName, lastName, password, start, version, channel);
                if (responseData.Success)
                {
                    responseData.InventorySkeleton = Inventory.CreateInventorySkeleton(responseData.AgentID);
                }
                XmlWriter writer = XmlWriter.Create(context.Response.OutputStream);
                responseData.ToXmlRpc(writer);
                writer.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 7
0
 void LoginWebpageHeadHandler(HttpRequestSignature signature, ref HttpListenerContext context)
 {
     context.Response.StatusCode        = (int)HttpStatusCode.OK;
     context.Response.StatusDescription = "OK";
 }