Skip to content

Commit

Permalink
Merge pull request smiley22#2 from ignacionr/master
Browse files Browse the repository at this point in the history
XEP-0280 Message Carbons
  • Loading branch information
pgstath committed May 24, 2015
2 parents bc8b2ae + 5f73418 commit 0b54da4
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 116 deletions.
5 changes: 5 additions & 0 deletions Client/XmppClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public class XmppClient : IDisposable {
/// Provides vcard Based Avatar functionality
/// </summary>
vCardAvatars vcardAvatars;
/// <summary>
/// Provides the Message Carbons extension
/// </summary>
MessageCarbons messageCarbons;

/// <summary>
/// The hostname of the XMPP server to connect to.
Expand Down Expand Up @@ -1573,6 +1577,7 @@ void LoadExtensions() {
FileTransferSettings = new FileTransferSettings(socks5Bytestreams,
siFileTransfer);
serverIpCheck = im.LoadExtension<ServerIpCheck>();
messageCarbons = im.LoadExtension<MessageCarbons>();
inBandRegistration = im.LoadExtension<InBandRegistration>();
chatStateNotifications = im.LoadExtension<ChatStateNotifications>();
bitsOfBinary = im.LoadExtension<BitsOfBinary>();
Expand Down
234 changes: 120 additions & 114 deletions Extensions/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,125 +3,131 @@ namespace Sharp.Xmpp.Extensions {
/// <summary>
/// An enumeration of supported XMPP extensions.
/// </summary>
public enum Extension {
/// <summary>
/// An extension for discovering information about other XMPP entities.
/// </summary>
/// <remarks>Defined in XEP-0030.</remarks>
ServiceDiscovery,
/// <summary>
/// An extension for retrieving information about the software application
/// associated with an XMPP entity.
/// </summary>
SoftwareVersion,
/// <summary>
/// An extension for broadcasting and dynamically discovering client,
/// device, or generic entity capabilities.
/// </summary>
EntityCapabilities,
/// <summary>
/// An extension for sending application-level pings over XML streams.
/// </summary>
Ping,
/// <summary>
/// An extension for getting the attention of another user.
/// </summary>
Attention,
/// <summary>
/// An extension for communicating the local time of an entity.
/// </summary>
EntityTime,
/// <summary>
/// An extension for communications blocking that is intended to be
/// simpler than privacy lists.
/// </summary>
BlockingCommand,
/// <summary>
/// An extension for publishing and subscribing to broadcast state change
/// events associated with an instant messaging and presence account.
/// </summary>
PersonalEventingProcotol,
/// <summary>
/// An extension for communicating information about music to which a user
/// is listening, including the title, track number, length and others.
/// </summary>
UserTune,
/// <summary>
/// An extension for exchanging user avatars, which are small images or
/// icons associated with human users.
/// </summary>
UserAvatar,
/// <summary>
/// An extension for for communicating information about user moods, such
/// as whether a person is currently happy, sad, angy, or annoyed.
/// </summary>
UserMood,
/// <summary>
/// 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.
/// </summary>
DataForms,
/// <summary>
/// An extension that enables two entities to mutually negotiate feature
/// options, such as parameters related to a file transfer or a
/// communications session.
/// </summary>
FeatureNegotiation,
/// <summary>
/// An extension for initiating a data stream between any two XMPP
/// entities.
/// </summary>
StreamInitiation,
/// <summary>
/// An extension for transferring files between two entities.
/// </summary>
SIFileTransfer,
/// <summary>
/// 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.
/// </summary>
InBandBytestreams,
/// <summary>
/// An extension for communicating information about user activities,
/// such as whether a person is currently working, travelling, or
/// relaxing.
/// </summary>
UserActivity,
/// <summary>
/// An extension for establishing an out-of-band bytestream between any
/// two XMPP users, mainly for the purpose of file transfer.
/// </summary>
Socks5Bytestreams,
/// <summary>
/// An extension that enables a client to discover its external IP
/// address.
/// </summary>
ServerIpCheck,
/// <summary>
/// An extension for in-band registration with XMPP-based instant messaging
/// servers and other services hosted on an XMPP network.
/// </summary>
InBandRegistration,
/// <summary>
/// An extension for including or referring to small bits of binary data in
/// an XML stanza.
/// </summary>
BitsOfBinary,
/// <summary>
/// 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.
/// </summary>
ChatStateNotifications,
public enum Extension
{
/// <summary>
/// An extension for discovering information about other XMPP entities.
/// </summary>
/// <remarks>Defined in XEP-0030.</remarks>
ServiceDiscovery,
/// <summary>
/// An extension for retrieving information about the software application
/// associated with an XMPP entity.
/// </summary>
SoftwareVersion,
/// <summary>
/// An extension for broadcasting and dynamically discovering client,
/// device, or generic entity capabilities.
/// </summary>
EntityCapabilities,
/// <summary>
/// An extension for sending application-level pings over XML streams.
/// </summary>
Ping,
/// <summary>
/// An extension for getting the attention of another user.
/// </summary>
Attention,
/// <summary>
/// An extension for communicating the local time of an entity.
/// </summary>
EntityTime,
/// <summary>
/// An extension for communications blocking that is intended to be
/// simpler than privacy lists.
/// </summary>
BlockingCommand,
/// <summary>
/// An extension for publishing and subscribing to broadcast state change
/// events associated with an instant messaging and presence account.
/// </summary>
PersonalEventingProcotol,
/// <summary>
/// An extension for communicating information about music to which a user
/// is listening, including the title, track number, length and others.
/// </summary>
UserTune,
/// <summary>
/// An extension for exchanging user avatars, which are small images or
/// icons associated with human users.
/// </summary>
UserAvatar,
/// <summary>
/// An extension for for communicating information about user moods, such
/// as whether a person is currently happy, sad, angy, or annoyed.
/// </summary>
UserMood,
/// <summary>
/// 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.
/// </summary>
DataForms,
/// <summary>
/// An extension that enables two entities to mutually negotiate feature
/// options, such as parameters related to a file transfer or a
/// communications session.
/// </summary>
FeatureNegotiation,
/// <summary>
/// An extension for initiating a data stream between any two XMPP
/// entities.
/// </summary>
StreamInitiation,
/// <summary>
/// An extension for transferring files between two entities.
/// </summary>
SIFileTransfer,
/// <summary>
/// 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.
/// </summary>
InBandBytestreams,
/// <summary>
/// An extension for communicating information about user activities,
/// such as whether a person is currently working, travelling, or
/// relaxing.
/// </summary>
UserActivity,
/// <summary>
/// An extension for establishing an out-of-band bytestream between any
/// two XMPP users, mainly for the purpose of file transfer.
/// </summary>
Socks5Bytestreams,
/// <summary>
/// An extension that enables a client to discover its external IP
/// address.
/// </summary>
ServerIpCheck,
/// <summary>
/// An extension for in-band registration with XMPP-based instant messaging
/// servers and other services hosted on an XMPP network.
/// </summary>
InBandRegistration,
/// <summary>
/// An extension for including or referring to small bits of binary data in
/// an XML stanza.
/// </summary>
BitsOfBinary,
/// <summary>
/// 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.
/// </summary>
ChatStateNotifications,
/// <summary>
/// An extestion for downloading-uploading avatar vcard data
/// </summary>
vCardsAvatars,
/// <summary>
/// Wrapper for providing Custom IQ Extensions
/// </summary>
CustomIqExtension
}
CustomIqExtension,
/// <summary>
/// An extension for receiving messages directed to the bare Jid
/// on multiple resources that have opted-in
/// </summary>
MessageCarbons
}
}
51 changes: 51 additions & 0 deletions Extensions/XEP-0280/MessageCarbons.cs
Original file line number Diff line number Diff line change
@@ -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<string> Namespaces
{
get { return _namespaces; }
}

public override Extension Xep
{
get { return Extension.MessageCarbons; }
}

public override void Initialize()
{
ecapa = im.GetExtension<EntityCapabilities>();
}

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)
{
;
}
}
}
6 changes: 4 additions & 2 deletions Sharp.Xmpp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="ARSoft.Tools.Net, Version=1.8.1.0, Culture=neutral, PublicKeyToken=1940454cd762ec57, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\pstath\MomentumApp\androidview\momentumandroidui\packages\ARSoft.Tools.Net.1.8.1\lib\ARSoft.Tools.Net.dll</HintPath>
<HintPath>packages\ARSoft.Tools.Net.1.8.1\lib\ARSoft.Tools.Net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -154,6 +154,7 @@
<Compile Include="Extensions\XEP-0231\BitsOfBinary.cs" />
<Compile Include="Extensions\XEP-0231\BobData.cs" />
<Compile Include="Extensions\XEP-0279\ServerIpCheck.cs" />
<Compile Include="Extensions\XEP-0280\MessageCarbons.cs" />
<Compile Include="Im\SubscriptionRequest.cs" />
<Compile Include="XmppDisconnectionException.cs" />
<Compile Include="XmppExceptions.cs" />
Expand Down Expand Up @@ -232,6 +233,7 @@
<None Include="ReleaseNotes.md" />
<None Include="UPNPLib" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 0b54da4

Please sign in to comment.