internal static IEnumerable <IfHeaderCondition> Parse(StringSource source, EntityTagComparer entityTagComparer)
        {
            while (!source.SkipWhiteSpace())
            {
                var       isNot = false;
                EntityTag?etag  = null;
                if (source.AdvanceIf("Not", StringComparison.OrdinalIgnoreCase))
                {
                    isNot = true;
                    source.SkipWhiteSpace();
                }

                Uri stateToken;
                if (CodedUrlParser.TryParse(source, out stateToken))
                {
                    // Coded-URL found
                }
                else if (source.Get() == '[')
                {
                    // Entity-tag found
                    etag = EntityTag.Parse(source).Single();
                    if (!source.AdvanceIf("]"))
                    {
                        throw new ArgumentException($"{source.Remaining} is not a valid condition (ETag not ending with ']')", nameof(source));
                    }
                }
                else
                {
                    source.Back();
                    break;
                }

                yield return(new IfHeaderCondition(isNot, stateToken, etag, entityTagComparer));
            }
        }
 private IfHeaderCondition(bool not, Uri stateToken, EntityTag?etag, EntityTagComparer etagComparer)
 {
     _etagComparer = etagComparer;
     Not           = not;
     StateToken    = stateToken;
     ETag          = etag;
 }
Example #3
0
        /// <summary>
        /// Parses the header string to get a new instance of the <see cref="IfMatchHeader"/> class
        /// </summary>
        /// <param name="s">The header string to parse</param>
        /// <param name="etagComparer">The entity tag comparer used for the <see cref="IsMatch"/> function</param>
        /// <returns>The new instance of the <see cref="IfMatchHeader"/> class</returns>
        public static IfMatchHeader Parse(string s, EntityTagComparer etagComparer)
        {
            if (string.IsNullOrWhiteSpace(s) || s == "*")
            {
                return(new IfMatchHeader());
            }

            return(new IfMatchHeader(EntityTag.Parse(s), etagComparer));
        }
Example #4
0
        /// <summary>
        /// Parses the text into a <see cref="IfHeader"/>
        /// </summary>
        /// <param name="s">The text to parse</param>
        /// <param name="etagComparer">The comparer to use for entity tag comparison</param>
        /// <param name="context">The WebDAV request context</param>
        /// <returns>The new <see cref="IfHeader"/></returns>
        public static IfHeader Parse(string s, EntityTagComparer etagComparer, IWebDavContext context)
        {
            var source = new StringSource(s);
            var lists  = IfHeaderList.Parse(source, etagComparer, context).ToList();

            if (!source.Empty)
            {
                throw new ArgumentException("Not an accepted list of conditions", nameof(s));
            }
            return(new IfHeader(lists));
        }
Example #5
0
        /// <summary>
        /// Parses the header string to get a new instance of the <see cref="IfMatchHeader"/> class
        /// </summary>
        /// <param name="s">The header values to parse</param>
        /// <param name="etagComparer">The entity tag comparer used for the <see cref="IsMatch"/> function</param>
        /// <returns>The new instance of the <see cref="IfMatchHeader"/> class</returns>
        public static IfMatchHeader Parse(IEnumerable <string> s, EntityTagComparer etagComparer)
        {
            var result = new List <EntityTag>();

            foreach (var etag in s)
            {
                if (etag == "*")
                {
                    return(new IfMatchHeader());
                }

                result.AddRange(EntityTag.Parse(etag));
            }

            if (result.Count == 0)
            {
                return(new IfMatchHeader());
            }

            return(new IfMatchHeader(result, etagComparer));
        }
        internal static IEnumerable <IfHeaderList> Parse(StringSource source, EntityTagComparer etagComparer, IWebDavContext context)
        {
            Uri previousResourceTag = context.PublicAbsoluteRequestUrl;

            while (!source.SkipWhiteSpace())
            {
                if (CodedUrlParser.TryParse(source, out var resourceTag))
                {
                    // Coded-URL found
                    if (!resourceTag.IsAbsoluteUri)
                    {
                        resourceTag = new Uri(context.PublicRootUrl, resourceTag);
                    }
                    previousResourceTag = resourceTag;
                    source.SkipWhiteSpace();
                }
                else
                {
                    resourceTag = previousResourceTag;
                }

                if (!source.AdvanceIf("("))
                {
                    throw new ArgumentException($"{source.Remaining} is not a valid list (not starting with a '(')", nameof(source));
                }
                var conditions = IfHeaderCondition.Parse(source, etagComparer).ToList();
                if (!source.AdvanceIf(")"))
                {
                    throw new ArgumentException($"{source.Remaining} is not a valid list (not ending with a ')')", nameof(source));
                }

                var relativeHref = context.PublicControllerUrl.IsBaseOf(resourceTag) ? AddRootSlashToUri(context.PublicControllerUrl.MakeRelativeUri(resourceTag)) : resourceTag;
                var path         = context.PublicControllerUrl.IsBaseOf(resourceTag) ? context.PublicControllerUrl.MakeRelativeUri(resourceTag) : resourceTag;
                yield return(new IfHeaderList(resourceTag, relativeHref, path, conditions));
            }
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IfMatchHeader"/> class.
 /// </summary>
 /// <param name="etags">The entity tags to match</param>
 /// <param name="etagComparer">The entity comparer to use</param>
 public IfMatchHeader(IEnumerable <EntityTag> etags, EntityTagComparer etagComparer)
 {
     _etags = new HashSet <EntityTag>(etags, etagComparer);
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IfNoneMatchHeader"/> class.
 /// </summary>
 /// <param name="etags">The entity tags to match</param>
 /// <param name="etagComparer">The entity comparer to use</param>
 private IfNoneMatchHeader(IEnumerable <EntityTag> etags, EntityTagComparer etagComparer)
 {
     _etags = new HashSet <EntityTag>(etags, etagComparer);
 }