Example #1
0
        /// <summary>
        /// Gets the Overwrite header : T or F
        /// </summary>
        /// <param name="request">The <see cref="IWebDavRequest"/> has the header included</param>
        /// <returns>The <see cref="bool"/> true if overwrite, false if no overwrite</returns>
        public static bool GetOverwriteHeader(IWebDavRequest request)
        {
            // get the value of the Overwrite header as a string
            string overwrite = request.Headers["Overwrite"];

            // check if the string is valid and if it equals T
            return(overwrite != null && overwrite.Equals("T"));
            // else, return false
        }
Example #2
0
        public static string GetLockTokenHeader(IWebDavRequest request)
        {
            if (!request.Headers.AllKeys.Contains("Lock-Token"))
            {
                return(string.Empty);
            }
            string token = request.Headers["Lock-Token"];

            return(token.Substring(1, token.Length - 2));
        }
Example #3
0
        /// <summary>
        /// Gets the Destination header as an URI
        /// </summary>
        /// <param name="request">The <see cref="IWebDavRequest"/> has the header included</param>
        /// <returns>The <see cref="Uri"/> containing the destination</returns>
        public static Uri GetDestinationHeader(IWebDavRequest request)
        {
            // get the value of the Destination header as a string
            string destinationUri = request.Headers["Destination"];

            // check if the string is valid
            if (!String.IsNullOrEmpty(destinationUri))
            {
                return(new Uri(destinationUri));
            }
            // else, throw exception
            throw new WebDavConflictException();
        }
Example #4
0
        /// <summary>
        /// Gets the Timeout header : Second-number
        /// </summary>
        /// <param name="request">The request with the request included</param>
        /// <returns>The value of the Timeout header as a string</returns>
        public static string GetTimeoutHeader(IWebDavRequest request)
        {
            // get the value of the timeout header as a string
            string timeout = request.Headers["Timeout"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (!String.IsNullOrEmpty(timeout) && !timeout.Equals("infinity") &&
                !timeout.Equals("Infinite, Second-4100000000"))
            {
                return(timeout);
            }
            // else, return the timeout value as if it was requested to be 4 days
            return("Second-345600");
        }
Example #5
0
        /// <summary>
        /// Reads the XML body of the
        /// <see cref="IWebDavRequest" />
        /// and converts it to an
        /// <see cref="XmlDocument" />
        /// </summary>
        /// <param name="request">The <see cref="IWebDavRequest" /></param>
        /// <returns>
        /// The <see cref="XmlDocument" /> that contains the request body
        /// </returns>
        private XmlDocument GetXmlDocument(IWebDavRequest request)
        {
            try
            {
                StreamReader reader      = new StreamReader(request.InputStream, Encoding.UTF8);
                string       requestBody = reader.ReadToEnd();
                reader.Close();

                if (!String.IsNullOrEmpty(requestBody))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(requestBody);
                    return(xmlDocument);
                }
            }
            catch (Exception)
            {
                WebDavServer.Log.Warn("XmlDocument has not been read correctly");
            }

            return(new XmlDocument());
        }
Example #6
0
        /// <summary>
        /// Gets the Depth header : 0, 1 or infinity
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerContext" /> with the response included</param>
        /// <returns>
        /// The values 0, 1 or -1 (for infinity)
        /// </returns>
        public static int GetDepthHeader(IWebDavRequest request)
        {
            // get the value of the depth header as a string
            string depth = request.Headers["Depth"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (String.IsNullOrEmpty(depth) || depth.Equals("infinity"))
            {
                return(DepthInfinity);
            }
            int value;

            if (!int.TryParse(depth, out value))
            {
                return(DepthInfinity);
            }
            if (value == 0 || value == 1)
            {
                return(value);
            }
            // else, return the infinity value
            return(DepthInfinity);
        }
Example #7
0
 public static string GetLockTokenIfHeader(IWebDavRequest request)
 {
     //(<urn:uuid:cfdc70da-7feb-4bfe-8cb7-18f97d8fecb1>)
     return(request.Headers.AllKeys.Contains("If") ? request.Headers["If"].Substring(2, request.Headers["If"].Length - 4) : string.Empty);
 }
        /// <summary>
        /// Gets the Destination header as an URI
        /// </summary>
        /// <param name="request">The <see cref="IWebDavRequest"/> has the header included</param>
        /// <returns>The <see cref="Uri"/> containing the destination</returns>
        public static Uri GetDestinationHeader(IWebDavRequest request)
        {
            // get the value of the Destination header as a string
            string destinationUri = request.Headers["Destination"];

            // check if the string is valid 
            if (!String.IsNullOrEmpty(destinationUri))
                return new Uri(destinationUri);
            // else, throw exception
            throw new WebDavConflictException();
        }
        /// <summary>
        /// Gets the Timeout header : Second-number
        /// </summary>
        /// <param name="request">The request with the request included</param>
        /// <returns>The value of the Timeout header as a string</returns>
        public static string GetTimeoutHeader(IWebDavRequest request)
        {
            // get the value of the timeout header as a string
            string timeout = request.Headers["Timeout"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (!String.IsNullOrEmpty(timeout) && !timeout.Equals("infinity") &&
                !timeout.Equals("Infinite, Second-4100000000"))
                return timeout;
            // else, return the timeout value as if it was requested to be 4 days
            return "Second-345600";
        }
 public static string GetLockTokenHeader(IWebDavRequest request)
 {
     if (!request.Headers.AllKeys.Contains("Lock-Token")) return string.Empty;
     string token = request.Headers["Lock-Token"];
     return (token.Substring(1, token.Length - 2));
 }
 public static string GetLockTokenIfHeader(IWebDavRequest request)
 {
     //(<urn:uuid:cfdc70da-7feb-4bfe-8cb7-18f97d8fecb1>)
     return request.Headers.AllKeys.Contains("If") ? request.Headers["If"].Substring(2, request.Headers["If"].Length-4) : string.Empty;
 }
        /// <summary>
        /// Gets the Overwrite header : T or F
        /// </summary>
        /// <param name="request">The <see cref="IWebDavRequest"/> has the header included</param>
        /// <returns>The <see cref="bool"/> true if overwrite, false if no overwrite</returns>
        public static bool GetOverwriteHeader(IWebDavRequest request)
        {
            // get the value of the Overwrite header as a string
            string overwrite = request.Headers["Overwrite"];

            // check if the string is valid and if it equals T
            return overwrite != null && overwrite.Equals("T");
            // else, return false
        }
        /// <summary>
        /// Gets the Depth header : 0, 1 or infinity
        /// </summary>
        /// <param name="request">The <see cref="IHttpListenerContext" /> with the response included</param>
        /// <returns>
        /// The values 0, 1 or -1 (for infinity)
        /// </returns>
        public static int GetDepthHeader(IWebDavRequest request)
        {
            // get the value of the depth header as a string
            string depth = request.Headers["Depth"];

            // check if the string is valid or not infinity
            // if so, try to parse it to an int
            if (String.IsNullOrEmpty(depth) || depth.Equals("infinity"))
                return DepthInfinity;
            int value;
            if (!int.TryParse(depth, out value))
                return DepthInfinity;
            if (value == 0 || value == 1)
                return value;
            // else, return the infinity value
            return DepthInfinity;
        }
        /// <summary>
        /// Reads the XML body of the 
        /// <see cref="IWebDavRequest" />
        /// and converts it to an 
        /// <see cref="XmlDocument" />
        /// </summary>
        /// <param name="request">The <see cref="IWebDavRequest" /></param>
        /// <returns>
        /// The <see cref="XmlDocument" /> that contains the request body
        /// </returns>
        private XmlDocument GetXmlDocument(IWebDavRequest request)
        {
            try
            {
                StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8);
                string requestBody = reader.ReadToEnd();
                reader.Close();

                if (!String.IsNullOrEmpty(requestBody))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(requestBody);
                    return xmlDocument;
                }
            }
            catch (Exception)
            {
                WebDavServer.Log.Warn("XmlDocument has not been read correctly");
            }

            return new XmlDocument();
        }