public void SetAttributeValue(string key, object value) { if (AllowedAttributes.Contains(key)) { Element.Add(new XAttribute(key, value)); } }
/// <summary> /// Initializes a new instance of the Body class. /// </summary> /// <param name="body"></param> public Task(string taskattributes) { Element = new XElement("Task", taskattributes); AllowedAttributes.Add("priority"); AllowedAttributes.Add("timeout"); }
IAttribute <T> CreateAttribute <T>(string name) { Type attribType = typeof(T); if (AllowedAttributes != null && AllowedAttributes.ContainsKey(name)) { return((IAttribute <T>)AllowedAttributes[name]()); } //if (!dynamicAttributesPermitted) // throw new ArgumentOutOfRangeException("name", "Attribute {0} is not allowed on this element.".With(name)); if (attribType.IsValueType || attribType == typeof(string) || typeof(Nullable).IsAssignableFrom(attribType)) { return(new PrimaryTypeAttributeNode <T>(name)); } if (attribType == typeof(MediaType)) { return((IAttribute <T>) new XhtmlAttributeNode <MediaType>(name, false, media => media.ToString(), str => new MediaType(str))); } if (attribType == typeof(IList <Uri>)) { return((IAttribute <T>) new CharacterSeparatedAttributeNode <Uri>(name, " ", uri => uri.ToString(), s => new Uri(s, UriKind.Absolute))); } if (attribType == typeof(IList <MediaType>)) { return((IAttribute <T>) new CharacterSeparatedAttributeNode <MediaType>(name, " ", mediatype => mediatype.ToString(), str => new MediaType(str))); } if (attribType == typeof(IList <string>)) { return((IAttribute <T>) new CharacterSeparatedAttributeNode <string>(name, " ", i => i, i => i)); } throw new InvalidOperationException("Could not automatically create attribute of type " + typeof(T)); }
/// <summary> /// Initializes a new instance of the Number class using the specified number. /// </summary> /// <param name="number"></param> public Number(string number) { Element = new XElement("Number", number); AllowedAttributes.Add("url"); AllowedAttributes.Add("method"); AllowedAttributes.Add("sendDigits"); }
/// <summary> /// Initializes a new instance of the Uri class. /// </summary> public Uri(string uri) { Element = new XElement("Uri"); Element.Add(uri); AllowedAttributes.Add("username"); AllowedAttributes.Add("password"); }
public Say(string text) { Element = new XElement("Say", text); AllowedAttributes.Add("voice"); AllowedAttributes.Add("language"); AllowedAttributes.Add("loop"); }
/// <summary> /// Initializes a new instance of the Queue class /// </summary> /// <param name="name">The name of the queue</param> public Queue() { Element = new XElement("Queue"); AllowedAttributes.Add("url"); AllowedAttributes.Add("reservationSid"); AllowedAttributes.Add("postworkActivitySid"); }
/// <summary> /// Initializes a new instance of the Enqueue class. /// </summary> /// <param name="name"></param> public Enqueue(string name) { Element = new XElement("Enqueue", name); AllowedAttributes.Add("action"); AllowedAttributes.Add("method"); AllowedAttributes.Add("waitUrl"); AllowedAttributes.Add("waitUrlMethod"); }
/// <summary> /// Initializes a new instance of the Sms class. /// </summary> public Sms() { Element = new XElement("Sms"); AllowedAttributes.Add("to"); AllowedAttributes.Add("from"); AllowedAttributes.Add("action"); AllowedAttributes.Add("method"); AllowedAttributes.Add("statusCallback"); }
/// <summary> /// Initializes a new instance of the Sip class. /// </summary> public Sip() { Element = new XElement("Sip"); AllowedChildren.Add("Uri"); AllowedAttributes.Add("username"); AllowedAttributes.Add("password"); AllowedAttributes.Add("url"); AllowedAttributes.Add("method"); }
public IAttribute this[string key] { get { if (_attributes[key] == null && AllowedAttributes != null) { if (AllowedAttributes.ContainsKey(key)) { _attributes[key] = AllowedAttributes[key](); } else { _attributes[key] = new PrimaryTypeAttributeNode <string>(key); } } return(_attributes[key]); } set { _attributes[key] = value; } }
/// <summary> /// Initializes a new instance of the Enqueue class. /// </summary> /// <param name="name"></param> public Enqueue(string name) { Element = new XElement("Enqueue", name); AllowedChildren.Add("TaskAttributes"); AllowedAttributes.Add("action"); AllowedAttributes.Add("method"); AllowedAttributes.Add("waitUrl"); AllowedAttributes.Add("waitUrlMethod"); AllowedAttributes.Add("workflowSid"); }
/// <summary> /// Initializes a new instance of the Conference class. /// </summary> public Conference() { Element = new XElement("Conference"); AllowedAttributes.Add("muted"); AllowedAttributes.Add("beep"); AllowedAttributes.Add("waitUrl"); AllowedAttributes.Add("waitMethod"); AllowedAttributes.Add("startConferenceOnEnter"); AllowedAttributes.Add("endConferenceOnExit"); }
/// <summary> /// Initializes a new instance of the Message class. /// </summary> public Message() { Element = new XElement("Message"); AllowedChildren.Add("Body"); AllowedChildren.Add("Media"); AllowedAttributes.Add("to"); AllowedAttributes.Add("from"); AllowedAttributes.Add("action"); AllowedAttributes.Add("method"); AllowedAttributes.Add("statusCallback"); }
public Record() { Element = new XElement("Record"); AllowedAttributes.Add("action"); AllowedAttributes.Add("method"); AllowedAttributes.Add("timeout"); AllowedAttributes.Add("finishOnKey"); AllowedAttributes.Add("maxlength"); AllowedAttributes.Add("transcribe"); AllowedAttributes.Add("transcribeCallback"); AllowedAttributes.Add("playBeep"); }
/// <summary> /// Initializes a new instance of the Gather class. /// </summary> public Gather() { Element = new XElement("Gather"); AllowedChildren.Add("Say"); AllowedChildren.Add("Play"); AllowedChildren.Add("Pause"); AllowedAttributes.Add("action"); AllowedAttributes.Add("finishOnKey"); AllowedAttributes.Add("method"); AllowedAttributes.Add("numDigits"); AllowedAttributes.Add("timeout"); }
public Dial() { Element = new XElement("Dial"); AllowedChildren.Add("Number"); AllowedChildren.Add("Client"); AllowedChildren.Add("Conference"); AllowedAttributes.Add("timeout"); AllowedAttributes.Add("callerId"); AllowedAttributes.Add("action"); AllowedAttributes.Add("method"); AllowedAttributes.Add("hangupOnStar"); AllowedAttributes.Add("timeLimit"); }
internal Md2HtmlSanitizer() { AllowedTags.Add(@"meta"); AllowedTags.Add(@"style"); AllowedAttributes.Add(@"content"); AllowedAttributes.Add(@"http-equiv"); AllowedCssProperties.Add(@"src"); RemovingAtRule += ChangedEvent; RemovingAttribute += ChangedEvent; RemovingCssClass += ChangedEvent; RemovingStyle += ChangedEvent; RemovingTag += ChangedEvent; }
public HtmlSanitizer() : base() { AllowedTags.Clear(); AllowedTags.Add("p"); AllowedTags.Add("h2"); AllowedTags.Add("strong"); AllowedTags.Add("em"); AllowedTags.Add("ul"); AllowedTags.Add("ol"); AllowedTags.Add("li"); AllowedTags.Add("a"); AllowedTags.Add("br"); AllowedAttributes.Clear(); AllowedAttributes.Add("href"); AllowedCssProperties.Clear(); AllowedAtRules.Clear(); }
/// <summary> /// Basic Load of node - validation and populating Attributes. /// </summary> /// <param name="node">XNode to load as <c>Fb2Node</c>.</param> /// <param name="parentNode">Parent node of node being loaded, can be <see langword="null"/>.</param> /// <param name="preserveWhitespace">Is ignored during <c>Fb2Node</c> loading.</param> /// <param name="loadUnsafe">Is ignored during <c>Fb2Node</c> loading.</param> /// <exception cref="ArgumentNullException"></exception> public virtual void Load( [In] XNode node, [In] Fb2Container?parentNode = null, bool preserveWhitespace = false, bool loadUnsafe = true, bool loadNamespaceMetadata = true) { Validate(node); Parent = parentNode; if (!(node is XElement element)) { return; } var allAttributes = element.Attributes(); if (loadNamespaceMetadata) { var defaultNodeNamespace = element.GetDefaultNamespace(); var namespaceDeclarationAttributes = allAttributes.Where(a => a.IsNamespaceDeclaration); NodeMetadata = new Fb2NodeMetadata(defaultNodeNamespace, namespaceDeclarationAttributes); } if (!AllowedAttributes.Any()) { return; } var filteredAttributes = allAttributes .Where(attr => AllowedAttributes.Contains(attr.Name.LocalName, StringComparer.InvariantCultureIgnoreCase)) .Select(attr => { var attributeNamespace = loadNamespaceMetadata ? attr.Name.Namespace?.NamespaceName : null; return(new Fb2Attribute(attr.Name.LocalName, attr.Value, attributeNamespace)); }); if (!filteredAttributes.Any()) { return; } attributes.AddRange(filteredAttributes); }
private bool IsAttributeValid(string attributeName, string value) { if (AllowedAttributes != null) { // No attributes are allowed if (!AllowedAttributes.Any()) { return(false); } if (!AllowedAttributes.Contains(attributeName)) { return(false); } } if (RequiredAttributes != null) { if (value == null && RequiredAttributes.Contains(attributeName)) { // Don't delete any required attributes return(false); } } if (AllowedValues != null) { if (AllowedValues.TryGetValue(attributeName, out var allowed) && !allowed.Contains(value.Trim())) { return(false); } } if (DisallowedValues != null) { if (DisallowedValues.TryGetValue(attributeName, out var disallowed) && disallowed.Contains(value.Trim())) { return(false); } } return(true); }
internal Md2HtmlSanitizer() { AllowedTags.Add(@"meta"); AllowedTags.Add(@"style"); AllowedAttributes.Add(@"content"); AllowedAttributes.Add(@"http-equiv"); AllowedAttributes.Add(@"id"); AllowedAttributes.Add(@"class"); AllowedCssProperties.Add(@"src"); AllowedCssProperties.Add(@"word-break"); AllowedCssProperties.Add(@"word-wrap"); AllowedCssProperties.Add(@"-moz-tab-size"); AllowedCssProperties.Add(@"-o-tab-size"); AllowedCssProperties.Add(@"tab-size"); AllowedCssProperties.Add(@"-webkit-hyphens"); AllowedCssProperties.Add(@"-moz-hyphens"); AllowedCssProperties.Add(@"-ms-hyphens"); AllowedCssProperties.Add(@"hyphens"); AllowedCssProperties.Add(@"background-position-x"); AllowedCssProperties.Add(@"background-position-y"); AllowedCssProperties.Add(@"transition-property"); AllowedCssProperties.Add(@"transition-duration"); AllowedCssProperties.Add(@"transition-timing-function"); AllowedCssProperties.Add(@"transition-delay"); AllowedCssProperties.Add(@"box-shadow"); AllowedSchemes.Add(@"file"); AllowedSchemes.Add(@"data"); AllowedAtRules.Add(CssRuleType.Media); AllowedAtRules.Add(CssRuleType.Keyframe); AllowedAtRules.Add(CssRuleType.Keyframes); RemovingAtRule += ChangedEvent; RemovingAttribute += ChangedEvent; RemovingCssClass += ChangedEvent; RemovingStyle += ChangedEvent; RemovingTag += ChangedEvent; }
public object Any(AllowedAttributes request) { return(request); }
/// <summary> /// Determines whether the specified attribute is allowed. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns> private bool IsAllowedAttribute(IAttr attribute) { return(AllowedAttributes.Contains(attribute.Name) // test html5 data- attributes || (AllowDataAttributes && attribute.Name != null && attribute.Name.StartsWith("data-", StringComparison.OrdinalIgnoreCase))); }
public object Any(AllowedAttributes request) { return request; }
/// <summary> /// AllowedAttributes Description /// </summary> /// <remarks> /// AllowedAttributes Description /// </remarks> /// <param name='aliased'> /// Range Description /// </param> /// <param name='body'> /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="HttpOperationException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse> GetWithHttpMessagesAsync(int aliased, AllowedAttributes body = default(AllowedAttributes), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { string accept = "application/json"; // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("aliased", aliased); tracingParameters.Add("body", body); tracingParameters.Add("accept", accept); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "allowed-attributes").ToString(); _url = _url.Replace("{Aliased}", System.Uri.EscapeDataString(Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(aliased, Client.SerializationSettings).Trim('"'))); // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("GET"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (accept != null) { if (_httpRequest.Headers.Contains("Accept")) { _httpRequest.Headers.Remove("Accept"); } _httpRequest.Headers.TryAddWithoutValidation("Accept", accept); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (body != null) { _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 400) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); object _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <object>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
/// <summary> /// Initializes a new instance of the Client class /// </summary> /// <param name="clientName">The name of the client</param> public Client(string clientName) { Element = new XElement("Client", clientName); AllowedAttributes.Add("url"); AllowedAttributes.Add("method"); }
/// <summary> /// Determines whether the specified attribute is allowed. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns> private bool IsAllowedAttribute(KeyValuePair <string, string> attribute) { return(AllowedAttributes.Contains(attribute.Key) // test html5 data- attributes || (AllowDataAttributes && attribute.Key != null && attribute.Key.StartsWith("data-", StringComparison.OrdinalIgnoreCase))); }
/// <summary> /// Initializes a new instance of the Redirect class. /// </summary> public Redirect() { Element = new XElement("Redirect"); AllowedAttributes.Add("method"); }
private void ValidateAttributes(XElement element, SettingsFile origin) { if (AllowedAttributes != null) { if (!AllowedAttributes.Any() && element.HasAttributes) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.NoAttributesAllowed, element.Name.LocalName, element.Attributes().Count()), origin.ConfigFilePath)); } foreach (var attribute in element.Attributes()) { if (!AllowedAttributes.Contains(attribute.Name.LocalName)) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.AttributeNotAllowed, attribute.Name.LocalName, element.Name.LocalName), origin.ConfigFilePath)); } } } if (RequiredAttributes != null) { foreach (var requireAttribute in RequiredAttributes) { var attribute = element.Attribute(requireAttribute); if (attribute == null) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.MissingRequiredAttribute, requireAttribute, element.Name.LocalName), origin.ConfigFilePath)); } } } if (AllowedValues != null) { foreach (var attributeValues in AllowedValues) { var attribute = element.Attribute(attributeValues.Key); if (attribute != null && !attributeValues.Value.Contains(attribute.Value.Trim())) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.AttributeValueNotAllowed, attribute.Name.LocalName, attribute.Value.Trim(), element.Name.LocalName), origin.ConfigFilePath)); } } } if (DisallowedValues != null) { foreach (var attributeValues in DisallowedValues) { var attribute = element.Attribute(attributeValues.Key); if (attribute != null && attributeValues.Value.Contains(attribute.Value.Trim())) { throw new NuGetConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UserSettings_UnableToParseConfigFile, string.Format(CultureInfo.CurrentCulture, Resources.AttributeValueNotAllowed, attribute.Name.LocalName, attribute.Value.Trim(), element.Name.LocalName), origin.ConfigFilePath)); } } } }
/// <summary> /// Initializes a new instance of the Pause class. /// </summary> public Pause() { Element = new XElement("Pause"); AllowedAttributes.Add("length"); }