Ejemplo n.º 1
0
        public Definitions(string definitionFile)
        {
            using (XmlReader reader = XmlReader.Create(definitionFile)) {
                XPathNavigator navigator = new XPathDocument(reader).CreateNavigator();

                bool caseSensitive = XmlConvert.ToBoolean(navigator.SelectSingleNode("/NxDSL-Defs").GetAttribute("caseSensitive", ""));

                XPathNodeIterator atomPatterns = navigator.SelectDescendants("AtomPattern", "", false);

                while (atomPatterns.MoveNext()) {
                    XPathNavigator atomPattern = atomPatterns.Current;

                    RegexOptions options = RegexOptions.Compiled;

                    if (!caseSensitive) {
                        options |= RegexOptions.IgnoreCase;
                    }

                    Regex regex = new Regex("^\\s*" + atomPattern.GetAttribute("regex", "") + "$", options);

                    definitions.Add(regex, atomPattern.InnerXml);
                }
            }
        }
Ejemplo n.º 2
0
        byte[] PropFindHandler(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string username;
            if (server.AuthenticateRequest(httpRequest, httpResponse, out username))
            {
                //PropertyRequestType requestType = PropertyRequestType.AllProperties;
                List<string> davProperties = new List<string>();
                List<string> validProperties = new List<string>();
                List<string> invalidProperties = new List<string>();

                if (httpRequest.ContentLength != 0)
                {
                    XPathNavigator requestNavigator = new XPathDocument(httpRequest.InputStream).CreateNavigator();
                    XPathNodeIterator propNodeIterator = requestNavigator.SelectDescendants("prop", "DAV:", false);
                    if (propNodeIterator.MoveNext())
                    {
                        XPathNodeIterator nodeChildren = propNodeIterator.Current.SelectChildren(XPathNodeType.All);
                        while (nodeChildren.MoveNext())
                        {
                            XPathNavigator currentNode = nodeChildren.Current;

                            if (currentNode.NodeType == XPathNodeType.Element)
                                davProperties.Add(currentNode.LocalName.ToLower());
                        }
                    }
                }

                using (MemoryStream responseStream = new MemoryStream())
                {
                    using (XmlTextWriter xmlWriter = new XmlTextWriter(responseStream, Encoding.ASCII))
                    {
                        xmlWriter.Formatting = Formatting.Indented;
                        xmlWriter.IndentChar = '\t';
                        xmlWriter.Indentation = 1;
                        xmlWriter.WriteStartDocument();

                        xmlWriter.WriteStartElement("D", "multistatus", "DAV:");
                        // Microsoft cruft (joy)
                        xmlWriter.WriteAttributeString("xmlns:b", "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882");
                        xmlWriter.WriteAttributeString("xmlns:c", "urn:schemas-microsoft-com:office:office");

                        DepthHeader depth = Depth.ParseDepth(httpRequest);

                        IList<IWebDAVResource> resources = server.OnPropFindConnector(username, httpRequest.Url.AbsolutePath, depth);
                        if (resources.Count > 0)
                        {
                            for (int i = 0; i < resources.Count; i++)
                                XmlResponse.WriteResponse(xmlWriter, davProperties, resources[i]);
                        }

                        xmlWriter.WriteEndElement(); // multistatus

                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();

                        httpResponse.KeepAlive = httpRequest.KeepAlive;
                        httpResponse.ContentType = "text/xml";
                        httpResponse.ContentEncoding = Encoding.UTF8;
                        httpResponse.AddHeader("DAV", "1");
                        httpResponse.AddHeader("MS-Author-Via", "DAV");
                        httpResponse.AddHeader("Cache-Control", "no-cache");
                        if (resources.Count > 0)
                        {
                            httpResponse.StatusCode = 207; // Multistatus

                            byte[] bytes = responseStream.ToArray();
                            httpResponse.ContentLength = bytes.Length;
                            return bytes;
                        }
                        else
                        {
                            //eventually this should be the same that is defined in HttpListener.Set404Handler()
                            //that however needs some work in HttpServer
                            httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                            httpResponse.StatusDescription = "Not Found";
                            string notFoundResponse = "<html><head><title>Page Not Found</title></head><body><h3>" + httpResponse.StatusDescription + "</h3></body></html>";
                            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundResponse);
                            httpResponse.ContentLength = buffer.Length;
                            return buffer;
                        }
                    }
                }
            }

            return OpenMetaverse.Utils.EmptyBytes;
        }
Ejemplo n.º 3
0
        void PropFindHandler(IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            Console.WriteLine("Received PROPFIND request");

            string username;
            if (server.AuthenticateRequest(request, response, out username))
            {
                //PropertyRequestType requestType = PropertyRequestType.AllProperties;
                List<string> davProperties = new List<string>();
                List<string> validProperties = new List<string>();
                List<string> invalidProperties = new List<string>();

                if (request.ContentLength != 0)
                {
                    XPathNavigator requestNavigator = new XPathDocument(request.Body).CreateNavigator();
                    XPathNodeIterator propNodeIterator = requestNavigator.SelectDescendants("prop", "DAV:", false);
                    if (propNodeIterator.MoveNext())
                    {
                        XPathNodeIterator nodeChildren = propNodeIterator.Current.SelectChildren(XPathNodeType.All);
                        while (nodeChildren.MoveNext())
                        {
                            XPathNavigator currentNode = nodeChildren.Current;

                            if (currentNode.NodeType == XPathNodeType.Element)
                                davProperties.Add(currentNode.LocalName.ToLower());
                        }
                    }
                }

                using (MemoryStream responseStream = new MemoryStream())
                {
                    XmlTextWriter xmlWriter = new XmlTextWriter(responseStream, Encoding.ASCII); //, Encoding.UTF8);

                    xmlWriter.Formatting = Formatting.Indented;
                    xmlWriter.IndentChar = '\t';
                    xmlWriter.Indentation = 1;
                    xmlWriter.WriteStartDocument();

                    xmlWriter.WriteStartElement("D", "multistatus", "DAV:");
                    // Microsoft cruft (joy)
                    xmlWriter.WriteAttributeString("xmlns:b", "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882");
                    xmlWriter.WriteAttributeString("xmlns:c", "urn:schemas-microsoft-com:office:office");

                    DepthHeader depth = Depth.ParseDepth(request);

                    IList<IWebDAVResource> resources = server.OnPropFindConnector(username, request.UriPath, depth);
                    if (resources.Count > 0)
                    {
                        for (int i = 0; i < resources.Count; i++)
                            XmlResponse.WriteResponse(xmlWriter, davProperties, resources[i]);
                    }

                    xmlWriter.WriteEndElement(); // multistatus

                    xmlWriter.WriteEndDocument();
                    xmlWriter.Flush();

                    response.Connection = request.Connection;
                    response.ContentType = "text/xml";
                    response.Encoding = Encoding.UTF8;
                    response.AddHeader("DAV", "1");
                    response.AddHeader("MS-Author-Via", "DAV");
                    response.AddHeader("Cache-Control", "no-cache");
                    if (resources.Count > 0)
                    {
                        response.Status = (HttpStatusCode)207; // Multistatus

                        byte[] bytes = responseStream.ToArray();
                        response.ContentLength = bytes.Length;
                        //Console.WriteLine(Encoding.UTF8.GetString(bytes));
                        response.Body.Write(bytes, 0, bytes.Length);
                    }
                    else
                    {
                        //eventually this should be the same that is defined in HttpListener.Set404Handler()
                        //that however needs some work in HttpServer
                        response.Status = HttpStatusCode.NotFound;
                        response.Reason = "Not Found";
                        string notFoundResponse = "<html><head><title>Page Not Found</title></head><body><h3>" + response.Reason + "</h3></body></html>";
                        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundResponse);
                        response.Body.Write(buffer, 0, buffer.Length);
                        response.ContentLength = buffer.Length;
                    }

                    xmlWriter.Close();
                }

                Console.WriteLine("Sending PROPFIND response for request to " + request.UriPath);
            }
            else
            {
                Console.WriteLine("Could not find username from PROPFIND request " + request.UriPath);
            }
        }
Ejemplo n.º 4
0
        void PropPatchHandler(IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            //parse following information
            // uri string/uri from header
            // namespace string from body xml
            string nspace = String.Empty;
            // set dictioany<property, value> from body xml
            Dictionary<string, string> setProperties = new Dictionary<string, string>();
            // remove list<property> from body xml
            List<string> removeProperties = new List<string>();

            Dictionary<string, HttpStatusCode> multiStatus = new Dictionary<string, HttpStatusCode>();

            string username;
            if (server.AuthenticateRequest(request, response, out username))
            {
                if (request.ContentLength != 0)
                {
                    #region parse body
                    XPathNavigator requestNavigator = new XPathDocument(request.Body).CreateNavigator();
                    XPathNodeIterator propNodeIterator = requestNavigator.SelectDescendants("propertyupdate", "DAV:", false);
                    if (propNodeIterator.MoveNext())
                    {
                        XPathNodeIterator nodeChildren = propNodeIterator.Current.SelectChildren(XPathNodeType.All);
                        while (nodeChildren.MoveNext())
                        {
                            XPathNavigator currentNode = nodeChildren.Current;
                            if (currentNode.NodeType == XPathNodeType.Element && currentNode.LocalName.ToLower() == "set")
                            {
                                if (currentNode.MoveToFirstChild())
                                {
                                    if (currentNode.MoveToFirstChild())
                                    {
                                        nspace = currentNode.NamespaceURI;
                                        setProperties.Add(currentNode.LocalName, currentNode.Value);
                                        while (currentNode.MoveToNext())
                                        {
                                            setProperties.Add(currentNode.LocalName, currentNode.Value);
                                        }
                                        currentNode.MoveToParent();
                                    }
                                    currentNode.MoveToParent();
                                }
                            }

                            if (currentNode.NodeType == XPathNodeType.Element && currentNode.LocalName.ToLower() == "remove")
                            {
                                if (currentNode.MoveToFirstChild())
                                {
                                    if (currentNode.MoveToFirstChild())
                                    {
                                        nspace = currentNode.NamespaceURI;
                                        removeProperties.Add(currentNode.LocalName);
                                        while (currentNode.MoveToNext())
                                        {
                                            removeProperties.Add(currentNode.LocalName);
                                        }
                                        currentNode.MoveToParent();
                                    }
                                    currentNode.MoveToParent();
                                }
                            }
                        }
                    }
                    #endregion

                    HttpStatusCode status = server.OnPropPatchConnector(username, request.Uri, request.UriPath, nspace, setProperties, removeProperties, out multiStatus);
                    response.Status = status;
                    if (status == (HttpStatusCode)207 && multiStatus != null)
                    {
                        byte[] bytes = WriteMultiStatusResponseBody(request.Uri.ToString(), nspace, multiStatus);
                        response.ContentLength = bytes.Length;
                        //Console.WriteLine(Encoding.UTF8.GetString(bytes));
                        response.Body.Write(bytes, 0, bytes.Length);
                    }
                }
                else
                    response.Status = HttpStatusCode.BadRequest;
            }
            else
                response.Status = HttpStatusCode.Unauthorized;
        }
Ejemplo n.º 5
0
        WebDAVLockRequest ParseRequest(OSHttpRequest request)
        {
            WebDAVLockRequest lockRequest = new WebDAVLockRequest();
            lockRequest.Path = request.Url.AbsolutePath;
            lockRequest.RequestedTimeout = request.Headers.GetValues("timeout"); //can contain multiple values, for example: "Timeout: Infinite, Second-604800"
            lockRequest.IfHeaders = request.Headers.GetValues("If"); //might be a request to refresh lock

            if (request.ContentLength != 0)
            {
                XPathNavigator requestNavigator = new XPathDocument(request.InputStream).CreateNavigator();
                XPathNodeIterator propNodeIterator = requestNavigator.SelectDescendants("lockinfo", "DAV:", false);
                if (propNodeIterator.MoveNext())
                {
                    XPathNodeIterator nodeChildren = propNodeIterator.Current.SelectChildren(XPathNodeType.All);
                    while (nodeChildren.MoveNext())
                    {
                        XPathNavigator currentNode = nodeChildren.Current;

                        if (currentNode.LocalName == "lockscope")
                        {
                            if (currentNode.HasChildren)
                            {
                                if (currentNode.MoveToFirstChild())
                                {
                                    lockRequest.LockScope = (LockScope)Enum.Parse(typeof(LockScope), currentNode.LocalName.ToLower());
                                    currentNode.MoveToParent();
                                }
                            }
                        }
                        else if (currentNode.LocalName == "owner")
                        {
                            lockRequest.OwnerNamespaceUri = currentNode.NamespaceURI;
                            if (currentNode.Value != null && currentNode.Value != String.Empty)
                                lockRequest.OwnerValue = currentNode.Value;
                            if (currentNode.MoveToFirstChild())
                            {
                                lockRequest.OwnerValues.Add(currentNode.LocalName, currentNode.Value);
                                while (currentNode.MoveToNext())
                                {
                                    lockRequest.OwnerValues.Add(currentNode.LocalName, currentNode.Value);
                                }
                                currentNode.MoveToParent();
                            }
                        }
                        else if (currentNode.LocalName == "locktype")
                        {
                            if (currentNode.MoveToFirstChild())
                            {
                                lockRequest.LockType = (LockType)Enum.Parse(typeof(LockType), currentNode.LocalName.ToLower());
                                currentNode.MoveToParent();
                            }
                        }
                    }
                }
            }

            return lockRequest;
        }
Ejemplo n.º 6
0
        byte[] PropPatchHandler(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            //parse following information
            // uri string/uri from header
            // namespace string from body xml
            string nspace = String.Empty;
            // set dictioany<property, value> from body xml
            Dictionary<string, string> setProperties = new Dictionary<string, string>();
            // remove list<property> from body xml
            List<string> removeProperties = new List<string>();

            Dictionary<string, HttpStatusCode> multiStatus = new Dictionary<string, HttpStatusCode>();

            string username;
            if (server.AuthenticateRequest(httpRequest, httpResponse, out username))
            {
                if (httpRequest.ContentLength != 0)
                {
                    #region parse body
                    XPathNavigator requestNavigator = new XPathDocument(httpRequest.InputStream).CreateNavigator();
                    XPathNodeIterator propNodeIterator = requestNavigator.SelectDescendants("propertyupdate", "DAV:", false);
                    if (propNodeIterator.MoveNext())
                    {
                        XPathNodeIterator nodeChildren = propNodeIterator.Current.SelectChildren(XPathNodeType.All);
                        while (nodeChildren.MoveNext())
                        {
                            XPathNavigator currentNode = nodeChildren.Current;
                            if (currentNode.NodeType == XPathNodeType.Element && currentNode.LocalName.ToLower() == "set")
                            {
                                if (currentNode.MoveToFirstChild())
                                {
                                    if (currentNode.MoveToFirstChild())
                                    {
                                        nspace = currentNode.NamespaceURI;
                                        setProperties.Add(currentNode.LocalName, currentNode.Value);
                                        while (currentNode.MoveToNext())
                                        {
                                            setProperties.Add(currentNode.LocalName, currentNode.Value);
                                        }
                                        currentNode.MoveToParent();
                                    }
                                    currentNode.MoveToParent();
                                }
                            }

                            if (currentNode.NodeType == XPathNodeType.Element && currentNode.LocalName.ToLower() == "remove")
                            {
                                if (currentNode.MoveToFirstChild())
                                {
                                    if (currentNode.MoveToFirstChild())
                                    {
                                        nspace = currentNode.NamespaceURI;
                                        removeProperties.Add(currentNode.LocalName);
                                        while (currentNode.MoveToNext())
                                        {
                                            removeProperties.Add(currentNode.LocalName);
                                        }
                                        currentNode.MoveToParent();
                                    }
                                    currentNode.MoveToParent();
                                }
                            }
                        }
                    }
                    #endregion
                    string[] ifHeaders = httpRequest.Headers.GetValues("If"); 
                    HttpStatusCode status = server.OnPropPatchConnector(username, httpRequest.Url, httpRequest.Url.AbsolutePath, nspace, setProperties, removeProperties, out multiStatus, ifHeaders);
                    httpResponse.StatusCode = (int)status;
                    if (status == (HttpStatusCode)207 && multiStatus != null)
                    {
                        byte[] bytes = WriteMultiStatusResponseBody(httpRequest.Url.ToString(), nspace, multiStatus);
                        httpResponse.ContentLength = bytes.Length;
                        return bytes;
                    }
                }
                else
                    httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            else
                httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;

            return OpenMetaverse.Utils.EmptyBytes;
        }