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); }
protected override void EncodeInitialElements(Uri requestUrl, ListContainersOperationContext loc, IListContainersResultCollection result, XmlWriter xmlWriter) { xmlWriter.WriteStartElement("EnumerationResults"); if (!VersioningHelper.IsPreAugust13OrInvalidVersion(loc.RequestVersion)) { string str = string.Concat(HttpRequestAccessorCommon.TrimEndSlash(requestUrl.GetLeftPart(UriPartial.Path)), "/"); xmlWriter.WriteAttributeString("ServiceEndpoint", str); } else { xmlWriter.WriteAttributeString("AccountName", requestUrl.GetLeftPart(UriPartial.Path)); } XmlListEncoderHelpers.WriteListOperationInfoToXml(xmlWriter, loc); xmlWriter.WriteStartElement(this.XmlContainersElementName); }
protected override void EncodeInitialElements(Uri requestUrl, ListBlobsOperationContext lboc, IListBlobsResultCollection result, XmlWriter xmlWriter) { xmlWriter.WriteStartElement("EnumerationResults"); if (!VersioningHelper.IsPreAugust13OrInvalidVersion(lboc.RequestVersion)) { string str = HttpRequestAccessorCommon.TrimEndSlash(requestUrl.GetLeftPart(UriPartial.Path)); int num = str.LastIndexOf("/"); xmlWriter.WriteAttributeString("ServiceEndpoint", str.Remove(num + 1)); xmlWriter.WriteAttributeString("ContainerName", str.Substring(num + 1)); } else { xmlWriter.WriteAttributeString("ContainerName", requestUrl.GetLeftPart(UriPartial.Path)); } XmlListEncoderHelpers.WriteListOperationInfoToXml(xmlWriter, lboc); xmlWriter.WriteStartElement("Blobs"); }
protected override void EncodeEntry(Uri requestUrl, ListBlobsOperationContext lboc, IListBlobResultsBlobProperties blobProps, XmlWriter xmlWriter) { string str; string httpString; string eTag; if (!blobProps.IsActualBlob) { xmlWriter.WriteStartElement("BlobPrefix"); this.WriteElementString(xmlWriter, "Name", blobProps.BlobName); } else { xmlWriter.WriteStartElement("Blob"); this.WriteElementString(xmlWriter, "Name", blobProps.BlobName); if (lboc.IsIncludingSnapshots && blobProps.Snapshot != DateTime.MaxValue) { this.WriteElementString(xmlWriter, "Snapshot", HttpUtilities.ConvertSnapshotDateTimeToHttpString(blobProps.Snapshot)); } if (lboc.ListingAcrossContainers) { NephosAssertionException.Assert(!string.IsNullOrEmpty(blobProps.ContainerName), string.Concat("XStore didn't return us valid ContainerName for this blob ", blobProps.BlobName, " when we are listing blobs across the account")); this.WriteElementString(xmlWriter, "ContainerName", blobProps.ContainerName); } if (lboc.IsIncludingUrlInResponse) { string empty = string.Empty; if (lboc.ListingAcrossContainers) { empty = string.Concat("/", blobProps.ContainerName); } string str1 = string.Concat(HttpRequestAccessorCommon.TrimEndSlash(requestUrl.GetLeftPart(UriPartial.Path)), empty); string str2 = HttpRequestAccessorCommon.TrimRootContainerNameFromEnd(str1, true); string str3 = string.Concat(str2, "/", blobProps.BlobName); if (lboc.IsIncludingSnapshots && blobProps.Snapshot != DateTime.MaxValue) { str3 = string.Concat(str3, HttpUtilities.GetSnapshotQueryParameterStringForUrl(blobProps.Snapshot)); } this.WriteElementString(xmlWriter, "Url", str3); } if (lboc.IsUsingPropertiesElement) { xmlWriter.WriteStartElement("Properties"); } string str4 = (lboc.IsUsingPropertiesElement ? "Last-Modified" : "LastModified"); string str5 = (lboc.IsUsingPropertiesElement ? "Content-Length" : "Size"); string str6 = (lboc.IsUsingPropertiesElement ? "Content-Type" : "ContentType"); string str7 = (lboc.IsUsingPropertiesElement ? "Content-Encoding" : "ContentEncoding"); string str8 = (lboc.IsUsingPropertiesElement ? "Content-Language" : "ContentLanguage"); string str9 = (lboc.IsUsingPropertiesElement ? "Cache-Control" : "CacheControl"); string str10 = (lboc.IsUsingPropertiesElement ? "Content-MD5" : "ContentMD5"); bool value = blobProps.LastModifiedTime.Value > DateTimeConstants.MinimumBlobLastModificationTime; if (value) { XmlWriter xmlWriter1 = xmlWriter; string str11 = str4; if (blobProps.LastModifiedTime.HasValue) { httpString = HttpUtilities.ConvertDateTimeToHttpString(blobProps.LastModifiedTime.Value); } else { httpString = null; } this.WriteElementString(xmlWriter1, str11, httpString); XmlWriter xmlWriter2 = xmlWriter; if (blobProps.LastModifiedTime.HasValue) { DateTime?lastModifiedTime = blobProps.LastModifiedTime; eTag = BasicHttpProcessor.GetETag(lastModifiedTime.Value, this.shouldEncloseEtagsInQuotes); } else { eTag = null; } this.WriteElementString(xmlWriter2, "Etag", eTag); } XmlWriter xmlWriter3 = xmlWriter; string str12 = str5; if (blobProps.ContentLength.HasValue) { str = blobProps.ContentLength.Value.ToString(CultureInfo.InvariantCulture); } else { str = null; } this.WriteElementString(xmlWriter3, str12, str); if (value) { this.WriteElementString(xmlWriter, str6, blobProps.ContentType); this.WriteElementString(xmlWriter, str7, blobProps.ContentEncoding); this.WriteElementString(xmlWriter, str8, blobProps.ContentLanguage); if (lboc.IsIncludingCrc64InResponse) { this.WriteElementString(xmlWriter, "Content-CRC64", blobProps.ContentCrc64); } if (lboc.IsUsingPropertiesElement) { this.WriteElementString(xmlWriter, str10, blobProps.ContentMD5); } if (lboc.IsIncludingCacheControlInResponse) { this.WriteElementString(xmlWriter, str9, blobProps.CacheControl); } if (lboc.IsIncludingContentDispositionInResponse) { this.WriteElementString(xmlWriter, "Content-Disposition", blobProps.ContentDisposition); } } if (lboc.IsIncludingBlobTypeInResponse) { if (blobProps.SequenceNumber.HasValue) { long num = blobProps.SequenceNumber.Value; this.WriteElementString(xmlWriter, "x-ms-blob-sequence-number", num.ToString()); } this.WriteElementString(xmlWriter, "BlobType", blobProps.BlobType); } if (lboc.IsIncludingLeaseStatusInResponse && blobProps.Snapshot == DateTime.MaxValue) { this.WriteElementString(xmlWriter, "LeaseStatus", blobProps.LeaseStatus); if (lboc.IsIncludingLeaseStateAndDurationInResponse) { if (!string.IsNullOrEmpty(blobProps.LeaseState)) { this.WriteElementString(xmlWriter, "LeaseState", blobProps.LeaseState); } if (!string.IsNullOrEmpty(blobProps.LeaseDuration)) { this.WriteElementString(xmlWriter, "LeaseDuration", blobProps.LeaseDuration); } } } if (lboc.IsIncludingCopyPropertiesInResponse) { if (!string.IsNullOrEmpty(blobProps.CopyId)) { this.WriteElementString(xmlWriter, "CopyId", blobProps.CopyId); } if (!string.IsNullOrEmpty(blobProps.CopySource)) { this.WriteElementString(xmlWriter, "CopySource", (this.obfuscateSourceUri ? HttpUtilities.ObfuscateSourceUri(blobProps.CopySource) : blobProps.CopySource)); } if (!string.IsNullOrEmpty(blobProps.CopyStatus)) { this.WriteElementString(xmlWriter, "CopyStatus", blobProps.CopyStatus); } if (!string.IsNullOrEmpty(blobProps.CopyStatusDescription)) { this.WriteElementString(xmlWriter, "CopyStatusDescription", blobProps.CopyStatusDescription); } if (!string.IsNullOrEmpty(blobProps.CopyProgress)) { this.WriteElementString(xmlWriter, "CopyProgress", blobProps.CopyProgress); } if (blobProps.CopyCompletionTime.HasValue && !string.IsNullOrEmpty(blobProps.CopyStatus) && !blobProps.CopyStatus.Equals("pending", StringComparison.OrdinalIgnoreCase)) { DateTime?copyCompletionTime = blobProps.CopyCompletionTime; this.WriteElementString(xmlWriter, "CopyCompletionTime", HttpUtilities.ConvertDateTimeToHttpString(copyCompletionTime.Value)); } } if (lboc.IsIncludingIncrementalCopy && blobProps.IsIncrementalCopy) { this.WriteElementString(xmlWriter, "IncrementalCopy", "true"); if (blobProps.LastCopySnapshot.HasValue && !string.IsNullOrEmpty(blobProps.CopyStatus) && blobProps.CopyStatus.Equals("success", StringComparison.OrdinalIgnoreCase)) { if (blobProps.LastCopySnapshot.Value <= DateTimeConstants.MinimumIncrementalCopySnapshotTime) { AlertsManager.AlertOrLogException("LastCopySnapshot set to Minimum value, while a valid timestamp was expected.", null, null); } DateTime?lastCopySnapshot = blobProps.LastCopySnapshot; this.WriteElementString(xmlWriter, "CopyDestinationSnapshot", HttpUtilities.ConvertSnapshotDateTimeToHttpString(lastCopySnapshot.Value)); } } if (lboc.IsIncludingEncryption) { this.WriteElementString(xmlWriter, "ServerEncrypted", (!blobProps.IsBlobEncrypted.HasValue || !blobProps.IsBlobEncrypted.Value ? "false" : "true")); } if (lboc.IsUsingPropertiesElement) { xmlWriter.WriteEndElement(); } if (value && lboc.IsFetchingMetadata) { MetadataEncoding.WriteMetadataToXml(xmlWriter, blobProps.Metadata, true, lboc.RequestVersion); } } xmlWriter.WriteEndElement(); }
public static void ParseSignatureParametersFromAuthorizationHeader(RequestContext requestContext, NephosUriComponents uriComponents, bool swallowException, out string accountName, out string signature, out SupportedAuthScheme?requestAuthScheme, out bool isAnonymousAccount) { string authorizationScheme; string authorizationSchemeParameters; accountName = null; signature = null; isAnonymousAccount = false; requestAuthScheme = null; try { try { authorizationScheme = requestContext.AuthorizationScheme; authorizationSchemeParameters = requestContext.AuthorizationSchemeParameters; } catch (HttpRequestHeaderNotFoundException httpRequestHeaderNotFoundException) { isAnonymousAccount = true; return; } catch (HttpRequestInvalidHeaderException httpRequestInvalidHeaderException1) { HttpRequestInvalidHeaderException httpRequestInvalidHeaderException = httpRequestInvalidHeaderException1; throw new InvalidAuthenticationInfoException(httpRequestInvalidHeaderException.Message, httpRequestInvalidHeaderException); } catch (HttpRequestDuplicateHeaderException httpRequestDuplicateHeaderException1) { HttpRequestDuplicateHeaderException httpRequestDuplicateHeaderException = httpRequestDuplicateHeaderException1; throw new InvalidAuthenticationInfoException(httpRequestDuplicateHeaderException.Message, httpRequestDuplicateHeaderException); } DateTime?nephosOrStandardDateHeader = null; try { nephosOrStandardDateHeader = HttpRequestAccessorCommon.GetNephosOrStandardDateHeader(requestContext.RequestHeaders); } catch (ArgumentException argumentException) { throw new AuthenticationFailureException("The Date header in the request is incorrect.", argumentException); } if (!nephosOrStandardDateHeader.HasValue) { throw new AuthenticationFailureException("Request date header not specified"); } if (nephosOrStandardDateHeader.Value.Ticks < DateTime.UtcNow.Subtract(ParameterLimits.DateHeaderLag).Ticks) { DateTime value = nephosOrStandardDateHeader.Value; throw new AuthenticationFailureException(string.Format("Request date header too old: '{0}'", HttpUtilities.ConvertDateTimeToHttpString(value.ToUniversalTime()))); } try { requestAuthScheme = new SupportedAuthScheme?((SupportedAuthScheme)Enum.Parse(typeof(SupportedAuthScheme), authorizationScheme, true)); } catch (ArgumentException argumentException1) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { authorizationScheme }; throw new AuthenticationFailureException(string.Format(invariantCulture, "Authentication scheme {0} is not supported", objArray)); } if (!requestAuthScheme.Equals(SupportedAuthScheme.SharedKey) && !requestAuthScheme.Equals(SupportedAuthScheme.SharedKeyLite) && !requestAuthScheme.Equals(SupportedAuthScheme.SignedKey)) { CultureInfo cultureInfo = CultureInfo.InvariantCulture; object[] objArray1 = new object[] { authorizationScheme }; throw new AuthenticationFailureException(string.Format(cultureInfo, "Authentication scheme {0} is not supported", objArray1)); } NephosAssertionException.Assert(requestAuthScheme.HasValue, "Authentication scheme in request has no value"); NephosAuthenticationManager.serviceSchemeParamsParserTable[requestContext.ServiceType][requestAuthScheme.Value](requestAuthScheme.Value, authorizationSchemeParameters, uriComponents, out accountName, out signature); } catch (Exception exception) { if (!swallowException) { throw; } } }
protected override void EncodeEntry(Uri requestUrl, ListContainersOperationContext loc, IListContainersResultContainerProperties collProps, XmlWriter xmlWriter) { string httpString; string eTag; xmlWriter.WriteStartElement(this.XmlContainerElementName); xmlWriter.WriteElementString("Name", collProps.ContainerName); if (loc.IsIncludingUrlInResponse) { string str = string.Concat(HttpRequestAccessorCommon.TrimEndSlash(requestUrl.GetLeftPart(UriPartial.Path)), "/", collProps.ContainerName); xmlWriter.WriteElementString("Url", str); } if (loc.IsUsingPropertiesElement) { xmlWriter.WriteStartElement("Properties"); } string str1 = (loc.IsUsingPropertiesElement ? "Last-Modified" : "LastModified"); XmlWriter xmlWriter1 = xmlWriter; string str2 = str1; if (collProps.LastModifiedTime.HasValue) { httpString = HttpUtilities.ConvertDateTimeToHttpString(collProps.LastModifiedTime.Value); } else { httpString = null; } xmlWriter1.WriteElementString(str2, httpString); XmlWriter xmlWriter2 = xmlWriter; if (collProps.LastModifiedTime.HasValue) { DateTime?lastModifiedTime = collProps.LastModifiedTime; eTag = BasicHttpProcessor.GetETag(lastModifiedTime.Value, this.shouldEncloseEtagsInQuotes); } else { eTag = null; } xmlWriter2.WriteElementString("Etag", eTag); if (loc.IsIncludingLeaseStateAndDurationInResponse) { if (!string.IsNullOrEmpty(collProps.LeaseStatus)) { xmlWriter.WriteElementString("LeaseStatus", collProps.LeaseStatus); } if (!string.IsNullOrEmpty(collProps.LeaseState)) { xmlWriter.WriteElementString("LeaseState", collProps.LeaseState); } if (!string.IsNullOrEmpty(collProps.LeaseDuration)) { xmlWriter.WriteElementString("LeaseDuration", collProps.LeaseDuration); } } if (loc.IsIncludingShareQuotaInResponse) { long containerQuotaInGB = collProps.ContainerQuotaInGB; xmlWriter.WriteElementString("Quota", containerQuotaInGB.ToString(CultureInfo.InvariantCulture)); } if (loc.IsIncludingPublicAccessInResponse && !string.IsNullOrEmpty(collProps.PublicAccessLevel)) { if (Comparison.StringEqualsIgnoreCase(collProps.PublicAccessLevel, "container") || Comparison.StringEqualsIgnoreCase(collProps.PublicAccessLevel, bool.TrueString)) { xmlWriter.WriteElementString("PublicAccess", "container"); } else if (Comparison.StringEqualsIgnoreCase(collProps.PublicAccessLevel, "blob")) { xmlWriter.WriteElementString("PublicAccess", "blob"); } } if (loc.IsUsingPropertiesElement) { xmlWriter.WriteEndElement(); } if (loc.IsFetchingMetadata) { MetadataEncoding.WriteMetadataToXml(xmlWriter, collProps.Metadata, true, loc.RequestVersion); } xmlWriter.WriteEndElement(); }