Esempio n. 1
0
        private static ConditionInformation ExecuteExtractors(ConditionalHeaders condHeaders, NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion, ConditionExtractor[] extractors)
        {
            ConditionInformation conditionInformation;
            ConditionInformation conditionInformation1 = null;

            ConditionExtractor[] conditionExtractorArray = extractors;
            int num = 0;

Label1:
            while (num < (int)conditionExtractorArray.Length)
            {
                ConditionExtractor conditionExtractor = conditionExtractorArray[num];
                try
                {
                    if (!conditionExtractor.ProcessConditionalHeader(condHeaders, requestHeaders, operationType, requestVersion, out conditionInformation1))
                    {
                        goto Label0;
                    }
                    else
                    {
                        conditionInformation = conditionInformation1;
                    }
                }
                catch (InvalidHeaderProtocolException invalidHeaderProtocolException)
                {
                    conditionInformation = null;
                }
                return(conditionInformation);
            }
            return(null);

Label0:
            num++;
            goto Label1;
        }
Esempio n. 2
0
        public static ConditionInformation GetConditionInfoFromRequest(NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion)
        {
            ConditionalHeaders conditionalHeadersFromRequest = ConditionExtractor.GetConditionalHeadersFromRequest(requestHeaders);

            if (conditionalHeadersFromRequest == null)
            {
                return(null);
            }
            if (operationType == OperationTypeForConditionParsing.ReadOperation || operationType == OperationTypeForConditionParsing.WriteOperation)
            {
                return(ConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, ConditionExtractor.extractors));
            }
            NephosAssertionException.Assert(operationType == OperationTypeForConditionParsing.CopyOperation);
            ConditionInformation copySourceIfModifiedSince = ConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, ConditionExtractor.extractors);
            ConditionInformation conditionInformation      = ConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, ConditionExtractor.copySourceExtractors);

            if (copySourceIfModifiedSince == null)
            {
                return(conditionInformation);
            }
            if (conditionInformation != null)
            {
                copySourceIfModifiedSince.CopySourceIfModifiedSince    = conditionInformation.CopySourceIfModifiedSince;
                copySourceIfModifiedSince.CopySourceIfNotModifiedSince = conditionInformation.CopySourceIfNotModifiedSince;
                copySourceIfModifiedSince.CopySourceIfMatch            = conditionInformation.CopySourceIfMatch;
                copySourceIfModifiedSince.CopySourceIfNoneMatch        = conditionInformation.CopySourceIfNoneMatch;
                NephosAssertionException.Assert(copySourceIfModifiedSince.ConditionFailStatusCode == conditionInformation.ConditionFailStatusCode);
            }
            return(copySourceIfModifiedSince);
        }
Esempio n. 3
0
 static ConditionExtractor()
 {
     ConditionExtractor[] ifModifiedConditionExtractor = new ConditionExtractor[] { new IfModifiedConditionExtractor(), new IfUnmodifiedConditionExtractor(), new IfMatchConditionExtractor(), new IfNoneMatchConditionExtractor(), new IfRangeConditionExtractor() };
     ConditionExtractor.extractors = ifModifiedConditionExtractor;
     ConditionExtractor[] copySourceIfModifiedConditionExtractor = new ConditionExtractor[] { new CopySourceIfModifiedConditionExtractor(), new CopySourceIfUnmodifiedConditionExtractor(), new CopySourceIfMatchConditionExtractor(), new CopySourceIfNoneMatchConditionExtractor() };
     ConditionExtractor.copySourceExtractors = copySourceIfModifiedConditionExtractor;
 }
Esempio n. 4
0
        public static ConditionInformation GetConditionInfoFromIncrementalCopyRequest(NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion)
        {
            ConditionalHeaders conditionalHeadersFromRequest = ConditionExtractor.GetConditionalHeadersFromRequest(requestHeaders);

            if (conditionalHeadersFromRequest == null)
            {
                return(null);
            }
            return(ConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, ConditionExtractor.extractors));
        }
Esempio n. 5
0
        protected override bool ProcessConditionalHeader(ConditionalHeaders condHeaders, NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion, out ConditionInformation outputCondition)
        {
            DateTime?nullable;

            if (!ConditionExtractor.ShouldThisVersionFailMultipleConditions(requestVersion))
            {
                if (!string.IsNullOrEmpty(condHeaders.IfRange))
                {
                    outputCondition = null;
                    return(false);
                }
                if (string.IsNullOrEmpty(condHeaders.IfUnmodifiedSince) || !string.IsNullOrEmpty(condHeaders.IfMatch))
                {
                    outputCondition = null;
                    return(false);
                }
                if (!string.IsNullOrEmpty(condHeaders.IfModifiedSince) || !string.IsNullOrEmpty(condHeaders.IfNoneMatch))
                {
                    outputCondition = null;
                    return(false);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(condHeaders.IfUnmodifiedSince))
                {
                    outputCondition = null;
                    return(false);
                }
                if (!string.IsNullOrEmpty(condHeaders.IfMatch))
                {
                    outputCondition = null;
                    return(false);
                }
                if (!string.IsNullOrEmpty(condHeaders.IfModifiedSince) || !string.IsNullOrEmpty(condHeaders.IfNoneMatch))
                {
                    throw new MultipleConditionHeaderProtocolException();
                }
            }
            ConditionInformation conditionInformation = new ConditionInformation()
            {
                ConditionFailStatusCode = HttpStatusCode.PreconditionFailed
            };

            if (!HttpUtilities.TryGetDateTimeFromHttpString(condHeaders.IfUnmodifiedSince, out nullable))
            {
                throw new InvalidHeaderProtocolException("If-Unmodified-Since", condHeaders.IfUnmodifiedSince);
            }
            conditionInformation.IfNotModifiedSince      = new DateTime?((nullable.Value < DateTime.MaxValue.AddSeconds(-1) ? nullable.Value.AddSeconds(1) : nullable.Value));
            conditionInformation.ResourceExistsCondition = new ResourceExistenceCondition?(ResourceExistenceCondition.MayExist);
            outputCondition = conditionInformation;
            return(true);
        }
Esempio n. 6
0
 public bool ProcessConditionalHeader(ConditionalHeaders condHeaders, NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion, ConditionInformation outputCondition)
 {
     if (ConditionExtractor.ShouldThisVersionFailMultipleConditions(requestVersion))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(condHeaders.IfRange))
     {
         return(false);
     }
     HttpRequestAccessorCommon.RemoveRangeHeaderValues(requestHeaders);
     return(true);
 }
Esempio n. 7
0
        public static ConditionInformation GetConditionInfoFromRequest(NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion)
        {
            ConditionalHeaders conditionalHeadersFromRequest = ConditionExtractor.GetConditionalHeadersFromRequest(requestHeaders);

            if (conditionalHeadersFromRequest == null)
            {
                return(null);
            }
            IStringDataEventStream info = Logger <IRestProtocolHeadLogger> .Instance.Info;

            object[] ifModifiedSince = new object[] { conditionalHeadersFromRequest.IfModifiedSince ?? "<null>", conditionalHeadersFromRequest.IfUnmodifiedSince ?? "<null>", conditionalHeadersFromRequest.IfMatch ?? "<null>", conditionalHeadersFromRequest.IfNoneMatch ?? "<null>", conditionalHeadersFromRequest.IfRange ?? "<null>", conditionalHeadersFromRequest.CopySourceIfModifiedSince ?? "<null>", conditionalHeadersFromRequest.CopySourceIfUnmodifiedSince ?? "<null>", conditionalHeadersFromRequest.CopySourceIfMatch ?? "<null>", conditionalHeadersFromRequest.CopySourceIfNoneMatch ?? "<null>" };
            info.Log("Conditional Headers:[IfModifiedSince = {0}, IfUnmodifiedSince = {1}, IfMatch = {2}, IfNoneMatch = {3}, IfRange = {4}, CopySourceIfModifiedSince = {5}, CopySourceIfUnmodifiedSince = {6}, CopySourceIfMatch = {7}, CopySourceIfNoneMatch = {8}]", ifModifiedSince);
            return(MultipleConditionExtractor.ExecuteExtractors(conditionalHeadersFromRequest, requestHeaders, operationType, requestVersion, MultipleConditionExtractor.Extractors));
        }
Esempio n. 8
0
 public static bool IsRequestConditional(NameValueCollection requestHeaders)
 {
     return(ConditionExtractor.GetConditionalHeadersFromRequest(requestHeaders) != null);
 }
Esempio n. 9
0
        protected override bool ProcessConditionalHeader(ConditionalHeaders condHeaders, NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion, out ConditionInformation outputCondition)
        {
            DateTime lastModifiedTimeFromETag;
            DateTime?nullable = null;

            if (!ConditionExtractor.ShouldThisVersionFailMultipleConditions(requestVersion))
            {
                if (!string.IsNullOrEmpty(condHeaders.IfRange))
                {
                    outputCondition = null;
                    return(false);
                }
                if (string.IsNullOrEmpty(condHeaders.CopySourceIfMatch))
                {
                    outputCondition = null;
                    return(false);
                }
                if (!string.IsNullOrEmpty(condHeaders.CopySourceIfNoneMatch) || !string.IsNullOrEmpty(condHeaders.CopySourceIfModifiedSince))
                {
                    outputCondition = null;
                    return(false);
                }
                if (Comparison.StringContains(condHeaders.CopySourceIfMatch, ","))
                {
                    throw new InvalidHeaderProtocolException("x-ms-source-if-match", condHeaders.CopySourceIfMatch);
                }
                if (!string.IsNullOrEmpty(condHeaders.CopySourceIfUnmodifiedSince) && !HttpUtilities.TryGetDateTimeFromHttpString(condHeaders.CopySourceIfUnmodifiedSince, out nullable))
                {
                    throw new InvalidHeaderProtocolException("x-ms-source-if-unmodified-since", condHeaders.CopySourceIfUnmodifiedSince);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(condHeaders.CopySourceIfMatch))
                {
                    outputCondition = null;
                    return(false);
                }
                if (!string.IsNullOrEmpty(condHeaders.CopySourceIfModifiedSince) || !string.IsNullOrEmpty(condHeaders.CopySourceIfNoneMatch))
                {
                    throw new MultipleConditionHeaderProtocolException();
                }
                if (Comparison.StringContains(condHeaders.CopySourceIfMatch, ","))
                {
                    throw new MultipleConditionHeaderProtocolException();
                }
            }
            ConditionInformation conditionInformation = new ConditionInformation()
            {
                ConditionFailStatusCode = HttpStatusCode.PreconditionFailed
            };

            if (Comparison.StringEqualsIgnoreCase(condHeaders.CopySourceIfMatch, "*"))
            {
                outputCondition = null;
                return(false);
            }
            try
            {
                lastModifiedTimeFromETag = BasicHttpProcessor.GetLastModifiedTimeFromETag(condHeaders.CopySourceIfMatch);
            }
            catch (InvalidHeaderProtocolException invalidHeaderProtocolException1)
            {
                InvalidHeaderProtocolException invalidHeaderProtocolException = invalidHeaderProtocolException1;
                if (!VersioningHelper.IsPreSeptember09OrInvalidVersion(requestVersion))
                {
                    throw new UnrecognizedIfMatchConditionException(new bool?(true), invalidHeaderProtocolException);
                }
                throw;
            }
            if (!VersioningHelper.IsPreSeptember09OrInvalidVersion(requestVersion))
            {
                conditionInformation.CopySourceIfMatch = new DateTime?(lastModifiedTimeFromETag);
            }
            else
            {
                conditionInformation.CopySourceIfNotModifiedSince = new DateTime?(lastModifiedTimeFromETag);
            }
            if (nullable.HasValue && !HttpUtilities.DateTimesEqualsUpToSeconds(nullable.Value, lastModifiedTimeFromETag))
            {
                outputCondition = null;
                return(false);
            }
            outputCondition = conditionInformation;
            return(true);
        }
Esempio n. 10
0
        protected override bool ProcessConditionalHeader(ConditionalHeaders condHeaders, NameValueCollection requestHeaders, OperationTypeForConditionParsing operationType, string requestVersion, out ConditionInformation outputCondition)
        {
            DateTime lastModifiedTimeFromETag;
            bool?    nullable;
            DateTime?nullable1 = null;

            if (!ConditionExtractor.ShouldThisVersionFailMultipleConditions(requestVersion))
            {
                if (!string.IsNullOrEmpty(condHeaders.IfRange))
                {
                    outputCondition = null;
                    return(false);
                }
                if (string.IsNullOrEmpty(condHeaders.IfMatch))
                {
                    outputCondition = null;
                    return(false);
                }
                if (!string.IsNullOrEmpty(condHeaders.IfNoneMatch) || !string.IsNullOrEmpty(condHeaders.IfModifiedSince))
                {
                    outputCondition = null;
                    return(false);
                }
                if (Comparison.StringContains(condHeaders.IfMatch, ","))
                {
                    throw new InvalidHeaderProtocolException("If-Match", condHeaders.IfMatch);
                }
                if (!string.IsNullOrEmpty(condHeaders.IfUnmodifiedSince) && !HttpUtilities.TryGetDateTimeFromHttpString(condHeaders.IfUnmodifiedSince, out nullable1))
                {
                    throw new InvalidHeaderProtocolException("If-Unmodified-Since", condHeaders.IfUnmodifiedSince);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(condHeaders.IfMatch))
                {
                    outputCondition = null;
                    return(false);
                }
                if (!string.IsNullOrEmpty(condHeaders.IfModifiedSince) || !string.IsNullOrEmpty(condHeaders.IfNoneMatch))
                {
                    throw new MultipleConditionHeaderProtocolException();
                }
                if (Comparison.StringContains(condHeaders.IfMatch, ","))
                {
                    throw new MultipleConditionHeaderProtocolException();
                }
            }
            ConditionInformation conditionInformation = new ConditionInformation()
            {
                ConditionFailStatusCode = HttpStatusCode.PreconditionFailed,
                ResourceExistsCondition = new ResourceExistenceCondition?(ResourceExistenceCondition.MustExist)
            };

            if (!Comparison.StringEqualsIgnoreCase(condHeaders.IfMatch, "*"))
            {
                try
                {
                    lastModifiedTimeFromETag = BasicHttpProcessor.GetLastModifiedTimeFromETag(condHeaders.IfMatch);
                }
                catch (InvalidHeaderProtocolException invalidHeaderProtocolException1)
                {
                    InvalidHeaderProtocolException invalidHeaderProtocolException = invalidHeaderProtocolException1;
                    if (!VersioningHelper.IsPreSeptember09OrInvalidVersion(requestVersion))
                    {
                        if (operationType == OperationTypeForConditionParsing.CopyOperation)
                        {
                            nullable = new bool?(false);
                        }
                        else
                        {
                            nullable = null;
                        }
                        throw new UnrecognizedIfMatchConditionException(nullable, invalidHeaderProtocolException);
                    }
                    throw;
                }
                if (!VersioningHelper.IsPreSeptember09OrInvalidVersion(requestVersion))
                {
                    conditionInformation.IfMatch = new DateTime[] { lastModifiedTimeFromETag };
                }
                else
                {
                    conditionInformation.IfNotModifiedSince      = new DateTime?(lastModifiedTimeFromETag);
                    conditionInformation.ResourceExistsCondition = new ResourceExistenceCondition?(ResourceExistenceCondition.MayExist);
                }
                if (nullable1.HasValue && !HttpUtilities.DateTimesEqualsUpToSeconds(nullable1.Value, lastModifiedTimeFromETag))
                {
                    outputCondition = null;
                    return(false);
                }
            }
            else
            {
                if (operationType == OperationTypeForConditionParsing.ReadOperation)
                {
                    outputCondition = null;
                    return(false);
                }
                if (nullable1.HasValue)
                {
                    conditionInformation.IfNotModifiedSince = new DateTime?((nullable1.Value < DateTime.MaxValue.AddSeconds(-1) ? nullable1.Value.AddSeconds(1) : nullable1.Value));
                }
            }
            outputCondition = conditionInformation;
            return(true);
        }