From 46cc5b763151cb1b6541fa3bad271ae0b458b357 Mon Sep 17 00:00:00 2001 From: Ignacio Nicolas Rodriguez Date: Mon, 27 Apr 2015 22:31:57 +0800 Subject: [PATCH 1/2] Fixed references so they work on NuGet/VStudio 2013 --- Sharp.Xmpp.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sharp.Xmpp.csproj b/Sharp.Xmpp.csproj index 961864b9..3a4e6261 100644 --- a/Sharp.Xmpp.csproj +++ b/Sharp.Xmpp.csproj @@ -53,8 +53,8 @@ - False - ..\pstath\MomentumApp\androidview\momentumandroidui\packages\ARSoft.Tools.Net.1.8.1\lib\ARSoft.Tools.Net.dll + packages\ARSoft.Tools.Net.1.8.1\lib\ARSoft.Tools.Net.dll + True From 5f734189334a634b7fee080584f4bd0a529885ef Mon Sep 17 00:00:00 2001 From: Ignacio Nicolas Rodriguez Date: Mon, 27 Apr 2015 22:53:46 +0800 Subject: [PATCH 2/2] XEP-0280 Message Carbons is implemented --- Client/XmppClient.cs | 5 + Extensions/Extension.cs | 234 +++++++++++++------------- Extensions/XEP-0280/MessageCarbons.cs | 51 ++++++ Sharp.Xmpp.csproj | 2 + 4 files changed, 178 insertions(+), 114 deletions(-) create mode 100644 Extensions/XEP-0280/MessageCarbons.cs diff --git a/Client/XmppClient.cs b/Client/XmppClient.cs index 157c024f..db3b62e5 100644 --- a/Client/XmppClient.cs +++ b/Client/XmppClient.cs @@ -124,6 +124,10 @@ public class XmppClient : IDisposable { /// Provides vcard Based Avatar functionality /// vCardAvatars vcardAvatars; + /// + /// Provides the Message Carbons extension + /// + MessageCarbons messageCarbons; /// /// The hostname of the XMPP server to connect to. @@ -1573,6 +1577,7 @@ void LoadExtensions() { FileTransferSettings = new FileTransferSettings(socks5Bytestreams, siFileTransfer); serverIpCheck = im.LoadExtension(); + messageCarbons = im.LoadExtension(); inBandRegistration = im.LoadExtension(); chatStateNotifications = im.LoadExtension(); bitsOfBinary = im.LoadExtension(); diff --git a/Extensions/Extension.cs b/Extensions/Extension.cs index 899a8c6a..8a257577 100644 --- a/Extensions/Extension.cs +++ b/Extensions/Extension.cs @@ -3,118 +3,119 @@ namespace Sharp.Xmpp.Extensions { /// /// An enumeration of supported XMPP extensions. /// - public enum Extension { - /// - /// An extension for discovering information about other XMPP entities. - /// - /// Defined in XEP-0030. - ServiceDiscovery, - /// - /// An extension for retrieving information about the software application - /// associated with an XMPP entity. - /// - SoftwareVersion, - /// - /// An extension for broadcasting and dynamically discovering client, - /// device, or generic entity capabilities. - /// - EntityCapabilities, - /// - /// An extension for sending application-level pings over XML streams. - /// - Ping, - /// - /// An extension for getting the attention of another user. - /// - Attention, - /// - /// An extension for communicating the local time of an entity. - /// - EntityTime, - /// - /// An extension for communications blocking that is intended to be - /// simpler than privacy lists. - /// - BlockingCommand, - /// - /// An extension for publishing and subscribing to broadcast state change - /// events associated with an instant messaging and presence account. - /// - PersonalEventingProcotol, - /// - /// An extension for communicating information about music to which a user - /// is listening, including the title, track number, length and others. - /// - UserTune, - /// - /// An extension for exchanging user avatars, which are small images or - /// icons associated with human users. - /// - UserAvatar, - /// - /// An extension for for communicating information about user moods, such - /// as whether a person is currently happy, sad, angy, or annoyed. - /// - UserMood, - /// - /// An extension extension for data forms that can be used in workflows - /// such as service configuration as well as for application-specific - /// data description and reporting. - /// - DataForms, - /// - /// An extension that enables two entities to mutually negotiate feature - /// options, such as parameters related to a file transfer or a - /// communications session. - /// - FeatureNegotiation, - /// - /// An extension for initiating a data stream between any two XMPP - /// entities. - /// - StreamInitiation, - /// - /// An extension for transferring files between two entities. - /// - SIFileTransfer, - /// - /// An extension that enables any two entities to establish a one-to-one - /// bytestream between themselves, where the data is broken down into - /// smaller chunks and transported in-band over XMPP. - /// - InBandBytestreams, - /// - /// An extension for communicating information about user activities, - /// such as whether a person is currently working, travelling, or - /// relaxing. - /// - UserActivity, - /// - /// An extension for establishing an out-of-band bytestream between any - /// two XMPP users, mainly for the purpose of file transfer. - /// - Socks5Bytestreams, - /// - /// An extension that enables a client to discover its external IP - /// address. - /// - ServerIpCheck, - /// - /// An extension for in-band registration with XMPP-based instant messaging - /// servers and other services hosted on an XMPP network. - /// - InBandRegistration, - /// - /// An extension for including or referring to small bits of binary data in - /// an XML stanza. - /// - BitsOfBinary, - /// - /// An extension for communicating the status of a user in a chat session, - /// thus indicating whether a chat partner is actively engaged in the chat, - /// composing a message, temporarily paused, inactive, or gone. - /// - ChatStateNotifications, + public enum Extension + { + /// + /// An extension for discovering information about other XMPP entities. + /// + /// Defined in XEP-0030. + ServiceDiscovery, + /// + /// An extension for retrieving information about the software application + /// associated with an XMPP entity. + /// + SoftwareVersion, + /// + /// An extension for broadcasting and dynamically discovering client, + /// device, or generic entity capabilities. + /// + EntityCapabilities, + /// + /// An extension for sending application-level pings over XML streams. + /// + Ping, + /// + /// An extension for getting the attention of another user. + /// + Attention, + /// + /// An extension for communicating the local time of an entity. + /// + EntityTime, + /// + /// An extension for communications blocking that is intended to be + /// simpler than privacy lists. + /// + BlockingCommand, + /// + /// An extension for publishing and subscribing to broadcast state change + /// events associated with an instant messaging and presence account. + /// + PersonalEventingProcotol, + /// + /// An extension for communicating information about music to which a user + /// is listening, including the title, track number, length and others. + /// + UserTune, + /// + /// An extension for exchanging user avatars, which are small images or + /// icons associated with human users. + /// + UserAvatar, + /// + /// An extension for for communicating information about user moods, such + /// as whether a person is currently happy, sad, angy, or annoyed. + /// + UserMood, + /// + /// An extension extension for data forms that can be used in workflows + /// such as service configuration as well as for application-specific + /// data description and reporting. + /// + DataForms, + /// + /// An extension that enables two entities to mutually negotiate feature + /// options, such as parameters related to a file transfer or a + /// communications session. + /// + FeatureNegotiation, + /// + /// An extension for initiating a data stream between any two XMPP + /// entities. + /// + StreamInitiation, + /// + /// An extension for transferring files between two entities. + /// + SIFileTransfer, + /// + /// An extension that enables any two entities to establish a one-to-one + /// bytestream between themselves, where the data is broken down into + /// smaller chunks and transported in-band over XMPP. + /// + InBandBytestreams, + /// + /// An extension for communicating information about user activities, + /// such as whether a person is currently working, travelling, or + /// relaxing. + /// + UserActivity, + /// + /// An extension for establishing an out-of-band bytestream between any + /// two XMPP users, mainly for the purpose of file transfer. + /// + Socks5Bytestreams, + /// + /// An extension that enables a client to discover its external IP + /// address. + /// + ServerIpCheck, + /// + /// An extension for in-band registration with XMPP-based instant messaging + /// servers and other services hosted on an XMPP network. + /// + InBandRegistration, + /// + /// An extension for including or referring to small bits of binary data in + /// an XML stanza. + /// + BitsOfBinary, + /// + /// An extension for communicating the status of a user in a chat session, + /// thus indicating whether a chat partner is actively engaged in the chat, + /// composing a message, temporarily paused, inactive, or gone. + /// + ChatStateNotifications, /// /// An extestion for downloading-uploading avatar vcard data /// @@ -122,6 +123,11 @@ public enum Extension { /// /// Wrapper for providing Custom IQ Extensions /// - CustomIqExtension - } + CustomIqExtension, + /// + /// An extension for receiving messages directed to the bare Jid + /// on multiple resources that have opted-in + /// + MessageCarbons + } } diff --git a/Extensions/XEP-0280/MessageCarbons.cs b/Extensions/XEP-0280/MessageCarbons.cs new file mode 100644 index 00000000..ed9d9c4d --- /dev/null +++ b/Extensions/XEP-0280/MessageCarbons.cs @@ -0,0 +1,51 @@ +using Sharp.Xmpp.Core; +using Sharp.Xmpp.Im; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sharp.Xmpp.Extensions +{ + internal class MessageCarbons: XmppExtension + { + static readonly string[] _namespaces = { "urn:xmpp:carbons:2" }; + private EntityCapabilities ecapa; + + public override IEnumerable Namespaces + { + get { return _namespaces; } + } + + public override Extension Xep + { + get { return Extension.MessageCarbons; } + } + + public override void Initialize() + { + ecapa = im.GetExtension(); + } + + public void EnableCarbons(bool enable = true) + { + if (!ecapa.Supports(im.Jid.Domain, Extension.MessageCarbons)) + { + throw new NotSupportedException("The XMPP server does not support " + + "the 'Message Carbons' extension."); + } + var iq = im.IqRequest(IqType.Set, null, im.Jid, + Xml.Element(enable ? "enable" : "disable", _namespaces[0])); + if (iq.Type == IqType.Error) + throw Util.ExceptionFromError(iq, "Message Carbons could not " + + "be enabled."); + } + + public MessageCarbons(XmppIm im) : + base(im) + { + ; + } + } +} diff --git a/Sharp.Xmpp.csproj b/Sharp.Xmpp.csproj index 3a4e6261..01b9e0bc 100644 --- a/Sharp.Xmpp.csproj +++ b/Sharp.Xmpp.csproj @@ -154,6 +154,7 @@ + @@ -232,6 +233,7 @@ +