| | | 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.Configuration; |
| | | 5 | | using System.Xml; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | public class XmlDictionaryReaderQuotasElement : ServiceModelConfigurationElement |
| | | 11 | | { |
| | | 12 | | // for all properties, a value of 0 means "just use the default" |
| | | 13 | | [ConfigurationProperty(ConfigurationStrings.MaxDepth, DefaultValue = 0)] |
| | | 14 | | [IntegerValidator(MinValue = 0)] |
| | | 15 | | public int MaxDepth |
| | | 16 | | { |
| | 42 | 17 | | get { return (int)base[ConfigurationStrings.MaxDepth]; } |
| | 0 | 18 | | set { base[ConfigurationStrings.MaxDepth] = value; } |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | [ConfigurationProperty(ConfigurationStrings.MaxStringContentLength, DefaultValue = 0)] |
| | | 22 | | [IntegerValidator(MinValue = 0)] |
| | | 23 | | public int MaxStringContentLength |
| | | 24 | | { |
| | 27 | 25 | | get { return (int)base[ConfigurationStrings.MaxStringContentLength]; } |
| | 0 | 26 | | set { base[ConfigurationStrings.MaxStringContentLength] = value; } |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | [ConfigurationProperty(ConfigurationStrings.MaxArrayLength, DefaultValue = 0)] |
| | | 30 | | [IntegerValidator(MinValue = 0)] |
| | | 31 | | public int MaxArrayLength |
| | | 32 | | { |
| | 27 | 33 | | get { return (int)base[ConfigurationStrings.MaxArrayLength]; } |
| | 0 | 34 | | set { base[ConfigurationStrings.MaxArrayLength] = value; } |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | [ConfigurationProperty(ConfigurationStrings.MaxBytesPerRead, DefaultValue = 0)] |
| | | 38 | | [IntegerValidator(MinValue = 0)] |
| | | 39 | | public int MaxBytesPerRead |
| | | 40 | | { |
| | 27 | 41 | | get { return (int)base[ConfigurationStrings.MaxBytesPerRead]; } |
| | 0 | 42 | | set { base[ConfigurationStrings.MaxBytesPerRead] = value; } |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | [ConfigurationProperty(ConfigurationStrings.MaxNameTableCharCount, DefaultValue = 0)] |
| | | 46 | | [IntegerValidator(MinValue = 0)] |
| | | 47 | | public int MaxNameTableCharCount |
| | | 48 | | { |
| | 27 | 49 | | get { return (int)base[ConfigurationStrings.MaxNameTableCharCount]; } |
| | 0 | 50 | | set { base[ConfigurationStrings.MaxNameTableCharCount] = value; } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | internal void ApplyConfiguration(XmlDictionaryReaderQuotas readerQuotas) |
| | | 54 | | { |
| | 27 | 55 | | if (readerQuotas == null) |
| | | 56 | | { |
| | 0 | 57 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(readerQuotas)); |
| | | 58 | | } |
| | 27 | 59 | | if (MaxDepth != 0) |
| | | 60 | | { |
| | 10 | 61 | | readerQuotas.MaxDepth = MaxDepth; |
| | | 62 | | } |
| | 27 | 63 | | if (MaxStringContentLength != 0) |
| | | 64 | | { |
| | 0 | 65 | | readerQuotas.MaxStringContentLength = MaxStringContentLength; |
| | | 66 | | } |
| | 27 | 67 | | if (MaxArrayLength != 0) |
| | | 68 | | { |
| | 0 | 69 | | readerQuotas.MaxArrayLength = MaxArrayLength; |
| | | 70 | | } |
| | 27 | 71 | | if (MaxBytesPerRead != 0) |
| | | 72 | | { |
| | 0 | 73 | | readerQuotas.MaxBytesPerRead = MaxBytesPerRead; |
| | | 74 | | } |
| | 27 | 75 | | if (MaxNameTableCharCount != 0) |
| | | 76 | | { |
| | 0 | 77 | | readerQuotas.MaxNameTableCharCount = MaxNameTableCharCount; |
| | | 78 | | } |
| | 27 | 79 | | } |
| | | 80 | | |
| | | 81 | | internal XmlDictionaryReaderQuotas Clone() |
| | | 82 | | { |
| | 19 | 83 | | var readerQuotas = new XmlDictionaryReaderQuotas(); |
| | 19 | 84 | | ApplyConfiguration(readerQuotas); |
| | 19 | 85 | | return readerQuotas; |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | internal void InitializeFrom(XmlDictionaryReaderQuotas readerQuotas) |
| | | 89 | | { |
| | 0 | 90 | | if (readerQuotas == null) |
| | | 91 | | { |
| | 0 | 92 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(readerQuotas)); |
| | | 93 | | } |
| | 0 | 94 | | if (readerQuotas.MaxDepth != EncoderDefaults.MaxDepth) |
| | | 95 | | { |
| | 0 | 96 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxDepth, readerQuotas.MaxDepth); |
| | | 97 | | } |
| | 0 | 98 | | if (readerQuotas.MaxStringContentLength != EncoderDefaults.MaxStringContentLength) |
| | | 99 | | { |
| | 0 | 100 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxStringContentLength, readerQuotas.MaxStringCon |
| | | 101 | | } |
| | 0 | 102 | | if (readerQuotas.MaxArrayLength != EncoderDefaults.MaxArrayLength) |
| | | 103 | | { |
| | 0 | 104 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxArrayLength, readerQuotas.MaxArrayLength); |
| | | 105 | | } |
| | 0 | 106 | | if (readerQuotas.MaxBytesPerRead != EncoderDefaults.MaxBytesPerRead) |
| | | 107 | | { |
| | 0 | 108 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBytesPerRead, readerQuotas.MaxBytesPerRead); |
| | | 109 | | } |
| | 0 | 110 | | if (readerQuotas.MaxNameTableCharCount != EncoderDefaults.MaxNameTableCharCount) |
| | | 111 | | { |
| | 0 | 112 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxNameTableCharCount, readerQuotas.MaxNameTableC |
| | | 113 | | } |
| | 0 | 114 | | } |
| | | 115 | | } |
| | | 116 | | |
| | | 117 | | internal static class EncoderDefaults |
| | | 118 | | { |
| | | 119 | | internal const int MaxReadPoolSize = 64; |
| | | 120 | | internal const int MaxWritePoolSize = 16; |
| | | 121 | | |
| | | 122 | | internal const CompressionFormat DefaultCompressionFormat = CompressionFormat.None; |
| | | 123 | | |
| | | 124 | | internal const int MaxDepth = 32; |
| | | 125 | | internal const int MaxStringContentLength = 8192; |
| | | 126 | | internal const int MaxArrayLength = 16384; |
| | | 127 | | internal const int MaxBytesPerRead = 4096; |
| | | 128 | | internal const int MaxNameTableCharCount = 16384; |
| | | 129 | | |
| | | 130 | | } |
| | | 131 | | |
| | | 132 | | } |