/// <summary> /// Selects a stream-method from the list of advertised methods. /// </summary> /// <param name="feature">The 'feature' element containing the data-form /// with advertised stream-methods.</param> /// <returns>The selected stream-method.</returns> /// <exception cref="ArgumentException">None of the advertised methods is /// supported.</exception> string SelectStreamMethod(XmlElement feature) { // See if we support any of the advertised stream-methods. DataForm form = FeatureNegotiation.Parse(feature); ListField field = form.Fields["stream-method"] as ListField; // Order of preference: Socks5, Ibb. string[] methods = new string[] { "http://jabber.org/protocol/bytestreams", "http://jabber.org/protocol/ibb" }; for (int i = 0; i < methods.Length; i++) { if (ForceInBandBytestreams && methods[i] != "http://jabber.org/protocol/ibb") { continue; } if (field.Values.Contains(methods[i])) { return(methods[i]); } } throw new ArgumentException("No supported method advertised."); }
private string SelectStreamMethod(XmlElement feature) { ListField field = FeatureNegotiation.Parse(feature).Fields["stream-method"] as ListField; string[] strArray = new string[] { "http://jabber.org/protocol/bytestreams", "http://jabber.org/protocol/ibb" }; for (int i = 0; i < strArray.Length; i++) { if ((!this.ForceInBandBytestreams || !(strArray[i] != "http://jabber.org/protocol/ibb")) && field.Values.Contains <string>(strArray[i])) { return(strArray[i]); } } throw new ArgumentException("No supported method advertised."); }
private string ParseStreamMethod(XmlElement feature) { feature.ThrowIfNull <XmlElement>("feature"); DataField field = FeatureNegotiation.Parse(feature).Fields["stream-method"]; if (field == null) { throw new ArgumentException("Missing or erroneous 'stream-method' field."); } string str = field.Values.FirstOrDefault <string>(); if (str == null) { throw new ArgumentException("No stream-method selected."); } return(str); }
/// <summary> /// Parses the selected stream-method from the specified 'feature' XML /// element. /// </summary> /// <param name="feature">The 'feature' XML element.</param> /// <returns>The stream method contained in the 'feature' XML /// element.</returns> /// <exception cref="ArgumentNullException">The feature parameter is /// null.</exception> /// <exception cref="ArgumentException">The feature element contains /// invalid data.</exception> string ParseStreamMethod(XmlElement feature) { feature.ThrowIfNull("feature"); DataForm form = FeatureNegotiation.Parse(feature); // The data-form must contain a field named 'stream-method'. var field = form.Fields["stream-method"]; if (field == null) { throw new ArgumentException("Missing or erroneous 'stream-method' field."); } string selected = field.Values.FirstOrDefault(); if (selected == null) { throw new ArgumentException("No stream-method selected."); } return(selected); }