/// <summary> /// Initializes a new instance of the Item class. /// </summary> /// <param name="jid">The JID of the item.</param> /// <param name="node">The node identifier of the item.</param> /// <param name="name">The name of the item.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public XmppItem(Jid jid, string node = null, string name = null) { jid.ThrowIfNull("jid"); Jid = jid; Node = node; Name = name; }
/// <summary> /// Initializes a new instance of the MoodChangedEventArgs class. /// </summary> /// <param name="jid">The JID of the XMPP entity that published the /// mood information.</param> /// <param name="mood">One of the values from the Mood enumeration.</param> /// <param name="description">A natural-language description of, or /// reason for, the mood.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public MoodChangedEventArgs(Jid jid, Mood mood, string description = null) { jid.ThrowIfNull("jid"); Jid = jid; Mood = mood; Description = description; }
/// <summary> /// Initializes a new instance of the AvatarChangedEventArgs class. /// </summary> /// <param name="jid">The JID of the XMPP entity that published the /// avatar information.</param> /// <param name="hash">The SHA-1 hash of the avatar image data.</param> /// <param name="avatar">The avatar information to include as part of /// the event.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public AvatarChangedEventArgs(Jid jid, string hash = null, Image avatar = null) { jid.ThrowIfNull("jid"); Jid = jid; Hash = hash; Avatar = avatar; }
/// <summary> /// Initializes a new instance of the StatusEventArgs class. /// </summary> /// <exception cref="ArgumentNullException">The jid parameter or the status /// parameter is null.</exception> public StatusEventArgs(Jid jid, Status status) { jid.ThrowIfNull("jid"); status.ThrowIfNull("status"); Jid = jid; Status = status; }
/// <summary> /// Create an archived chat id /// </summary> /// <param name="with">The id of the entity that the conversation was with</param> /// <param name="start">The start date of the conversation</param> public ArchivedChatId(Jid with, DateTimeOffset start) { with.ThrowIfNull("with"); With = with; Start = start; }
/// <summary> /// Queries the XMPP entity with the specified JID for its software /// version. /// </summary> /// <param name="jid">The JID of the XMPP entity to query.</param> /// <returns>An instance of the VersionInformation class containing the /// entity's software version.</returns> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> /// <exception cref="NotSupportedException">The XMPP entity with /// the specified JID does not support the 'Software Version' XMPP /// extension.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> public VersionInformation GetVersion(Jid jid) { jid.ThrowIfNull("jid"); if (!ecapa.Supports(jid, Extension.SoftwareVersion)) { throw new NotSupportedException("The XMPP entity does not support the " + "'Software Version' extension."); } Iq response = im.IqRequest(IqType.Get, jid, im.Jid, Xml.Element("query", "jabber:iq:version")); if (response.Type == IqType.Error) { throw Util.ExceptionFromError(response, "The version could not be retrieved."); } // Parse the response. var query = response.Data["query"]; if (query == null || query.NamespaceURI != "jabber:iq:version") { throw new XmppException("Erroneous server response: " + response); } if (query["name"] == null || query["version"] == null) { throw new XmppException("Missing name or version element: " + response); } string os = query["os"] != null ? query["os"].InnerText : null; return(new VersionInformation(query["name"].InnerText, query["version"].InnerText, os)); }
/// <summary> /// Initializes a new instance of the PrivacyRule class. /// </summary> /// <param name="jid">The JID the privacy rule applies to.</param> /// <param name="allow">True to allow entities affected by this rule; Otherwise /// false.</param> /// <param name="order">The order of the privacy rule.</param> /// <param name="granularity">Specifies which kinds of stanzas should be /// allowed or blocked, respectively.</param> /// <exception cref="ArgumentNullException">The jid parameter is null.</exception> public JidPrivacyRule(Jid jid, bool allow, uint order, PrivacyGranularity granularity = 0) : base(allow, order, granularity) { jid.ThrowIfNull("jid"); Jid = jid; }
/// <summary> /// Initializes a new instance of the MoodChangedEventArgs class. /// </summary> /// <param name="jid">The JID of the XMPP entity that published the /// mood information.</param> /// <param name="mood">One of the values from the Mood enumeration.</param> /// <param name="description">A natural-language description of, or /// reason for, the mood.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public MoodChangedEventArgs(Jid jid, Mood mood, string description = null) { jid.ThrowIfNull("jid"); Jid = jid; Mood = mood; Description = description; }
/// <summary> /// Queries the XMPP entity with the specified JID for identity information. /// </summary> /// <param name="jid">The JID of the XMPP entity to query.</param> /// <returns>An enumerable collection of identities of the XMPP entity /// with the specified JID.</returns> /// <exception cref="ArgumentNullException">The jid parameter /// is null.</exception> /// <exception cref="NotSupportedException">The query could not be /// performed or the response was invalid.</exception> private IEnumerable <Identity> QueryIdentities(Jid jid) { jid.ThrowIfNull("jid"); Iq iq = im.IqRequest(IqType.Get, jid, im.Jid, Xml.Element("query", "http://jabber.org/protocol/disco#info")); if (iq.Type != IqType.Result) { throw new NotSupportedException("Could not query features: " + iq); } // Parse the result. var query = iq.Data["query"]; if (query == null || query.NamespaceURI != "http://jabber.org/protocol/disco#info") { throw new NotSupportedException("Erroneous response: " + iq); } ISet <Identity> idents = new HashSet <Identity>(); foreach (XmlElement e in query.GetElementsByTagName("identity")) { string cat = e.GetAttribute("category"), type = e.GetAttribute("type"), name = e.GetAttribute("name"); if (String.IsNullOrEmpty(cat) || String.IsNullOrEmpty(type)) { continue; } idents.Add(new Identity(cat, type, String.IsNullOrEmpty(name) ? null : name)); } return(idents); }
/// <summary> /// Determines whether the XMPP entity with the specified JID supports the /// specified XMPP extension. /// </summary> /// <typeparam name="T">The XMPP extension to probe for.</typeparam> /// <param name="jid">The JID of the XMPP entity.</param> /// <returns>true if the XMPP entity with the specified JID supports the /// specified XMPP extension; Otherwise false.</returns> /// <exception cref="ArgumentNullException">The jid parameter is null.</exception> /// <exception cref="NotSupportedException">The XMPP entity with the specified /// JID does not support querying of feature information.</exception> public bool Supports <T>(Jid jid) where T : XmppExtension { jid.ThrowIfNull("jid"); T ext = im.GetExtension <T>(); return(Supports(jid, ext.Xep)); }
/// <summary> /// Initializes a new instance of the SISession class. /// </summary> /// <param name="sid">The identifier of the session.</param> /// <param name="stream">The IO-stream from which data is read, or to /// which data is written.</param> /// <param name="size">The total number of bytes to read from, or to /// write to the stream.</param> /// <param name="receiving">true if data is being received over the session; /// Otherwise false.</param> /// <param name="from">The JID of the XMPP entity that wishes to send data.</param> /// <param name="to">The JID of the XMPP entity that wishes to receive /// data.</param> /// <param name="extension">The instance of the data-stream extension /// negotiated during session-initiation.</param> /// <exception cref="ArgumentNullException">The sid parameter or the stream /// parameter or the from parameter or the to parameter or the extension /// parameter is null.</exception> /// <exception cref="ArgumentException">The receiving parameter is true, but /// the specified stream cannot be written, or the receiving parameter is /// false, but the specified stream cannot be read.</exception> /// <exception cref="ArgumentOutOfRangeException">The size parameter is /// negative.</exception> public SISession(string sid, Stream stream, long size, bool receiving, Jid from, Jid to, IDataStream extension) { sid.ThrowIfNull("sid"); stream.ThrowIfNull("stream"); size.ThrowIfOutOfRange(0, Int64.MaxValue); from.ThrowIfNull("from"); to.ThrowIfNull("to"); extension.ThrowIfNull("extension"); if (receiving && !stream.CanWrite) { throw new ArgumentException("The specified stream cannot be written."); } if (!receiving && !stream.CanRead) { throw new ArgumentException("The specified stream cannot be read."); } Sid = sid; Stream = stream; Size = size; Count = 0; Receiving = receiving; From = from; To = to; Extension = extension; }
/// <summary> /// Initializes a new instance of the MessageEventArgs class. /// </summary> /// <exception cref="ArgumentNullException">The jid parameter or the message /// parameter is null.</exception> public MessageEventArgs(Jid jid, Message message) { jid.ThrowIfNull("jid"); message.ThrowIfNull("message"); Jid = jid; Message = message; }
/// <summary> /// Queries for occupants in a room, /// This will fail if you do not have permissions. /// </summary> /// <param name="room">Chat room to query</param> /// <returns>An enumerable collection of items of the XMPP entity /// with the specified IRoom.</returns> /// <exception cref="ArgumentNullException">The IRoom jid parameter /// is null.</exception> /// <exception cref="NotSupportedException">The query could not be /// performed or the response was invalid.</exception> private IEnumerable <Occupant> QueryOccupants(Jid room) { room.ThrowIfNull("room"); var items = QueryItems(room, Xml.Element("query", MucNs.NsRequestItems)); return(items.Select(x => new Occupant(x.Jid, x.Affiliation, x.Role))); }
/// <summary> /// Initializes a new instance of the Streamhost class. /// </summary> /// <param name="jid">The JID of the streamhost.</param> /// <param name="host">The hostname of the streamhost.</param> /// <param name="port">The port on which the streamhost is accepting /// connections.</param> /// <exception cref="ArgumentNullException">The jid parameter or the /// host parameter is null.</exception> /// <exception cref="ArgumentException">The host parameter is the empty /// string.</exception> /// <exception cref="ArgumentOutOfRangeException">The port parameter is /// not between 0 and 65535.</exception> public Streamhost(Jid jid, string host, int port) { jid.ThrowIfNull("jid"); host.ThrowIfNullOrEmpty("host"); port.ThrowIfOutOfRange("port", 0, 65535); Jid = jid; Host = host; Port = port; }
/// <summary> /// Initializes a new instance of the MessageEventArgs class. /// </summary> /// <exception cref="ArgumentNullException">The jid parameter or the message /// parameter is null.</exception> public MessageEventArgs(Jid jid, Message message, Boolean carbonCopy = false) { jid.ThrowIfNull("jid"); message.ThrowIfNull("message"); Jid = jid; Message = message; CarbonCopy = carbonCopy; }
/// <summary> /// Add a Jid value to this form /// </summary> /// <param name="name">The name of the value</param> /// <param name="value">The value to add</param> /// <returns>This data form</returns> public DataForm AddValue(string name, Jid value) { value.ThrowIfNull(); element.Child(new JidField(name, value).ToXmlElement()); return(this); }
/// <summary> /// Requests the avatar image with the specified hash from the node service /// running at the specified JID. It downloads it asynchronysly and executes /// a specified callback action when finished /// </summary> /// <param name="jid">The JID of the node service to request the avatar /// image from.</param> /// <param name="filepath">The full location of the file that the Avatar file we be written.</param> /// <param name="callback">A callback Action to be invoked after the end of the file write. </param> /// <exception cref="ArgumentNullException">The jid or the filepath parameter is null.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> public async Task RequestAvatar(Jid jid, string filepath, Func <Task> callback) { jid.ThrowIfNull("jid"); filepath.ThrowIfNull("filePath"); //Make the request var xml = Xml.Element("vCard", "vcard-temp"); Func <string, Iq, Task> call = async(id, iq) => { XmlElement query = iq.Data["vCard"]; if (iq.Data["vCard"].NamespaceURI == "vcard-temp") { XElement root = XElement.Parse(iq.Data.OuterXml); XNamespace aw = "vcard-temp"; //SOS the correct namespace IEnumerable <string> b64collection = (from el in root.Descendants(aw + "BINVAL") select(string) el); string b64 = null; if (b64collection != null) { b64 = b64collection.FirstOrDefault(); if (b64 != null) { try { byte[] data = Convert.FromBase64String(b64); if (data != null) { string dir = Path.GetDirectoryName(filepath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (var file = new FileStream(filepath, FileMode.Create, System.IO.FileAccess.Write)) { await file.WriteAsync(data, 0, data.Length); } if (callback != null) { await callback(); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error downloading and writing avatar file" + e.StackTrace + e.ToString()); //Exception is not contained here. Fix? } } } } }; //The Request is Async await im.IqRequestAsync(IqType.Get, jid, im.Jid, xml, null, call); }
/// <summary> /// Retrieves an enumerable collection of XMPP extensions that the XMPP /// entity with the specified JID supports. /// </summary> /// <param name="jid">The JID of the XMPP entity to retrieve supported /// extensions for.</param> /// <returns>An enumerable collection of XMPP extensions supported by the /// XMPP entity with the specified JID.</returns> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> /// <exception cref="NotSupportedException">The XMPP entity with the /// specified JID does not support querying of feature information.</exception> public IEnumerable <Extension> GetExtensions(Jid jid) { jid.ThrowIfNull("jid"); if (!cache.ContainsKey(jid)) { cache.Add(jid, QueryFeatures(jid)); } return(cache[jid]); }
public IEnumerable <Extension> GetExtensions(Jid jid) { jid.ThrowIfNull <Jid>("jid"); if (!this.cache.ContainsKey(jid)) { this.cache.Add(jid, this.QueryFeatures(jid)); } return(this.cache[jid]); }
/// <summary> /// Initializes a new instance of the Streamhost class. /// </summary> /// <param name="jid">The JID of the streamhost.</param> /// <param name="host">The hostname of the streamhost.</param> /// <param name="port">The port on which the streamhost is accepting /// connections.</param> /// <exception cref="ArgumentNullException">The jid parameter or the /// host parameter is null.</exception> /// <exception cref="ArgumentException">The host parameter is the empty /// string.</exception> /// <exception cref="ArgumentOutOfRangeException">The port parameter is /// not between 0 and 65535.</exception> public Streamhost(Jid jid, string host, int port) { jid.ThrowIfNull("jid"); host.ThrowIfNullOrEmpty("host"); port.ThrowIfOutOfRange("port", 0, 65535); Jid = jid; Host = host; Port = port; }
/// <summary> /// Initializes a new instance of the ActivityChangedEventArgs class. /// </summary> /// <param name="jid">The JID of the XMPP entity that published the /// activity information.</param> /// <param name="activity">One of the values from the GeneralActivity /// enumeration.</param> /// <param name="specific">A value from the SpecificActivity enumeration /// best describing the user's activity in more detail.</param> /// <param name="description">A natural-language description of, or /// reason for, the activity.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public ActivityChangedEventArgs(Jid jid, GeneralActivity activity, SpecificActivity specific = SpecificActivity.Other, string description = null) { jid.ThrowIfNull("jid"); Jid = jid; Activity = activity; Specific = specific; Description = description; }
/// <summary> /// Requests the avatar image with the specified hash from the node service /// running at the specified JID. It downloads it asynchronysly and executes /// a specified callback action when finished /// </summary> /// <param name="jid">The JID of the node service to request the avatar /// image from.</param> /// <param name="filepath">The full location of the file that the Avatar file we be written.</param> /// <param name="callback">A callback Action to be invoked after the end of the file write. </param> /// <exception cref="ArgumentNullException">The jid or the filepath parameter is null.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> public void RequestAvatar(Jid jid, string filepath, Action callback) { jid.ThrowIfNull("jid"); filepath.ThrowIfNull("filePath"); //Make the request var xml = Xml.Element("vCard", "vcard-temp"); //The Request is Async //im.IqRequestAsync(IqType.Get, jid, im.Jid, xml, null, (id, iq) => //{ // XElement query = iq.Data.Element("vCard"); // if (iq.Data.Element("vCard").GetDefaultNamespace().NamespaceName == "vcard-temp") // { // XElement root = XElement.Parse(iq.Data.Value); // XNamespace aw = "vcard-temp"; //SOS the correct namespace // IEnumerable<string> b64collection = (from el in root.Descendants(aw + "BINVAL") // select (string)el); // string b64 = null; // if (b64collection != null) // { // b64 = b64collection.FirstOrDefault(); // if (b64 != null) // { // try // { // byte[] data = Convert.FromBase64String(b64); // if (data != null) // { // string dir = Path.GetDirectoryName(filepath); // if (!Directory.Exists(dir)) // { // Directory.CreateDirectory(dir); // } // using (var file = new FileStream(filepath, FileMode.Create, System.IO.FileAccess.Write)) // { // file.Write(data, 0, data.Length); // } // if (callback != null) // { // callback.Invoke(); // } // } // } // catch (Exception e) // { // System.Diagnostics.Debug.WriteLine("Error downloading and writing avatar file" + e.StackTrace + e.ToString()); // //Exception is not contained here. Fix? // } // } // } // } //}); }
/// <summary> /// Offers the specified file to the XMPP user with the specified JID and, if /// accepted by the user, transfers the file. /// </summary> /// <param name="to">The JID of the XMPP user to offer the file to.</param> /// <param name="path">The path of the file to transfer.</param> /// <param name="cb">a callback method invoked once the other site has /// accepted or rejected the file-transfer request.</param> /// <param name="description">A description of the file so the receiver can /// better understand what is being sent.</param> /// <returns>Sid of file transfer</returns> /// <exception cref="ArgumentNullException">The to parameter or the path /// parameter is null.</exception> /// <exception cref="ArgumentException">path is a zero-length string, /// contains only white space, or contains one or more invalid /// characters.</exception> /// <exception cref="PathTooLongException">The specified path, file name, /// or both exceed the system-defined maximum length.</exception> /// <exception cref="DirectoryNotFoundException">The specified path is /// invalid, (for example, it is on an unmapped drive).</exception> /// <exception cref="UnauthorizedAccessException">path specified a /// directory, or the caller does not have the required /// permission.</exception> /// <exception cref="FileNotFoundException">The file specified in path /// was not found.</exception> /// <exception cref="NotSupportedException">path is in an invalid /// format, or the XMPP entity with the specified JID does not support /// the 'SI File Transfer' XMPP extension.</exception> /// <exception cref="XmppErrorException">The server or the XMPP entity /// with the specified JID returned an XMPP error code. Use the Error /// property of the XmppErrorException to obtain the specific error /// condition.</exception> /// <exception cref="XmppException">The server returned invalid data or /// another unspecified XMPP error occurred.</exception> public async Task <string> InitiateFileTransfer(Jid to, string path, string description = null, Func <bool, FileTransfer, Task> cb = null) { to.ThrowIfNull("to"); path.ThrowIfNull("path"); FileInfo info = new FileInfo(path); return(await InitiateFileTransfer(to, File.OpenRead(path), info.Name, info.Length, description, cb)); }
/// <summary> /// Initialised a new instance of the item class. /// This instance is used for member list creation and modification. /// </summary> /// <param name="jid">JID</param> /// <param name="node">The node identifier of the item.</param> /// <param name="name">The name of the item.</param> /// <param name="nickname">Occupant nickname</param> /// <param name="role">Privilege level within a room.</param> /// <param name="affiliation">A long-lived association or connection with a room.</param> public XmppItem(Jid jid, string node = null, string name = null, string nickname = null, string role = null, string affiliation = null) { jid.ThrowIfNull("jid"); Jid = jid; Node = node; Name = name; Nick = nickname; Role = role; Affiliation = affiliation; }
/// <summary> /// Initializes a new instance of the Item class. /// </summary> /// <param name="jid">The JID of the item.</param> /// <param name="node">The node identifier of the item.</param> /// <param name="name">The name of the item.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public Item(Jid jid, string node = null, string name = null) { jid.ThrowIfNull("jid"); Jid = jid; Node = node; Name = name; Affiliation = null; Nick = null; Role = null; }
/// <summary> /// Offers the specified file to the XMPP user with the specified JID and, if /// accepted by the user, transfers the file. /// </summary> /// <param name="to">The JID of the XMPP user to offer the file to.</param> /// <param name="path">The path of the file to transfer.</param> /// <param name="cb">a callback method invoked once the other site has /// accepted or rejected the file-transfer request.</param> /// <param name="description">A description of the file so the receiver can /// better understand what is being sent.</param> /// <exception cref="ArgumentNullException">The to parameter or the path /// parameter is null.</exception> /// <exception cref="ArgumentException">path is a zero-length string, /// contains only white space, or contains one or more invalid /// characters.</exception> /// <exception cref="PathTooLongException">The specified path, file name, /// or both exceed the system-defined maximum length.</exception> /// <exception cref="DirectoryNotFoundException">The specified path is /// invalid, (for example, it is on an unmapped drive).</exception> /// <exception cref="UnauthorizedAccessException">path specified a /// directory, or the caller does not have the required /// permission.</exception> /// <exception cref="FileNotFoundException">The file specified in path /// was not found.</exception> /// <exception cref="NotSupportedException">path is in an invalid /// format, or the XMPP entity with the specified JID does not support /// the 'SI File Transfer' XMPP extension.</exception> /// <exception cref="XmppErrorException">The server or the XMPP entity /// with the specified JID returned an XMPP error code. Use the Error /// property of the XmppErrorException to obtain the specific error /// condition.</exception> /// <exception cref="XmppException">The server returned invalid data or /// another unspecified XMPP error occurred.</exception> public void InitiateFileTransfer(Jid to, string path, string description = null, Action <bool, FileTransfer> cb = null) { to.ThrowIfNull("to"); path.ThrowIfNull("path"); FileInfo info = new FileInfo(path); InitiateFileTransfer(to, File.OpenRead(path), info.Name, info.Length, description, cb); }
/// <summary> /// Set your nickname in the room. /// </summary> public void SetNickName(Jid room, string nickname) { room.ThrowIfNull("room"); nickname.ThrowIfNullOrEmpty("nickname"); Jid request = new Jid(room.Domain, room.Node, nickname); var msg = new Core.Presence(request, im.Jid, null, null, null); im.SendPresence(new Im.Presence(msg)); }
/// <summary> /// Initializes a new instance of the ActivityChangedEventArgs class. /// </summary> /// <param name="jid">The JID of the XMPP entity that published the /// activity information.</param> /// <param name="activity">One of the values from the GeneralActivity /// enumeration.</param> /// <param name="specific">A value from the SpecificActivity enumeration /// best describing the user's activity in more detail.</param> /// <param name="description">A natural-language description of, or /// reason for, the activity.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public ActivityChangedEventArgs(Jid jid, GeneralActivity activity, SpecificActivity specific = SpecificActivity.Other, string description = null) { jid.ThrowIfNull("jid"); Jid = jid; Activity = activity; Specific = specific; Description = description; }
/// <summary> /// Queries for occupants in a room, /// This will fail if you do not have permissions. /// </summary> /// <param name="room">Chat room to query</param> /// <param name="role">Queried user role</param> /// <returns>An enumerable collection of items of the XMPP entity /// with the specified IRoom.</returns> /// <exception cref="ArgumentNullException">The IRoom jid parameter /// is null.</exception> /// <exception cref="NotSupportedException">The query could not be /// performed or the response was invalid.</exception> private IEnumerable <Occupant> QueryOccupants(Jid room, Role role) { room.ThrowIfNull("room"); var queryElement = Xml.Element("query", MucNs.NsAdmin) .Child(Xml.Element("item").Attr("role", role.ToString().ToLower())); var items = QueryItems(room, queryElement); return(items.Select(x => new Occupant(x.Jid, x.Affiliation, x.Role))); }
/// <summary> /// Sets the chat-state for the conversation with the XMPP user with the /// specified JID. /// </summary> /// <param name="jid">The JID of the XMPP user to set the chat-state /// for.</param> /// <param name="state">The new chat-state.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public async Task SetChatState(Jid jid, ChatState state) { jid.ThrowIfNull("jid"); Message m = new Message(jid); m.Type = MessageType.Chat; m.Data.Child(Xml.Element(state.ToString().ToLowerInvariant(), "http://jabber.org/protocol/chatstates")); await im.SendMessage(m); }
public Message(Jid to, string body = null, string subject = null, string thread = null, MessageType type = 0, CultureInfo language = null) : base(to, null, null, null, language) { this.timestamp = DateTime.Now; to.ThrowIfNull <Jid>("to"); this.AlternateSubjects = new XmlDictionary(base.element, "subject", "xml:lang"); this.AlternateBodies = new XmlDictionary(base.element, "body", "xml:lang"); this.Type = type; this.Body = body; this.Subject = subject; this.Thread = thread; }
/// <summary> /// Gets the attention of the XMPP user with the specified JID. /// </summary> /// <param name="jid">The JID of the user to grab the attention of.</param> /// <param name="message">A message to sent along.</param> /// <exception cref="ArgumentNullException">The jid parameter /// is null.</exception> /// <exception cref="NotSupportedException">The XMPP entity with /// the specified JID does not support the 'Attention' XMPP /// extension.</exception> public void GetAttention(Jid jid, string message = null) { jid.ThrowIfNull("jid"); if(!ecapa.Supports(jid, Extension.Attention)) { throw new NotSupportedException("The XMPP entity does not support the " + "'Attention' extension."); } Im.Message m = new Im.Message(jid, message); // Add the 'attention' element to the message. m.Data.Child(Xml.Element("attention", "urn:xmpp:attention:0")); im.SendMessage(m); }
/// <summary> /// Initialised a new instance of the item class. /// This instance is used for member list creation and modification. /// </summary> /// <param name="affiliation">A long-lived association or connection with a room.</param> /// <param name="jid">JID</param> /// <param name="nickname">Occupant nickname</param> /// <param name="role">Privilege level within a room.</param> public Item(string affiliation, Jid jid, string nickname = null, string role = null) { affiliation.ThrowIfNull("affiliation"); jid.ThrowIfNull("jid"); Affiliation = affiliation; Jid = jid; Nick = nickname; Role = role; Node = null; Name = null; }
/// <summary> /// Requests the avatar image with the specified hash from the node service /// running at the specified JID. /// </summary> /// <param name="jid">The JID of the node service to request the avatar /// image from.</param> /// <param name="hash">The hash of the avatar image to retrieve.</param> /// <returns>An Image instance representing the retrieved avatar image.</returns> /// <exception cref="ArgumentNullException">The jid parameter or the /// hash parameter is null.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> public void RequestAvatar(Jid jid, string filepath, Action callback) { jid.ThrowIfNull("jid"); //Make the request var xml = Xml.Element("vCard", "vcard-temp"); //var result = im.IqRequest(IqType.Get, jid, im.Jid, xml); im.IqRequestAsync(IqType.Get, jid, im.Jid, xml, null, (id, iq) => { XmlElement query = iq.Data["vCard"]; if (iq.Data["vCard"].NamespaceURI == "vcard-temp") { XElement root = XElement.Parse(iq.Data.OuterXml); XNamespace aw = "vcard-temp"; //SOS the correct namespace IEnumerable <string> b64collection = (from el in root.Descendants(aw + "BINVAL") select(string) el); string b64 = null; if (b64collection != null) { b64 = b64collection.FirstOrDefault(); if (b64 != null) { try { byte[] data = Convert.FromBase64String(b64); //string hashvalue = Hash(data); if (data != null) { string dir = Path.GetDirectoryName(filepath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (var file = new FileStream(filepath, FileMode.Create, System.IO.FileAccess.Write)) { file.Write(data, 0, data.Length); } if (callback != null) { callback.Invoke(); } } } catch (Exception e) { Console.WriteLine("Error downloading and writing avatar file" + e); } } } } }); //Check the result }
/// <summary> /// Initializes a new instance of the Message class. /// </summary> /// <param name="to">The JID of the intended recipient.</param> /// <param name="body">The content of the message.</param> /// <param name="subject">The subject of the message.</param> /// <param name="thread">The conversation thread this message belongs to.</param> /// <param name="type">The type of the message. Can be one of the values from /// the MessagType enumeration.</param> /// <param name="language">The language of the XML character data of /// the stanza.</param> /// <exception cref="ArgumentNullException">The to parameter is null.</exception> /// <exception cref="ArgumentException">The body parameter is the empty string.</exception> public Message(Jid to, string body = null, string subject = null, string thread = null, MessageType type = MessageType.Normal, CultureInfo language = null) : base(to, null, null, null, language) { to.ThrowIfNull("to"); AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang"); AlternateBodies = new XmlDictionary(element, "body", "xml:lang"); Type = type; Body = body; Subject = subject; Thread = thread; }
public void GetAttention(Jid jid, string message = null) { jid.ThrowIfNull <Jid>("jid"); if (!this.ecapa.Supports(jid, new Extension[] { Extension.Attention })) { throw new NotSupportedException("The XMPP entity does not support the 'Attention' extension."); } Message message2 = new Message(jid, message, null, null, MessageType.Normal, null); message2.Data.Child(Xml.Element("attention", "urn:xmpp:attention:0")); base.im.SendMessage(message2); }
/// <summary> /// Initializes a new instance of the Message class. /// </summary> /// <param name="to">The JID of the intended recipient.</param> /// <param name="body">The content of the message.</param> /// <param name="subject">The subject of the message.</param> /// <param name="thread">The conversation thread this message belongs to.</param> /// <param name="type">The type of the message. Can be one of the values from /// the MessagType enumeration.</param> /// <param name="language">The language of the XML character data of /// the stanza.</param> /// <exception cref="ArgumentNullException">The to parameter is null.</exception> /// <exception cref="ArgumentException">The body parameter is the empty string.</exception> public Message(Jid to, string body = null, string subject = null, string thread = null, MessageType type = MessageType.Normal, CultureInfo language = null) : base(to, null, null, null, language) { to.ThrowIfNull("to"); AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang"); AlternateBodies = new XmlDictionary(element, "body", "xml:lang"); Type = type; Body = body; Subject = subject; Thread = thread; }
/// <summary> /// Initializes a new instance of the Message class. /// </summary> /// <param name="to">The JID of the intended recipient.</param> /// <param name="body">The content of the message.</param> /// <param name="subject">The subject of the message.</param> /// <param name="thread">The conversation thread this message belongs to.</param> /// <param name="type">The type of the message. Can be one of the values from /// the MessagType enumeration.</param> /// <param name="language">The language of the XML character data of /// the stanza.</param> /// <exception cref="ArgumentNullException">The to parameter is null.</exception> /// <exception cref="ArgumentException">The body parameter is the empty string.</exception> public Message(Jid to, string body = null, string subject = null, string thread = null, MessageType type = MessageType.Normal, CultureInfo language = null) : base(to, null, null, null, language) { to.ThrowIfNull("to"); AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang"); AlternateBodies = new XmlDictionary(element, "body", "xml:lang"); Type = type; Body = SecurityElement.Escape(body); Subject = SecurityElement.Escape(subject); Thread = thread; Timestamp = DelayedDelivery.GetDelayedTimestampOrNow(element); }
/// <summary> /// Gets the attention of the XMPP user with the specified JID. /// </summary> /// <param name="jid">The JID of the user to grab the attention of.</param> /// <param name="message">A message to sent along.</param> /// <exception cref="ArgumentNullException">The jid parameter /// is null.</exception> /// <exception cref="NotSupportedException">The XMPP entity with /// the specified JID does not support the 'Attention' XMPP /// extension.</exception> public void GetAttention(Jid jid, string message = null) { jid.ThrowIfNull("jid"); if (!ecapa.Supports(jid, Extension.Attention)) { throw new NotSupportedException("The XMPP entity does not support the " + "'Attention' extension."); } Im.Message m = new Im.Message(jid, message); // Add the 'attention' element to the message. m.Data.Child(Xml.Element("attention", "urn:xmpp:attention:0")); im.SendMessage(m); }
/// <summary> /// Determines whether the XMPP entity with the specified JID has the /// identity with the specified category and type attributes. /// </summary> /// <param name="jid">The JID of the XMPP entity.</param> /// <param name="category">The category of the identity to probe for.</param> /// <param name="type">The type of the identity to probe for.</param> /// <returns>true if the XMPP entity with the specified JID has the /// identity with the specified attributes; Otherwise false.</returns> /// <exception cref="ArgumentNullException">The jid parameter or the /// category parameter or the type parameter is null.</exception> /// <exception cref="NotSupportedException">The XMPP entity with /// the specified JID does not support querying of feature /// information.</exception> public bool HasIdentity(Jid jid, string category, string type) { jid.ThrowIfNull("jid"); category.ThrowIfNull("category"); type.ThrowIfNull("type"); foreach (Identity ident in GetIdentities(jid)) { if (ident.Category == category && ident.Type == type) { return(true); } } return(false); }
/// <summary> /// Initializes a new instance of the FileTransfer class. /// </summary> /// <param name="from">The JID of the XMPP entity that is sending the /// file.</param> /// <param name="to">The JID of the XMPP entity that is receiving the /// file.</param> /// <param name="name">The name of the file.</param> /// <param name="size">The size of the file, in bytes.</param> /// <param name="sessionId">The session id associated with the /// file-transfer.</param> /// <param name="description">A description of the file.</param> /// <param name="transferred">The number of bytes transferred.</param> /// <exception cref="ArgumentNullException">The from parameter or the to /// parameter or the name parameter is null.</exception> /// <exception cref="ArgumentOutOfRangeException">The size parameter /// is negative.</exception> internal FileTransfer(Jid from, Jid to, string name, long size, string sessionId = null, string description = null, long transferred = 0) { from.ThrowIfNull("from"); to.ThrowIfNull("to"); name.ThrowIfNull("name"); size.ThrowIfOutOfRange("size", 0, Int64.MaxValue); transferred.ThrowIfOutOfRange("transferred", 0, size); From = from; To = to; Name = name; Size = size; SessionId = sessionId; Description = description; Transferred = transferred; }
/// <summary> /// Initializes a new instance of the RosterItem class. /// </summary> /// <param name="jid">The JID of the user this item will be associated /// with.</param> /// <param name="name">The nickname with which to associate the JID.</param> /// <param name="state">One of the values from the SubscriptionState /// enumeration.</param> /// <param name="pending">True if the user has requested subscription but /// has not received the contact's response.</param> /// <param name="groups">An enumerable collection of groups to categorize /// this item in.</param> /// <exception cref="ArgumentNullException">The jid parameter is null.</exception> internal RosterItem(Jid jid, string name, SubscriptionState state, bool pending, IEnumerable<string> groups) { jid.ThrowIfNull("jid"); Jid = jid; Name = name; if (groups != null) { foreach (string s in groups) { if (String.IsNullOrEmpty(s)) continue; this.groups.Add(s); } } SubscriptionState = state; Pending = pending; }
/// <summary> /// Initializes a new instance of the Message class. /// </summary> /// <param name="to">The JID of the intended recipient.</param> /// <param name="bodies">A dictionary of message bodies. The dictionary /// keys denote the languages of the message bodies and must be valid /// ISO 2 letter language codes.</param> /// <param name="subjects">A dictionary of message subjects. The dictionary /// keys denote the languages of the message subjects and must be valid /// ISO 2 letter language codes.</param> /// <param name="thread">The conversation thread this message belongs to.</param> /// <param name="type">The type of the message. Can be one of the values from /// the MessagType enumeration.</param> /// <param name="language">The language of the XML character data of /// the stanza.</param> /// <exception cref="ArgumentNullException">The to parametr or the bodies /// parameter is null.</exception> public Message(Jid to, IDictionary<string, string> bodies, IDictionary<string, string> subjects = null, string thread = null, MessageType type = MessageType.Normal, CultureInfo language = null) : base(to, null, null, null, language) { to.ThrowIfNull("to"); bodies.ThrowIfNull("bodies"); AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang"); AlternateBodies = new XmlDictionary(element, "body", "xml:lang"); Type = type; foreach (var pair in bodies) AlternateBodies.Add(pair.Key, pair.Value); if (subjects != null) { foreach (var pair in subjects) AlternateSubjects.Add(pair.Key, pair.Value); } Thread = thread; }
/// <summary> /// Fetch a page of archived messages from a chat /// </summary> /// <param name="pageRequest">Paging options</param> /// <param name="with">The id of the entity that the chat was with</param> /// <param name="start">The start time of the chat</param> public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, Jid with, DateTimeOffset start) { pageRequest.ThrowIfNull(); with.ThrowIfNull(); var request = Xml.Element("retrieve", xmlns); request.Attr("with", with.ToString()); request.Attr("start", start.ToXmppDateTimeString()); var setNode = pageRequest.ToXmlElement(); request.Child(setNode); var response = IM.IqRequest(IqType.Get, null, null, request); if (response.Type == IqType.Error) { throw Util.ExceptionFromError(response, "Failed to get archived chat messages"); } return new ArchivedChatPage(response.Data["chat"]); }
/// <summary> /// Initializes a new instance of the ChatStateChangedEventArgs class. /// </summary> /// <param name="jid">The JID of the XMPP entity that published the /// chat-state.</param> /// <param name="state">The chat-state of the XMPP entity with the specified /// JID.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> public ChatStateChangedEventArgs(Jid jid, ChatState state) { jid.ThrowIfNull("jid"); Jid = jid; ChatState = state; }
/// <summary> /// Requests the avatar image with the specified hash from the node service /// running at the specified JID. /// </summary> /// <param name="jid">The JID of the node service to request the avatar /// image from.</param> /// <param name="hash">The hash of the avatar image to retrieve.</param> /// <returns>An Image instance representing the retrieved avatar image.</returns> /// <exception cref="ArgumentNullException">The jid parameter or the /// hash parameter is null.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> Image RequestImage(Jid jid, string hash) { jid.ThrowIfNull("jid"); hash.ThrowIfNull("hash"); XmlElement item = pep.RetrieveItem(jid, "urn:xmpp:avatar:data", hash); if (item["data"] == null || item["data"].NamespaceURI != "urn:xmpp:avatar:data") throw new XmppException("Erroneous avatar data: " + item); string b64 = item["data"].InnerText; // Try to decode the base64-string and create an Image instance from the // decoded binary data. try { byte[] data = Convert.FromBase64String(b64); using (var ms = new MemoryStream(data)) { return Image.FromStream(ms); } } catch (Exception e) { throw new XmppException("Invalid image data.", e); } }
/// <summary> /// Retrieves the SISession instance with the specified session id and /// with the specified sender and receiver. /// </summary> /// <param name="sid">The id of the session to retrieve.</param> /// <param name="from">The JID of the sender.</param> /// <param name="to">The JID of the receiver.</param> /// <returns>The SISession instance with the specified attributes, or null /// if no such SISession instance exists.</returns> /// <exception cref="ArgumentNullException">The sid parameter or the from /// parameter or the to parameter is null.</exception> public SISession GetSession(string sid, Jid from, Jid to) { sid.ThrowIfNull("sid"); from.ThrowIfNull("from"); to.ThrowIfNull("to"); SISession value; if (!siSessions.TryGetValue(sid, out value)) return null; if (value.From != from || value.To != to) return null; return value; }
/// <summary> /// Offers the specified file to the XMPP user with the specified JID and, if /// accepted by the user, transfers the file. /// </summary> /// <param name="to">The JID of the XMPP user to offer the file to.</param> /// <param name="path">The path of the file to transfer.</param> /// <param name="cb">a callback method invoked once the other site has /// accepted or rejected the file-transfer request.</param> /// <param name="description">A description of the file so the receiver can /// better understand what is being sent.</param> /// <returns>Sid of file transfer</returns> /// <exception cref="ArgumentNullException">The to parameter or the path /// parameter is null.</exception> /// <exception cref="ArgumentException">path is a zero-length string, /// contains only white space, or contains one or more invalid /// characters.</exception> /// <exception cref="PathTooLongException">The specified path, file name, /// or both exceed the system-defined maximum length.</exception> /// <exception cref="DirectoryNotFoundException">The specified path is /// invalid, (for example, it is on an unmapped drive).</exception> /// <exception cref="UnauthorizedAccessException">path specified a /// directory, or the caller does not have the required /// permission.</exception> /// <exception cref="FileNotFoundException">The file specified in path /// was not found.</exception> /// <exception cref="NotSupportedException">path is in an invalid /// format, or the XMPP entity with the specified JID does not support /// the 'SI File Transfer' XMPP extension.</exception> /// <exception cref="XmppErrorException">The server or the XMPP entity /// with the specified JID returned an XMPP error code. Use the Error /// property of the XmppErrorException to obtain the specific error /// condition.</exception> /// <exception cref="XmppException">The server returned invalid data or /// another unspecified XMPP error occurred.</exception> public string InitiateFileTransfer(Jid to, string path, string description = null, Action<bool, FileTransfer> cb = null) { to.ThrowIfNull("to"); path.ThrowIfNull("path"); FileInfo info = new FileInfo(path); return InitiateFileTransfer(to, File.OpenRead(path), info.Name, info.Length, description, cb); }
/// <summary> /// Offers the XMPP user with the specified JID the file with the specified /// name and, if accepted by the user, transfers the file using the supplied /// stream. /// </summary> /// <param name="to">The JID of the XMPP user to offer the file to.</param> /// <param name="stream">The stream to read the file-data from.</param> /// <param name="name">The name of the file, as offered to the XMPP user /// with the specified JID.</param> /// <param name="size">The number of bytes to transfer.</param> /// <param name="cb">A callback method invoked once the other site has /// accepted or rejected the file-transfer request.</param> /// <param name="description">A description of the file so the receiver can /// better understand what is being sent.</param> /// <returns>Sid of file transfer</returns> /// <exception cref="ArgumentNullException">The to parameter or the stream /// parameter or the name parameter is null.</exception> /// <exception cref="ArgumentOutOfRangeException">The value of the size /// parameter is negative.</exception> /// <exception cref="NotSupportedException">The XMPP entity with the /// specified JID does not support the 'SI File Transfer' XMPP /// extension.</exception> /// <exception cref="XmppErrorException">The server or the XMPP entity /// with the specified JID returned an XMPP error code. Use the Error /// property of the XmppErrorException to obtain the specific error /// condition.</exception> /// <exception cref="XmppException">The server returned invalid data or /// another unspecified XMPP error occurred.</exception> public string InitiateFileTransfer(Jid to, Stream stream, string name, long size, string description = null, Action<bool, FileTransfer> cb = null) { to.ThrowIfNull("to"); stream.ThrowIfNull("stream"); name.ThrowIfNull("name"); size.ThrowIfOutOfRange(0, Int64.MaxValue); //FIXME FIXME //if (!ecapa.Supports(to, Extension.SIFileTransfer)) { // throw new NotSupportedException("The XMPP entity does not support the " + // "'SI File Transfer' extension."); //} //FIXME FIXME // Perform stream-initiation asynchronously so that the caller is not // blocked until the other site has either accepted or rejected our offer. return InitiateStreamAsync(to, name, size, description, (result, iq) => { OnInitiationResult(result, to, name, stream, size, description, cb); }); }
/// <summary> /// Removes the item with the specified JID from the user's roster. /// </summary> /// <param name="jid">The JID of the roster item to remove.</param> /// <exception cref="ArgumentNullException">The jid parameter is null.</exception> /// <exception cref="IOException">There was a failure while writing to or reading /// from the network.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is not /// connected to a remote host, or the XmppClient instance has not authenticated with /// the XMPP server.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object has been /// disposed.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> public void RemoveContact(Jid jid) { AssertValid(); jid.ThrowIfNull("jid"); // This removes the contact from the user's roster AND also cancels any // subscriptions. im.RemoveFromRoster(jid); }
/// <summary> /// Adds the contact with the specified JID to the user's roster. /// </summary> /// <param name="jid">The JID of the contact to add to the user's roster.</param> /// <param name="name">The nickname with which to associate the contact.</param> /// <param name="groups">An array of groups or categories the new contact /// will be added to.</param> /// <remarks>This method creates a new item on the user's roster and requests /// a subscription from the contact with the specified JID.</remarks> /// <exception cref="ArgumentNullException">The jid parameter is null.</exception> /// <exception cref="IOException">There was a failure while writing to or reading /// from the network.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is not /// connected to a remote host, or the XmppClient instance has not authenticated with /// the XMPP server.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object has been /// disposed.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> public void AddContact(Jid jid, string name = null, params string[] groups) { AssertValid(); jid.ThrowIfNull("jid"); // Create a roster item for the new contact. im.AddToRoster(new RosterItem(jid, name, groups)); // Request a subscription from the contact. im.RequestSubscription(jid); }
/// <summary> /// Sends a chat message with the specified content to the specified JID. /// </summary> /// <param name="to">The JID of the intended recipient.</param> /// <param name="bodies">A dictionary of message bodies. The dictionary /// keys denote the languages of the message bodies and must be valid /// ISO 2 letter language codes.</param> /// <param name="subjects">A dictionary of message subjects. The dictionary /// keys denote the languages of the message subjects and must be valid /// ISO 2 letter language codes.</param> /// <param name="thread">The conversation thread the message belongs to.</param> /// <param name="type">The type of the message. Can be one of the values from /// the MessagType enumeration.</param> /// <param name="language">The language of the XML character data of /// the stanza.</param> /// <exception cref="ArgumentNullException">The to parameter or the bodies /// parameter is null.</exception> /// <exception cref="IOException">There was a failure while writing to or reading /// from the network.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is not /// connected to a remote host, or the XmppClient instance has not authenticated with /// the XMPP server.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object has been /// disposed.</exception> /// <remarks> /// An XMPP chat-message may contain multiple subjects and bodies in different /// languages. Use this method in order to send a message that contains copies of the /// message content in several distinct languages. /// </remarks> /// <include file='Examples.xml' path='S22/Xmpp/Client/XmppClient[@name="SendMessage-2"]/*'/> public void SendMessage(Jid to, IDictionary<string, string> bodies, IDictionary<string, string> subjects = null, string thread = null, MessageType type = MessageType.Normal, CultureInfo language = null) { AssertValid(); to.ThrowIfNull("to"); bodies.ThrowIfNull("bodies"); im.SendMessage(to, bodies, subjects, thread, type, language); }
/// <summary> /// Sends a chat message with the specified content to the specified JID. /// </summary> /// <param name="to">The JID of the intended recipient.</param> /// <param name="body">The content of the message.</param> /// <param name="subject">The subject of the message.</param> /// <param name="thread">The conversation thread the message belongs to.</param> /// <param name="type">The type of the message. Can be one of the values from /// the MessagType enumeration.</param> /// <param name="language">The language of the XML character data of /// the stanza.</param> /// <exception cref="ArgumentNullException">The to parameter or the body parameter /// is null.</exception> /// <exception cref="ArgumentException">The body parameter is the empty /// string.</exception> /// <exception cref="IOException">There was a failure while writing to or reading /// from the network.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is not /// connected to a remote host, or the XmppClient instance has not authenticated with /// the XMPP server.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object has been /// disposed.</exception> /// <include file='Examples.xml' path='S22/Xmpp/Client/XmppClient[@name="SendMessage-1"]/*'/> public void SendMessage(Jid to, string body, string subject = null, string thread = null, MessageType type = MessageType.Normal, CultureInfo language = null) { AssertValid(); to.ThrowIfNull("to"); body.ThrowIfNullOrEmpty("body"); im.SendMessage(to, body, subject, thread, type, language); }
/// <summary> /// Unblocks all communication to and from the XMPP entity with the specified /// JID. /// </summary> /// <param name="jid">The JID of the XMPP entity to unblock.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> /// <exception cref="NotSupportedException">The server does not support the /// 'Blocking Command' extension and does not support privacy-list management. /// </exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is /// not connected to a remote host.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is /// not connected to a remote host.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object /// has been disposed.</exception> public void Unblock(Jid jid) { AssertValid(); jid.ThrowIfNull("jid"); // If our server supports the 'Blocking Command' extension, we can just // use that. if (block.Supported) block.Unblock(jid); else { // Privacy list blocking. If our server doesn't support privacy lists, we're // out of luck. PrivacyList privacyList = null; string name = im.GetDefaultPrivacyList(); if (name != null) privacyList = im.GetPrivacyList(name); // If no default list has been set, look for a 'blocklist' list. foreach (var list in im.GetPrivacyLists()) { if (list.Name == "blocklist") privacyList = list; } // No blocklist found. if (privacyList == null) return; ISet<JidPrivacyRule> set = new HashSet<JidPrivacyRule>(); foreach (var rule in privacyList) { if (rule is JidPrivacyRule) { var jidRule = rule as JidPrivacyRule; if (jidRule.Jid == jid && jidRule.Allow == false) set.Add(jidRule); } } foreach (var rule in set) privacyList.Remove(rule); // Save the privacy list and activate it. if (privacyList.Count == 0) { im.SetDefaultPrivacyList(); im.RemovePrivacyList(privacyList.Name); } else { im.EditPrivacyList(privacyList); im.SetDefaultPrivacyList(privacyList.Name); } } }
/// <summary> /// Blocks all communication to and from the XMPP entity with the specified JID. /// </summary> /// <param name="jid">The JID of the XMPP entity to block.</param> /// <exception cref="ArgumentNullException">The jid parameter is /// null.</exception> /// <exception cref="NotSupportedException">The server does not support the /// 'Blocking Command' extension and does not support privacy-list management. /// </exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is /// not connected to a remote host.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object /// has been disposed.</exception> public void Block(Jid jid) { AssertValid(); jid.ThrowIfNull("jid"); // If our server supports the 'Blocking Command' extension, we can just // use that. if (block.Supported) block.Block(jid); else { // Privacy list blocking. If our server doesn't support privacy lists, we're // out of luck. PrivacyList privacyList = null; string name = im.GetDefaultPrivacyList(); if (name != null) privacyList = im.GetPrivacyList(name); // If no default list has been set, look for a 'blocklist' list. foreach (var list in im.GetPrivacyLists()) { if (list.Name == "blocklist") privacyList = list; } // If 'blocklist' doesn't exist, create it and set it as default. if (privacyList == null) privacyList = new PrivacyList("blocklist"); privacyList.Add(new JidPrivacyRule(jid, false, 0), true); // Save the privacy list and activate it. im.EditPrivacyList(privacyList); im.SetDefaultPrivacyList(privacyList.Name); im.SetActivePrivacyList(privacyList.Name); } }
/// <summary> /// Cancels the specified file-transfer. /// </summary> /// <param name="from">From Jid</param> /// <param name="sid">Sid</param> /// <param name="to">To Jid</param> /// <exception cref="ArgumentNullException">The transfer parameter is /// null.</exception> /// <exception cref="ArgumentException">The specified transfer instance does /// not represent an active data-transfer operation.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is not /// connected to a remote host, or the XmppClient instance has not authenticated with /// the XMPP server.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object has been /// disposed.</exception> public void CancelFileTransfer(string sid, Jid from, Jid to) { #if DEBUG System.Diagnostics.Debug.WriteLine("XmppClient CancelFileTransfer, sid {0}, from {1}, to {2}", sid, from.ToString(), to.ToString()); #endif AssertValid(); sid.ThrowIfNullOrEmpty("sid"); from.ThrowIfNull("from"); to.ThrowIfNull("to"); siFileTransfer.CancelFileTransfer(sid, from, to); }
/// <summary> /// Initializes a new instance of the SubscriptionRefusedEventArgs class. /// </summary> /// <exception cref="ArgumentNullException">The jid parameter is null.</exception> public SubscriptionRefusedEventArgs(Jid jid) { jid.ThrowIfNull("jid"); Jid = jid; }
/// <summary> /// Cancels the specified file-transfer. /// </summary> /// <param name="from">From Jid</param> /// <param name="sid">Sid</param> /// <param name="to">To Jid</param> /// <exception cref="ArgumentNullException">The transfer parameter is /// null.</exception> /// <exception cref="ArgumentException">The specified transfer instance does /// not represent an active data-transfer operation.</exception> public void CancelFileTransfer(string sid, Jid from, Jid to) { sid.ThrowIfNullOrEmpty("sid"); from.ThrowIfNull("from"); to.ThrowIfNull("to"); SISession session = GetSession(sid, from, to); if (session == null) { throw new ArgumentException(String.Format("The specified transfer instance does not " + "represent an active data-transfer operation.:sid {0}, file {1}, from {2}, to {3}", session.Sid, session.Stream.ToString(), session.From, session.To)); } session.Extension.CancelTransfer(session); }
/// <summary> /// Initializes a new instance of the SISession class. /// </summary> /// <param name="sid">The identifier of the session.</param> /// <param name="stream">The IO-stream from which data is read, or to /// which data is written.</param> /// <param name="size">The total number of bytes to read from, or to /// write to the stream.</param> /// <param name="receiving">true if data is being received over the session; /// Otherwise false.</param> /// <param name="from">The JID of the XMPP entity that wishes to send data.</param> /// <param name="to">The JID of the XMPP entity that wishes to receive /// data.</param> /// <param name="extension">The instance of the data-stream extension /// negotiated during session-initiation.</param> /// <exception cref="ArgumentNullException">The sid parameter or the stream /// parameter or the from parameter or the to parameter or the extension /// parameter is null.</exception> /// <exception cref="ArgumentException">The receiving parameter is true, but /// the specified stream cannot be written, or the receiving parameter is /// false, but the specified stream cannot be read.</exception> /// <exception cref="ArgumentOutOfRangeException">The size parameter is /// negative.</exception> public SISession(string sid, Stream stream, long size, bool receiving, Jid from, Jid to, IDataStream extension) { sid.ThrowIfNull("sid"); stream.ThrowIfNull("stream"); size.ThrowIfOutOfRange(0, Int64.MaxValue); from.ThrowIfNull("from"); to.ThrowIfNull("to"); extension.ThrowIfNull("extension"); if (receiving && !stream.CanWrite) throw new ArgumentException("The specified stream cannot be written."); if (!receiving && !stream.CanRead) throw new ArgumentException("The specified stream cannot be read."); Sid = sid; Stream = stream; Size = size; Count = 0; Receiving = receiving; From = from; To = to; Extension = extension; }
/// <summary> /// Add a Jid value to this form /// </summary> /// <param name="name">The name of the value</param> /// <param name="value">The value to add</param> /// <returns>This data form</returns> public DataForm AddValue(string name, Jid value) { value.ThrowIfNull(); Element.Child(new JidField(name, value).ToXmlElement()); return this; }