| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Xml; |
| | | 5 | | using CoreWCF.Runtime; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | internal static class EncoderHelpers |
| | | 10 | | { |
| | | 11 | | internal static XmlDictionaryReaderQuotas GetBufferedReadQuotas(XmlDictionaryReaderQuotas encoderQuotas) |
| | | 12 | | { |
| | 1189 | 13 | | XmlDictionaryReaderQuotas bufferedReadQuotas = new XmlDictionaryReaderQuotas(); |
| | 1189 | 14 | | encoderQuotas.CopyTo(bufferedReadQuotas); |
| | | 15 | | |
| | | 16 | | // now we have the quotas from the encoder, we need to update the values with the new quotas from the defaul |
| | 1189 | 17 | | if (IsDefaultQuota(bufferedReadQuotas, XmlDictionaryReaderQuotaTypes.MaxStringContentLength)) |
| | | 18 | | { |
| | 1004 | 19 | | bufferedReadQuotas.MaxStringContentLength = EncoderDefaults.BufferedReadDefaultMaxStringContentLength; |
| | | 20 | | } |
| | | 21 | | |
| | 1189 | 22 | | if (IsDefaultQuota(bufferedReadQuotas, XmlDictionaryReaderQuotaTypes.MaxArrayLength)) |
| | | 23 | | { |
| | 1005 | 24 | | bufferedReadQuotas.MaxArrayLength = EncoderDefaults.BufferedReadDefaultMaxArrayLength; |
| | | 25 | | } |
| | | 26 | | |
| | 1189 | 27 | | if (IsDefaultQuota(bufferedReadQuotas, XmlDictionaryReaderQuotaTypes.MaxBytesPerRead)) |
| | | 28 | | { |
| | 1005 | 29 | | bufferedReadQuotas.MaxBytesPerRead = EncoderDefaults.BufferedReadDefaultMaxBytesPerRead; |
| | | 30 | | } |
| | | 31 | | |
| | 1189 | 32 | | if (IsDefaultQuota(bufferedReadQuotas, XmlDictionaryReaderQuotaTypes.MaxNameTableCharCount)) |
| | | 33 | | { |
| | 1005 | 34 | | bufferedReadQuotas.MaxNameTableCharCount = EncoderDefaults.BufferedReadDefaultMaxNameTableCharCount; |
| | | 35 | | } |
| | | 36 | | |
| | 1189 | 37 | | if (IsDefaultQuota(bufferedReadQuotas, XmlDictionaryReaderQuotaTypes.MaxDepth)) |
| | | 38 | | { |
| | 1005 | 39 | | bufferedReadQuotas.MaxDepth = EncoderDefaults.BufferedReadDefaultMaxDepth; |
| | | 40 | | } |
| | | 41 | | |
| | 1189 | 42 | | return bufferedReadQuotas; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | private static bool IsDefaultQuota(XmlDictionaryReaderQuotas quotas, XmlDictionaryReaderQuotaTypes quotaType) |
| | | 46 | | { |
| | | 47 | | switch (quotaType) |
| | | 48 | | { |
| | | 49 | | case XmlDictionaryReaderQuotaTypes.MaxDepth: |
| | | 50 | | case XmlDictionaryReaderQuotaTypes.MaxStringContentLength: |
| | | 51 | | case XmlDictionaryReaderQuotaTypes.MaxArrayLength: |
| | | 52 | | case XmlDictionaryReaderQuotaTypes.MaxBytesPerRead: |
| | | 53 | | case XmlDictionaryReaderQuotaTypes.MaxNameTableCharCount: |
| | 5945 | 54 | | return (quotas.ModifiedQuotas & quotaType) == 0x00; |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | Fx.Assert("invalid quota type."); |
| | 0 | 58 | | return false; |
| | | 59 | | } |
| | | 60 | | } |
| | | 61 | | } |