mirror of
https://github.com/ONLYOFFICE/XMPPServer.git
synced 2025-04-18 14:44:10 +03:00
initial commit
This commit is contained in:
commit
08556dff87
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
**/obj/
|
||||
**/bin/
|
||||
/packages/
|
||||
*.suo
|
||||
*.user
|
||||
build/*.log
|
||||
build/deploy
|
||||
.vs/
|
||||
.vscode/
|
||||
ASC.Xmpp.Server.Launcher/Logs
|
701
ASC.Xmpp.Core/ASC.Xmpp.Core.csproj
Normal file
701
ASC.Xmpp.Core/ASC.Xmpp.Core.csproj
Normal file
@ -0,0 +1,701 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{91EA0D0B-D3BA-497F-AFEB-2CAD59DEBA0E}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<AssemblyName>ASC.Xmpp.Core</AssemblyName>
|
||||
<DelaySign>false</DelaySign>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>ASC.Xmpp.Core</RootNamespace>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<TrunkDir>..\..\..\</TrunkDir>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
<IsWebBootstrapper>true</IsWebBootstrapper>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>http://localhost/ASC.Xmpp/</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Web</InstallFrom>
|
||||
<UpdateEnabled>true</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<OutputPath>$(TrunkDir)web\studio\ASC.Web.Studio\bin\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;DEBUG;SSL;WIN32;NET_2;STRINGPREP</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
<Optimize>false</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;SSL;WIN32;NET_2;STRINGPREP</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
<Optimize>true</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>none</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ASC.Common">
|
||||
<HintPath>..\redistributable\ASC.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
</Reference>
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.XML</Name>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="protocol\iq\chatmarkers\Chatmarkers.cs" />
|
||||
<Compile Include="utils\exceptions\JidException.cs" />
|
||||
<Compile Include="protocol\Id.cs" />
|
||||
<Compile Include="utils\Idn\CombiningClass.cs" />
|
||||
<Compile Include="utils\Idn\Composition.cs" />
|
||||
<Compile Include="utils\Idn\DecompositionKeys.cs" />
|
||||
<Compile Include="utils\Idn\DecompositionMappings.cs" />
|
||||
<Compile Include="utils\Idn\IDNA.cs" />
|
||||
<Compile Include="utils\Idn\IDNAException.cs" />
|
||||
<Compile Include="utils\Idn\NFKC.cs" />
|
||||
<Compile Include="utils\Idn\Punycode.cs" />
|
||||
<Compile Include="utils\Idn\PunycodeException.cs" />
|
||||
<Compile Include="utils\Idn\RFC3454.cs" />
|
||||
<Compile Include="utils\Idn\Stringprep.cs" />
|
||||
<Compile Include="utils\Idn\StringprepException.cs" />
|
||||
<Compile Include="protocol\Jid.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Collections\BareJidComparer.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Collections\FullJidComparer.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\exceptions\RegisterException.cs" />
|
||||
<Compile Include="utils\exceptions\XmlRpcException.cs" />
|
||||
<Compile Include="protocol\ElementType.cs" />
|
||||
<Compile Include="IO\Compression\Checksums\Adler32.cs" />
|
||||
<Compile Include="IO\Compression\Checksums\IChecksum.cs" />
|
||||
<Compile Include="IO\Compression\DeflaterConstants.cs" />
|
||||
<Compile Include="IO\Compression\DeflaterEngine.cs" />
|
||||
<Compile Include="IO\Compression\DeflaterHuffman.cs" />
|
||||
<Compile Include="IO\Compression\DeflaterPending.cs" />
|
||||
<Compile Include="IO\Compression\InflaterDynHeader.cs" />
|
||||
<Compile Include="IO\Compression\InflaterHuffmanTree.cs" />
|
||||
<Compile Include="IO\Compression\PendingBuffer.cs" />
|
||||
<Compile Include="IO\Compression\SharpZipBaseException.cs" />
|
||||
<Compile Include="IO\Compression\Streams\StreamManipulator.cs" />
|
||||
<Compile Include="protocol\ElementFactory.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IO\Compression\Deflater.cs" />
|
||||
<Compile Include="IO\Compression\Inflater.cs" />
|
||||
<Compile Include="IO\Compression\Streams\OutputWindow.cs" />
|
||||
<Compile Include="protocol\Base\DirectionalElement.cs" />
|
||||
<Compile Include="protocol\Base\Stanza.cs" />
|
||||
<Compile Include="protocol\client\Handler.cs" />
|
||||
<Compile Include="protocol\client\ShowType.cs" />
|
||||
<Compile Include="protocol\component\Error.cs" />
|
||||
<Compile Include="protocol\component\Handler.cs" />
|
||||
<Compile Include="protocol\component\IQ.cs" />
|
||||
<Compile Include="protocol\component\Message.cs" />
|
||||
<Compile Include="protocol\component\Presence.cs" />
|
||||
<Compile Include="protocol\extensions\amp\Action.cs" />
|
||||
<Compile Include="protocol\extensions\amp\Amp.cs" />
|
||||
<Compile Include="protocol\extensions\amp\Condition.cs" />
|
||||
<Compile Include="protocol\extensions\amp\Rule.cs" />
|
||||
<Compile Include="protocol\extensions\bookmarks\Conference.cs" />
|
||||
<Compile Include="protocol\extensions\bookmarks\Storage.cs" />
|
||||
<Compile Include="protocol\extensions\bookmarks\StorageIq.cs" />
|
||||
<Compile Include="protocol\extensions\bookmarks\Url.cs" />
|
||||
<Compile Include="protocol\extensions\bosh\BoshType.cs" />
|
||||
<Compile Include="protocol\extensions\bytestreams\Activate.cs" />
|
||||
<Compile Include="protocol\extensions\bytestreams\ByteStream.cs" />
|
||||
<Compile Include="protocol\extensions\bytestreams\ByteStreamIq.cs" />
|
||||
<Compile Include="protocol\extensions\bytestreams\Mode.cs" />
|
||||
<Compile Include="protocol\extensions\bytestreams\StreamHost.cs" />
|
||||
<Compile Include="protocol\extensions\bytestreams\StreamHostUsed.cs" />
|
||||
<Compile Include="protocol\extensions\bytestreams\UdpSuccess.cs" />
|
||||
<Compile Include="protocol\extensions\caps\Capabilities.cs" />
|
||||
<Compile Include="protocol\extensions\html\Body.cs" />
|
||||
<Compile Include="protocol\extensions\bosh\Body.cs" />
|
||||
<Compile Include="protocol\extensions\ibb\Base.cs" />
|
||||
<Compile Include="protocol\extensions\ibb\Close.cs" />
|
||||
<Compile Include="protocol\extensions\ibb\Data.cs" />
|
||||
<Compile Include="protocol\extensions\ibb\Open.cs" />
|
||||
<Compile Include="protocol\extensions\msgreceipts\Received.cs" />
|
||||
<Compile Include="protocol\extensions\msgreceipts\Request.cs" />
|
||||
<Compile Include="protocol\extensions\multicast\Address.cs" />
|
||||
<Compile Include="protocol\extensions\multicast\Addresses.cs" />
|
||||
<Compile Include="protocol\extensions\multicast\AddressType.cs" />
|
||||
<Compile Include="protocol\extensions\nickname\Nickname.cs" />
|
||||
<Compile Include="protocol\extensions\ping\Ping.cs" />
|
||||
<Compile Include="protocol\extensions\ping\PingIq.cs" />
|
||||
<Compile Include="protocol\extensions\si\SIIq.cs" />
|
||||
<Compile Include="protocol\iq\agent\Agent.cs" />
|
||||
<Compile Include="protocol\iq\agent\Agents.cs" />
|
||||
<Compile Include="protocol\iq\agent\AgentsIq.cs" />
|
||||
<Compile Include="protocol\iq\blocklist\BlockItem.cs" />
|
||||
<Compile Include="protocol\iq\blocklist\Blocklist.cs" />
|
||||
<Compile Include="protocol\iq\browse\Browse.cs" />
|
||||
<Compile Include="protocol\iq\browse\BrowseIq.cs" />
|
||||
<Compile Include="protocol\iq\browse\BrowseItem.cs" />
|
||||
<Compile Include="protocol\iq\browse\Service.cs" />
|
||||
<Compile Include="protocol\iq\jingle\GoogleJingle.cs" />
|
||||
<Compile Include="protocol\iq\jingle\Jingle.cs" />
|
||||
<Compile Include="protocol\iq\disco\Features.cs" />
|
||||
<Compile Include="protocol\iq\register\RegisterEventArgs.cs" />
|
||||
<Compile Include="protocol\iq\time\EntityTime.cs" />
|
||||
<Compile Include="protocol\iq\vcard\Gender.cs" />
|
||||
<Compile Include="protocol\sasl\TMToken.cs" />
|
||||
<Compile Include="protocol\sasl\FailureCondition.cs" />
|
||||
<Compile Include="protocol\server\Presence.cs" />
|
||||
<Compile Include="protocol\x\muc\Actor.cs" />
|
||||
<Compile Include="protocol\Base\Avatar.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\Base\Group.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\Base\Item.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\Base\RosterItem.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\Base\Stream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\client\Error.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\client\IQ.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\client\Message.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\client\MessageType.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\client\Presence.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\client\PresenceType.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\Stream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\component\Handshake.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\component\Log.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\component\Route.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\chatstates\Active.cs" />
|
||||
<Compile Include="protocol\extensions\chatstates\Chatstate.cs" />
|
||||
<Compile Include="protocol\extensions\chatstates\Composing.cs" />
|
||||
<Compile Include="protocol\extensions\chatstates\Gone.cs" />
|
||||
<Compile Include="protocol\extensions\chatstates\Inactive.cs" />
|
||||
<Compile Include="protocol\extensions\chatstates\Paused.cs" />
|
||||
<Compile Include="protocol\extensions\commands\Action.cs" />
|
||||
<Compile Include="protocol\extensions\commands\Actions.cs" />
|
||||
<Compile Include="protocol\extensions\commands\Command.cs" />
|
||||
<Compile Include="protocol\extensions\commands\Note.cs" />
|
||||
<Compile Include="protocol\extensions\commands\NoteType.cs" />
|
||||
<Compile Include="protocol\extensions\commands\Status.cs" />
|
||||
<Compile Include="protocol\extensions\compression\Compress.cs" />
|
||||
<Compile Include="protocol\extensions\compression\Compressed.cs" />
|
||||
<Compile Include="protocol\extensions\geoloc\GeoLoc.cs" />
|
||||
<Compile Include="protocol\extensions\geoloc\GeoLocIq.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Access.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Affiliation.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\AffiliationType.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Affiliations.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Configure.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Create.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\event\Delete.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\event\Item.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\event\Items.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\event\Purge.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Items.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Options.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Affiliate.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Affiliates.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Delete.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Pending.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\PubSub.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\PubSubIq.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Purge.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Subscriber.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Subscribers.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\SubscribeOptions.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Subscription.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\event\Event.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Item.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\owner\Configure.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Publish.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\PubSubAction.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\PubSub.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\PubSubIq.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Retract.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Subscribe.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Subscriptions.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\SubscriptionState.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Type.cs" />
|
||||
<Compile Include="protocol\extensions\pubsub\Unsubscribe.cs" />
|
||||
<Compile Include="protocol\iq\privacy\Action.cs" />
|
||||
<Compile Include="protocol\iq\privacy\Active.cs" />
|
||||
<Compile Include="protocol\iq\privacy\Stanza.cs" />
|
||||
<Compile Include="protocol\iq\privacy\Default.cs" />
|
||||
<Compile Include="protocol\iq\privacy\Item.cs" />
|
||||
<Compile Include="protocol\iq\privacy\List.cs" />
|
||||
<Compile Include="protocol\iq\privacy\Privacy.cs" />
|
||||
<Compile Include="protocol\iq\privacy\PrivacyIq.cs" />
|
||||
<Compile Include="protocol\iq\privacy\Type.cs" />
|
||||
<Compile Include="protocol\iq\rpc\MethodCall.cs" />
|
||||
<Compile Include="protocol\iq\rpc\MethodResponse.cs" />
|
||||
<Compile Include="protocol\iq\rpc\Rpc.cs" />
|
||||
<Compile Include="protocol\iq\rpc\RpcIq.cs" />
|
||||
<Compile Include="protocol\stream\feature\compression\Compression.cs" />
|
||||
<Compile Include="protocol\extensions\compression\CompressionMethod.cs" />
|
||||
<Compile Include="protocol\extensions\compression\Failure.cs" />
|
||||
<Compile Include="protocol\extensions\html\Html.cs" />
|
||||
<Compile Include="protocol\extensions\jivesoftware\phone\PhoneAction.cs" />
|
||||
<Compile Include="protocol\extensions\jivesoftware\phone\ActionType.cs" />
|
||||
<Compile Include="protocol\extensions\jivesoftware\phone\PhoneEvent.cs" />
|
||||
<Compile Include="protocol\extensions\jivesoftware\phone\PhoneStatusType.cs" />
|
||||
<Compile Include="protocol\extensions\jivesoftware\phone\PhoneStatus.cs" />
|
||||
<Compile Include="protocol\stream\feature\compression\Method.cs" />
|
||||
<Compile Include="protocol\x\data\FieldContainer.cs" />
|
||||
<Compile Include="protocol\x\data\Item.cs" />
|
||||
<Compile Include="protocol\x\data\Reported.cs" />
|
||||
<Compile Include="protocol\x\Event.cs" />
|
||||
<Compile Include="protocol\extensions\featureneg\FeatureNeg.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\featureneg\FeatureNegIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\filetransfer\File.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\filetransfer\Range.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\primary\Primary.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\shim\Header.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\shim\Headers.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\extensions\si\SI.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\auth\Auth.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\auth\AuthIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\avatar\Avatar.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\avatar\AvatarIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\disco\DiscoFeature.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\disco\DiscoIdentity.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\disco\DiscoInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\disco\DiscoInfoIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\disco\DiscoItem.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\disco\DiscoItems.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\disco\DiscoItemsIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\last\Last.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\last\LastIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\oob\Oob.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\oob\OobIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\private\Private.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\private\PrivateIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\register\Register.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\register\RegisterIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\roster\Delimiter.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\roster\Roster.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\roster\RosterIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\roster\RosterItem.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\search\Search.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\search\SearchIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\search\SearchItem.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\time\Time.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\time\TimeIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\Address.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\Email.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\Name.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\Organization.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\Photo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\Telephone.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\Vcard.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\vcard\VcardIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\version\Version.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\version\VersionIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Abort.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Auth.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Challenge.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Failure.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Mechanism.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Mechanisms.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Response.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\sasl\Success.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\storage\Avatar.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\storage\AvatarIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\bind\Bind.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\bind\BindIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\Error.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\stream\Features.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\stream\feature\Register.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\session\Session.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\session\SessionIq.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\tls\Failure.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\tls\Proceed.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\tls\StartTls.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\Avatar.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\Conference.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\data\Data.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\data\Field.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\data\FieldTypes.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\data\Option.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\data\Value.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\Delay.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\muc\Destroy.cs" />
|
||||
<Compile Include="protocol\x\muc\iq\admin\Admin.cs" />
|
||||
<Compile Include="protocol\x\muc\iq\admin\AdminIq.cs" />
|
||||
<Compile Include="protocol\x\muc\iq\admin\Item.cs" />
|
||||
<Compile Include="protocol\x\muc\Affiliation.cs" />
|
||||
<Compile Include="protocol\x\muc\Decline.cs" />
|
||||
<Compile Include="protocol\x\muc\History.cs" />
|
||||
<Compile Include="protocol\x\muc\Invitation.cs" />
|
||||
<Compile Include="protocol\x\muc\Invite.cs" />
|
||||
<Compile Include="protocol\x\muc\iq\owner\Owner.cs" />
|
||||
<Compile Include="protocol\x\muc\iq\owner\OwnerIq.cs" />
|
||||
<Compile Include="protocol\x\muc\iq\Unique.cs" />
|
||||
<Compile Include="protocol\x\muc\Item.cs" />
|
||||
<Compile Include="protocol\x\muc\Muc.cs" />
|
||||
<Compile Include="protocol\x\muc\Status.cs" />
|
||||
<Compile Include="protocol\x\muc\StatusCode.cs" />
|
||||
<Compile Include="protocol\x\muc\iq\UniqueIQ.cs" />
|
||||
<Compile Include="protocol\x\muc\User.cs" />
|
||||
<Compile Include="protocol\x\muc\Role.cs" />
|
||||
<Compile Include="protocol\x\rosterx\RosterItem.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\x\rosterx\RosterX.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\iq\privacy\RuleManager.cs" />
|
||||
<Compile Include="protocol\x\tm\history\History.cs" />
|
||||
<Compile Include="protocol\x\tm\history\HistoryItem.cs" />
|
||||
<Compile Include="protocol\x\tm\history\PrivateLog.cs" />
|
||||
<Compile Include="protocol\x\tm\history\PrivateLogItem.cs" />
|
||||
<Compile Include="protocol\x\vcard_update\VcardUpdate.cs" />
|
||||
<Compile Include="authorization\SaslEventArgs.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="authorization\DigestMD5\Step1.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="authorization\DigestMD5\Step2.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="authorization\Mechanism.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="authorization\Plain\PlainMechanism.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="protocol\Uri.cs" />
|
||||
<Compile Include="utils\Date.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\ElementSerializer.cs" />
|
||||
<Compile Include="utils\Enum.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Hash.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\Dom\Comment.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\Dom\Document.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\Dom\DomLoader.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\Dom\Element.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\Dom\ElementList.cs" />
|
||||
<Compile Include="utils\Xml\Dom\Node.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\Dom\NodeList.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\Dom\Text.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IO\StringWriterWithEncoding.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\StreamParser.cs" />
|
||||
<Compile Include="utils\Xml\xpnet\BufferAggregate.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\xpnet\ContentToken.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\xpnet\Encoding.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\xpnet\Exceptions.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\xpnet\NS.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\xpnet\Position.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\xpnet\Token.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utils\Xml\xpnet\UTF8Encoding.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
160
ASC.Xmpp.Core/IO/Compression/Checksums/Adler32.cs
Normal file
160
ASC.Xmpp.Core/IO/Compression/Checksums/Adler32.cs
Normal file
@ -0,0 +1,160 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression.Checksums
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Computes Adler32 checksum for a stream of data. An Adler32 checksum is not as reliable as a CRC32 checksum, but a lot faster to compute. The specification for Adler32 may be found in RFC 1950. ZLIB Compressed Data Format Specification version 3.3) From that document: "ADLER32 (Adler-32 checksum) This contains a checksum value of the uncompressed data (excluding any dictionary data) computed according to Adler-32 algorithm. This algorithm is a 32-bit extension and improvement of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 standard. Adler-32 is composed of two sums accumulated per byte: s1 is the sum of all bytes, s2 is the sum of all s1 values. Both sums are done modulo 65521. s1 is initialized to 1, s2 to zero. The Adler-32 checksum is stored as s2*65536 + s1 in most- significant-byte first (network) order." "8.2. The Adler-32 algorithm The Adler-32 algorithm is much faster than the CRC32 algorithm yet still provides an extremely low probability of undetected errors. The modulo on unsigned long accumulators can be delayed for 5552 bytes, so the modulo operation time is negligible. If the bytes are a, b, c, the second sum is 3a + 2b + c + 3, and so is position and order sensitive, unlike the first sum, which is just a checksum. That 65521 is prime is important to avoid a possible large class of two-byte errors that leave the check unchanged. (The Fletcher checksum uses 255, which is not prime and which also makes the Fletcher check insensitive to single byte changes 0 - 255.) The sum s1 is initialized to 1 instead of zero to make the length of the sequence part of s2, so that the length does not have to be checked separately. (Any sequence of zeroes has a Fletcher checksum of zero.)"
|
||||
/// </summary>
|
||||
/// <see cref="ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream" />
|
||||
/// <see cref="ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream" />
|
||||
public sealed class Adler32 : IChecksum
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// largest prime smaller than 65536
|
||||
/// </summary>
|
||||
private static readonly uint BASE = 65521;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private uint checksum;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the Adler32 class. The checksum starts off with a value of 1.
|
||||
/// </summary>
|
||||
public Adler32()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Resets the Adler32 checksum to the initial value.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
checksum = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the checksum with the byte b.
|
||||
/// </summary>
|
||||
/// <param name="bval"> The data value to add. The high byte of the int is ignored. </param>
|
||||
public void Update(int bval)
|
||||
{
|
||||
// We could make a length 1 byte array and call update again, but I
|
||||
// would rather not have that overhead
|
||||
uint s1 = checksum & 0xFFFF;
|
||||
uint s2 = checksum >> 16;
|
||||
|
||||
s1 = (s1 + ((uint) bval & 0xFF))%BASE;
|
||||
s2 = (s1 + s2)%BASE;
|
||||
|
||||
checksum = (s2 << 16) + s1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the checksum with an array of bytes.
|
||||
/// </summary>
|
||||
/// <param name="buffer"> The source of the data to update with. </param>
|
||||
public void Update(byte[] buffer)
|
||||
{
|
||||
Update(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the checksum with the bytes taken from the array.
|
||||
/// </summary>
|
||||
/// <param name="buf"> an array of bytes </param>
|
||||
/// <param name="off"> the start of the data used for this update </param>
|
||||
/// <param name="len"> the number of bytes to use for this update </param>
|
||||
public void Update(byte[] buf, int off, int len)
|
||||
{
|
||||
if (buf == null)
|
||||
{
|
||||
throw new ArgumentNullException("buf");
|
||||
}
|
||||
|
||||
if (off < 0 || len < 0 || off + len > buf.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
// (By Per Bothner)
|
||||
uint s1 = checksum & 0xFFFF;
|
||||
uint s2 = checksum >> 16;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
// We can defer the modulo operation:
|
||||
// s1 maximally grows from 65521 to 65521 + 255 * 3800
|
||||
// s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
|
||||
int n = 3800;
|
||||
if (n > len)
|
||||
{
|
||||
n = len;
|
||||
}
|
||||
|
||||
len -= n;
|
||||
while (--n >= 0)
|
||||
{
|
||||
s1 = s1 + (uint) (buf[off++] & 0xFF);
|
||||
s2 = s2 + s1;
|
||||
}
|
||||
|
||||
s1 %= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
|
||||
checksum = (s2 << 16) | s1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IChecksum Members
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Adler32 data checksum computed so far.
|
||||
/// </summary>
|
||||
public long Value
|
||||
{
|
||||
get { return checksum; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
67
ASC.Xmpp.Core/IO/Compression/Checksums/IChecksum.cs
Normal file
67
ASC.Xmpp.Core/IO/Compression/Checksums/IChecksum.cs
Normal file
@ -0,0 +1,67 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression.Checksums
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface to compute a data checksum used by checked input/output streams. A data checksum can be updated by one byte or with a byte array. After each update the value of the current checksum can be returned by calling <code>getValue</code> . The complete checksum object can also be reset so it can be used again with new data.
|
||||
/// </summary>
|
||||
public interface IChecksum
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Returns the data checksum computed so far.
|
||||
/// </summary>
|
||||
long Value { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Resets the data checksum as if no update was ever called.
|
||||
/// </summary>
|
||||
void Reset();
|
||||
|
||||
/// <summary>
|
||||
/// Adds one byte to the data checksum.
|
||||
/// </summary>
|
||||
/// <param name="bval"> the data value to add. The high byte of the int is ignored. </param>
|
||||
void Update(int bval);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the data checksum with the bytes taken from the array.
|
||||
/// </summary>
|
||||
/// <param name="buffer"> buffer an array of bytes </param>
|
||||
void Update(byte[] buffer);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the byte array to the data checksum.
|
||||
/// </summary>
|
||||
/// <param name="buf"> the buffer which contains the data </param>
|
||||
/// <param name="off"> the offset in the buffer where the data starts </param>
|
||||
/// <param name="len"> the length of the data </param>
|
||||
void Update(byte[] buf, int off, int len);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
507
ASC.Xmpp.Core/IO/Compression/Deflater.cs
Normal file
507
ASC.Xmpp.Core/IO/Compression/Deflater.cs
Normal file
@ -0,0 +1,507 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// This is the Deflater class. The deflater class compresses input with the deflate algorithm described in RFC 1951. It has several compression levels and three different strategies described below. This class is <i>not</i> thread safe. This is inherent in the API, due to the split of deflate and setInput. author of the original java version : Jochen Hoenicke
|
||||
/// </summary>
|
||||
public class Deflater
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// The best and slowest compression level. This tries to find very long and distant string repetitions.
|
||||
/// </summary>
|
||||
public static int BEST_COMPRESSION = 9;
|
||||
|
||||
/// <summary>
|
||||
/// The worst but fastest compression level.
|
||||
/// </summary>
|
||||
public static int BEST_SPEED = 1;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int BUSY_STATE = 0x10;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int CLOSED_STATE = 0x7f;
|
||||
|
||||
/// <summary>
|
||||
/// The default compression level.
|
||||
/// </summary>
|
||||
public static int DEFAULT_COMPRESSION = -1;
|
||||
|
||||
/// <summary>
|
||||
/// The compression method. This is the only method supported so far. There is no need to use this constant at all.
|
||||
/// </summary>
|
||||
public static int DEFLATED = 8;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int FINISHED_STATE = 0x1e;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int FINISHING_STATE = 0x1c;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int FLUSHING_STATE = 0x14;
|
||||
|
||||
/*
|
||||
* The Deflater can do the following state transitions:
|
||||
*
|
||||
* (1) -> INIT_STATE ----> INIT_FINISHING_STATE ---.
|
||||
* / | (2) (5) |
|
||||
* / v (5) |
|
||||
* (3)| SETDICT_STATE ---> SETDICT_FINISHING_STATE |(3)
|
||||
* \ | (3) | ,-------'
|
||||
* | | | (3) /
|
||||
* v v (5) v v
|
||||
* (1) -> BUSY_STATE ----> FINISHING_STATE
|
||||
* | (6)
|
||||
* v
|
||||
* FINISHED_STATE
|
||||
* \_____________________________________/
|
||||
* | (7)
|
||||
* v
|
||||
* CLOSED_STATE
|
||||
*
|
||||
* (1) If we should produce a header we start in INIT_STATE, otherwise
|
||||
* we start in BUSY_STATE.
|
||||
* (2) A dictionary may be set only when we are in INIT_STATE, then
|
||||
* we change the state as indicated.
|
||||
* (3) Whether a dictionary is set or not, on the first call of deflate
|
||||
* we change to BUSY_STATE.
|
||||
* (4) -- intentionally left blank -- :)
|
||||
* (5) FINISHING_STATE is entered, when flush() is called to indicate that
|
||||
* there is no more INPUT. There are also states indicating, that
|
||||
* the header wasn't written yet.
|
||||
* (6) FINISHED_STATE is entered, when everything has been flushed to the
|
||||
* internal pending output buffer.
|
||||
* (7) At any time (7)
|
||||
*
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int INIT_STATE = 0;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int IS_FINISHING = 0x08;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int IS_FLUSHING = 0x04;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int IS_SETDICT = 0x01;
|
||||
|
||||
/// <summary>
|
||||
/// This level won't compress at all but output uncompressed blocks.
|
||||
/// </summary>
|
||||
public static int NO_COMPRESSION;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int SETDICT_STATE = 0x01;
|
||||
|
||||
/// <summary>
|
||||
/// The deflater engine.
|
||||
/// </summary>
|
||||
private readonly DeflaterEngine engine;
|
||||
|
||||
// private static int INIT_FINISHING_STATE = 0x08;
|
||||
// private static int SETDICT_FINISHING_STATE = 0x09;
|
||||
|
||||
/// <summary>
|
||||
/// If true no Zlib/RFC1950 headers or footers are generated
|
||||
/// </summary>
|
||||
private readonly bool noZlibHeaderOrFooter;
|
||||
|
||||
/// <summary>
|
||||
/// The pending output.
|
||||
/// </summary>
|
||||
private readonly DeflaterPending pending;
|
||||
|
||||
/// <summary>
|
||||
/// Compression level.
|
||||
/// </summary>
|
||||
private int level;
|
||||
|
||||
/// <summary>
|
||||
/// The current state.
|
||||
/// </summary>
|
||||
private int state;
|
||||
|
||||
/// <summary>
|
||||
/// The total bytes of output written.
|
||||
/// </summary>
|
||||
private long totalOut;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new deflater with default compression level.
|
||||
/// </summary>
|
||||
public Deflater() : this(DEFAULT_COMPRESSION, false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new deflater with given compression level.
|
||||
/// </summary>
|
||||
/// <param name="lvl"> the compression level, a value between NO_COMPRESSION and BEST_COMPRESSION, or DEFAULT_COMPRESSION. </param>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">if lvl is out of range.</exception>
|
||||
public Deflater(int lvl) : this(lvl, false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new deflater with given compression level.
|
||||
/// </summary>
|
||||
/// <param name="level"> the compression level, a value between NO_COMPRESSION and BEST_COMPRESSION. </param>
|
||||
/// <param name="noZlibHeaderOrFooter"> true, if we should suppress the Zlib/RFC1950 header at the beginning and the adler checksum at the end of the output. This is useful for the GZIP/PKZIP formats. </param>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">if lvl is out of range.</exception>
|
||||
public Deflater(int level, bool noZlibHeaderOrFooter)
|
||||
{
|
||||
if (level == DEFAULT_COMPRESSION)
|
||||
{
|
||||
level = 6;
|
||||
}
|
||||
else if (level < NO_COMPRESSION || level > BEST_COMPRESSION)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("level");
|
||||
}
|
||||
|
||||
pending = new DeflaterPending();
|
||||
engine = new DeflaterEngine(pending);
|
||||
this.noZlibHeaderOrFooter = noZlibHeaderOrFooter;
|
||||
SetStrategy(DeflateStrategy.Default);
|
||||
SetLevel(level);
|
||||
Reset();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current adler checksum of the data that was processed so far.
|
||||
/// </summary>
|
||||
public int Adler
|
||||
{
|
||||
get { return engine.Adler; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the stream was finished and no more output bytes are available.
|
||||
/// </summary>
|
||||
public bool IsFinished
|
||||
{
|
||||
get { return state == FINISHED_STATE && pending.IsFlushed; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true, if the input buffer is empty. You should then call setInput(). NOTE: This method can also return true when the stream was finished.
|
||||
/// </summary>
|
||||
public bool IsNeedingInput
|
||||
{
|
||||
get { return engine.NeedsInput(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of input bytes processed so far.
|
||||
/// </summary>
|
||||
public int TotalIn
|
||||
{
|
||||
get { return engine.TotalIn; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of output bytes so far.
|
||||
/// </summary>
|
||||
public long TotalOut
|
||||
{
|
||||
get { return totalOut; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Resets the deflater. The deflater acts afterwards as if it was just created with the same compression level and strategy as it had before.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
state = noZlibHeaderOrFooter ? BUSY_STATE : INIT_STATE;
|
||||
totalOut = 0;
|
||||
pending.Reset();
|
||||
engine.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flushes the current input block. Further calls to deflate() will produce enough output to inflate everything in the current input block. This is not part of Sun's JDK so I have made it package private. It is used by DeflaterOutputStream to implement flush().
|
||||
/// </summary>
|
||||
public void Flush()
|
||||
{
|
||||
state |= IS_FLUSHING;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finishes the deflater with the current input block. It is an error to give more input after this method was called. This method must be called to force all bytes to be flushed.
|
||||
/// </summary>
|
||||
public void Finish()
|
||||
{
|
||||
state |= IS_FLUSHING | IS_FINISHING;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the data which should be compressed next. This should be only called when needsInput indicates that more input is needed. If you call setInput when needsInput() returns false, the previous input that is still pending will be thrown away. The given byte array should not be changed, before needsInput() returns true again. This call is equivalent to <code>setInput(input, 0, input.length)</code> .
|
||||
/// </summary>
|
||||
/// <param name="input"> the buffer containing the input data. </param>
|
||||
/// <exception cref="System.InvalidOperationException">if the buffer was finished() or ended().</exception>
|
||||
public void SetInput(byte[] input)
|
||||
{
|
||||
SetInput(input, 0, input.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the data which should be compressed next. This should be only called when needsInput indicates that more input is needed. The given byte array should not be changed, before needsInput() returns true again.
|
||||
/// </summary>
|
||||
/// <param name="input"> the buffer containing the input data. </param>
|
||||
/// <param name="off"> the start of the data. </param>
|
||||
/// <param name="len"> the length of the data. </param>
|
||||
/// <exception cref="System.InvalidOperationException">if the buffer was finished() or ended() or if previous input is still pending.</exception>
|
||||
public void SetInput(byte[] input, int off, int len)
|
||||
{
|
||||
if ((state & IS_FINISHING) != 0)
|
||||
{
|
||||
throw new InvalidOperationException("finish()/end() already called");
|
||||
}
|
||||
|
||||
engine.SetInput(input, off, len);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the compression level. There is no guarantee of the exact position of the change, but if you call this when needsInput is true the change of compression level will occur somewhere near before the end of the so far given input.
|
||||
/// </summary>
|
||||
/// <param name="lvl"> the new compression level. </param>
|
||||
public void SetLevel(int lvl)
|
||||
{
|
||||
if (lvl == DEFAULT_COMPRESSION)
|
||||
{
|
||||
lvl = 6;
|
||||
}
|
||||
else if (lvl < NO_COMPRESSION || lvl > BEST_COMPRESSION)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("lvl");
|
||||
}
|
||||
|
||||
if (level != lvl)
|
||||
{
|
||||
level = lvl;
|
||||
engine.SetLevel(lvl);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get current compression level
|
||||
/// </summary>
|
||||
/// <returns> Returns the current compression level </returns>
|
||||
public int GetLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the compression strategy. Strategy is one of DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED. For the exact position where the strategy is changed, the same as for setLevel() applies.
|
||||
/// </summary>
|
||||
/// <param name="strategy"> The new compression strategy. </param>
|
||||
public void SetStrategy(DeflateStrategy strategy)
|
||||
{
|
||||
engine.Strategy = strategy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deflates the current input block with to the given array.
|
||||
/// </summary>
|
||||
/// <param name="output"> The buffer where compressed data is stored </param>
|
||||
/// <returns> The number of compressed bytes added to the output, or 0 if either needsInput() or finished() returns true or length is zero. </returns>
|
||||
public int Deflate(byte[] output)
|
||||
{
|
||||
return Deflate(output, 0, output.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deflates the current input block to the given array.
|
||||
/// </summary>
|
||||
/// <param name="output"> Buffer to store the compressed data. </param>
|
||||
/// <param name="offset"> Offset into the output array. </param>
|
||||
/// <param name="length"> The maximum number of bytes that may be stored. </param>
|
||||
/// <returns> The number of compressed bytes added to the output, or 0 if either needsInput() or finished() returns true or length is zero. </returns>
|
||||
/// <exception cref="System.InvalidOperationException">If end() was previously called.</exception>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">If offset and/or length don't match the array length.</exception>
|
||||
public int Deflate(byte[] output, int offset, int length)
|
||||
{
|
||||
int origLength = length;
|
||||
|
||||
if (state == CLOSED_STATE)
|
||||
{
|
||||
throw new InvalidOperationException("Deflater closed");
|
||||
}
|
||||
|
||||
if (state < BUSY_STATE)
|
||||
{
|
||||
/* output header */
|
||||
int header = (DEFLATED + ((DeflaterConstants.MAX_WBITS - 8) << 4)) << 8;
|
||||
int level_flags = (level - 1) >> 1;
|
||||
if (level_flags < 0 || level_flags > 3)
|
||||
{
|
||||
level_flags = 3;
|
||||
}
|
||||
|
||||
header |= level_flags << 6;
|
||||
if ((state & IS_SETDICT) != 0)
|
||||
{
|
||||
/* Dictionary was set */
|
||||
header |= DeflaterConstants.PRESET_DICT;
|
||||
}
|
||||
|
||||
header += 31 - (header%31);
|
||||
|
||||
pending.WriteShortMSB(header);
|
||||
if ((state & IS_SETDICT) != 0)
|
||||
{
|
||||
int chksum = engine.Adler;
|
||||
engine.ResetAdler();
|
||||
pending.WriteShortMSB(chksum >> 16);
|
||||
pending.WriteShortMSB(chksum & 0xffff);
|
||||
}
|
||||
|
||||
state = BUSY_STATE | (state & (IS_FLUSHING | IS_FINISHING));
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int count = pending.Flush(output, offset, length);
|
||||
offset += count;
|
||||
totalOut += count;
|
||||
length -= count;
|
||||
|
||||
if (length == 0 || state == FINISHED_STATE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!engine.Deflate((state & IS_FLUSHING) != 0, (state & IS_FINISHING) != 0))
|
||||
{
|
||||
if (state == BUSY_STATE)
|
||||
{
|
||||
/* We need more input now */
|
||||
return origLength - length;
|
||||
}
|
||||
else if (state == FLUSHING_STATE)
|
||||
{
|
||||
if (level != NO_COMPRESSION)
|
||||
{
|
||||
/* We have to supply some lookahead. 8 bit lookahead
|
||||
* is needed by the zlib inflater, and we must fill
|
||||
* the next byte, so that all bits are flushed.
|
||||
*/
|
||||
int neededbits = 8 + ((-pending.BitCount) & 7);
|
||||
while (neededbits > 0)
|
||||
{
|
||||
/* write a static tree block consisting solely of
|
||||
* an EOF:
|
||||
*/
|
||||
pending.WriteBits(2, 10);
|
||||
neededbits -= 10;
|
||||
}
|
||||
}
|
||||
|
||||
state = BUSY_STATE;
|
||||
}
|
||||
else if (state == FINISHING_STATE)
|
||||
{
|
||||
pending.AlignToByte();
|
||||
|
||||
// Compressed data is complete. Write footer information if required.
|
||||
if (!noZlibHeaderOrFooter)
|
||||
{
|
||||
int adler = engine.Adler;
|
||||
pending.WriteShortMSB(adler >> 16);
|
||||
pending.WriteShortMSB(adler & 0xffff);
|
||||
}
|
||||
|
||||
state = FINISHED_STATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return origLength - length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the dictionary which should be used in the deflate process. This call is equivalent to <code>setDictionary(dict, 0, dict.Length)</code> .
|
||||
/// </summary>
|
||||
/// <param name="dict"> the dictionary. </param>
|
||||
/// <exception cref="System.InvalidOperationException">if setInput () or deflate () were already called or another dictionary was already set.</exception>
|
||||
public void SetDictionary(byte[] dict)
|
||||
{
|
||||
SetDictionary(dict, 0, dict.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the dictionary which should be used in the deflate process. The dictionary is a byte array containing strings that are likely to occur in the data which should be compressed. The dictionary is not stored in the compressed output, only a checksum. To decompress the output you need to supply the same dictionary again.
|
||||
/// </summary>
|
||||
/// <param name="dict"> The dictionary data </param>
|
||||
/// <param name="offset"> An offset into the dictionary. </param>
|
||||
/// <param name="length"> The length of the dictionary data to use </param>
|
||||
/// <exception cref="System.InvalidOperationException">If setInput () or deflate () were already called or another dictionary was already set.</exception>
|
||||
public void SetDictionary(byte[] dict, int offset, int length)
|
||||
{
|
||||
if (state != INIT_STATE)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
state = SETDICT_STATE;
|
||||
engine.SetDictionary(dict, offset, length);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
174
ASC.Xmpp.Core/IO/Compression/DeflaterConstants.cs
Normal file
174
ASC.Xmpp.Core/IO/Compression/DeflaterConstants.cs
Normal file
@ -0,0 +1,174 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// This class contains constants used for deflation.
|
||||
/// </summary>
|
||||
public class DeflaterConstants
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Sets internal buffer sizes for Huffman encoding
|
||||
/// </summary>
|
||||
public const int DEFAULT_MEM_LEVEL = 8;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int DEFLATE_FAST = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int DEFLATE_SLOW = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int DEFLATE_STORED = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Identifies dynamic tree in Zip file
|
||||
/// </summary>
|
||||
public const int DYN_TREES = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int HASH_BITS = DEFAULT_MEM_LEVEL + 7;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int HASH_MASK = HASH_SIZE - 1;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int HASH_SHIFT = (HASH_BITS + MIN_MATCH - 1)/MIN_MATCH;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int HASH_SIZE = 1 << HASH_BITS;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int MAX_DIST = WSIZE - MIN_LOOKAHEAD;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int MAX_MATCH = 258;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int MAX_WBITS = 15;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int MIN_MATCH = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int PENDING_BUF_SIZE = 1 << (DEFAULT_MEM_LEVEL + 8);
|
||||
|
||||
/// <summary>
|
||||
/// Header flag indicating a preset dictionary for deflation
|
||||
/// </summary>
|
||||
public const int PRESET_DICT = 0x20;
|
||||
|
||||
/// <summary>
|
||||
/// Identifies static tree in Zip file
|
||||
/// </summary>
|
||||
public const int STATIC_TREES = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Written to Zip file to identify a stored block
|
||||
/// </summary>
|
||||
public const int STORED_BLOCK = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int WMASK = WSIZE - 1;
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public const int WSIZE = 1 << MAX_WBITS;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public static int[] COMPR_FUNC = {0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public static int[] GOOD_LENGTH = {0, 4, 4, 4, 4, 8, 8, 8, 32, 32};
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public static int MAX_BLOCK_SIZE = Math.Min(65535, PENDING_BUF_SIZE - 5);
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public static int[] MAX_CHAIN = {0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096};
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public static int[] MAX_LAZY = {0, 4, 5, 6, 4, 16, 16, 32, 128, 258};
|
||||
|
||||
/// <summary>
|
||||
/// Internal compression engine constant
|
||||
/// </summary>
|
||||
public static int[] NICE_LENGTH = {0, 8, 16, 32, 16, 32, 128, 128, 258, 258};
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
900
ASC.Xmpp.Core/IO/Compression/DeflaterEngine.cs
Normal file
900
ASC.Xmpp.Core/IO/Compression/DeflaterEngine.cs
Normal file
@ -0,0 +1,900 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.IO.Compression.Checksums;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Strategies for deflater
|
||||
/// </summary>
|
||||
public enum DeflateStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// The default strategy
|
||||
/// </summary>
|
||||
Default = 0,
|
||||
|
||||
/// <summary>
|
||||
/// This strategy will only allow longer string repetitions. It is useful for random data with a small character set.
|
||||
/// </summary>
|
||||
Filtered = 1,
|
||||
|
||||
/// <summary>
|
||||
/// This strategy will not look for string repetitions at all. It only encodes with Huffman trees (which means, that more common characters get a smaller encoding.
|
||||
/// </summary>
|
||||
HuffmanOnly = 2
|
||||
}
|
||||
|
||||
// DEFLATE ALGORITHM:
|
||||
// The uncompressed stream is inserted into the window array. When
|
||||
// the window array is full the first half is thrown away and the
|
||||
// second half is copied to the beginning.
|
||||
// The head array is a hash table. Three characters build a hash value
|
||||
// and they the value points to the corresponding index in window of
|
||||
// the last string with this hash. The prev array implements a
|
||||
// linked list of matches with the same hash: prev[index & WMASK] points
|
||||
// to the previous index with the same hash.
|
||||
|
||||
/// <summary>
|
||||
/// Low level compression engine for deflate algorithm which uses a 32K sliding window with secondary compression from Huffman/Shannon-Fano codes.
|
||||
/// </summary>
|
||||
public class DeflaterEngine : DeflaterConstants
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int TOO_FAR = 4096;
|
||||
|
||||
/// <summary>
|
||||
/// The adler checksum
|
||||
/// </summary>
|
||||
private readonly Adler32 adler;
|
||||
|
||||
/// <summary>
|
||||
/// Hashtable, hashing three characters to an index for window, so that window[index]..window[index+2] have this hash code. Note that the array should really be unsigned short, so you need to and the values with 0xffff.
|
||||
/// </summary>
|
||||
private readonly short[] head;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly DeflaterHuffman huffman;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly DeflaterPending pending;
|
||||
|
||||
/// <summary>
|
||||
/// <code>prev[index & WMASK]</code> points to the previous index that has the same hash code as the string starting at index. This way entries with the same hash code are in a linked list. Note that the array should really be unsigned short, so you need to and the values with 0xffff.
|
||||
/// </summary>
|
||||
private readonly short[] prev;
|
||||
|
||||
/// <summary>
|
||||
/// This array contains the part of the uncompressed stream that is of relevance. The current character is indexed by strstart.
|
||||
/// </summary>
|
||||
private readonly byte[] window;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int blockStart;
|
||||
|
||||
/// <summary>
|
||||
/// The current compression function.
|
||||
/// </summary>
|
||||
private int comprFunc;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int goodLength;
|
||||
|
||||
/// <summary>
|
||||
/// The input data for compression.
|
||||
/// </summary>
|
||||
private byte[] inputBuf;
|
||||
|
||||
/// <summary>
|
||||
/// The end offset of the input data.
|
||||
/// </summary>
|
||||
private int inputEnd;
|
||||
|
||||
/// <summary>
|
||||
/// The offset into inputBuf, where input data starts.
|
||||
/// </summary>
|
||||
private int inputOff;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int ins_h;
|
||||
|
||||
/// <summary>
|
||||
/// lookahead is the number of characters starting at strstart in window that are valid. So window[strstart] until window[strstart+lookahead-1] are valid characters.
|
||||
/// </summary>
|
||||
private int lookahead;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int matchLen;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int matchStart;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int max_chain;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int max_lazy;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int niceLength;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private bool prevAvailable;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private DeflateStrategy strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Points to the current character in the window.
|
||||
/// </summary>
|
||||
private int strstart;
|
||||
|
||||
/// <summary>
|
||||
/// The total bytes of input read.
|
||||
/// </summary>
|
||||
private int totalIn;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Construct instance with pending buffer
|
||||
/// </summary>
|
||||
/// <param name="pending"> Pending buffer to use </param>
|
||||
/// >
|
||||
public DeflaterEngine(DeflaterPending pending)
|
||||
{
|
||||
this.pending = pending;
|
||||
huffman = new DeflaterHuffman(pending);
|
||||
adler = new Adler32();
|
||||
|
||||
window = new byte[2*WSIZE];
|
||||
head = new short[HASH_SIZE];
|
||||
prev = new short[WSIZE];
|
||||
|
||||
// We start at index 1, to avoid an implementation deficiency, that
|
||||
// we cannot build a repeat pattern at index 0.
|
||||
blockStart = strstart = 1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Get current value of Adler checksum
|
||||
/// </summary>
|
||||
public int Adler
|
||||
{
|
||||
get { return (int) adler.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the <see cref="DeflateStrategy">deflate strategy</see>
|
||||
/// </summary>
|
||||
public DeflateStrategy Strategy
|
||||
{
|
||||
get { return strategy; }
|
||||
|
||||
set { strategy = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Total data processed
|
||||
/// </summary>
|
||||
public int TotalIn
|
||||
{
|
||||
get { return totalIn; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Reset internal state
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
huffman.Reset();
|
||||
adler.Reset();
|
||||
blockStart = strstart = 1;
|
||||
lookahead = 0;
|
||||
totalIn = 0;
|
||||
prevAvailable = false;
|
||||
matchLen = MIN_MATCH - 1;
|
||||
|
||||
for (int i = 0; i < HASH_SIZE; i++)
|
||||
{
|
||||
head[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < WSIZE; i++)
|
||||
{
|
||||
prev[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset Adler checksum
|
||||
/// </summary>
|
||||
public void ResetAdler()
|
||||
{
|
||||
adler.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the deflate level (0-9)
|
||||
/// </summary>
|
||||
/// <param name="lvl"> </param>
|
||||
public void SetLevel(int lvl)
|
||||
{
|
||||
goodLength = GOOD_LENGTH[lvl];
|
||||
max_lazy = MAX_LAZY[lvl];
|
||||
niceLength = NICE_LENGTH[lvl];
|
||||
max_chain = MAX_CHAIN[lvl];
|
||||
|
||||
if (COMPR_FUNC[lvl] != comprFunc)
|
||||
{
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING) {
|
||||
Console.WriteLine("Change from " + comprFunc + " to "
|
||||
+ DeflaterConstants.COMPR_FUNC[lvl]);
|
||||
}
|
||||
*/
|
||||
switch (comprFunc)
|
||||
{
|
||||
case DEFLATE_STORED:
|
||||
if (strstart > blockStart)
|
||||
{
|
||||
huffman.FlushStoredBlock(window, blockStart, strstart - blockStart, false);
|
||||
blockStart = strstart;
|
||||
}
|
||||
|
||||
UpdateHash();
|
||||
break;
|
||||
case DEFLATE_FAST:
|
||||
if (strstart > blockStart)
|
||||
{
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, false);
|
||||
blockStart = strstart;
|
||||
}
|
||||
|
||||
break;
|
||||
case DEFLATE_SLOW:
|
||||
if (prevAvailable)
|
||||
{
|
||||
huffman.TallyLit(window[strstart - 1] & 0xff);
|
||||
}
|
||||
|
||||
if (strstart > blockStart)
|
||||
{
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, false);
|
||||
blockStart = strstart;
|
||||
}
|
||||
|
||||
prevAvailable = false;
|
||||
matchLen = MIN_MATCH - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
comprFunc = COMPR_FUNC[lvl];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill the window
|
||||
/// </summary>
|
||||
public void FillWindow()
|
||||
{
|
||||
/* If the window is almost full and there is insufficient lookahead,
|
||||
* move the upper half to the lower one to make room in the upper half.
|
||||
*/
|
||||
if (strstart >= WSIZE + MAX_DIST)
|
||||
{
|
||||
SlideWindow();
|
||||
}
|
||||
|
||||
/* If there is not enough lookahead, but still some input left,
|
||||
* read in the input
|
||||
*/
|
||||
while (lookahead < MIN_LOOKAHEAD && inputOff < inputEnd)
|
||||
{
|
||||
int more = 2*WSIZE - lookahead - strstart;
|
||||
|
||||
if (more > inputEnd - inputOff)
|
||||
{
|
||||
more = inputEnd - inputOff;
|
||||
}
|
||||
|
||||
Array.Copy(inputBuf, inputOff, window, strstart + lookahead, more);
|
||||
adler.Update(inputBuf, inputOff, more);
|
||||
|
||||
inputOff += more;
|
||||
totalIn += more;
|
||||
lookahead += more;
|
||||
}
|
||||
|
||||
if (lookahead >= MIN_MATCH)
|
||||
{
|
||||
UpdateHash();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set compression dictionary
|
||||
/// </summary>
|
||||
/// <param name="buffer"> </param>
|
||||
/// <param name="offset"> </param>
|
||||
/// <param name="length"> </param>
|
||||
public void SetDictionary(byte[] buffer, int offset, int length)
|
||||
{
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING && strstart != 1) {
|
||||
throw new InvalidOperationException("strstart not 1");
|
||||
}
|
||||
*/
|
||||
adler.Update(buffer, offset, length);
|
||||
if (length < MIN_MATCH)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (length > MAX_DIST)
|
||||
{
|
||||
offset += length - MAX_DIST;
|
||||
length = MAX_DIST;
|
||||
}
|
||||
|
||||
Array.Copy(buffer, offset, window, strstart, length);
|
||||
|
||||
UpdateHash();
|
||||
--length;
|
||||
while (--length > 0)
|
||||
{
|
||||
InsertString();
|
||||
strstart++;
|
||||
}
|
||||
|
||||
strstart += 2;
|
||||
blockStart = strstart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deflate drives actual compression of data
|
||||
/// </summary>
|
||||
/// <param name="flush"> </param>
|
||||
/// <param name="finish"> </param>
|
||||
/// <returns> </returns>
|
||||
public bool Deflate(bool flush, bool finish)
|
||||
{
|
||||
bool progress;
|
||||
do
|
||||
{
|
||||
FillWindow();
|
||||
bool canFlush = flush && inputOff == inputEnd;
|
||||
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("window: ["+blockStart+","+strstart+","
|
||||
// +lookahead+"], "+comprFunc+","+canFlush);
|
||||
// }
|
||||
switch (comprFunc)
|
||||
{
|
||||
case DEFLATE_STORED:
|
||||
progress = DeflateStored(canFlush, finish);
|
||||
break;
|
||||
case DEFLATE_FAST:
|
||||
progress = DeflateFast(canFlush, finish);
|
||||
break;
|
||||
case DEFLATE_SLOW:
|
||||
progress = DeflateSlow(canFlush, finish);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException("unknown comprFunc");
|
||||
}
|
||||
} while (pending.IsFlushed && progress);
|
||||
|
||||
/* repeat while we have no pending output and progress was made */
|
||||
return progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets input data to be deflated. Should only be called when <code>NeedsInput()</code> returns true
|
||||
/// </summary>
|
||||
/// <param name="buf"> The buffer containing input data. </param>
|
||||
/// <param name="off"> The index of the first byte of data. </param>
|
||||
/// <param name="len"> The number of bytes of data to use as input. </param>
|
||||
public void SetInput(byte[] buf, int off, int len)
|
||||
{
|
||||
if (inputOff < inputEnd)
|
||||
{
|
||||
throw new InvalidOperationException("Old input was not completely processed");
|
||||
}
|
||||
|
||||
int end = off + len;
|
||||
|
||||
/* We want to throw an ArrayIndexOutOfBoundsException early. The
|
||||
* check is very tricky: it also handles integer wrap around.
|
||||
*/
|
||||
if (0 > off || off > end || end > buf.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
inputBuf = buf;
|
||||
inputOff = off;
|
||||
inputEnd = end;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if input is needed via <see cref="SetInput">SetInput</see>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public bool NeedsInput()
|
||||
{
|
||||
return inputEnd == inputOff;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private void UpdateHash()
|
||||
{
|
||||
/*
|
||||
if (DEBUGGING) {
|
||||
Console.WriteLine("updateHash: "+strstart);
|
||||
}
|
||||
*/
|
||||
ins_h = (window[strstart] << HASH_SHIFT) ^ window[strstart + 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts the current string in the head hash and returns the previous value for this hash.
|
||||
/// </summary>
|
||||
/// <returns> The previous hash value </returns>
|
||||
private int InsertString()
|
||||
{
|
||||
short match;
|
||||
int hash = ((ins_h << HASH_SHIFT) ^ window[strstart + (MIN_MATCH - 1)]) & HASH_MASK;
|
||||
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING) {
|
||||
if (hash != (((window[strstart] << (2*HASH_SHIFT)) ^
|
||||
(window[strstart + 1] << HASH_SHIFT) ^
|
||||
(window[strstart + 2])) & HASH_MASK)) {
|
||||
throw new SharpZipBaseException("hash inconsistent: " + hash + "/"
|
||||
+window[strstart] + ","
|
||||
+window[strstart+1] + ","
|
||||
+window[strstart+2] + "," + HASH_SHIFT);
|
||||
}
|
||||
}
|
||||
*/
|
||||
prev[strstart & WMASK] = match = head[hash];
|
||||
head[hash] = (short) strstart;
|
||||
ins_h = hash;
|
||||
return match & 0xffff;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private void SlideWindow()
|
||||
{
|
||||
Array.Copy(window, WSIZE, window, 0, WSIZE);
|
||||
matchStart -= WSIZE;
|
||||
strstart -= WSIZE;
|
||||
blockStart -= WSIZE;
|
||||
|
||||
/* Slide the hash table (could be avoided with 32 bit values
|
||||
* at the expense of memory usage).
|
||||
*/
|
||||
for (int i = 0; i < HASH_SIZE; ++i)
|
||||
{
|
||||
int m = head[i] & 0xffff;
|
||||
head[i] = (short) (m >= WSIZE ? (m - WSIZE) : 0);
|
||||
}
|
||||
|
||||
/* Slide the prev table. */
|
||||
for (int i = 0; i < WSIZE; i++)
|
||||
{
|
||||
int m = prev[i] & 0xffff;
|
||||
prev[i] = (short) (m >= WSIZE ? (m - WSIZE) : 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the best (longest) string in the window matching the string starting at strstart. Preconditions: <code>strstart + MAX_MATCH <= window.length.</code>
|
||||
/// </summary>
|
||||
/// <param name="curMatch"> </param>
|
||||
/// <returns> True if a match greater than the minimum length is found </returns>
|
||||
private bool FindLongestMatch(int curMatch)
|
||||
{
|
||||
int chainLength = max_chain;
|
||||
int niceLength = this.niceLength;
|
||||
short[] prev = this.prev;
|
||||
int scan = strstart;
|
||||
int match;
|
||||
int best_end = strstart + matchLen;
|
||||
int best_len = Math.Max(matchLen, MIN_MATCH - 1);
|
||||
|
||||
int limit = Math.Max(strstart - MAX_DIST, 0);
|
||||
|
||||
int strend = strstart + MAX_MATCH - 1;
|
||||
byte scan_end1 = window[best_end - 1];
|
||||
byte scan_end = window[best_end];
|
||||
|
||||
/* Do not waste too much time if we already have a good match: */
|
||||
if (best_len >= goodLength)
|
||||
{
|
||||
chainLength >>= 2;
|
||||
}
|
||||
|
||||
/* Do not look for matches beyond the end of the input. This is necessary
|
||||
* to make deflate deterministic.
|
||||
*/
|
||||
if (niceLength > lookahead)
|
||||
{
|
||||
niceLength = lookahead;
|
||||
}
|
||||
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING && strstart > 2 * WSIZE - MIN_LOOKAHEAD) {
|
||||
throw new InvalidOperationException("need lookahead");
|
||||
}
|
||||
*/
|
||||
do
|
||||
{
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING && curMatch >= strstart) {
|
||||
throw new InvalidOperationException("future match");
|
||||
}
|
||||
*/
|
||||
if (window[curMatch + best_len] != scan_end || window[curMatch + best_len - 1] != scan_end1 ||
|
||||
window[curMatch] != window[scan] || window[curMatch + 1] != window[scan + 1])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
match = curMatch + 2;
|
||||
scan += 2;
|
||||
|
||||
/* We check for insufficient lookahead only every 8th comparison;
|
||||
* the 256th check will be made at strstart + 258.
|
||||
*/
|
||||
while (window[++scan] == window[++match] && window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] && window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] && window[++scan] == window[++match] &&
|
||||
window[++scan] == window[++match] && window[++scan] == window[++match] && scan < strend)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (scan > best_end)
|
||||
{
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING && ins_h == 0)
|
||||
System.err.println("Found match: "+curMatch+"-"+(scan-strstart));
|
||||
*/
|
||||
matchStart = curMatch;
|
||||
best_end = scan;
|
||||
best_len = scan - strstart;
|
||||
|
||||
if (best_len >= niceLength)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
scan_end1 = window[best_end - 1];
|
||||
scan_end = window[best_end];
|
||||
}
|
||||
|
||||
scan = strstart;
|
||||
} while ((curMatch = prev[curMatch & WMASK] & 0xffff) > limit && --chainLength != 0);
|
||||
|
||||
matchLen = Math.Min(best_len, lookahead);
|
||||
return matchLen >= MIN_MATCH;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="flush"> </param>
|
||||
/// <param name="finish"> </param>
|
||||
/// <returns> </returns>
|
||||
private bool DeflateStored(bool flush, bool finish)
|
||||
{
|
||||
if (!flush && lookahead == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
strstart += lookahead;
|
||||
lookahead = 0;
|
||||
|
||||
int storedLen = strstart - blockStart;
|
||||
|
||||
if ((storedLen >= MAX_BLOCK_SIZE) || /* Block is full */
|
||||
(blockStart < WSIZE && storedLen >= MAX_DIST) || /* Block may move out of window */ flush)
|
||||
{
|
||||
bool lastBlock = finish;
|
||||
if (storedLen > MAX_BLOCK_SIZE)
|
||||
{
|
||||
storedLen = MAX_BLOCK_SIZE;
|
||||
lastBlock = false;
|
||||
}
|
||||
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING) {
|
||||
Console.WriteLine("storedBlock["+storedLen+","+lastBlock+"]");
|
||||
}
|
||||
*/
|
||||
huffman.FlushStoredBlock(window, blockStart, storedLen, lastBlock);
|
||||
blockStart += storedLen;
|
||||
return !lastBlock;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="flush"> </param>
|
||||
/// <param name="finish"> </param>
|
||||
/// <returns> </returns>
|
||||
private bool DeflateFast(bool flush, bool finish)
|
||||
{
|
||||
if (lookahead < MIN_LOOKAHEAD && !flush)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (lookahead >= MIN_LOOKAHEAD || flush)
|
||||
{
|
||||
if (lookahead == 0)
|
||||
{
|
||||
/* We are flushing everything */
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, finish);
|
||||
blockStart = strstart;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strstart > 2*WSIZE - MIN_LOOKAHEAD)
|
||||
{
|
||||
/* slide window, as findLongestMatch needs this.
|
||||
* This should only happen when flushing and the window
|
||||
* is almost full.
|
||||
*/
|
||||
SlideWindow();
|
||||
}
|
||||
|
||||
int hashHead;
|
||||
if (lookahead >= MIN_MATCH && (hashHead = InsertString()) != 0 &&
|
||||
strategy != DeflateStrategy.HuffmanOnly && strstart - hashHead <= MAX_DIST &&
|
||||
FindLongestMatch(hashHead))
|
||||
{
|
||||
/* longestMatch sets matchStart and matchLen */
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING) {
|
||||
for (int i = 0 ; i < matchLen; i++) {
|
||||
if (window[strstart+i] != window[matchStart + i]) {
|
||||
throw new SharpZipBaseException("Match failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
// -jr- Hak hak hak this stops problems with fast/low compression and index out of range
|
||||
if (huffman.TallyDist(strstart - matchStart, matchLen))
|
||||
{
|
||||
bool lastBlock = finish && lookahead == 0;
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock);
|
||||
blockStart = strstart;
|
||||
}
|
||||
|
||||
lookahead -= matchLen;
|
||||
if (matchLen <= max_lazy && lookahead >= MIN_MATCH)
|
||||
{
|
||||
while (--matchLen > 0)
|
||||
{
|
||||
++strstart;
|
||||
InsertString();
|
||||
}
|
||||
|
||||
++strstart;
|
||||
}
|
||||
else
|
||||
{
|
||||
strstart += matchLen;
|
||||
if (lookahead >= MIN_MATCH - 1)
|
||||
{
|
||||
UpdateHash();
|
||||
}
|
||||
}
|
||||
|
||||
matchLen = MIN_MATCH - 1;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No match found */
|
||||
huffman.TallyLit(window[strstart] & 0xff);
|
||||
++strstart;
|
||||
--lookahead;
|
||||
}
|
||||
|
||||
if (huffman.IsFull())
|
||||
{
|
||||
bool lastBlock = finish && lookahead == 0;
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock);
|
||||
blockStart = strstart;
|
||||
return !lastBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="flush"> </param>
|
||||
/// <param name="finish"> </param>
|
||||
/// <returns> </returns>
|
||||
private bool DeflateSlow(bool flush, bool finish)
|
||||
{
|
||||
if (lookahead < MIN_LOOKAHEAD && !flush)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (lookahead >= MIN_LOOKAHEAD || flush)
|
||||
{
|
||||
if (lookahead == 0)
|
||||
{
|
||||
if (prevAvailable)
|
||||
{
|
||||
huffman.TallyLit(window[strstart - 1] & 0xff);
|
||||
}
|
||||
|
||||
prevAvailable = false;
|
||||
|
||||
// We are flushing everything
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING && !flush) {
|
||||
throw new SharpZipBaseException("Not flushing, but no lookahead");
|
||||
}
|
||||
*/
|
||||
huffman.FlushBlock(window, blockStart, strstart - blockStart, finish);
|
||||
blockStart = strstart;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strstart >= 2*WSIZE - MIN_LOOKAHEAD)
|
||||
{
|
||||
/* slide window, as findLongestMatch need this.
|
||||
* This should only happen when flushing and the window
|
||||
* is almost full.
|
||||
*/
|
||||
SlideWindow();
|
||||
}
|
||||
|
||||
int prevMatch = matchStart;
|
||||
int prevLen = matchLen;
|
||||
if (lookahead >= MIN_MATCH)
|
||||
{
|
||||
int hashHead = InsertString();
|
||||
if (strategy != DeflateStrategy.HuffmanOnly && hashHead != 0 &&
|
||||
strstart - hashHead <= MAX_DIST && FindLongestMatch(hashHead))
|
||||
{
|
||||
/* longestMatch sets matchStart and matchLen */
|
||||
|
||||
/* Discard match if too small and too far away */
|
||||
if (matchLen <= 5 &&
|
||||
(strategy == DeflateStrategy.Filtered ||
|
||||
(matchLen == MIN_MATCH && strstart - matchStart > TOO_FAR)))
|
||||
{
|
||||
matchLen = MIN_MATCH - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* previous match was better */
|
||||
if (prevLen >= MIN_MATCH && matchLen <= prevLen)
|
||||
{
|
||||
/*
|
||||
if (DeflaterConstants.DEBUGGING) {
|
||||
for (int i = 0 ; i < matchLen; i++) {
|
||||
if (window[strstart-1+i] != window[prevMatch + i])
|
||||
throw new SharpZipBaseException();
|
||||
}
|
||||
}
|
||||
*/
|
||||
huffman.TallyDist(strstart - 1 - prevMatch, prevLen);
|
||||
prevLen -= 2;
|
||||
do
|
||||
{
|
||||
strstart++;
|
||||
lookahead--;
|
||||
if (lookahead >= MIN_MATCH)
|
||||
{
|
||||
InsertString();
|
||||
}
|
||||
} while (--prevLen > 0);
|
||||
strstart ++;
|
||||
lookahead--;
|
||||
prevAvailable = false;
|
||||
matchLen = MIN_MATCH - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prevAvailable)
|
||||
{
|
||||
huffman.TallyLit(window[strstart - 1] & 0xff);
|
||||
}
|
||||
|
||||
prevAvailable = true;
|
||||
strstart++;
|
||||
lookahead--;
|
||||
}
|
||||
|
||||
if (huffman.IsFull())
|
||||
{
|
||||
int len = strstart - blockStart;
|
||||
if (prevAvailable)
|
||||
{
|
||||
len--;
|
||||
}
|
||||
|
||||
bool lastBlock = finish && lookahead == 0 && !prevAvailable;
|
||||
huffman.FlushBlock(window, blockStart, len, lastBlock);
|
||||
blockStart += len;
|
||||
return !lastBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
1081
ASC.Xmpp.Core/IO/Compression/DeflaterHuffman.cs
Normal file
1081
ASC.Xmpp.Core/IO/Compression/DeflaterHuffman.cs
Normal file
File diff suppressed because it is too large
Load Diff
40
ASC.Xmpp.Core/IO/Compression/DeflaterPending.cs
Normal file
40
ASC.Xmpp.Core/IO/Compression/DeflaterPending.cs
Normal file
@ -0,0 +1,40 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
/// <summary>
|
||||
/// This class stores the pending output of the Deflater. author of the original java version : Jochen Hoenicke
|
||||
/// </summary>
|
||||
public class DeflaterPending : PendingBuffer
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Construct instance with default buffer size
|
||||
/// </summary>
|
||||
public DeflaterPending() : base(DeflaterConstants.PENDING_BUF_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
812
ASC.Xmpp.Core/IO/Compression/Inflater.cs
Normal file
812
ASC.Xmpp.Core/IO/Compression/Inflater.cs
Normal file
@ -0,0 +1,812 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.IO.Compression.Checksums;
|
||||
using ASC.Xmpp.Core.IO.Compression.Streams;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Inflater is used to decompress data that has been compressed according to the "deflate" standard described in rfc1951. By default Zlib (rfc1950) headers and footers are expected in the input. You can use constructor <code>public Inflater(bool noHeader)</code> passing true if there is no Zlib header information The usage is as following. First you have to set some input with <code>setInput()</code> , then inflate() it. If inflate doesn't inflate any bytes there may be three reasons: <ul>
|
||||
/// <li>needsInput() returns true because the input buffer is empty.
|
||||
/// You have to provide more input with
|
||||
/// <code>setInput()</code>
|
||||
/// .
|
||||
/// NOTE: needsInput() also returns true when, the stream is finished.</li>
|
||||
/// <li>needsDictionary() returns true, you have to provide a preset
|
||||
/// dictionary with
|
||||
/// <code>setDictionary()</code>
|
||||
/// .</li>
|
||||
/// <li>finished() returns true, the inflater has finished.</li>
|
||||
/// </ul> Once the first output byte is produced, a dictionary will not be needed at a later stage. author of the original java version : John Leuner, Jochen Hoenicke
|
||||
/// </summary>
|
||||
public class Inflater
|
||||
{
|
||||
/// <summary>
|
||||
/// Copy lengths for literal codes 257..285
|
||||
/// </summary>
|
||||
private static readonly int[] CPLENS = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51,
|
||||
59
|
||||
, 67, 83, 99, 115, 131, 163, 195, 227, 258
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Extra bits for literal codes 257..285
|
||||
/// </summary>
|
||||
private static readonly int[] CPLEXT = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
|
||||
4,
|
||||
5, 5, 5, 5, 0
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Copy offsets for distance codes 0..29
|
||||
/// </summary>
|
||||
private static readonly int[] CPDIST = {
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385,
|
||||
513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385,
|
||||
24577
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Extra bits for distance codes
|
||||
/// </summary>
|
||||
private static readonly int[] CPDEXT = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
|
||||
10, 11, 11, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// These are the possible states for an inflater
|
||||
/// </summary>
|
||||
private const int DECODE_HEADER = 0;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_DICT = 1;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_BLOCKS = 2;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_STORED_LEN1 = 3;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_STORED_LEN2 = 4;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_STORED = 5;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_DYN_HEADER = 6;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_HUFFMAN = 7;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_HUFFMAN_LENBITS = 8;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_HUFFMAN_DIST = 9;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_HUFFMAN_DISTBITS = 10;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DECODE_CHKSUM = 11;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int FINISHED = 12;
|
||||
|
||||
/// <summary>
|
||||
/// This variable contains the current state.
|
||||
/// </summary>
|
||||
private int mode;
|
||||
|
||||
/// <summary>
|
||||
/// The adler checksum of the dictionary or of the decompressed stream, as it is written in the header resp. footer of the compressed stream. Only valid if mode is DECODE_DICT or DECODE_CHKSUM.
|
||||
/// </summary>
|
||||
private int readAdler;
|
||||
|
||||
/// <summary>
|
||||
/// The number of bits needed to complete the current state. This is valid, if mode is DECODE_DICT, DECODE_CHKSUM, DECODE_HUFFMAN_LENBITS or DECODE_HUFFMAN_DISTBITS.
|
||||
/// </summary>
|
||||
private int neededBits;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int repLength;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int repDist;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int uncomprLen;
|
||||
|
||||
/// <summary>
|
||||
/// True, if the last block flag was set in the last block of the inflated stream. This means that the stream ends after the current block.
|
||||
/// </summary>
|
||||
private bool isLastBlock;
|
||||
|
||||
/// <summary>
|
||||
/// The total number of inflated bytes.
|
||||
/// </summary>
|
||||
private int totalOut;
|
||||
|
||||
/// <summary>
|
||||
/// The total number of bytes set with setInput(). This is not the value returned by the TotalIn property, since this also includes the unprocessed input.
|
||||
/// </summary>
|
||||
private int totalIn;
|
||||
|
||||
/// <summary>
|
||||
/// This variable stores the noHeader flag that was given to the constructor. True means, that the inflated stream doesn't contain a Zlib header or footer.
|
||||
/// </summary>
|
||||
private readonly bool noHeader;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly StreamManipulator input;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly OutputWindow outputWindow;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private InflaterDynHeader dynHeader;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private InflaterHuffmanTree litlenTree;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private InflaterHuffmanTree distTree;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly Adler32 adler;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new inflater or RFC1951 decompressor RFC1950/Zlib headers and footers will be expected in the input data
|
||||
/// </summary>
|
||||
public Inflater() : this(false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new inflater.
|
||||
/// </summary>
|
||||
/// <param name="noHeader"> True if no RFC1950/Zlib header and footer fields are expected in the input data This is used for GZIPed/Zipped input. For compatibility with Sun JDK you should provide one byte of input more than needed in this case. </param>
|
||||
public Inflater(bool noHeader)
|
||||
{
|
||||
this.noHeader = noHeader;
|
||||
adler = new Adler32();
|
||||
input = new StreamManipulator();
|
||||
outputWindow = new OutputWindow();
|
||||
mode = noHeader ? DECODE_BLOCKS : DECODE_HEADER;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the inflater so that a new stream can be decompressed. All pending input and output will be discarded.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
mode = noHeader ? DECODE_BLOCKS : DECODE_HEADER;
|
||||
totalIn = totalOut = 0;
|
||||
input.Reset();
|
||||
outputWindow.Reset();
|
||||
dynHeader = null;
|
||||
litlenTree = null;
|
||||
distTree = null;
|
||||
isLastBlock = false;
|
||||
adler.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a zlib/RFC1950 header.
|
||||
/// </summary>
|
||||
/// <returns> False if more input is needed. </returns>
|
||||
/// <exception cref="SharpZipBaseException">The header is invalid.</exception>
|
||||
private bool DecodeHeader()
|
||||
{
|
||||
int header = input.PeekBits(16);
|
||||
if (header < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(16);
|
||||
|
||||
/* The header is written in "wrong" byte order */
|
||||
header = ((header << 8) | (header >> 8)) & 0xffff;
|
||||
if (header%31 != 0)
|
||||
{
|
||||
throw new SharpZipBaseException("Header checksum illegal");
|
||||
}
|
||||
|
||||
if ((header & 0x0f00) != (Deflater.DEFLATED << 8))
|
||||
{
|
||||
throw new SharpZipBaseException("Compression Method unknown");
|
||||
}
|
||||
|
||||
/* Maximum size of the backwards window in bits.
|
||||
* We currently ignore this, but we could use it to make the
|
||||
* inflater window more space efficient. On the other hand the
|
||||
* full window (15 bits) is needed most times, anyway.
|
||||
int max_wbits = ((header & 0x7000) >> 12) + 8;
|
||||
*/
|
||||
if ((header & 0x0020) == 0)
|
||||
{
|
||||
// Dictionary flag?
|
||||
mode = DECODE_BLOCKS;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = DECODE_DICT;
|
||||
neededBits = 32;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes the dictionary checksum after the deflate header.
|
||||
/// </summary>
|
||||
/// <returns> False if more input is needed. </returns>
|
||||
private bool DecodeDict()
|
||||
{
|
||||
while (neededBits > 0)
|
||||
{
|
||||
int dictByte = input.PeekBits(8);
|
||||
if (dictByte < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(8);
|
||||
readAdler = (readAdler << 8) | dictByte;
|
||||
neededBits -= 8;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes the huffman encoded symbols in the input stream.
|
||||
/// </summary>
|
||||
/// <returns> false if more input is needed, true if output window is full or the current block ends. </returns>
|
||||
/// <exception cref="SharpZipBaseException">if deflated stream is invalid.</exception>
|
||||
private bool DecodeHuffman()
|
||||
{
|
||||
int free = outputWindow.GetFreeSpace();
|
||||
while (free >= 258)
|
||||
{
|
||||
int symbol;
|
||||
switch (mode)
|
||||
{
|
||||
case DECODE_HUFFMAN:
|
||||
|
||||
/* This is the inner loop so it is optimized a bit */
|
||||
while (((symbol = litlenTree.GetSymbol(input)) & ~0xff) == 0)
|
||||
{
|
||||
outputWindow.Write(symbol);
|
||||
if (--free < 258)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (symbol < 257)
|
||||
{
|
||||
if (symbol < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* symbol == 256: end of block */
|
||||
distTree = null;
|
||||
litlenTree = null;
|
||||
mode = DECODE_BLOCKS;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
repLength = CPLENS[symbol - 257];
|
||||
neededBits = CPLEXT[symbol - 257];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new SharpZipBaseException("Illegal rep length code");
|
||||
}
|
||||
|
||||
goto case DECODE_HUFFMAN_LENBITS; /* fall through */
|
||||
|
||||
case DECODE_HUFFMAN_LENBITS:
|
||||
if (neededBits > 0)
|
||||
{
|
||||
mode = DECODE_HUFFMAN_LENBITS;
|
||||
int i = input.PeekBits(neededBits);
|
||||
if (i < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(neededBits);
|
||||
repLength += i;
|
||||
}
|
||||
|
||||
mode = DECODE_HUFFMAN_DIST;
|
||||
goto case DECODE_HUFFMAN_DIST; /* fall through */
|
||||
|
||||
case DECODE_HUFFMAN_DIST:
|
||||
symbol = distTree.GetSymbol(input);
|
||||
if (symbol < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
repDist = CPDIST[symbol];
|
||||
neededBits = CPDEXT[symbol];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new SharpZipBaseException("Illegal rep dist code");
|
||||
}
|
||||
|
||||
goto case DECODE_HUFFMAN_DISTBITS; /* fall through */
|
||||
|
||||
case DECODE_HUFFMAN_DISTBITS:
|
||||
if (neededBits > 0)
|
||||
{
|
||||
mode = DECODE_HUFFMAN_DISTBITS;
|
||||
int i = input.PeekBits(neededBits);
|
||||
if (i < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(neededBits);
|
||||
repDist += i;
|
||||
}
|
||||
|
||||
outputWindow.Repeat(repLength, repDist);
|
||||
free -= repLength;
|
||||
mode = DECODE_HUFFMAN;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new SharpZipBaseException("Inflater unknown mode");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes the adler checksum after the deflate stream.
|
||||
/// </summary>
|
||||
/// <returns> false if more input is needed. </returns>
|
||||
/// <exception cref="SharpZipBaseException">If checksum doesn't match.</exception>
|
||||
private bool DecodeChksum()
|
||||
{
|
||||
while (neededBits > 0)
|
||||
{
|
||||
int chkByte = input.PeekBits(8);
|
||||
if (chkByte < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(8);
|
||||
readAdler = (readAdler << 8) | chkByte;
|
||||
neededBits -= 8;
|
||||
}
|
||||
|
||||
if ((int) adler.Value != readAdler)
|
||||
{
|
||||
throw new SharpZipBaseException("Adler chksum doesn't match: " + (int) adler.Value + " vs. " +
|
||||
readAdler);
|
||||
}
|
||||
|
||||
mode = FINISHED;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes the deflated stream.
|
||||
/// </summary>
|
||||
/// <returns> false if more input is needed, or if finished. </returns>
|
||||
/// <exception cref="SharpZipBaseException">if deflated stream is invalid.</exception>
|
||||
private bool Decode()
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case DECODE_HEADER:
|
||||
return DecodeHeader();
|
||||
case DECODE_DICT:
|
||||
return DecodeDict();
|
||||
case DECODE_CHKSUM:
|
||||
return DecodeChksum();
|
||||
|
||||
case DECODE_BLOCKS:
|
||||
if (isLastBlock)
|
||||
{
|
||||
if (noHeader)
|
||||
{
|
||||
mode = FINISHED;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
input.SkipToByteBoundary();
|
||||
neededBits = 32;
|
||||
mode = DECODE_CHKSUM;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int type = input.PeekBits(3);
|
||||
if (type < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(3);
|
||||
|
||||
if ((type & 1) != 0)
|
||||
{
|
||||
isLastBlock = true;
|
||||
}
|
||||
|
||||
switch (type >> 1)
|
||||
{
|
||||
case DeflaterConstants.STORED_BLOCK:
|
||||
input.SkipToByteBoundary();
|
||||
mode = DECODE_STORED_LEN1;
|
||||
break;
|
||||
case DeflaterConstants.STATIC_TREES:
|
||||
litlenTree = InflaterHuffmanTree.defLitLenTree;
|
||||
distTree = InflaterHuffmanTree.defDistTree;
|
||||
mode = DECODE_HUFFMAN;
|
||||
break;
|
||||
case DeflaterConstants.DYN_TREES:
|
||||
dynHeader = new InflaterDynHeader();
|
||||
mode = DECODE_DYN_HEADER;
|
||||
break;
|
||||
default:
|
||||
throw new SharpZipBaseException("Unknown block type " + type);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case DECODE_STORED_LEN1:
|
||||
{
|
||||
if ((uncomprLen = input.PeekBits(16)) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(16);
|
||||
mode = DECODE_STORED_LEN2;
|
||||
}
|
||||
|
||||
goto case DECODE_STORED_LEN2; /* fall through */
|
||||
|
||||
case DECODE_STORED_LEN2:
|
||||
{
|
||||
int nlen = input.PeekBits(16);
|
||||
if (nlen < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(16);
|
||||
if (nlen != (uncomprLen ^ 0xffff))
|
||||
{
|
||||
throw new SharpZipBaseException("broken uncompressed block");
|
||||
}
|
||||
|
||||
mode = DECODE_STORED;
|
||||
}
|
||||
|
||||
goto case DECODE_STORED; /* fall through */
|
||||
|
||||
case DECODE_STORED:
|
||||
{
|
||||
int more = outputWindow.CopyStored(input, uncomprLen);
|
||||
uncomprLen -= more;
|
||||
if (uncomprLen == 0)
|
||||
{
|
||||
mode = DECODE_BLOCKS;
|
||||
return true;
|
||||
}
|
||||
|
||||
return !input.IsNeedingInput;
|
||||
}
|
||||
|
||||
case DECODE_DYN_HEADER:
|
||||
if (!dynHeader.Decode(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
litlenTree = dynHeader.BuildLitLenTree();
|
||||
distTree = dynHeader.BuildDistTree();
|
||||
mode = DECODE_HUFFMAN;
|
||||
goto case DECODE_HUFFMAN; /* fall through */
|
||||
|
||||
case DECODE_HUFFMAN:
|
||||
case DECODE_HUFFMAN_LENBITS:
|
||||
case DECODE_HUFFMAN_DIST:
|
||||
case DECODE_HUFFMAN_DISTBITS:
|
||||
return DecodeHuffman();
|
||||
|
||||
case FINISHED:
|
||||
return false;
|
||||
|
||||
default:
|
||||
throw new SharpZipBaseException("Inflater.Decode unknown mode");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the preset dictionary. This should only be called, if needsDictionary() returns true and it should set the same dictionary, that was used for deflating. The getAdler() function returns the checksum of the dictionary needed.
|
||||
/// </summary>
|
||||
/// <param name="buffer"> The dictionary. </param>
|
||||
public void SetDictionary(byte[] buffer)
|
||||
{
|
||||
SetDictionary(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the preset dictionary. This should only be called, if needsDictionary() returns true and it should set the same dictionary, that was used for deflating. The getAdler() function returns the checksum of the dictionary needed.
|
||||
/// </summary>
|
||||
/// <param name="buffer"> The dictionary. </param>
|
||||
/// <param name="offset"> The offset into buffer where the dictionary starts. </param>
|
||||
/// <param name="len"> The length of the dictionary. </param>
|
||||
/// <exception cref="System.InvalidOperationException">No dictionary is needed.</exception>
|
||||
/// <exception cref="SharpZipBaseException">The adler checksum for the buffer is invalid</exception>
|
||||
public void SetDictionary(byte[] buffer, int offset, int len)
|
||||
{
|
||||
if (!IsNeedingDictionary)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
adler.Update(buffer, offset, len);
|
||||
if ((int) adler.Value != readAdler)
|
||||
{
|
||||
throw new SharpZipBaseException("Wrong adler checksum");
|
||||
}
|
||||
|
||||
adler.Reset();
|
||||
outputWindow.CopyDict(buffer, offset, len);
|
||||
mode = DECODE_BLOCKS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the input. This should only be called, if needsInput() returns true.
|
||||
/// </summary>
|
||||
/// <param name="buf"> the input. </param>
|
||||
public void SetInput(byte[] buf)
|
||||
{
|
||||
SetInput(buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the input. This should only be called, if needsInput() returns true.
|
||||
/// </summary>
|
||||
/// <param name="buffer"> The source of input data </param>
|
||||
/// <param name="offset"> The offset into buffer where the input starts. </param>
|
||||
/// <param name="length"> The number of bytes of input to use. </param>
|
||||
/// <exception cref="System.InvalidOperationException">No input is needed.</exception>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">The off and/or len are wrong.</exception>
|
||||
public void SetInput(byte[] buffer, int offset, int length)
|
||||
{
|
||||
input.SetInput(buffer, offset, length);
|
||||
totalIn += length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inflates the compressed stream to the output buffer. If this returns 0, you should check, whether needsDictionary(), needsInput() or finished() returns true, to determine why no further output is produced.
|
||||
/// </summary>
|
||||
/// <param name="buf"> the output buffer. </param>
|
||||
/// <returns> the number of bytes written to the buffer, 0 if no further output can be produced. </returns>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">if buf has length 0.</exception>
|
||||
/// <exception cref="System.FormatException">if deflated stream is invalid.</exception>
|
||||
public int Inflate(byte[] buf)
|
||||
{
|
||||
return Inflate(buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inflates the compressed stream to the output buffer. If this returns 0, you should check, whether needsDictionary(), needsInput() or finished() returns true, to determine why no further output is produced.
|
||||
/// </summary>
|
||||
/// <param name="buf"> the output buffer. </param>
|
||||
/// <param name="offset"> the offset into buffer where the output should start. </param>
|
||||
/// <param name="len"> the maximum length of the output. </param>
|
||||
/// <returns> the number of bytes written to the buffer, 0 if no further output can be produced. </returns>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">if len is <= 0.</exception>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">if the offset and/or len are wrong.</exception>
|
||||
/// <exception cref="System.FormatException">if deflated stream is invalid.</exception>
|
||||
public int Inflate(byte[] buf, int offset, int len)
|
||||
{
|
||||
if (len < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("len < 0");
|
||||
}
|
||||
|
||||
// Special case: len may be zero
|
||||
if (len == 0)
|
||||
{
|
||||
if (IsFinished == false)
|
||||
{
|
||||
// -jr- 08-Nov-2003 INFLATE_BUG fix..
|
||||
Decode();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
// Check for correct buff, off, len triple
|
||||
if (off < 0 || off + len >= buf.Length) {
|
||||
throw new ArgumentException("off/len outside buf bounds");
|
||||
}
|
||||
*/
|
||||
int count = 0;
|
||||
int more;
|
||||
do
|
||||
{
|
||||
if (mode != DECODE_CHKSUM)
|
||||
{
|
||||
/* Don't give away any output, if we are waiting for the
|
||||
* checksum in the input stream.
|
||||
*
|
||||
* With this trick we have always:
|
||||
* needsInput() and not finished()
|
||||
* implies more output can be produced.
|
||||
*/
|
||||
more = outputWindow.CopyOutput(buf, offset, len);
|
||||
adler.Update(buf, offset, more);
|
||||
offset += more;
|
||||
count += more;
|
||||
totalOut += more;
|
||||
len -= more;
|
||||
if (len == 0)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
}
|
||||
} while (Decode() || (outputWindow.GetAvailable() > 0 && mode != DECODE_CHKSUM));
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true, if the input buffer is empty. You should then call setInput(). NOTE: This method also returns true when the stream is finished.
|
||||
/// </summary>
|
||||
public bool IsNeedingInput
|
||||
{
|
||||
get { return input.IsNeedingInput; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true, if a preset dictionary is needed to inflate the input.
|
||||
/// </summary>
|
||||
public bool IsNeedingDictionary
|
||||
{
|
||||
get { return mode == DECODE_DICT && neededBits == 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true, if the inflater has finished. This means, that no input is needed and no output can be produced.
|
||||
/// </summary>
|
||||
public bool IsFinished
|
||||
{
|
||||
get { return mode == FINISHED && outputWindow.GetAvailable() == 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the adler checksum. This is either the checksum of all uncompressed bytes returned by inflate(), or if needsDictionary() returns true (and thus no output was yet produced) this is the adler checksum of the expected dictionary.
|
||||
/// </summary>
|
||||
/// <returns> the adler checksum. </returns>
|
||||
public int Adler
|
||||
{
|
||||
get { return IsNeedingDictionary ? readAdler : (int) adler.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of output bytes returned by inflate().
|
||||
/// </summary>
|
||||
/// <returns> the total number of output bytes. </returns>
|
||||
public int TotalOut
|
||||
{
|
||||
get { return totalOut; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of processed compressed input bytes.
|
||||
/// </summary>
|
||||
/// <returns> The total number of bytes of processed input bytes. </returns>
|
||||
public int TotalIn
|
||||
{
|
||||
get { return totalIn - RemainingInput; }
|
||||
}
|
||||
|
||||
#if TEST_HAK
|
||||
|
||||
// <summary>
|
||||
/// -jr test hak trying to figure out a bug
|
||||
///</summary>
|
||||
public int UnseenInput {
|
||||
get {
|
||||
return totalIn - ((input.AvailableBits + 7) >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// -jr test hak trying to figure out a bug
|
||||
///</summary>
|
||||
public int PlainTotalIn {
|
||||
get {
|
||||
return totalIn;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of unprocessed input bytes. Useful, if the end of the stream is reached and you want to further process the bytes after the deflate stream.
|
||||
/// </summary>
|
||||
/// <returns> The number of bytes of the input which have not been processed. </returns>
|
||||
public int RemainingInput
|
||||
{
|
||||
get { return input.AvailableBytes; }
|
||||
}
|
||||
}
|
||||
}
|
310
ASC.Xmpp.Core/IO/Compression/InflaterDynHeader.cs
Normal file
310
ASC.Xmpp.Core/IO/Compression/InflaterDynHeader.cs
Normal file
@ -0,0 +1,310 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.IO.Compression.Streams;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
internal class InflaterDynHeader
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int BLLENS = 3;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int BLNUM = 2;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int DNUM = 1;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int LENS = 4;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int LNUM = 0;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private const int REPS = 5;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static readonly int[] BL_ORDER = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1
|
||||
, 15
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static readonly int[] repBits = {2, 3, 7};
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static readonly int[] repMin = {3, 3, 11};
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private byte[] blLens;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private InflaterHuffmanTree blTree;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int blnum;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int dnum;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private byte lastLen;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private byte[] litdistLens;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int lnum;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int mode;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int num;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int ptr;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int repSymbol;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="input"> </param>
|
||||
/// <returns> </returns>
|
||||
/// <exception cref="SharpZipBaseException"></exception>
|
||||
public bool Decode(StreamManipulator input)
|
||||
{
|
||||
decode_loop:
|
||||
for (;;)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case LNUM:
|
||||
lnum = input.PeekBits(5);
|
||||
if (lnum < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
lnum += 257;
|
||||
input.DropBits(5);
|
||||
|
||||
// System.err.println("LNUM: "+lnum);
|
||||
mode = DNUM;
|
||||
goto case DNUM; // fall through
|
||||
case DNUM:
|
||||
dnum = input.PeekBits(5);
|
||||
if (dnum < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dnum++;
|
||||
input.DropBits(5);
|
||||
|
||||
// System.err.println("DNUM: "+dnum);
|
||||
num = lnum + dnum;
|
||||
litdistLens = new byte[num];
|
||||
mode = BLNUM;
|
||||
goto case BLNUM; // fall through
|
||||
case BLNUM:
|
||||
blnum = input.PeekBits(4);
|
||||
if (blnum < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
blnum += 4;
|
||||
input.DropBits(4);
|
||||
blLens = new byte[19];
|
||||
ptr = 0;
|
||||
|
||||
// System.err.println("BLNUM: "+blnum);
|
||||
mode = BLLENS;
|
||||
goto case BLLENS; // fall through
|
||||
case BLLENS:
|
||||
while (ptr < blnum)
|
||||
{
|
||||
int len = input.PeekBits(3);
|
||||
if (len < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(3);
|
||||
|
||||
// System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
|
||||
blLens[BL_ORDER[ptr]] = (byte) len;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
blTree = new InflaterHuffmanTree(blLens);
|
||||
blLens = null;
|
||||
ptr = 0;
|
||||
mode = LENS;
|
||||
goto case LENS; // fall through
|
||||
case LENS:
|
||||
{
|
||||
int symbol;
|
||||
while (((symbol = blTree.GetSymbol(input)) & ~15) == 0)
|
||||
{
|
||||
/* Normal case: symbol in [0..15] */
|
||||
|
||||
// System.err.println("litdistLens["+ptr+"]: "+symbol);
|
||||
litdistLens[ptr++] = lastLen = (byte) symbol;
|
||||
|
||||
if (ptr == num)
|
||||
{
|
||||
/* Finished */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* need more input ? */
|
||||
if (symbol < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* otherwise repeat code */
|
||||
if (symbol >= 17)
|
||||
{
|
||||
/* repeat zero */
|
||||
// System.err.println("repeating zero");
|
||||
lastLen = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr == 0)
|
||||
{
|
||||
throw new SharpZipBaseException();
|
||||
}
|
||||
}
|
||||
|
||||
repSymbol = symbol - 16;
|
||||
}
|
||||
|
||||
mode = REPS;
|
||||
goto case REPS; // fall through
|
||||
case REPS:
|
||||
{
|
||||
int bits = repBits[repSymbol];
|
||||
int count = input.PeekBits(bits);
|
||||
if (count < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
input.DropBits(bits);
|
||||
count += repMin[repSymbol];
|
||||
|
||||
// System.err.println("litdistLens repeated: "+count);
|
||||
if (ptr + count > num)
|
||||
{
|
||||
throw new SharpZipBaseException();
|
||||
}
|
||||
|
||||
while (count-- > 0)
|
||||
{
|
||||
litdistLens[ptr++] = lastLen;
|
||||
}
|
||||
|
||||
if (ptr == num)
|
||||
{
|
||||
/* Finished */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
mode = LENS;
|
||||
goto decode_loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public InflaterHuffmanTree BuildLitLenTree()
|
||||
{
|
||||
var litlenLens = new byte[lnum];
|
||||
Array.Copy(litdistLens, 0, litlenLens, 0, lnum);
|
||||
return new InflaterHuffmanTree(litlenLens);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public InflaterHuffmanTree BuildDistTree()
|
||||
{
|
||||
var distLens = new byte[dnum];
|
||||
Array.Copy(litdistLens, lnum, distLens, 0, dnum);
|
||||
return new InflaterHuffmanTree(distLens);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
272
ASC.Xmpp.Core/IO/Compression/InflaterHuffmanTree.cs
Normal file
272
ASC.Xmpp.Core/IO/Compression/InflaterHuffmanTree.cs
Normal file
@ -0,0 +1,272 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.IO.Compression.Streams;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Huffman tree used for inflation
|
||||
/// </summary>
|
||||
public class InflaterHuffmanTree
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// Distance tree
|
||||
/// </summary>
|
||||
public static InflaterHuffmanTree defDistTree;
|
||||
|
||||
/// <summary>
|
||||
/// Literal length tree
|
||||
/// </summary>
|
||||
public static InflaterHuffmanTree defLitLenTree;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int MAX_BITLEN = 15;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private short[] tree;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <exception cref="SharpZipBaseException"></exception>
|
||||
static InflaterHuffmanTree()
|
||||
{
|
||||
try
|
||||
{
|
||||
var codeLengths = new byte[288];
|
||||
int i = 0;
|
||||
while (i < 144)
|
||||
{
|
||||
codeLengths[i++] = 8;
|
||||
}
|
||||
|
||||
while (i < 256)
|
||||
{
|
||||
codeLengths[i++] = 9;
|
||||
}
|
||||
|
||||
while (i < 280)
|
||||
{
|
||||
codeLengths[i++] = 7;
|
||||
}
|
||||
|
||||
while (i < 288)
|
||||
{
|
||||
codeLengths[i++] = 8;
|
||||
}
|
||||
|
||||
defLitLenTree = new InflaterHuffmanTree(codeLengths);
|
||||
|
||||
codeLengths = new byte[32];
|
||||
i = 0;
|
||||
while (i < 32)
|
||||
{
|
||||
codeLengths[i++] = 5;
|
||||
}
|
||||
|
||||
defDistTree = new InflaterHuffmanTree(codeLengths);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new SharpZipBaseException("InflaterHuffmanTree: static tree length illegal");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Huffman tree from the array of code lengths.
|
||||
/// </summary>
|
||||
/// <param name="codeLengths"> the array of code lengths </param>
|
||||
public InflaterHuffmanTree(byte[] codeLengths)
|
||||
{
|
||||
BuildTree(codeLengths);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Reads the next symbol from input. The symbol is encoded using the huffman tree.
|
||||
/// </summary>
|
||||
/// <param name="input"> input the input source. </param>
|
||||
/// <returns> the next symbol, or -1 if not enough input is available. </returns>
|
||||
public int GetSymbol(StreamManipulator input)
|
||||
{
|
||||
int lookahead, symbol;
|
||||
if ((lookahead = input.PeekBits(9)) >= 0)
|
||||
{
|
||||
if ((symbol = tree[lookahead]) >= 0)
|
||||
{
|
||||
input.DropBits(symbol & 15);
|
||||
return symbol >> 4;
|
||||
}
|
||||
|
||||
int subtree = -(symbol >> 4);
|
||||
int bitlen = symbol & 15;
|
||||
if ((lookahead = input.PeekBits(bitlen)) >= 0)
|
||||
{
|
||||
symbol = tree[subtree | (lookahead >> 9)];
|
||||
input.DropBits(symbol & 15);
|
||||
return symbol >> 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
int bits = input.AvailableBits;
|
||||
lookahead = input.PeekBits(bits);
|
||||
symbol = tree[subtree | (lookahead >> 9)];
|
||||
if ((symbol & 15) <= bits)
|
||||
{
|
||||
input.DropBits(symbol & 15);
|
||||
return symbol >> 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int bits = input.AvailableBits;
|
||||
lookahead = input.PeekBits(bits);
|
||||
symbol = tree[lookahead];
|
||||
if (symbol >= 0 && (symbol & 15) <= bits)
|
||||
{
|
||||
input.DropBits(symbol & 15);
|
||||
return symbol >> 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="codeLengths"> </param>
|
||||
private void BuildTree(byte[] codeLengths)
|
||||
{
|
||||
var blCount = new int[MAX_BITLEN + 1];
|
||||
var nextCode = new int[MAX_BITLEN + 1];
|
||||
|
||||
for (int i = 0; i < codeLengths.Length; i++)
|
||||
{
|
||||
int bits = codeLengths[i];
|
||||
if (bits > 0)
|
||||
{
|
||||
blCount[bits]++;
|
||||
}
|
||||
}
|
||||
|
||||
int code = 0;
|
||||
int treeSize = 512;
|
||||
for (int bits = 1; bits <= MAX_BITLEN; bits++)
|
||||
{
|
||||
nextCode[bits] = code;
|
||||
code += blCount[bits] << (16 - bits);
|
||||
if (bits >= 10)
|
||||
{
|
||||
/* We need an extra table for bit lengths >= 10. */
|
||||
int start = nextCode[bits] & 0x1ff80;
|
||||
int end = code & 0x1ff80;
|
||||
treeSize += (end - start) >> (16 - bits);
|
||||
}
|
||||
}
|
||||
|
||||
/* -jr comment this out! doesnt work for dynamic trees and pkzip 2.04g
|
||||
if (code != 65536)
|
||||
{
|
||||
throw new SharpZipBaseException("Code lengths don't add up properly.");
|
||||
}
|
||||
*/
|
||||
/* Now create and fill the extra tables from longest to shortest
|
||||
* bit len. This way the sub trees will be aligned.
|
||||
*/
|
||||
tree = new short[treeSize];
|
||||
int treePtr = 512;
|
||||
for (int bits = MAX_BITLEN; bits >= 10; bits--)
|
||||
{
|
||||
int end = code & 0x1ff80;
|
||||
code -= blCount[bits] << (16 - bits);
|
||||
int start = code & 0x1ff80;
|
||||
for (int i = start; i < end; i += 1 << 7)
|
||||
{
|
||||
tree[DeflaterHuffman.BitReverse(i)] = (short) ((-treePtr << 4) | bits);
|
||||
treePtr += 1 << (bits - 9);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < codeLengths.Length; i++)
|
||||
{
|
||||
int bits = codeLengths[i];
|
||||
if (bits == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
code = nextCode[bits];
|
||||
int revcode = DeflaterHuffman.BitReverse(code);
|
||||
if (bits <= 9)
|
||||
{
|
||||
do
|
||||
{
|
||||
tree[revcode] = (short) ((i << 4) | bits);
|
||||
revcode += 1 << bits;
|
||||
} while (revcode < 512);
|
||||
}
|
||||
else
|
||||
{
|
||||
int subTree = tree[revcode & 511];
|
||||
int treeLen = 1 << (subTree & 15);
|
||||
subTree = -(subTree >> 4);
|
||||
do
|
||||
{
|
||||
tree[subTree | (revcode >> 9)] = (short) ((i << 4) | bits);
|
||||
revcode += 1 << bits;
|
||||
} while (revcode < treeLen);
|
||||
}
|
||||
|
||||
nextCode[bits] = code + (1 << (16 - bits));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
246
ASC.Xmpp.Core/IO/Compression/PendingBuffer.cs
Normal file
246
ASC.Xmpp.Core/IO/Compression/PendingBuffer.cs
Normal file
@ -0,0 +1,246 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is general purpose class for writing data to a buffer. It allows you to write bits as well as bytes Based on DeflaterPending.java author of the original java version : Jochen Hoenicke
|
||||
/// </summary>
|
||||
public class PendingBuffer
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int bitCount;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private uint bits;
|
||||
|
||||
/// <summary>
|
||||
/// Internal work buffer
|
||||
/// </summary>
|
||||
protected byte[] buf;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int end;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int start;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// construct instance using default buffer size of 4096
|
||||
/// </summary>
|
||||
public PendingBuffer() : this(4096)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// construct instance using specified buffer size
|
||||
/// </summary>
|
||||
/// <param name="bufsize"> size to use for internal buffer </param>
|
||||
public PendingBuffer(int bufsize)
|
||||
{
|
||||
buf = new byte[bufsize];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// The number of bits written to the buffer
|
||||
/// </summary>
|
||||
public int BitCount
|
||||
{
|
||||
get { return bitCount; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if buffer has been flushed
|
||||
/// </summary>
|
||||
public bool IsFlushed
|
||||
{
|
||||
get { return end == 0; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Clear internal state/buffers
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
start = end = bitCount = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// write a byte to buffer
|
||||
/// </summary>
|
||||
/// <param name="b"> value to write </param>
|
||||
public void WriteByte(int b)
|
||||
{
|
||||
buf[end++] = (byte) b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a short value to buffer LSB first
|
||||
/// </summary>
|
||||
/// <param name="s"> value to write </param>
|
||||
public void WriteShort(int s)
|
||||
{
|
||||
buf[end++] = (byte) s;
|
||||
buf[end++] = (byte) (s >> 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// write an integer LSB first
|
||||
/// </summary>
|
||||
/// <param name="s"> value to write </param>
|
||||
public void WriteInt(int s)
|
||||
{
|
||||
buf[end++] = (byte) s;
|
||||
buf[end++] = (byte) (s >> 8);
|
||||
buf[end++] = (byte) (s >> 16);
|
||||
buf[end++] = (byte) (s >> 24);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a block of data to buffer
|
||||
/// </summary>
|
||||
/// <param name="block"> data to write </param>
|
||||
/// <param name="offset"> offset of first byte to write </param>
|
||||
/// <param name="len"> number of bytes to write </param>
|
||||
public void WriteBlock(byte[] block, int offset, int len)
|
||||
{
|
||||
Array.Copy(block, offset, buf, end, len);
|
||||
end += len;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Align internal buffer on a byte boundary
|
||||
/// </summary>
|
||||
public void AlignToByte()
|
||||
{
|
||||
if (bitCount > 0)
|
||||
{
|
||||
buf[end++] = (byte) bits;
|
||||
if (bitCount > 8)
|
||||
{
|
||||
buf[end++] = (byte) (bits >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
bits = 0;
|
||||
bitCount = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write bits to internal buffer
|
||||
/// </summary>
|
||||
/// <param name="b"> source of bits </param>
|
||||
/// <param name="count"> number of bits to write </param>
|
||||
public void WriteBits(int b, int count)
|
||||
{
|
||||
// if (DeflaterConstants.DEBUGGING) {
|
||||
// //Console.WriteLine("writeBits("+b+","+count+")");
|
||||
// }
|
||||
bits |= (uint) (b << bitCount);
|
||||
bitCount += count;
|
||||
if (bitCount >= 16)
|
||||
{
|
||||
buf[end++] = (byte) bits;
|
||||
buf[end++] = (byte) (bits >> 8);
|
||||
bits >>= 16;
|
||||
bitCount -= 16;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a short value to internal buffer most significant byte first
|
||||
/// </summary>
|
||||
/// <param name="s"> value to write </param>
|
||||
public void WriteShortMSB(int s)
|
||||
{
|
||||
buf[end++] = (byte) (s >> 8);
|
||||
buf[end++] = (byte) s;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flushes the pending buffer into the given output array. If the output array is to small, only a partial flush is done.
|
||||
/// </summary>
|
||||
/// <param name="output"> the output array; </param>
|
||||
/// <param name="offset"> the offset into output array; </param>
|
||||
/// <param name="length"> length the maximum number of bytes to store; </param>
|
||||
/// <exception name="ArgumentOutOfRangeException">IndexOutOfBoundsException if offset or length are invalid.</exception>
|
||||
/// <returns> </returns>
|
||||
public int Flush(byte[] output, int offset, int length)
|
||||
{
|
||||
if (bitCount >= 8)
|
||||
{
|
||||
buf[end++] = (byte) bits;
|
||||
bits >>= 8;
|
||||
bitCount -= 8;
|
||||
}
|
||||
|
||||
if (length > end - start)
|
||||
{
|
||||
length = end - start;
|
||||
Array.Copy(buf, start, output, offset, length);
|
||||
start = 0;
|
||||
end = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(buf, start, output, offset, length);
|
||||
start += length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert internal buffer to byte array. Buffer is empty on completion
|
||||
/// </summary>
|
||||
/// <returns> converted buffer contents contents </returns>
|
||||
public byte[] ToByteArray()
|
||||
{
|
||||
var ret = new byte[end - start];
|
||||
Array.Copy(buf, start, ret, 0, ret.Length);
|
||||
start = 0;
|
||||
end = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
59
ASC.Xmpp.Core/IO/Compression/SharpZipBaseException.cs
Normal file
59
ASC.Xmpp.Core/IO/Compression/SharpZipBaseException.cs
Normal file
@ -0,0 +1,59 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression
|
||||
{
|
||||
/// <summary>
|
||||
/// SharpZipBaseException is the base exception class for the SharpZipLibrary. All library exceptions are derived from this.
|
||||
/// </summary>
|
||||
public class SharpZipBaseException : ApplicationException
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SharpZipLibraryException class.
|
||||
/// </summary>
|
||||
public SharpZipBaseException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SharpZipLibraryException class with a specified error message.
|
||||
/// </summary>
|
||||
/// <param name="msg"> </param>
|
||||
public SharpZipBaseException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SharpZipLibraryException class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
||||
/// </summary>
|
||||
/// <param name="message"> Error message string </param>
|
||||
/// <param name="innerException"> The inner exception </param>
|
||||
public SharpZipBaseException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
256
ASC.Xmpp.Core/IO/Compression/Streams/OutputWindow.cs
Normal file
256
ASC.Xmpp.Core/IO/Compression/Streams/OutputWindow.cs
Normal file
@ -0,0 +1,256 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression.Streams
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Contains the output from the Inflation process. We need to have a window so that we can refer backwards into the output stream to repeat stuff. <br /> Author of the original java version : John Leuner
|
||||
/// </summary>
|
||||
public class OutputWindow
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static readonly int WINDOW_MASK = WINDOW_SIZE - 1;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static int WINDOW_SIZE = 1 << 15;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly byte[] window = new byte[WINDOW_SIZE]; // The window is 2^15 bytes
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int windowEnd;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int windowFilled;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Write a byte to this output window
|
||||
/// </summary>
|
||||
/// <param name="abyte"> value to write </param>
|
||||
/// <exception cref="InvalidOperationException">if window is full</exception>
|
||||
public void Write(int abyte)
|
||||
{
|
||||
if (windowFilled++ == WINDOW_SIZE)
|
||||
{
|
||||
throw new InvalidOperationException("Window full");
|
||||
}
|
||||
|
||||
window[windowEnd++] = (byte) abyte;
|
||||
windowEnd &= WINDOW_MASK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a byte pattern already in the window itself
|
||||
/// </summary>
|
||||
/// <param name="len"> length of pattern to copy </param>
|
||||
/// <param name="dist"> distance from end of window pattern occurs </param>
|
||||
/// <exception cref="InvalidOperationException">If the repeated data overflows the window</exception>
|
||||
public void Repeat(int len, int dist)
|
||||
{
|
||||
if ((windowFilled += len) > WINDOW_SIZE)
|
||||
{
|
||||
throw new InvalidOperationException("Window full");
|
||||
}
|
||||
|
||||
int rep_start = (windowEnd - dist) & WINDOW_MASK;
|
||||
int border = WINDOW_SIZE - len;
|
||||
if (rep_start <= border && windowEnd < border)
|
||||
{
|
||||
if (len <= dist)
|
||||
{
|
||||
Array.Copy(window, rep_start, window, windowEnd, len);
|
||||
windowEnd += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We have to copy manually, since the repeat pattern overlaps. */
|
||||
while (len-- > 0)
|
||||
{
|
||||
window[windowEnd++] = window[rep_start++];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SlowRepeat(rep_start, len, dist);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy from input manipulator to internal window
|
||||
/// </summary>
|
||||
/// <param name="input"> source of data </param>
|
||||
/// <param name="len"> length of data to copy </param>
|
||||
/// <returns> the number of bytes copied </returns>
|
||||
public int CopyStored(StreamManipulator input, int len)
|
||||
{
|
||||
len = Math.Min(Math.Min(len, WINDOW_SIZE - windowFilled), input.AvailableBytes);
|
||||
int copied;
|
||||
|
||||
int tailLen = WINDOW_SIZE - windowEnd;
|
||||
if (len > tailLen)
|
||||
{
|
||||
copied = input.CopyBytes(window, windowEnd, tailLen);
|
||||
if (copied == tailLen)
|
||||
{
|
||||
copied += input.CopyBytes(window, 0, len - tailLen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = input.CopyBytes(window, windowEnd, len);
|
||||
}
|
||||
|
||||
windowEnd = (windowEnd + copied) & WINDOW_MASK;
|
||||
windowFilled += copied;
|
||||
return copied;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy dictionary to window
|
||||
/// </summary>
|
||||
/// <param name="dict"> source dictionary </param>
|
||||
/// <param name="offset"> offset of start in source dictionary </param>
|
||||
/// <param name="len"> length of dictionary </param>
|
||||
/// <exception cref="InvalidOperationException">If window isnt empty</exception>
|
||||
public void CopyDict(byte[] dict, int offset, int len)
|
||||
{
|
||||
if (windowFilled > 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
if (len > WINDOW_SIZE)
|
||||
{
|
||||
offset += len - WINDOW_SIZE;
|
||||
len = WINDOW_SIZE;
|
||||
}
|
||||
|
||||
Array.Copy(dict, offset, window, 0, len);
|
||||
windowEnd = len & WINDOW_MASK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get remaining unfilled space in window
|
||||
/// </summary>
|
||||
/// <returns> Number of bytes left in window </returns>
|
||||
public int GetFreeSpace()
|
||||
{
|
||||
return WINDOW_SIZE - windowFilled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get bytes available for output in window
|
||||
/// </summary>
|
||||
/// <returns> Number of bytes filled </returns>
|
||||
public int GetAvailable()
|
||||
{
|
||||
return windowFilled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy contents of window to output
|
||||
/// </summary>
|
||||
/// <param name="output"> buffer to copy to </param>
|
||||
/// <param name="offset"> offset to start at </param>
|
||||
/// <param name="len"> number of bytes to count </param>
|
||||
/// <returns> The number of bytes copied </returns>
|
||||
/// <exception cref="InvalidOperationException">If a window underflow occurs</exception>
|
||||
public int CopyOutput(byte[] output, int offset, int len)
|
||||
{
|
||||
int copy_end = windowEnd;
|
||||
if (len > windowFilled)
|
||||
{
|
||||
len = windowFilled;
|
||||
}
|
||||
else
|
||||
{
|
||||
copy_end = (windowEnd - windowFilled + len) & WINDOW_MASK;
|
||||
}
|
||||
|
||||
int copied = len;
|
||||
int tailLen = len - copy_end;
|
||||
|
||||
if (tailLen > 0)
|
||||
{
|
||||
Array.Copy(window, WINDOW_SIZE - tailLen, output, offset, tailLen);
|
||||
offset += tailLen;
|
||||
len = copy_end;
|
||||
}
|
||||
|
||||
Array.Copy(window, copy_end - len, output, offset, len);
|
||||
windowFilled -= copied;
|
||||
if (windowFilled < 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
return copied;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset by clearing window so <see cref="GetAvailable">GetAvailable</see> returns 0
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
windowFilled = windowEnd = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="repStart"> </param>
|
||||
/// <param name="len"> </param>
|
||||
/// <param name="dist"> </param>
|
||||
private void SlowRepeat(int repStart, int len, int dist)
|
||||
{
|
||||
while (len-- > 0)
|
||||
{
|
||||
window[windowEnd++] = window[repStart++];
|
||||
windowEnd &= WINDOW_MASK;
|
||||
repStart &= WINDOW_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
251
ASC.Xmpp.Core/IO/Compression/Streams/StreamManipulator.cs
Normal file
251
ASC.Xmpp.Core/IO/Compression/Streams/StreamManipulator.cs
Normal file
@ -0,0 +1,251 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.IO.Compression.Streams
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// This class allows us to retrieve a specified number of bits from the input buffer, as well as copy big byte blocks. It uses an int buffer to store up to 31 bits for direct manipulation. This guarantees that we can get at least 16 bits, but we only need at most 15, so this is all safe. There are some optimizations in this class, for example, you must never peek more than 8 bits more than needed, and you must first peek bits before you may drop them. This is not a general purpose class but optimized for the behaviour of the Inflater. authors of the original java version : John Leuner, Jochen Hoenicke
|
||||
/// </summary>
|
||||
public class StreamManipulator
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int bits_in_buffer;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private uint buffer;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private byte[] window;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int window_end;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private int window_start;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bits available in the bit buffer. This must be only called when a previous PeekBits() returned -1.
|
||||
/// </summary>
|
||||
/// <returns> the number of bits available. </returns>
|
||||
public int AvailableBits
|
||||
{
|
||||
get { return bits_in_buffer; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bytes available.
|
||||
/// </summary>
|
||||
/// <returns> The number of bytes available. </returns>
|
||||
public int AvailableBytes
|
||||
{
|
||||
get { return window_end - window_start + (bits_in_buffer >> 3); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true when SetInput can be called
|
||||
/// </summary>
|
||||
public bool IsNeedingInput
|
||||
{
|
||||
get { return window_start == window_end; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get the next n bits but don't increase input pointer. n must be less or equal 16 and if this call succeeds, you must drop at least n - 8 bits in the next call.
|
||||
/// </summary>
|
||||
/// <param name="n"> </param>
|
||||
/// <returns> the value of the bits, or -1 if not enough bits available. */ </returns>
|
||||
public int PeekBits(int n)
|
||||
{
|
||||
if (bits_in_buffer < n)
|
||||
{
|
||||
if (window_start == window_end)
|
||||
{
|
||||
return -1; // ok
|
||||
}
|
||||
|
||||
buffer |=
|
||||
(uint)
|
||||
((window[window_start++] & 0xff | (window[window_start++] & 0xff) << 8) << bits_in_buffer);
|
||||
bits_in_buffer += 16;
|
||||
}
|
||||
|
||||
return (int) (buffer & ((1 << n) - 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops the next n bits from the input. You should have called PeekBits with a bigger or equal n before, to make sure that enough bits are in the bit buffer.
|
||||
/// </summary>
|
||||
/// <param name="n"> </param>
|
||||
public void DropBits(int n)
|
||||
{
|
||||
buffer >>= n;
|
||||
bits_in_buffer -= n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next n bits and increases input pointer. This is equivalent to PeekBits followed by dropBits, except for correct error handling.
|
||||
/// </summary>
|
||||
/// <param name="n"> </param>
|
||||
/// <returns> the value of the bits, or -1 if not enough bits available. </returns>
|
||||
public int GetBits(int n)
|
||||
{
|
||||
int bits = PeekBits(n);
|
||||
if (bits >= 0)
|
||||
{
|
||||
DropBits(n);
|
||||
}
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skips to the next byte boundary.
|
||||
/// </summary>
|
||||
public void SkipToByteBoundary()
|
||||
{
|
||||
buffer >>= bits_in_buffer & 7;
|
||||
bits_in_buffer &= ~7;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies length bytes from input buffer to output buffer starting at output[offset]. You have to make sure, that the buffer is byte aligned. If not enough bytes are available, copies fewer bytes.
|
||||
/// </summary>
|
||||
/// <param name="output"> The buffer to copy bytes to. </param>
|
||||
/// <param name="offset"> The offset in the buffer at which copying starts </param>
|
||||
/// <param name="length"> The length to copy, 0 is allowed. </param>
|
||||
/// <returns> The number of bytes copied, 0 if no bytes were available. </returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Length is less than zero</exception>
|
||||
/// <exception cref="InvalidOperationException">Bit buffer isnt byte aligned</exception>
|
||||
public int CopyBytes(byte[] output, int offset, int length)
|
||||
{
|
||||
if (length < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("length");
|
||||
}
|
||||
|
||||
if ((bits_in_buffer & 7) != 0)
|
||||
{
|
||||
/* bits_in_buffer may only be 0 or a multiple of 8 */
|
||||
throw new InvalidOperationException("Bit buffer is not byte aligned!");
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
while (bits_in_buffer > 0 && length > 0)
|
||||
{
|
||||
output[offset++] = (byte) buffer;
|
||||
buffer >>= 8;
|
||||
bits_in_buffer -= 8;
|
||||
length--;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
int avail = window_end - window_start;
|
||||
if (length > avail)
|
||||
{
|
||||
length = avail;
|
||||
}
|
||||
|
||||
Array.Copy(window, window_start, output, offset, length);
|
||||
window_start += length;
|
||||
|
||||
if (((window_start - window_end) & 1) != 0)
|
||||
{
|
||||
/* We always want an even number of bytes in input, see peekBits */
|
||||
buffer = (uint) (window[window_start++] & 0xff);
|
||||
bits_in_buffer = 8;
|
||||
}
|
||||
|
||||
return count + length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// resets state and empties internal buffers
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
buffer = (uint) (window_start = window_end = bits_in_buffer = 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add more input for consumption. Only call when IsNeedingInput returns true
|
||||
/// </summary>
|
||||
/// <param name="buf"> data to be input </param>
|
||||
/// <param name="off"> offset of first byte of input </param>
|
||||
/// <param name="len"> length of input </param>
|
||||
public void SetInput(byte[] buf, int off, int len)
|
||||
{
|
||||
if (window_start < window_end)
|
||||
{
|
||||
throw new InvalidOperationException("Old input was not completely processed");
|
||||
}
|
||||
|
||||
int end = off + len;
|
||||
|
||||
/* We want to throw an ArrayIndexOutOfBoundsException early. The
|
||||
* check is very tricky: it also handles integer wrap around.
|
||||
*/
|
||||
if (0 > off || off > end || end > buf.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
if ((len & 1) != 0)
|
||||
{
|
||||
/* We always want an even number of bytes in input, see peekBits */
|
||||
buffer |= (uint) ((buf[off++] & 0xff) << bits_in_buffer);
|
||||
bits_in_buffer += 8;
|
||||
}
|
||||
|
||||
window = buf;
|
||||
window_start = off;
|
||||
window_end = end;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
67
ASC.Xmpp.Core/IO/StringWriterWithEncoding.cs
Normal file
67
ASC.Xmpp.Core/IO/StringWriterWithEncoding.cs
Normal file
@ -0,0 +1,67 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is inherited from the StringWriter Class The standard StringWriter class supports no encoding With this Class we can set the Encoding of a StringWriter in the Constructor
|
||||
/// </summary>
|
||||
public class StringWriterWithEncoding : StringWriter
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly Encoding m_Encoding;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="encoding"> </param>
|
||||
public StringWriterWithEncoding(Encoding encoding)
|
||||
{
|
||||
m_Encoding = encoding;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public override Encoding Encoding
|
||||
{
|
||||
get { return m_Encoding; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
86
ASC.Xmpp.Core/Properties/AssemblyInfo.cs
Normal file
86
ASC.Xmpp.Core/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,86 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#endregion
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
|
||||
[assembly: AssemblyTitle("ASC.Xmpp.Core")]
|
||||
[assembly: AssemblyDescription("ASC.Xmpp.Core library")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Ascensio System SIA")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("(c) Ascensio System SIA. All rights reserved")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("1.1.0")]
|
||||
|
||||
//
|
||||
// In order to sign your assembly you must specify a key to use. Refer to the
|
||||
// Microsoft .NET Framework documentation for more information on assembly signing.
|
||||
//
|
||||
// Use the attributes below to control which key is used for signing.
|
||||
//
|
||||
// Notes:
|
||||
// (*) If no key is specified - the assembly cannot be signed.
|
||||
// (*) KeyName refers to a key that has been installed in the Crypto Service
|
||||
// Provider (CSP) on your machine.
|
||||
// (*) If the key file and a key name attributes are both specified, the
|
||||
// following processing occurs:
|
||||
// (1) If the KeyName can be found in the CSP - that key is used.
|
||||
// (2) If the KeyName does not exist and the KeyFile does exist, the key
|
||||
// in the file is installed into the CSP and used.
|
||||
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
|
||||
// documentation for more information on this.
|
||||
//
|
||||
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
||||
// There was no need yet for a .NET 1.1 Condition. So use MONOSSL here
|
||||
// because its only used with .NET 1.1
|
||||
#if CF || MONOSSL
|
||||
[assembly: AssemblyKeyFile(@"..\..\key.snk")]
|
||||
#endif
|
||||
//[assembly: AssemblyKeyName("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
43
ASC.Xmpp.Core/app.config
Normal file
43
ASC.Xmpp.Core/app.config
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.8.6.0" newVersion="1.8.6.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="StackExchange.Redis.Extensions.Core" publicKeyToken="d7d863643bcd13ef" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.Pipelines" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Channels" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
296
ASC.Xmpp.Core/authorization/DigestMD5/Step1.cs
Normal file
296
ASC.Xmpp.Core/authorization/DigestMD5/Step1.cs
Normal file
@ -0,0 +1,296 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.authorization.DigestMD5
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for Step1.
|
||||
/// </summary>
|
||||
public class Step1 : Mechanism
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Algorithm;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Charset = "utf-8";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Nonce;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Qop; // = "auth";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Realm;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Rspauth;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Step1()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="message"> </param>
|
||||
public Step1(string message)
|
||||
{
|
||||
Parse(message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Algorithm
|
||||
{
|
||||
get { return m_Algorithm; }
|
||||
|
||||
set { m_Algorithm = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Charset
|
||||
{
|
||||
get { return m_Charset; }
|
||||
|
||||
set { m_Charset = value; }
|
||||
}
|
||||
|
||||
public Encoding Encoding
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return Encoding.GetEncoding(Charset);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Nonce
|
||||
{
|
||||
get { return m_Nonce; }
|
||||
|
||||
set { m_Nonce = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Qop
|
||||
{
|
||||
get { return m_Qop; }
|
||||
|
||||
set { m_Qop = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Realm
|
||||
{
|
||||
get { return m_Realm; }
|
||||
|
||||
set { m_Realm = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Rspauth
|
||||
{
|
||||
get { return m_Rspauth; }
|
||||
|
||||
set { m_Rspauth = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Parse(utils.Xml.Dom.Node e)
|
||||
{
|
||||
}
|
||||
|
||||
#region Utility methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="message"> </param>
|
||||
/// <exception cref="ChallengeParseException"></exception>
|
||||
private void Parse(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
while (start < message.Length)
|
||||
{
|
||||
int equalPos = message.IndexOf('=', start);
|
||||
if (equalPos > 0)
|
||||
{
|
||||
// look if the next char is a quote
|
||||
if (message.Substring(equalPos + 1, 1) == "\"")
|
||||
{
|
||||
// quoted value, find the end now
|
||||
end = message.IndexOf('"', equalPos + 2);
|
||||
ParsePair(message.Substring(start, end - start + 1));
|
||||
start = end + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// value is not quoted, ends at the next comma or end of string
|
||||
end = message.IndexOf(',', equalPos + 1);
|
||||
if (end == -1)
|
||||
{
|
||||
end = message.Length;
|
||||
}
|
||||
|
||||
ParsePair(message.Substring(start, end - start));
|
||||
|
||||
start = end + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ChallengeParseException("Unable to parse challenge");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="pair"> </param>
|
||||
private void ParsePair(string pair)
|
||||
{
|
||||
int equalPos = pair.IndexOf("=");
|
||||
if (equalPos > 0)
|
||||
{
|
||||
string key = pair.Substring(0, equalPos);
|
||||
string data;
|
||||
|
||||
// is the value quoted?
|
||||
if (pair.Substring(equalPos + 1, 1) == "\"")
|
||||
{
|
||||
data = pair.Substring(equalPos + 2, pair.Length - equalPos - 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = pair.Substring(equalPos + 1);
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case "realm":
|
||||
m_Realm = data;
|
||||
break;
|
||||
case "nonce":
|
||||
m_Nonce = data;
|
||||
break;
|
||||
case "qop":
|
||||
m_Qop = data;
|
||||
break;
|
||||
case "charset":
|
||||
m_Charset = data;
|
||||
break;
|
||||
case "algorithm":
|
||||
m_Algorithm = data;
|
||||
break;
|
||||
case "rspauth":
|
||||
m_Rspauth = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// Mechanism
|
||||
|
||||
/*
|
||||
nonce="deqOGux/N6hDPtf9vkGMU5Vzae+zfrqpBIvh6LovbBM=",
|
||||
realm="amessage.de",
|
||||
qop="auth,auth-int,auth-conf",
|
||||
cipher="rc4-40,rc4-56,rc4,des,3des",
|
||||
maxbuf=1024,
|
||||
charset=utf-8,
|
||||
algorithm=md5-sess
|
||||
*/
|
||||
|
||||
#region Nested type: ChallengeParseException
|
||||
|
||||
/// <summary>
|
||||
/// Exception occurs when we were unable to parse the challenge
|
||||
/// </summary>
|
||||
public class ChallengeParseException : Exception
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="message"> </param>
|
||||
public ChallengeParseException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
490
ASC.Xmpp.Core/authorization/DigestMD5/Step2.cs
Normal file
490
ASC.Xmpp.Core/authorization/DigestMD5/Step2.cs
Normal file
@ -0,0 +1,490 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using ASC.Xmpp.Core.utils;
|
||||
|
||||
#endregion
|
||||
|
||||
#if CF
|
||||
using agsXMPP.util;
|
||||
#endif
|
||||
|
||||
namespace ASC.Xmpp.Core.authorization.DigestMD5
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for Step2.
|
||||
/// </summary>
|
||||
public class Step2 : Step1
|
||||
{
|
||||
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Authzid;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Cnonce;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_DigestUri;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Nc;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private string m_Response;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Step2()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// parses a message and returns the step2 object
|
||||
/// </summary>
|
||||
/// <param name="message"> </param>
|
||||
/// <param name="challengeEncoding">challenge encoding </param>
|
||||
public Step2(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
while (start < message.Length)
|
||||
{
|
||||
int equalPos = message.IndexOf('=', start);
|
||||
if (equalPos > 0)
|
||||
{
|
||||
// look if the next char is a quote
|
||||
if (message.Substring(equalPos + 1, 1) == "\"")
|
||||
{
|
||||
// quoted value, find the end now
|
||||
end = message.IndexOf('"', equalPos + 2);
|
||||
ParsePair(message.Substring(start, end - start + 1));
|
||||
start = end + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// value is not quoted, ends at the next comma or end of string
|
||||
end = message.IndexOf(',', equalPos + 1);
|
||||
if (end == -1)
|
||||
{
|
||||
end = message.Length;
|
||||
}
|
||||
|
||||
ParsePair(message.Substring(start, end - start));
|
||||
|
||||
start = end + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ChallengeParseException("Unable to parse challenge");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Authzid
|
||||
{
|
||||
get { return m_Authzid; }
|
||||
|
||||
set { m_Authzid = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Cnonce
|
||||
{
|
||||
get { return m_Cnonce; }
|
||||
|
||||
set { m_Cnonce = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string DigestUri
|
||||
{
|
||||
get { return m_DigestUri; }
|
||||
|
||||
set { m_DigestUri = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Nc
|
||||
{
|
||||
get { return m_Nc; }
|
||||
|
||||
set { m_Nc = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Response
|
||||
{
|
||||
get { return m_Response; }
|
||||
|
||||
set { m_Response = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="username"> </param>
|
||||
/// <param name="pwddata"> </param>
|
||||
/// <returns> </returns>
|
||||
public bool Authorize(string username, string pwddata)
|
||||
{
|
||||
if (Response == GenerateResponse(username, pwddata, "AUTHENTICATE"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return GenerateMessage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string GenerateResponse(string username, string password, string method)
|
||||
{
|
||||
byte[] H1;
|
||||
byte[] H2;
|
||||
byte[] H3;
|
||||
|
||||
// byte[] temp;
|
||||
string A1;
|
||||
string A2;
|
||||
string A3;
|
||||
string p1;
|
||||
string p2;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(username);
|
||||
sb.Append(":");
|
||||
sb.Append(Realm);
|
||||
sb.Append(":");
|
||||
sb.Append(password);
|
||||
|
||||
#if !CF
|
||||
H1 = new MD5CryptoServiceProvider().ComputeHash(Encoding.GetBytes(sb.ToString()));
|
||||
#else
|
||||
|
||||
// H1 = Encoding.GetBytes(util.Hash.MD5Hash(sb.ToString()));
|
||||
H1 = util.Hash.MD5Hash(Encoding.GetBytes(sb.ToString()));
|
||||
#endif
|
||||
|
||||
sb.Remove(0, sb.Length);
|
||||
sb.Append(":");
|
||||
sb.Append(Nonce);
|
||||
sb.Append(":");
|
||||
sb.Append(Cnonce);
|
||||
|
||||
if (m_Authzid != null)
|
||||
{
|
||||
sb.Append(":");
|
||||
sb.Append(m_Authzid);
|
||||
}
|
||||
|
||||
A1 = sb.ToString();
|
||||
|
||||
// sb.Remove(0, sb.Length);
|
||||
// sb.Append(Encoding.Default.GetChars(H1));
|
||||
// //sb.Append(Encoding.ASCII.GetChars(H1));
|
||||
// sb.Append(A1);
|
||||
byte[] bA1 = Encoding.ASCII.GetBytes(A1);
|
||||
var bH1A1 = new byte[H1.Length + bA1.Length];
|
||||
|
||||
// Array.Copy(H1, bH1A1, H1.Length);
|
||||
Array.Copy(H1, 0, bH1A1, 0, H1.Length);
|
||||
Array.Copy(bA1, 0, bH1A1, H1.Length, bA1.Length);
|
||||
#if !CF
|
||||
H1 = new MD5CryptoServiceProvider().ComputeHash(bH1A1);
|
||||
|
||||
// Console.WriteLine(util.Hash.HexToString(H1));
|
||||
#else
|
||||
|
||||
// H1 = Encoding.Default.GetBytes(util.Hash.MD5Hash(sb.ToString()));
|
||||
// H1 =util.Hash.MD5Hash(Encoding.Default.GetBytes(sb.ToString()));
|
||||
H1 =util.Hash.MD5Hash(bH1A1);
|
||||
#endif
|
||||
sb.Remove(0, sb.Length);
|
||||
sb.Append(method);
|
||||
sb.Append(":");
|
||||
sb.Append(m_DigestUri);
|
||||
if (Qop.CompareTo("auth") != 0)
|
||||
{
|
||||
sb.Append(":00000000000000000000000000000000");
|
||||
}
|
||||
|
||||
A2 = sb.ToString();
|
||||
H2 = Encoding.ASCII.GetBytes(A2);
|
||||
|
||||
#if !CF
|
||||
H2 = new MD5CryptoServiceProvider().ComputeHash(H2);
|
||||
#else
|
||||
|
||||
// H2 = Encoding.Default.GetBytes(util.Hash.MD5Hash(H2));
|
||||
H2 =util.Hash.MD5Hash(H2);
|
||||
#endif
|
||||
|
||||
// create p1 and p2 as the hex representation of H1 and H2
|
||||
p1 = Hash.HexToString(H1).ToLower();
|
||||
p2 = Hash.HexToString(H2).ToLower();
|
||||
|
||||
sb.Remove(0, sb.Length);
|
||||
sb.Append(p1);
|
||||
sb.Append(":");
|
||||
sb.Append(Nonce);
|
||||
sb.Append(":");
|
||||
sb.Append(m_Nc);
|
||||
sb.Append(":");
|
||||
sb.Append(m_Cnonce);
|
||||
sb.Append(":");
|
||||
sb.Append(base.Qop);
|
||||
sb.Append(":");
|
||||
sb.Append(p2);
|
||||
|
||||
A3 = sb.ToString();
|
||||
#if !CF
|
||||
H3 = new MD5CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(A3));
|
||||
#else
|
||||
|
||||
// H3 = Encoding.Default.GetBytes(util.Hash.MD5Hash(A3));
|
||||
H3 =util.Hash.MD5Hash(Encoding.ASCII.GetBytes(A3));
|
||||
#endif
|
||||
return Hash.HexToString(H3).ToLower();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility methods
|
||||
|
||||
/// <summary>
|
||||
/// Does the server support Auth?
|
||||
/// </summary>
|
||||
/// <param name="qop"> </param>
|
||||
/// <returns> </returns>
|
||||
private bool SupportsAuth(string qop)
|
||||
{
|
||||
string[] auth = qop.Split(',');
|
||||
|
||||
// This overload was not available in the CF, so updated this to the following
|
||||
// bool ret = Array.IndexOf(auth, "auth") < 0 ? false : true;
|
||||
bool ret = Array.IndexOf(auth, "auth", auth.GetLowerBound(0), auth.Length) < 0 ? false : true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="pair"> </param>
|
||||
private void ParsePair(string pair)
|
||||
{
|
||||
int equalPos = pair.IndexOf("=");
|
||||
if (equalPos > 0)
|
||||
{
|
||||
string key = pair.Substring(0, equalPos).Trim();
|
||||
string data;
|
||||
|
||||
// is the value quoted?
|
||||
if (pair.Substring(equalPos + 1, 1) == "\"")
|
||||
{
|
||||
data = pair.Substring(equalPos + 2, pair.Length - equalPos - 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = pair.Substring(equalPos + 1);
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case "realm":
|
||||
Realm = data;
|
||||
break;
|
||||
case "nonce":
|
||||
Nonce = data;
|
||||
break;
|
||||
case "cnonce":
|
||||
Cnonce = data;
|
||||
break;
|
||||
case "qop":
|
||||
Qop = data;
|
||||
break;
|
||||
case "username":
|
||||
Username = data;
|
||||
break;
|
||||
case "charset":
|
||||
Charset = data;
|
||||
break;
|
||||
case "algorithm":
|
||||
Algorithm = data;
|
||||
break;
|
||||
case "rspauth":
|
||||
Rspauth = data;
|
||||
break;
|
||||
case "nc":
|
||||
Nc = data;
|
||||
break;
|
||||
case "digest-uri":
|
||||
DigestUri = data;
|
||||
break;
|
||||
case "response":
|
||||
Response = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private void GenerateCnonce()
|
||||
{
|
||||
// Lenght of the Session ID on bytes,
|
||||
// 32 bytes equaly 64 chars
|
||||
// 16^64 possibilites for the session IDs (4.294.967.296)
|
||||
// This should be unique enough
|
||||
int m_lenght = 32;
|
||||
|
||||
RandomNumberGenerator RNG = RandomNumberGenerator.Create();
|
||||
|
||||
var buf = new byte[m_lenght];
|
||||
RNG.GetBytes(buf);
|
||||
|
||||
m_Cnonce = Hash.HexToString(buf).ToLower();
|
||||
|
||||
// m_Cnonce = "e163ceed6cfbf8c1559a9ff373b292c2f926b65719a67a67c69f7f034c50aba3";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private void GenerateNc()
|
||||
{
|
||||
int nc = 1;
|
||||
m_Nc = nc.ToString().PadLeft(8, '0');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private void GenerateDigestUri()
|
||||
{
|
||||
m_DigestUri = "xmpp/" + base.Server;
|
||||
}
|
||||
|
||||
// HEX( KD ( HEX(H(A1)),
|
||||
// {
|
||||
// nonce-value, ":" nc-value, ":",
|
||||
// cnonce-value, ":", qop-value, ":", HEX(H(A2)) }))
|
||||
// If authzid is specified, then A1 is
|
||||
// A1 = { H( { username-value, ":", realm-value, ":", passwd } ),
|
||||
// ":", nonce-value, ":", cnonce-value, ":", authzid-value }
|
||||
// If authzid is not specified, then A1 is
|
||||
// A1 = { H( { username-value, ":", realm-value, ":", passwd } ),
|
||||
// ":", nonce-value, ":", cnonce-value }
|
||||
// where
|
||||
// passwd = *OCTET
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
private string GenerateMessage()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("username=");
|
||||
sb.Append(AddQuotes(Username));
|
||||
sb.Append(",");
|
||||
sb.Append("realm=");
|
||||
sb.Append(AddQuotes(Realm));
|
||||
sb.Append(",");
|
||||
sb.Append("nonce=");
|
||||
sb.Append(AddQuotes(Nonce));
|
||||
sb.Append(",");
|
||||
sb.Append("cnonce=");
|
||||
sb.Append(AddQuotes(Cnonce));
|
||||
sb.Append(",");
|
||||
sb.Append("nc=");
|
||||
sb.Append(Nc);
|
||||
sb.Append(",");
|
||||
sb.Append("qop=");
|
||||
sb.Append(base.Qop);
|
||||
sb.Append(",");
|
||||
sb.Append("digest-uri=");
|
||||
sb.Append(AddQuotes(DigestUri));
|
||||
sb.Append(",");
|
||||
sb.Append("charset=");
|
||||
sb.Append(Charset);
|
||||
sb.Append(",");
|
||||
sb.Append("response=");
|
||||
sb.Append(Response);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// return the given string with quotes
|
||||
/// </summary>
|
||||
/// <param name="s"> </param>
|
||||
/// <returns> </returns>
|
||||
private string AddQuotes(string s)
|
||||
{
|
||||
string quote = "\"";
|
||||
return quote + s + quote;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
74
ASC.Xmpp.Core/authorization/Mechanism.cs
Normal file
74
ASC.Xmpp.Core/authorization/Mechanism.cs
Normal file
@ -0,0 +1,74 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.authorization
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Mechanism.
|
||||
/// </summary>
|
||||
public abstract class Mechanism
|
||||
{
|
||||
#region Members
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Server { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Username { // lower case that until i implement our c# port of libIDN
|
||||
get; set; }
|
||||
|
||||
//public XmppClientConnection XmppClientConnection { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="con"> </param>
|
||||
public abstract void Init();
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="e"> </param>
|
||||
public abstract void Parse(Node e);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
95
ASC.Xmpp.Core/authorization/Plain/PlainMechanism.cs
Normal file
95
ASC.Xmpp.Core/authorization/Plain/PlainMechanism.cs
Normal file
@ -0,0 +1,95 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.authorization.Plain
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for PlainMechanism.
|
||||
/// </summary>
|
||||
public class PlainMechanism : Mechanism
|
||||
{
|
||||
#region Members
|
||||
|
||||
//private XmppClientConnection m_XmppClient = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="con"> </param>
|
||||
public override void Init()
|
||||
{
|
||||
// m_XmppClient = con;
|
||||
|
||||
// <auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">$Message</auth>
|
||||
//m_XmppClient.Send(new Auth(MechanismType.PLAIN, Message()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="e"> </param>
|
||||
public override void Parse(Node e)
|
||||
{
|
||||
// not needed here in PLAIN mechanism
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
private string Message()
|
||||
{
|
||||
// NULL Username NULL Password
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// sb.Append( (char) 0 );
|
||||
// sb.Append(this.m_XmppClient.MyJID.Bare);
|
||||
sb.Append((char) 0);
|
||||
sb.Append(Username);
|
||||
sb.Append((char) 0);
|
||||
sb.Append(Password);
|
||||
|
||||
byte[] msg = Encoding.UTF8.GetBytes(sb.ToString());
|
||||
return Convert.ToBase64String(msg, 0, msg.Length);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
91
ASC.Xmpp.Core/authorization/SaslEventArgs.cs
Normal file
91
ASC.Xmpp.Core/authorization/SaslEventArgs.cs
Normal file
@ -0,0 +1,91 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using ASC.Xmpp.Core.protocol.sasl;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.authorization
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender"> </param>
|
||||
/// <param name="args"> </param>
|
||||
public delegate void SaslEventHandler(object sender, SaslEventArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class SaslEventArgs
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private bool m_Auto = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public SaslEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="mechanisms"> </param>
|
||||
public SaslEventArgs(Mechanisms mechanisms)
|
||||
{
|
||||
Mechanisms = mechanisms;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Set Auto to true if the library should choose the mechanism Set it to false for choosing the authentication method yourself
|
||||
/// </summary>
|
||||
public bool Auto
|
||||
{
|
||||
get { return m_Auto; }
|
||||
|
||||
set { m_Auto = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SASL Mechanism for authentication as string
|
||||
/// </summary>
|
||||
public string Mechanism { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Mechanisms Mechanisms { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
// by default the library chooses the auth method
|
||||
}
|
||||
}
|
387
ASC.Xmpp.Core/authorization/SaslHandler.cs
Normal file
387
ASC.Xmpp.Core/authorization/SaslHandler.cs
Normal file
@ -0,0 +1,387 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.sasl
|
||||
{
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using Factory;
|
||||
using protocol.client;
|
||||
using protocol.iq.bind;
|
||||
using protocol.iq.session;
|
||||
using protocol.sasl;
|
||||
using protocol.stream;
|
||||
using Xml;
|
||||
using Xml.Dom;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for SaslHandler.
|
||||
/// </summary>
|
||||
internal class SaslHandler : IDisposable
|
||||
{
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public event ObjectHandler OnSaslEnd;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public event SaslEventHandler OnSaslStart;
|
||||
|
||||
#endregion
|
||||
|
||||
// Track whether Dispose has been called.
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private bool disposed = false;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private Mechanism m_Mechanism = null;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private XmppClientConnection m_XmppClient = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="conn">
|
||||
/// </param>
|
||||
public SaslHandler(XmppClientConnection conn)
|
||||
{
|
||||
m_XmppClient = conn;
|
||||
|
||||
m_XmppClient.StreamParser.OnStreamElement += new StreamHandler(OnStreamElement);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// Use C# destructor syntax for finalization code.
|
||||
// This destructor will run only if the Dispose method
|
||||
// does not get called.
|
||||
// It gives your base class the opportunity to finalize.
|
||||
// Do not provide destructors in types derived from this class.
|
||||
#region Overrides
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
~SaslHandler()
|
||||
{
|
||||
// Do not re-create Dispose clean-up code here.
|
||||
// Calling Dispose(false) is optimal in terms of
|
||||
// readability and maintainability.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
internal void DoBind()
|
||||
{
|
||||
m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Binding);
|
||||
|
||||
BindIq bIq;
|
||||
if (m_XmppClient.Resource == null || m_XmppClient.Resource.Length == 0)
|
||||
{
|
||||
bIq = new BindIq(IqType.set, new Jid(m_XmppClient.Server));
|
||||
}
|
||||
else
|
||||
{
|
||||
bIq = new BindIq(IqType.set, new Jid(m_XmppClient.Server), m_XmppClient.Resource);
|
||||
}
|
||||
|
||||
m_XmppClient.IqGrabber.SendIq(bIq, new IqCB(BindResult), null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utility methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender">
|
||||
/// </param>
|
||||
/// <param name="iq">
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// </param>
|
||||
private void BindResult(object sender, IQ iq, object data)
|
||||
{
|
||||
// Once the server has generated a resource identifier for the client or accepted the resource
|
||||
// identifier provided by the client, it MUST return an IQ stanza of type "result"
|
||||
// to the client, which MUST include a <jid/> child element that specifies the full JID for
|
||||
// the connected resource as determined by the server:
|
||||
|
||||
// Server informs client of successful resource binding:
|
||||
// <iq type='result' id='bind_2'>
|
||||
// <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
|
||||
// <jid>somenode@example.com/someresource</jid>
|
||||
// </bind>
|
||||
// </iq>
|
||||
if (iq.Type == IqType.result)
|
||||
{
|
||||
// i assume the server could assign another resource here to the client
|
||||
// so grep the resource assigned by the server now
|
||||
Element bind = iq.SelectSingleElement(typeof (Bind));
|
||||
if (bind != null)
|
||||
{
|
||||
Jid jid = ((Bind) bind).Jid;
|
||||
m_XmppClient.Resource = jid.Resource;
|
||||
m_XmppClient.Username = jid.User;
|
||||
}
|
||||
|
||||
m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Binded);
|
||||
m_XmppClient.m_Binded = true;
|
||||
|
||||
m_XmppClient.DoRaiseEventBinded();
|
||||
|
||||
// success, so start the session now
|
||||
m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.StartSession);
|
||||
SessionIq sIq = new SessionIq(IqType.set, new Jid(m_XmppClient.Server));
|
||||
m_XmppClient.IqGrabber.SendIq(sIq, new IqCB(SessionResult), null);
|
||||
}
|
||||
else if (iq.Type == IqType.error)
|
||||
{
|
||||
// TODO, handle bind errors
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender">
|
||||
/// </param>
|
||||
/// <param name="iq">
|
||||
/// </param>
|
||||
/// <param name="data">
|
||||
/// </param>
|
||||
private void SessionResult(object sender, IQ iq, object data)
|
||||
{
|
||||
if (iq.Type == IqType.result)
|
||||
{
|
||||
m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.SessionStarted);
|
||||
m_XmppClient.RaiseOnLogin();
|
||||
}
|
||||
else if (iq.Type == IqType.error) {}
|
||||
}
|
||||
|
||||
// Dispose(bool disposing) executes in two distinct scenarios.
|
||||
// If disposing equals true, the method has been called directly
|
||||
// or indirectly by a user's code. Managed and unmanaged resources
|
||||
// can be disposed.
|
||||
// If disposing equals false, the method has been called by the
|
||||
// runtime from inside the finalizer and you should not reference
|
||||
// other objects. Only unmanaged resources can be disposed.
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// </param>
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!disposed)
|
||||
{
|
||||
// If disposing equals true, dispose all managed
|
||||
// and unmanaged resources.
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed resources.
|
||||
// Remove the event handler or we will be in trouble with too many events
|
||||
m_XmppClient.StreamParser.OnStreamElement -= new StreamHandler(OnStreamElement);
|
||||
m_XmppClient = null;
|
||||
m_Mechanism = null;
|
||||
}
|
||||
|
||||
// Call the appropriate methods to clean up
|
||||
// unmanaged resources here.
|
||||
// If disposing is false,
|
||||
// only the following code is executed.
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender">
|
||||
/// </param>
|
||||
/// <param name="e">
|
||||
/// </param>
|
||||
internal void OnStreamElement(object sender, Node e)
|
||||
{
|
||||
if (m_XmppClient.XmppConnectionState == XmppConnectionState.Securing ||
|
||||
m_XmppClient.XmppConnectionState == XmppConnectionState.StartCompression)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.GetType() == typeof (Features))
|
||||
{
|
||||
Features f = e as Features;
|
||||
if (!m_XmppClient.Authenticated)
|
||||
{
|
||||
// RECV: <stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
|
||||
// <mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism>
|
||||
// </mechanisms>
|
||||
// <register xmlns='http://jabber.org/features/iq-register'/>
|
||||
// </stream:features>
|
||||
// SENT: <auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
|
||||
// Select a SASL mechanism
|
||||
SaslEventArgs args = new SaslEventArgs(f.Mechanisms);
|
||||
|
||||
if (OnSaslStart != null)
|
||||
{
|
||||
OnSaslStart(this, args);
|
||||
}
|
||||
|
||||
if (args.Auto == true)
|
||||
{
|
||||
// Library handles the Sasl stuff
|
||||
if (f.Mechanisms != null)
|
||||
{
|
||||
if (m_XmppClient.UseStartTLS == false && m_XmppClient.UseSSL == false &&
|
||||
f.Mechanisms.SupportsMechanism(MechanismType.X_GOOGLE_TOKEN))
|
||||
{
|
||||
// This is the only way to connect to GTalk on a unsecure Socket for now
|
||||
// Secure authentication is done over https requests to pass the
|
||||
// authentication credentials on a secure connection
|
||||
args.Mechanism =
|
||||
protocol.sasl.Mechanism.GetMechanismName(MechanismType.X_GOOGLE_TOKEN);
|
||||
}
|
||||
else if (f.Mechanisms.SupportsMechanism(MechanismType.DIGEST_MD5))
|
||||
{
|
||||
args.Mechanism =
|
||||
protocol.sasl.Mechanism.GetMechanismName(MechanismType.DIGEST_MD5);
|
||||
}
|
||||
else if (f.Mechanisms.SupportsMechanism(MechanismType.PLAIN))
|
||||
{
|
||||
args.Mechanism = protocol.sasl.Mechanism.GetMechanismName(MechanismType.PLAIN);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Mechanism = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hack for Google
|
||||
// TODO: i don't think we need this anymore. This was in an very early version of the gtalk server.
|
||||
args.Mechanism = null;
|
||||
|
||||
// args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.PLAIN);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Mechanism != null)
|
||||
{
|
||||
m_Mechanism = SaslFactory.GetMechanism(args.Mechanism);
|
||||
|
||||
// Set properties for the SASL mechanism
|
||||
m_Mechanism.Username = m_XmppClient.Username;
|
||||
m_Mechanism.Password = m_XmppClient.Password;
|
||||
m_Mechanism.Server = m_XmppClient.Server;
|
||||
|
||||
// Call Init Method on the mechanism
|
||||
m_Mechanism.Init(m_XmppClient);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_XmppClient.RequestLoginInfo();
|
||||
}
|
||||
}
|
||||
else if (!m_XmppClient.Binded)
|
||||
{
|
||||
if (f.SupportsBind)
|
||||
{
|
||||
m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Binding);
|
||||
|
||||
BindIq bIq;
|
||||
if (m_XmppClient.Resource == null || m_XmppClient.Resource.Length == 0)
|
||||
{
|
||||
bIq = new BindIq(IqType.set, new Jid(m_XmppClient.Server));
|
||||
}
|
||||
else
|
||||
{
|
||||
bIq = new BindIq(IqType.set, new Jid(m_XmppClient.Server), m_XmppClient.Resource);
|
||||
}
|
||||
|
||||
m_XmppClient.IqGrabber.SendIq(bIq, new IqCB(BindResult), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e.GetType() == typeof (Challenge))
|
||||
{
|
||||
if (m_Mechanism != null && !m_XmppClient.Authenticated)
|
||||
{
|
||||
m_Mechanism.Parse(e);
|
||||
}
|
||||
}
|
||||
else if (e.GetType() == typeof (Success))
|
||||
{
|
||||
// SASL authentication was successfull
|
||||
if (OnSaslEnd != null)
|
||||
{
|
||||
OnSaslEnd(this);
|
||||
}
|
||||
|
||||
m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Authenticated);
|
||||
|
||||
m_Mechanism = null;
|
||||
|
||||
m_XmppClient.Reset();
|
||||
}
|
||||
else if (e.GetType() == typeof (Failure))
|
||||
{
|
||||
// Authentication failure
|
||||
m_XmppClient.FireOnAuthError(e as Element);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
100
ASC.Xmpp.Core/protocol/Base/Avatar.cs
Normal file
100
ASC.Xmpp.Core/protocol/Base/Avatar.cs
Normal file
@ -0,0 +1,100 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.Base
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
// Avatar is in multiple Namespaces. So better to work with a Base class
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for Avatar.
|
||||
/// </summary>
|
||||
public class Avatar : Element
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Avatar()
|
||||
{
|
||||
TagName = "query";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public byte[] Data
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasTag("data"))
|
||||
{
|
||||
return Convert.FromBase64String(GetTag("data"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
set { SetTag("data", Convert.ToBase64String(value, 0, value.Length)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string MimeType
|
||||
{
|
||||
get
|
||||
{
|
||||
Element data = SelectSingleElement("data");
|
||||
if (data != null)
|
||||
{
|
||||
return GetAttribute("mimetype");
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Element data = SelectSingleElement("data");
|
||||
if (data != null)
|
||||
{
|
||||
SetAttribute("mimetype", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
169
ASC.Xmpp.Core/protocol/Base/DirectionalElement.cs
Normal file
169
ASC.Xmpp.Core/protocol/Base/DirectionalElement.cs
Normal file
@ -0,0 +1,169 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.Base
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Base XMPP Element This must ne used to build all other new packets
|
||||
/// </summary>
|
||||
public abstract class DirectionalElement : Element
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public DirectionalElement()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="tag"> </param>
|
||||
public DirectionalElement(string tag) : base(tag)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="tag"> </param>
|
||||
/// <param name="ns"> </param>
|
||||
public DirectionalElement(string tag, string ns) : base(tag)
|
||||
{
|
||||
Namespace = ns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="tag"> </param>
|
||||
/// <param name="text"> </param>
|
||||
/// <param name="ns"> </param>
|
||||
public DirectionalElement(string tag, string text, string ns) : base(tag, text)
|
||||
{
|
||||
Namespace = ns;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public int InternalId { get; set; }
|
||||
|
||||
public DateTime DbStamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Jid From
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasAttribute("from"))
|
||||
{
|
||||
return new Jid(GetAttribute("from"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
SetAttribute("from", value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveAttribute("from");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Jid To
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasAttribute("to"))
|
||||
{
|
||||
return new Jid(GetAttribute("to"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
SetAttribute("to", value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveAttribute("to");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool Switched { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Switches the from and to attributes when existing
|
||||
/// </summary>
|
||||
public void SwitchDirection()
|
||||
{
|
||||
Jid from = From;
|
||||
Jid to = To;
|
||||
|
||||
// Remove from and to now
|
||||
RemoveAttribute("from");
|
||||
RemoveAttribute("to");
|
||||
|
||||
Jid helper = null;
|
||||
|
||||
helper = from;
|
||||
from = to;
|
||||
to = helper;
|
||||
|
||||
From = from;
|
||||
To = to;
|
||||
|
||||
Switched = !Switched;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
50
ASC.Xmpp.Core/protocol/Base/Group.cs
Normal file
50
ASC.Xmpp.Core/protocol/Base/Group.cs
Normal file
@ -0,0 +1,50 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Group.
|
||||
/// </summary>
|
||||
public class Group : Element
|
||||
{
|
||||
public Group()
|
||||
{
|
||||
TagName = "group";
|
||||
}
|
||||
|
||||
public Group(string groupname) : this()
|
||||
{
|
||||
Name = groupname;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets or sets the Name of the contact group
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
set { Value = value; }
|
||||
get { return Value; }
|
||||
}
|
||||
}
|
||||
}
|
85
ASC.Xmpp.Core/protocol/Base/Item.cs
Normal file
85
ASC.Xmpp.Core/protocol/Base/Item.cs
Normal file
@ -0,0 +1,85 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.Base
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for Item.
|
||||
/// </summary>
|
||||
public class Item : Element
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Item()
|
||||
{
|
||||
TagName = "item";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Jid Jid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasAttribute("jid"))
|
||||
{
|
||||
return new Jid(GetAttribute("jid"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
SetAttribute("jid", value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return GetAttribute("name"); }
|
||||
|
||||
set { SetAttribute("name", value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
111
ASC.Xmpp.Core/protocol/Base/RosterItem.cs
Normal file
111
ASC.Xmpp.Core/protocol/Base/RosterItem.cs
Normal file
@ -0,0 +1,111 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.Base
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
// jabber:iq:roster
|
||||
// <iq from="gnauck@myjabber.net/Office" id="doroster_1" type="result">
|
||||
// <query xmlns="jabber:iq:roster">
|
||||
// <item subscription="both" name="Nachtkrapp" jid="50198521@icq.myjabber.net"><group>ICQ</group></item>
|
||||
// <item subscription="both" name="czerkasov" jid="62764180@icq.myjabber.net"><group>ICQ</group></item>
|
||||
// <item subscription="both" name="Poacher" jid="92179686@icq.myjabber.net"><group>ICQ</group></item>
|
||||
// <item subscription="both" name="Diabolo" jid="102840558@icq.myjabber.net"><group>ICQ</group></item>
|
||||
// </query>
|
||||
// </iq>
|
||||
|
||||
// # "none" -- the user does not have a subscription to the contact's presence information, and the contact does not have a subscription to the user's presence information
|
||||
// # "to" -- the user has a subscription to the contact's presence information, but the contact does not have a subscription to the user's presence information
|
||||
// # "from" -- the contact has a subscription to the user's presence information, but the user does not have a subscription to the contact's presence information
|
||||
// # "both" -- both the user and the contact have subscriptions to each other's presence information
|
||||
|
||||
/// <summary>
|
||||
/// Item is used in jabber:iq:roster, x roster
|
||||
/// </summary>
|
||||
public class RosterItem : Item
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Groups a roster Item is assigned to
|
||||
/// </summary>
|
||||
public ElementList GetGroups()
|
||||
{
|
||||
return SelectElements("group");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new group to the Rosteritem
|
||||
/// </summary>
|
||||
/// <param name="groupname"> </param>
|
||||
public void AddGroup(string groupname)
|
||||
{
|
||||
var g = new Group(groupname);
|
||||
AddChild(g);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="groupname"> </param>
|
||||
/// <returns> </returns>
|
||||
public bool HasGroup(string groupname)
|
||||
{
|
||||
ElementList groups = GetGroups();
|
||||
foreach (Group g in groups)
|
||||
{
|
||||
if (g.Name == groupname)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="groupname"> </param>
|
||||
public void RemoveGroup(string groupname)
|
||||
{
|
||||
ElementList groups = GetGroups();
|
||||
foreach (Group g in groups)
|
||||
{
|
||||
if (g.Name == groupname)
|
||||
{
|
||||
g.Remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
134
ASC.Xmpp.Core/protocol/Base/Stanza.cs
Normal file
134
ASC.Xmpp.Core/protocol/Base/Stanza.cs
Normal file
@ -0,0 +1,134 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Base XMPP Element This must ne used to build all other new packets
|
||||
/// </summary>
|
||||
public abstract class Stanza : DirectionalElement
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Stanza()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="tag"> </param>
|
||||
public Stanza(string tag) : base(tag)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="tag"> </param>
|
||||
/// <param name="ns"> </param>
|
||||
public Stanza(string tag, string ns) : base(tag)
|
||||
{
|
||||
Namespace = ns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="tag"> </param>
|
||||
/// <param name="text"> </param>
|
||||
/// <param name="ns"> </param>
|
||||
public Stanza(string tag, string text, string ns) : base(tag, text)
|
||||
{
|
||||
Namespace = ns;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string Id
|
||||
{
|
||||
get { return GetAttribute("id"); }
|
||||
|
||||
set { SetAttribute("id", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// XML Language attribute
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The language 'xml:lang' attribute SHOULD be included by the initiating entity on the header for the initial stream to specify the default language of any human-readable XML character data it sends over that stream. If the attribute is included, the receiving entity SHOULD remember that value as the default for both the initial stream and the response stream; if the attribute is not included, the receiving entity SHOULD use a configurable default value for both streams, which it MUST communicate in the header for the response stream. For all stanzas sent over the initial stream, if the initiating entity does not include an 'xml:lang' attribute, the receiving entity SHOULD apply the default value; if the initiating entity does include an 'xml:lang' attribute, the receiving entity MUST NOT modify or delete it (see also xml:langxml:lang). The value of the 'xml:lang' attribute MUST conform to the format defined in RFC 3066 (Tags for the Identification of Languages, January 2001.[LANGTAGS]).
|
||||
/// </remarks>
|
||||
public string Language
|
||||
{
|
||||
get { return GetAttribute("xml:lang"); }
|
||||
|
||||
set { SetAttribute("xml:lang", value); }
|
||||
}
|
||||
|
||||
public bool HasFrom
|
||||
{
|
||||
get { return From != null; }
|
||||
}
|
||||
|
||||
public bool HasTo
|
||||
{
|
||||
get { return To != null; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Generates a automatic id for the packet. !!! Overwrites existing Ids
|
||||
/// </summary>
|
||||
public void GenerateId()
|
||||
{
|
||||
string sId = protocol.Id.GetNextId();
|
||||
Id = sId;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
///// <summary>
|
||||
///// Error Child Element
|
||||
///// </summary>
|
||||
// public agsXMPP.protocol.client.Error Error
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return SelectSingleElement(typeof(agsXMPP.protocol.client.Error)) as agsXMPP.protocol.client.Error;
|
||||
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// if (HasTag(typeof(agsXMPP.protocol.client.Error)))
|
||||
// RemoveTag(typeof(agsXMPP.protocol.client.Error));
|
||||
|
||||
// if (value != null)
|
||||
// this.AddChild(value);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
64
ASC.Xmpp.Core/protocol/Base/Stream.cs
Normal file
64
ASC.Xmpp.Core/protocol/Base/Stream.cs
Normal file
@ -0,0 +1,64 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Stream.
|
||||
/// </summary>
|
||||
public class Stream : Stanza
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Stream()
|
||||
{
|
||||
TagName = "stream";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// The StreamID of the current JabberSession. Returns null when none available.
|
||||
/// </summary>
|
||||
public string StreamId
|
||||
{
|
||||
get { return GetAttribute("id"); }
|
||||
|
||||
set { SetAttribute("id", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See XMPP-Core 4.4.1 "Version Support"
|
||||
/// </summary>
|
||||
public string Version
|
||||
{
|
||||
get { return GetAttribute("version"); }
|
||||
|
||||
set { SetAttribute("version", value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
502
ASC.Xmpp.Core/protocol/ElementFactory.cs
Normal file
502
ASC.Xmpp.Core/protocol/ElementFactory.cs
Normal file
@ -0,0 +1,502 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
using ASC.Xmpp.Core.protocol.component;
|
||||
using ASC.Xmpp.Core.protocol.extensions.amp;
|
||||
using ASC.Xmpp.Core.protocol.extensions.bookmarks;
|
||||
using ASC.Xmpp.Core.protocol.extensions.bytestreams;
|
||||
using ASC.Xmpp.Core.protocol.extensions.caps;
|
||||
using ASC.Xmpp.Core.protocol.extensions.chatstates;
|
||||
using ASC.Xmpp.Core.protocol.extensions.commands;
|
||||
using ASC.Xmpp.Core.protocol.extensions.compression;
|
||||
using ASC.Xmpp.Core.protocol.extensions.featureneg;
|
||||
using ASC.Xmpp.Core.protocol.extensions.filetransfer;
|
||||
using ASC.Xmpp.Core.protocol.extensions.geoloc;
|
||||
using ASC.Xmpp.Core.protocol.extensions.html;
|
||||
using ASC.Xmpp.Core.protocol.extensions.ibb;
|
||||
using ASC.Xmpp.Core.protocol.extensions.jivesoftware.phone;
|
||||
using ASC.Xmpp.Core.protocol.extensions.msgreceipts;
|
||||
using ASC.Xmpp.Core.protocol.extensions.multicast;
|
||||
using ASC.Xmpp.Core.protocol.extensions.nickname;
|
||||
using ASC.Xmpp.Core.protocol.extensions.ping;
|
||||
using ASC.Xmpp.Core.protocol.extensions.primary;
|
||||
using ASC.Xmpp.Core.protocol.extensions.pubsub;
|
||||
using ASC.Xmpp.Core.protocol.extensions.pubsub.owner;
|
||||
using ASC.Xmpp.Core.protocol.extensions.shim;
|
||||
using ASC.Xmpp.Core.protocol.extensions.si;
|
||||
using ASC.Xmpp.Core.protocol.iq.agent;
|
||||
using ASC.Xmpp.Core.protocol.iq.bind;
|
||||
using ASC.Xmpp.Core.protocol.iq.blocklist;
|
||||
using ASC.Xmpp.Core.protocol.iq.browse;
|
||||
using ASC.Xmpp.Core.protocol.iq.chatmarkers;
|
||||
using ASC.Xmpp.Core.protocol.iq.disco;
|
||||
using ASC.Xmpp.Core.protocol.iq.jingle;
|
||||
using ASC.Xmpp.Core.protocol.iq.last;
|
||||
using ASC.Xmpp.Core.protocol.iq.oob;
|
||||
using ASC.Xmpp.Core.protocol.iq.privacy;
|
||||
using ASC.Xmpp.Core.protocol.iq.@private;
|
||||
using ASC.Xmpp.Core.protocol.iq.register;
|
||||
using ASC.Xmpp.Core.protocol.iq.roster;
|
||||
using ASC.Xmpp.Core.protocol.iq.rpc;
|
||||
using ASC.Xmpp.Core.protocol.iq.search;
|
||||
using ASC.Xmpp.Core.protocol.iq.session;
|
||||
using ASC.Xmpp.Core.protocol.iq.time;
|
||||
using ASC.Xmpp.Core.protocol.iq.vcard;
|
||||
using ASC.Xmpp.Core.protocol.sasl;
|
||||
using ASC.Xmpp.Core.protocol.stream.feature.compression;
|
||||
using ASC.Xmpp.Core.protocol.tls;
|
||||
using ASC.Xmpp.Core.protocol.x;
|
||||
using ASC.Xmpp.Core.protocol.x.data;
|
||||
using ASC.Xmpp.Core.protocol.x.muc;
|
||||
using ASC.Xmpp.Core.protocol.x.muc.iq;
|
||||
using ASC.Xmpp.Core.protocol.x.muc.iq.admin;
|
||||
using ASC.Xmpp.Core.protocol.x.muc.iq.owner;
|
||||
using ASC.Xmpp.Core.protocol.x.rosterx;
|
||||
using ASC.Xmpp.Core.protocol.x.tm.history;
|
||||
using ASC.Xmpp.Core.protocol.x.vcard_update;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Active = ASC.Xmpp.Core.protocol.iq.privacy.Active;
|
||||
using Address = ASC.Xmpp.Core.protocol.extensions.multicast.Address;
|
||||
using Affiliation = ASC.Xmpp.Core.protocol.extensions.pubsub.Affiliation;
|
||||
using Auth = ASC.Xmpp.Core.protocol.iq.auth.Auth;
|
||||
using Avatar = ASC.Xmpp.Core.protocol.iq.avatar.Avatar;
|
||||
using Conference = ASC.Xmpp.Core.protocol.x.Conference;
|
||||
using Configure = ASC.Xmpp.Core.protocol.extensions.pubsub.owner.Configure;
|
||||
using Data = ASC.Xmpp.Core.protocol.x.data.Data;
|
||||
using Delete = ASC.Xmpp.Core.protocol.extensions.pubsub.owner.Delete;
|
||||
using Event = ASC.Xmpp.Core.protocol.x.Event;
|
||||
using Failure = ASC.Xmpp.Core.protocol.tls.Failure;
|
||||
using History = ASC.Xmpp.Core.protocol.x.muc.History;
|
||||
using IQ = ASC.Xmpp.Core.protocol.client.IQ;
|
||||
using Item = ASC.Xmpp.Core.protocol.iq.privacy.Item;
|
||||
using Items = ASC.Xmpp.Core.protocol.extensions.pubsub.@event.Items;
|
||||
using Message = ASC.Xmpp.Core.protocol.client.Message;
|
||||
using Presence = ASC.Xmpp.Core.protocol.client.Presence;
|
||||
using PubSub = ASC.Xmpp.Core.protocol.extensions.pubsub.owner.PubSub;
|
||||
using Purge = ASC.Xmpp.Core.protocol.extensions.pubsub.owner.Purge;
|
||||
using RosterItem = ASC.Xmpp.Core.protocol.iq.roster.RosterItem;
|
||||
using Status = ASC.Xmpp.Core.protocol.x.muc.Status;
|
||||
using Type = System.Type;
|
||||
using Version = ASC.Xmpp.Core.protocol.iq.version.Version;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol
|
||||
{
|
||||
|
||||
#region using
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Factory class that implements the factory pattern for builing our Elements.
|
||||
/// </summary>
|
||||
public class ElementFactory
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// This Hashtable stores Mapping of protocol (tag/namespace) to the agsXMPP objects
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, Type> m_table = new Dictionary<string, Type>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
static ElementFactory()
|
||||
{
|
||||
AddElementType("iq", Uri.CLIENT, typeof (IQ));
|
||||
AddElementType("message", Uri.CLIENT, typeof (Message));
|
||||
AddElementType("presence", Uri.CLIENT, typeof (Presence));
|
||||
AddElementType("error", Uri.CLIENT, typeof (client.Error));
|
||||
|
||||
AddElementType("agent", Uri.IQ_AGENTS, typeof (Agent));
|
||||
|
||||
AddElementType("item", Uri.IQ_ROSTER, typeof (RosterItem));
|
||||
AddElementType("group", Uri.IQ_ROSTER, typeof (Group));
|
||||
AddElementType("group", Uri.X_ROSTERX, typeof (Group));
|
||||
|
||||
AddElementType("item", Uri.IQ_SEARCH, typeof (SearchItem));
|
||||
|
||||
// Stream stuff
|
||||
AddElementType("stream", Uri.STREAM, typeof (Stream));
|
||||
AddElementType("error", Uri.STREAM, typeof (Error));
|
||||
|
||||
AddElementType("server", Uri.IQ_GOOGLE_JINGLE, typeof (Server));
|
||||
AddElementType("stun", Uri.IQ_GOOGLE_JINGLE, typeof (Stun));
|
||||
AddElementType("query", Uri.IQ_GOOGLE_JINGLE, typeof (GoogleJingle));
|
||||
|
||||
AddElementType("query", Uri.IQ_AUTH, typeof (Auth));
|
||||
AddElementType("query", Uri.IQ_AGENTS, typeof (Agents));
|
||||
AddElementType("query", Uri.IQ_ROSTER, typeof (Roster));
|
||||
AddElementType("query", Uri.IQ_LAST, typeof (Last));
|
||||
AddElementType("query", Uri.IQ_VERSION, typeof (Version));
|
||||
AddElementType("query", Uri.IQ_TIME, typeof (Time));
|
||||
AddElementType("query", Uri.IQ_OOB, typeof (Oob));
|
||||
AddElementType("query", Uri.IQ_SEARCH, typeof (Search));
|
||||
AddElementType("query", Uri.IQ_BROWSE, typeof (Browse));
|
||||
AddElementType("query", Uri.IQ_AVATAR, typeof (Avatar));
|
||||
AddElementType("query", Uri.IQ_REGISTER, typeof (Register));
|
||||
AddElementType("query", Uri.IQ_PRIVATE, typeof (Private));
|
||||
|
||||
AddElementType("blocklist", Uri.IQ_BLOCKLIST, typeof (Blocklist));
|
||||
AddElementType("block", Uri.IQ_BLOCKLIST, typeof (Block));
|
||||
AddElementType("unblock", Uri.IQ_BLOCKLIST, typeof (Unblock));
|
||||
|
||||
// Privacy Lists
|
||||
AddElementType("query", Uri.IQ_PRIVACY, typeof (Privacy));
|
||||
AddElementType("item", Uri.IQ_PRIVACY, typeof (Item));
|
||||
AddElementType("list", Uri.IQ_PRIVACY, typeof (List));
|
||||
AddElementType("active", Uri.IQ_PRIVACY, typeof (Active));
|
||||
AddElementType("default", Uri.IQ_PRIVACY, typeof (Default));
|
||||
|
||||
// Browse
|
||||
AddElementType("service", Uri.IQ_BROWSE, typeof (Service));
|
||||
AddElementType("item", Uri.IQ_BROWSE, typeof (BrowseItem));
|
||||
|
||||
// Service Discovery
|
||||
AddElementType("query", Uri.DISCO_ITEMS, typeof (DiscoItems));
|
||||
AddElementType("query", Uri.DISCO_INFO, typeof (DiscoInfo));
|
||||
AddElementType("feature", Uri.DISCO_INFO, typeof (DiscoFeature));
|
||||
AddElementType("identity", Uri.DISCO_INFO, typeof (DiscoIdentity));
|
||||
AddElementType("item", Uri.DISCO_ITEMS, typeof (DiscoItem));
|
||||
|
||||
AddElementType("x", Uri.X_DELAY, typeof (Delay));
|
||||
AddElementType("x", Uri.X_AVATAR, typeof (x.Avatar));
|
||||
AddElementType("x", Uri.X_CONFERENCE, typeof (Conference));
|
||||
AddElementType("x", Uri.X_EVENT, typeof (Event));
|
||||
|
||||
// AddElementType("x", Uri.STORAGE_AVATAR, typeof(agsXMPP.protocol.storage.Avatar));
|
||||
AddElementType("query", Uri.STORAGE_AVATAR, typeof (storage.Avatar));
|
||||
|
||||
// XData Stuff
|
||||
AddElementType("x", Uri.X_DATA, typeof (x.data.Data));
|
||||
AddElementType("field", Uri.X_DATA, typeof (Field));
|
||||
AddElementType("option", Uri.X_DATA, typeof (Option));
|
||||
AddElementType("value", Uri.X_DATA, typeof (Value));
|
||||
AddElementType("reported", Uri.X_DATA, typeof (Reported));
|
||||
AddElementType("item", Uri.X_DATA, typeof (x.data.Item));
|
||||
|
||||
AddElementType("features", Uri.STREAM, typeof (Features));
|
||||
|
||||
AddElementType("register", Uri.FEATURE_IQ_REGISTER, typeof (stream.feature.Register));
|
||||
AddElementType("compression", Uri.FEATURE_COMPRESS, typeof (Compression));
|
||||
AddElementType("method", Uri.FEATURE_COMPRESS, typeof (Method));
|
||||
|
||||
AddElementType("jingle", Uri.IQ_JINGLE1, typeof (Jingle));
|
||||
AddElementType("jingle", Uri.IQ_JINGLE0, typeof (Jingle));
|
||||
AddElementType("bind", Uri.BIND, typeof (Bind));
|
||||
AddElementType("unbind", Uri.BIND, typeof (Bind));
|
||||
AddElementType("session", Uri.SESSION, typeof (Session));
|
||||
|
||||
// TLS stuff
|
||||
AddElementType("failure", Uri.TLS, typeof (Failure));
|
||||
AddElementType("proceed", Uri.TLS, typeof (Proceed));
|
||||
AddElementType("starttls", Uri.TLS, typeof (StartTls));
|
||||
|
||||
// SASL stuff
|
||||
AddElementType("mechanisms", Uri.SASL, typeof (Mechanisms));
|
||||
AddElementType("mechanism", Uri.SASL, typeof (Mechanism));
|
||||
AddElementType("auth", Uri.SASL, typeof (sasl.Auth));
|
||||
AddElementType("x-tmtoken", Uri.SASL, typeof (TMToken)); //TeamLab token
|
||||
AddElementType("response", Uri.SASL, typeof (Response));
|
||||
AddElementType("challenge", Uri.SASL, typeof (Challenge));
|
||||
|
||||
// TODO, this is a dirty hacks for the buggy BOSH Proxy
|
||||
// BEGIN
|
||||
AddElementType("challenge", Uri.CLIENT, typeof (Challenge));
|
||||
AddElementType("success", Uri.CLIENT, typeof (Success));
|
||||
|
||||
// END
|
||||
AddElementType("failure", Uri.SASL, typeof (sasl.Failure));
|
||||
AddElementType("abort", Uri.SASL, typeof (Abort));
|
||||
AddElementType("success", Uri.SASL, typeof (Success));
|
||||
|
||||
// Vcard stuff
|
||||
AddElementType("vCard", Uri.VCARD, typeof (Vcard));
|
||||
AddElementType("TEL", Uri.VCARD, typeof (Telephone));
|
||||
AddElementType("ORG", Uri.VCARD, typeof (Organization));
|
||||
AddElementType("N", Uri.VCARD, typeof (Name));
|
||||
AddElementType("EMAIL", Uri.VCARD, typeof (Email));
|
||||
AddElementType("ADR", Uri.VCARD, typeof (Address));
|
||||
#if !CF
|
||||
AddElementType("PHOTO", Uri.VCARD, typeof (Photo));
|
||||
#endif
|
||||
|
||||
// Server stuff
|
||||
// AddElementType("stream", Uri.SERVER, typeof(agsXMPP.protocol.server.Stream));
|
||||
// AddElementType("message", Uri.SERVER, typeof(agsXMPP.protocol.server.Message));
|
||||
|
||||
// Component stuff
|
||||
AddElementType("handshake", Uri.ACCEPT, typeof (Handshake));
|
||||
AddElementType("log", Uri.ACCEPT, typeof (Log));
|
||||
AddElementType("route", Uri.ACCEPT, typeof (Route));
|
||||
AddElementType("iq", Uri.ACCEPT, typeof (component.IQ));
|
||||
AddElementType("message", Uri.ACCEPT, typeof (component.Message));
|
||||
AddElementType("presence", Uri.ACCEPT, typeof (component.Presence));
|
||||
AddElementType("error", Uri.ACCEPT, typeof (component.Error));
|
||||
|
||||
// Extensions (JEPS)
|
||||
AddElementType("headers", Uri.SHIM, typeof (Header));
|
||||
AddElementType("header", Uri.SHIM, typeof (Headers));
|
||||
AddElementType("roster", Uri.ROSTER_DELIMITER, typeof (Delimiter));
|
||||
AddElementType("p", Uri.PRIMARY, typeof (Primary));
|
||||
AddElementType("nick", Uri.NICK, typeof (Nickname));
|
||||
|
||||
AddElementType("item", Uri.X_ROSTERX, typeof (x.rosterx.RosterItem));
|
||||
AddElementType("x", Uri.X_ROSTERX, typeof (RosterX));
|
||||
|
||||
// Filetransfer stuff
|
||||
AddElementType("file", Uri.SI_FILE_TRANSFER, typeof (File));
|
||||
AddElementType("range", Uri.SI_FILE_TRANSFER, typeof (Range));
|
||||
|
||||
// FeatureNeg
|
||||
AddElementType("feature", Uri.FEATURE_NEG, typeof (FeatureNeg));
|
||||
|
||||
// Bytestreams
|
||||
AddElementType("query", Uri.BYTESTREAMS, typeof (ByteStream));
|
||||
AddElementType("streamhost", Uri.BYTESTREAMS, typeof (StreamHost));
|
||||
AddElementType("streamhost-used", Uri.BYTESTREAMS, typeof (StreamHostUsed));
|
||||
AddElementType("activate", Uri.BYTESTREAMS, typeof (Activate));
|
||||
AddElementType("udpsuccess", Uri.BYTESTREAMS, typeof (UdpSuccess));
|
||||
|
||||
AddElementType("si", Uri.SI, typeof (SI));
|
||||
|
||||
AddElementType("html", Uri.XHTML_IM, typeof (Html));
|
||||
AddElementType("body", Uri.XHTML, typeof (Body));
|
||||
|
||||
AddElementType("compressed", Uri.COMPRESS, typeof (Compressed));
|
||||
AddElementType("compress", Uri.COMPRESS, typeof (Compress));
|
||||
AddElementType("failure", Uri.COMPRESS, typeof (extensions.compression.Failure));
|
||||
|
||||
// MUC (JEP-0045 Multi User Chat)
|
||||
AddElementType("x", Uri.MUC, typeof (Muc));
|
||||
AddElementType("x", Uri.MUC_USER, typeof (User));
|
||||
AddElementType("item", Uri.MUC_USER, typeof (x.muc.Item));
|
||||
AddElementType("status", Uri.MUC_USER, typeof (Status));
|
||||
AddElementType("invite", Uri.MUC_USER, typeof (Invite));
|
||||
AddElementType("decline", Uri.MUC_USER, typeof (Decline));
|
||||
AddElementType("actor", Uri.MUC_USER, typeof (Actor));
|
||||
AddElementType("history", Uri.MUC, typeof (History));
|
||||
AddElementType("query", Uri.MUC_ADMIN, typeof (Admin));
|
||||
AddElementType("item", Uri.MUC_ADMIN, typeof (x.muc.iq.admin.Item));
|
||||
AddElementType("query", Uri.MUC_OWNER, typeof (Owner));
|
||||
AddElementType("destroy", Uri.MUC_OWNER, typeof (Destroy));
|
||||
AddElementType("unique", Uri.MUC_UNIQUE, typeof (Unique));
|
||||
|
||||
//Jabber xep-003 Addressing
|
||||
AddElementType("addresses", Uri.ADDRESS, typeof (Addresses));
|
||||
AddElementType("address", Uri.ADDRESS, typeof (Address));
|
||||
|
||||
|
||||
// Jabber RPC JEP 0009
|
||||
AddElementType("query", Uri.IQ_RPC, typeof (Rpc));
|
||||
AddElementType("methodCall", Uri.IQ_RPC, typeof (MethodCall));
|
||||
AddElementType("methodResponse", Uri.IQ_RPC, typeof (MethodResponse));
|
||||
|
||||
// Chatstates Jep-0085
|
||||
AddElementType("active", Uri.CHATSTATES, typeof (extensions.chatstates.Active));
|
||||
AddElementType("inactive", Uri.CHATSTATES, typeof (Inactive));
|
||||
AddElementType("composing", Uri.CHATSTATES, typeof (Composing));
|
||||
AddElementType("paused", Uri.CHATSTATES, typeof (Paused));
|
||||
AddElementType("gone", Uri.CHATSTATES, typeof (Gone));
|
||||
|
||||
// Jivesoftware Extenstions
|
||||
AddElementType("phone-event", Uri.JIVESOFTWARE_PHONE, typeof (PhoneEvent));
|
||||
AddElementType("phone-action", Uri.JIVESOFTWARE_PHONE, typeof (PhoneAction));
|
||||
AddElementType("phone-status", Uri.JIVESOFTWARE_PHONE, typeof (PhoneStatus));
|
||||
|
||||
// Jingle stuff is in heavy development, we commit this once the most changes on the Jeps are done
|
||||
// AddElementType("jingle", Uri.JINGLE, typeof(agsXMPP.protocol.extensions.jingle.Jingle));
|
||||
// AddElementType("candidate", Uri.JINGLE, typeof(agsXMPP.protocol.extensions.jingle.Candidate));
|
||||
AddElementType("c", Uri.CAPS, typeof (Capabilities));
|
||||
|
||||
AddElementType("geoloc", Uri.GEOLOC, typeof (GeoLoc));
|
||||
|
||||
// Xmpp Ping
|
||||
AddElementType("ping", Uri.PING, typeof (Ping));
|
||||
|
||||
// Ad-Hock Commands
|
||||
AddElementType("command", Uri.COMMANDS, typeof (Command));
|
||||
AddElementType("actions", Uri.COMMANDS, typeof (Actions));
|
||||
AddElementType("note", Uri.COMMANDS, typeof (Note));
|
||||
|
||||
// **********
|
||||
// * PubSub *
|
||||
// **********
|
||||
// Owner namespace
|
||||
AddElementType("affiliate", Uri.PUBSUB_OWNER, typeof (Affiliate));
|
||||
AddElementType("affiliates", Uri.PUBSUB_OWNER, typeof (Affiliates));
|
||||
AddElementType("configure", Uri.PUBSUB_OWNER, typeof (Configure));
|
||||
AddElementType("delete", Uri.PUBSUB_OWNER, typeof (Delete));
|
||||
AddElementType("pending", Uri.PUBSUB_OWNER, typeof (Pending));
|
||||
AddElementType("pubsub", Uri.PUBSUB_OWNER, typeof (PubSub));
|
||||
AddElementType("purge", Uri.PUBSUB_OWNER, typeof (Purge));
|
||||
AddElementType("subscriber", Uri.PUBSUB_OWNER, typeof (Subscriber));
|
||||
AddElementType("subscribers", Uri.PUBSUB_OWNER, typeof (Subscribers));
|
||||
|
||||
// Event namespace
|
||||
AddElementType("delete", Uri.PUBSUB_EVENT, typeof (extensions.pubsub.@event.Delete));
|
||||
AddElementType("event", Uri.PUBSUB_EVENT, typeof (extensions.pubsub.@event.Event));
|
||||
AddElementType("item", Uri.PUBSUB_EVENT, typeof (extensions.pubsub.@event.Item));
|
||||
AddElementType("items", Uri.PUBSUB_EVENT, typeof (Items));
|
||||
AddElementType("purge", Uri.PUBSUB_EVENT, typeof (extensions.pubsub.@event.Purge));
|
||||
|
||||
// Main Pubsub namespace
|
||||
AddElementType("affiliation", Uri.PUBSUB, typeof (Affiliation));
|
||||
AddElementType("affiliations", Uri.PUBSUB, typeof (Affiliations));
|
||||
AddElementType("configure", Uri.PUBSUB, typeof (extensions.pubsub.Configure));
|
||||
AddElementType("create", Uri.PUBSUB, typeof (Create));
|
||||
AddElementType("configure", Uri.PUBSUB, typeof (extensions.pubsub.Configure));
|
||||
AddElementType("item", Uri.PUBSUB, typeof (extensions.pubsub.Item));
|
||||
AddElementType("items", Uri.PUBSUB, typeof (extensions.pubsub.Items));
|
||||
AddElementType("options", Uri.PUBSUB, typeof (Options));
|
||||
AddElementType("publish", Uri.PUBSUB, typeof (Publish));
|
||||
AddElementType("pubsub", Uri.PUBSUB, typeof (extensions.pubsub.PubSub));
|
||||
AddElementType("retract", Uri.PUBSUB, typeof (Retract));
|
||||
AddElementType("subscribe", Uri.PUBSUB, typeof (Subscribe));
|
||||
AddElementType("subscribe-options", Uri.PUBSUB, typeof (SubscribeOptions));
|
||||
AddElementType("subscription", Uri.PUBSUB, typeof (Subscription));
|
||||
AddElementType("subscriptions", Uri.PUBSUB, typeof (Subscriptions));
|
||||
AddElementType("unsubscribe", Uri.PUBSUB, typeof (Unsubscribe));
|
||||
|
||||
// HTTP Binding XEP-0124
|
||||
AddElementType("body", Uri.HTTP_BIND, typeof (extensions.bosh.Body));
|
||||
|
||||
// Message receipts XEP-0184
|
||||
AddElementType("received", Uri.MSG_RECEIPT, typeof (Received));
|
||||
AddElementType("request", Uri.MSG_RECEIPT, typeof (Request));
|
||||
|
||||
// Bookmark storage XEP-0048
|
||||
AddElementType("storage", Uri.STORAGE_BOOKMARKS, typeof (Storage));
|
||||
AddElementType("url", Uri.STORAGE_BOOKMARKS, typeof (Url));
|
||||
AddElementType("conference",
|
||||
Uri.STORAGE_BOOKMARKS,
|
||||
typeof (extensions.bookmarks.Conference));
|
||||
|
||||
// XEP-0047: In-Band Bytestreams (IBB)
|
||||
AddElementType("open", Uri.IBB, typeof (Open));
|
||||
AddElementType("data", Uri.IBB, typeof (extensions.ibb.Data));
|
||||
AddElementType("close", Uri.IBB, typeof (Close));
|
||||
|
||||
// XEP-0153: vCard-Based Avatars
|
||||
AddElementType("x", Uri.VCARD_UPDATE, typeof (VcardUpdate));
|
||||
|
||||
// AMP
|
||||
AddElementType("amp", Uri.AMP, typeof (Amp));
|
||||
AddElementType("rule", Uri.AMP, typeof (Rule));
|
||||
|
||||
// XEP-0202: Entity Time
|
||||
AddElementType("time", Uri.ENTITY_TIME, typeof (EntityTime));
|
||||
|
||||
//Team lab
|
||||
AddElementType("query", Uri.X_TM_IQ_HISTORY, typeof (x.tm.history.History));
|
||||
AddElementType("item", Uri.X_TM_IQ_HISTORY, typeof (HistoryItem));
|
||||
|
||||
AddElementType("query", Uri.MSG_CHAT_MARKERS, typeof(Chatmarkers));
|
||||
AddElementType("item", Uri.MSG_CHAT_MARKERS, typeof(Chatmarkers));
|
||||
|
||||
AddElementType("query", Uri.X_TM_IQ_PRIVATELOG, typeof (PrivateLog));
|
||||
AddElementType("item", Uri.X_TM_IQ_PRIVATELOG, typeof (PrivateLogItem));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds new Element Types to the Hashtable Use this function also to register your own created Elements. If a element is already registered it gets overwritten. This behaviour is also useful if you you want to overwrite classes and add your own derived classes to the factory.
|
||||
/// </summary>
|
||||
/// <param name="tag"> FQN </param>
|
||||
/// <param name="ns"> </param>
|
||||
/// <param name="t"> </param>
|
||||
public static void AddElementType(string tag, string ns, Type t)
|
||||
{
|
||||
var et = new ElementType(tag, ns);
|
||||
string key = et.ToString();
|
||||
|
||||
// added thread safety on a user request
|
||||
lock (m_table)
|
||||
{
|
||||
m_table[key] = t;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="prefix"> </param>
|
||||
/// <param name="tag"> </param>
|
||||
/// <param name="ns"> </param>
|
||||
/// <returns> </returns>
|
||||
public static Element GetElement(string prefix, string tag, string ns)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
ns = string.Empty;
|
||||
}
|
||||
|
||||
var et = new ElementType(tag, ns);
|
||||
var key = et.ToString();
|
||||
|
||||
Element ret;
|
||||
if (m_table.ContainsKey(key))
|
||||
{
|
||||
ret = (Element) Activator.CreateInstance(m_table[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = new Element(tag);
|
||||
}
|
||||
|
||||
ret.Prefix = prefix;
|
||||
|
||||
if (ns != string.Empty)
|
||||
{
|
||||
ret.Namespace = ns;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static string GetElementNamespace(Type type)
|
||||
{
|
||||
foreach (var entry in m_table)
|
||||
{
|
||||
if (entry.Value == type)
|
||||
{
|
||||
var name = (string) entry.Key;
|
||||
return name.Contains(":") ? name.Substring(0, name.LastIndexOf(":")) : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
75
ASC.Xmpp.Core/protocol/ElementType.cs
Normal file
75
ASC.Xmpp.Core/protocol/ElementType.cs
Normal file
@ -0,0 +1,75 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region file header
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class ElementType
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly string m_Namespace;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private readonly string m_TagName;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="TagName"> </param>
|
||||
/// <param name="Namespace"> </param>
|
||||
public ElementType(string TagName, string Namespace)
|
||||
{
|
||||
m_TagName = TagName;
|
||||
m_Namespace = Namespace;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public override string ToString()
|
||||
{
|
||||
if ((m_Namespace != null) && (m_Namespace != string.Empty))
|
||||
{
|
||||
return m_Namespace + ":" + m_TagName;
|
||||
}
|
||||
|
||||
return m_TagName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
455
ASC.Xmpp.Core/protocol/Error.cs
Normal file
455
ASC.Xmpp.Core/protocol/Error.cs
Normal file
@ -0,0 +1,455 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/*
|
||||
<stream:error>
|
||||
<defined-condition xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
|
||||
<text xmlns='urn:ietf:params:xml:ns:xmpp-streams'
|
||||
xml:lang='langcode'>
|
||||
OPTIONAL descriptive text
|
||||
</text>
|
||||
[OPTIONAL application-specific condition element]
|
||||
</stream:error>
|
||||
*/
|
||||
|
||||
/*
|
||||
RFC 4.7.3. Defined Conditions
|
||||
|
||||
The following stream-level error conditions are defined:
|
||||
|
||||
* <bad-format/> -- the entity has sent XML that cannot be processed; this error MAY be used instead of the more specific XML-related errors, such as <bad-namespace-prefix/>, <invalid-xml/>, <restricted-xml/>, <unsupported-encoding/>, and <xml-not-well-formed/>, although the more specific errors are preferred.
|
||||
* <bad-namespace-prefix/> -- the entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)).
|
||||
* <conflict/> -- the server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream.
|
||||
* <connection-timeout/> -- the entity has not generated any traffic over the stream for some period of time (configurable according to a local service policy).
|
||||
* <host-gone/> -- the value of the 'to' attribute provided by the initiating entity in the stream header corresponds to a hostname that is no longer hosted by the server.
|
||||
* <host-unknown/> -- the value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server.
|
||||
* <improper-addressing/> -- a stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value).
|
||||
* <internal-server-error/> -- the server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream.
|
||||
* <invalid-from/> -- the JID or hostname provided in a 'from' address does not match an authorized JID or validated domain negotiated between servers via SASL or dialback, or between a client and a server via authentication and resource binding.
|
||||
* <invalid-id/> -- the stream ID or dialback ID is invalid or does not match an ID previously provided.
|
||||
* <invalid-namespace/> -- the streams namespace name is something other than "http://etherx.jabber.org/streams" or the dialback namespace name is something other than "jabber:server:dialback" (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)).
|
||||
* <invalid-xml/> -- the entity has sent invalid XML over the stream to a server that performs validation (see Validation (Validation)).
|
||||
* <not-authorized/> -- the entity has attempted to send data before the stream has been authenticated, or otherwise is not authorized to perform an action related to stream negotiation; the receiving entity MUST NOT process the offending stanza before sending the stream error.
|
||||
* <policy-violation/> -- the entity has violated some local service policy; the server MAY choose to specify the policy in the <text/> element or an application-specific condition element.
|
||||
* <remote-connection-failed/> -- the server is unable to properly connect to a remote entity that is required for authentication or authorization.
|
||||
* <resource-constraint/> -- the server lacks the system resources necessary to service the stream.
|
||||
* <restricted-xml/> -- the entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character (see Restrictions (Restrictions)).
|
||||
* <see-other-host/> -- the server will not provide service to the initiating entity but is redirecting traffic to another host; the server SHOULD specify the alternate hostname or IP address (which MUST be a valid domain identifier) as the XML character data of the <see-other-host/> element.
|
||||
* <system-shutdown/> -- the server is being shut down and all active streams are being closed.
|
||||
* <undefined-condition/> -- the error condition is not one of those defined by the other conditions in this list; this error condition SHOULD be used only in conjunction with an application-specific condition.
|
||||
* <unsupported-encoding/> -- the initiating entity has encoded the stream in an encoding that is not supported by the server (see Character Encoding (Character Encoding)).
|
||||
* <unsupported-stanza-type/> -- the initiating entity has sent a first-level child of the stream that is not supported by the server.
|
||||
* <unsupported-version/> -- the value of the 'version' attribute provided by the initiating entity in the stream header specifies a version of XMPP that is not supported by the server; the server MAY specify the version(s) it supports in the <text/> element.
|
||||
* <xml-not-well-formed/> -- the initiating entity has sent XML that is not well-formed as defined by [XML] (Bray, T., Paoli, J., Sperberg-McQueen, C., and E. Maler, <EFBFBD>Extensible Markup Language (XML) 1.0 (2nd ed),<EFBFBD> October 2000.).
|
||||
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public enum StreamErrorCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// unknown error condition
|
||||
/// </summary>
|
||||
UnknownCondition = -1,
|
||||
|
||||
/// <summary>
|
||||
/// the entity has sent XML that cannot be processed; this error MAY be used instead of the more specific XML-related errors, such as <bad-namespace-prefix/>, <invalid-xml/>, <restricted-xml/>, <unsupported-encoding/>, and <xml-not-well-formed/>, although the more specific errors are preferred.
|
||||
/// </summary>
|
||||
BadFormat,
|
||||
|
||||
/// <summary>
|
||||
/// the entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)).
|
||||
/// </summary>
|
||||
BadNamespacePrefix,
|
||||
|
||||
/// <summary>
|
||||
/// the server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream.
|
||||
/// </summary>
|
||||
Conflict,
|
||||
|
||||
/// <summary>
|
||||
/// the entity has not generated any traffic over the stream for some period of time (configurable according to a local service policy).
|
||||
/// </summary>
|
||||
ConnectionTimeout,
|
||||
|
||||
/// <summary>
|
||||
/// the value of the 'to' attribute provided by the initiating entity in the stream header corresponds to a hostname that is no longer hosted by the server.
|
||||
/// </summary>
|
||||
HostGone,
|
||||
|
||||
/// <summary>
|
||||
/// the value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server.
|
||||
/// </summary>
|
||||
HostUnknown,
|
||||
|
||||
/// <summary>
|
||||
/// a stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value).
|
||||
/// </summary>
|
||||
ImproperAddressing,
|
||||
|
||||
/// <summary>
|
||||
/// the server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream.
|
||||
/// </summary>
|
||||
InternalServerError,
|
||||
|
||||
/// <summary>
|
||||
/// the JID or hostname provided in a 'from' address does not match an authorized JID or validated domain negotiated between servers via SASL or dialback, or between a client and a server via authentication and resource binding.
|
||||
/// </summary>
|
||||
InvalidFrom,
|
||||
|
||||
/// <summary>
|
||||
/// the stream ID or dialback ID is invalid or does not match an ID previously provided.
|
||||
/// </summary>
|
||||
InvalidId,
|
||||
|
||||
/// <summary>
|
||||
/// the streams namespace name is something other than "http://etherx.jabber.org/streams" or the dialback namespace name is something other than "jabber:server:dialback" (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)).
|
||||
/// </summary>
|
||||
InvalidNamespace,
|
||||
|
||||
/// <summary>
|
||||
/// the entity has sent invalid XML over the stream to a server that performs validation.
|
||||
/// </summary>
|
||||
InvalidXml,
|
||||
|
||||
/// <summary>
|
||||
/// the entity has attempted to send data before the stream has been authenticated, or otherwise is not authorized to perform an action related to stream negotiation; the receiving entity MUST NOT process the offending stanza before sending the stream error.
|
||||
/// </summary>
|
||||
NotAuthorized,
|
||||
|
||||
/// <summary>
|
||||
/// the entity has violated some local service policy; the server MAY choose to specify the policy in the <text/> element or an application-specific condition element.
|
||||
/// </summary>
|
||||
PolicyViolation,
|
||||
|
||||
/// <summary>
|
||||
/// the server is unable to properly connect to a remote entity that is required for authentication or authorization.
|
||||
/// </summary>
|
||||
RemoteConnectionFailed,
|
||||
|
||||
/// <summary>
|
||||
/// the server lacks the system resources necessary to service the stream.
|
||||
/// </summary>
|
||||
ResourceConstraint,
|
||||
|
||||
/// <summary>
|
||||
/// the entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character (see Restrictions (Restrictions)).
|
||||
/// </summary>
|
||||
RestrictedXml,
|
||||
|
||||
/// <summary>
|
||||
/// the server will not provide service to the initiating entity but is redirecting traffic to another host; the server SHOULD specify the alternate hostname or IP address (which MUST be a valid domain identifier) as the XML character data of the <see-other-host/> element.
|
||||
/// </summary>
|
||||
SeeOtherHost,
|
||||
|
||||
/// <summary>
|
||||
/// the server is being shut down and all active streams are being closed.
|
||||
/// </summary>
|
||||
SystemShutdown,
|
||||
|
||||
/// <summary>
|
||||
/// the error condition is not one of those defined by the other conditions in this list; this error condition SHOULD be used only in conjunction with an application-specific condition.
|
||||
/// </summary>
|
||||
UndefinedCondition,
|
||||
|
||||
/// <summary>
|
||||
/// the initiating entity has encoded the stream in an encoding that is not supported by the server.
|
||||
/// </summary>
|
||||
UnsupportedEncoding,
|
||||
|
||||
/// <summary>
|
||||
/// the initiating entity has sent a first-level child of the stream that is not supported by the server.
|
||||
/// </summary>
|
||||
UnsupportedStanzaType,
|
||||
|
||||
/// <summary>
|
||||
/// the value of the 'version' attribute provided by the initiating entity in the stream header specifies a version of XMPP that is not supported by the server; the server MAY specify the version(s) it supports in the <text/> element.
|
||||
/// </summary>
|
||||
UnsupportedVersion,
|
||||
|
||||
/// <summary>
|
||||
/// the initiating entity has sent XML that is not well-formed as defined by the XML specs.
|
||||
/// </summary>
|
||||
XmlNotWellFormed
|
||||
}
|
||||
|
||||
// <stream:error>Invalid handshake</stream:error>
|
||||
// <stream:error>Socket override by another connection.</stream:error>
|
||||
|
||||
/// <summary>
|
||||
/// Stream Errors <stream:error>
|
||||
/// </summary>
|
||||
public class Error : Element
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Error()
|
||||
{
|
||||
TagName = "error";
|
||||
Namespace = Uri.STREAM;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="condition"> </param>
|
||||
public Error(StreamErrorCondition condition) : this()
|
||||
{
|
||||
Condition = condition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public StreamErrorCondition Condition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasTag("bad-format"))
|
||||
{
|
||||
return StreamErrorCondition.BadFormat;
|
||||
}
|
||||
else if (HasTag("bad-namespace-prefix"))
|
||||
{
|
||||
return StreamErrorCondition.BadNamespacePrefix;
|
||||
}
|
||||
else if (HasTag("conflict"))
|
||||
{
|
||||
return StreamErrorCondition.Conflict;
|
||||
}
|
||||
else if (HasTag("connection-timeout"))
|
||||
{
|
||||
return StreamErrorCondition.ConnectionTimeout;
|
||||
}
|
||||
else if (HasTag("host-gone"))
|
||||
{
|
||||
return StreamErrorCondition.HostGone;
|
||||
}
|
||||
else if (HasTag("host-unknown"))
|
||||
{
|
||||
return StreamErrorCondition.HostUnknown;
|
||||
}
|
||||
else if (HasTag("improper-addressing"))
|
||||
{
|
||||
return StreamErrorCondition.ImproperAddressing;
|
||||
}
|
||||
else if (HasTag("internal-server-error"))
|
||||
{
|
||||
return StreamErrorCondition.InternalServerError;
|
||||
}
|
||||
else if (HasTag("invalid-from"))
|
||||
{
|
||||
return StreamErrorCondition.InvalidFrom;
|
||||
}
|
||||
else if (HasTag("invalid-id"))
|
||||
{
|
||||
return StreamErrorCondition.InvalidId;
|
||||
}
|
||||
else if (HasTag("invalid-namespace"))
|
||||
{
|
||||
return StreamErrorCondition.InvalidNamespace;
|
||||
}
|
||||
else if (HasTag("invalid-xml"))
|
||||
{
|
||||
return StreamErrorCondition.InvalidXml;
|
||||
}
|
||||
else if (HasTag("not-authorized"))
|
||||
{
|
||||
return StreamErrorCondition.NotAuthorized;
|
||||
}
|
||||
else if (HasTag("policy-violation"))
|
||||
{
|
||||
return StreamErrorCondition.PolicyViolation;
|
||||
}
|
||||
else if (HasTag("remote-connection-failed"))
|
||||
{
|
||||
return StreamErrorCondition.RemoteConnectionFailed;
|
||||
}
|
||||
else if (HasTag("resource-constraint"))
|
||||
{
|
||||
return StreamErrorCondition.ResourceConstraint;
|
||||
}
|
||||
else if (HasTag("restricted-xml"))
|
||||
{
|
||||
return StreamErrorCondition.RestrictedXml;
|
||||
}
|
||||
else if (HasTag("see-other-host"))
|
||||
{
|
||||
return StreamErrorCondition.SeeOtherHost;
|
||||
}
|
||||
else if (HasTag("system-shutdown"))
|
||||
{
|
||||
return StreamErrorCondition.SystemShutdown;
|
||||
}
|
||||
else if (HasTag("undefined-condition"))
|
||||
{
|
||||
return StreamErrorCondition.UndefinedCondition;
|
||||
}
|
||||
else if (HasTag("unsupported-encoding"))
|
||||
{
|
||||
return StreamErrorCondition.UnsupportedEncoding;
|
||||
}
|
||||
else if (HasTag("unsupported-stanza-type"))
|
||||
{
|
||||
return StreamErrorCondition.UnsupportedStanzaType;
|
||||
}
|
||||
else if (HasTag("unsupported-version"))
|
||||
{
|
||||
return StreamErrorCondition.UnsupportedVersion;
|
||||
}
|
||||
else if (HasTag("xml-not-well-formed"))
|
||||
{
|
||||
return StreamErrorCondition.XmlNotWellFormed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return StreamErrorCondition.UnknownCondition;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case StreamErrorCondition.BadFormat:
|
||||
SetTag("bad-format", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.BadNamespacePrefix:
|
||||
SetTag("bad-namespace-prefix", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.Conflict:
|
||||
SetTag("conflict", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.ConnectionTimeout:
|
||||
SetTag("connection-timeout", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.HostGone:
|
||||
SetTag("host-gone", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.HostUnknown:
|
||||
SetTag("host-unknown", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.ImproperAddressing:
|
||||
SetTag("improper-addressing", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.InternalServerError:
|
||||
SetTag("internal-server-error", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.InvalidFrom:
|
||||
SetTag("invalid-from", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.InvalidId:
|
||||
SetTag("invalid-id", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.InvalidNamespace:
|
||||
SetTag("invalid-namespace", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.InvalidXml:
|
||||
SetTag("invalid-xml", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.NotAuthorized:
|
||||
SetTag("not-authorized", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.PolicyViolation:
|
||||
SetTag("policy-violation", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.RemoteConnectionFailed:
|
||||
SetTag("remote-connection-failed", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.ResourceConstraint:
|
||||
SetTag("resource-constraint", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.RestrictedXml:
|
||||
SetTag("restricted-xml", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.SeeOtherHost:
|
||||
SetTag("see-other-host", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.SystemShutdown:
|
||||
SetTag("system-shutdown", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.UndefinedCondition:
|
||||
SetTag("undefined-condition", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.UnsupportedEncoding:
|
||||
SetTag("unsupported-encoding", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.UnsupportedStanzaType:
|
||||
SetTag("unsupported-stanza-type", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.UnsupportedVersion:
|
||||
SetTag("unsupported-version", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
case StreamErrorCondition.XmlNotWellFormed:
|
||||
SetTag("xml-not-well-formed", string.Empty, Uri.STREAMS);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>The <text/> element is OPTIONAL. If included, it SHOULD be used only to provide descriptive or diagnostic information
|
||||
/// that supplements the meaning of a defined condition or application-specific condition.</para> <para>It SHOULD NOT be interpreted programmatically by an application.
|
||||
/// It SHOULD NOT be used as the error message presented to a user, but MAY be shown in addition to the error message
|
||||
/// associated with the included condition element (or elements).</para>
|
||||
/// </summary>
|
||||
public string Text
|
||||
{
|
||||
get { return GetTag("text"); }
|
||||
|
||||
set { SetTag("text", value, Uri.STREAMS); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/*
|
||||
public Error(string msg) : this()
|
||||
{
|
||||
Message = msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The error Description
|
||||
/// </summary>
|
||||
public string Message
|
||||
{
|
||||
get { return this.Value; }
|
||||
set { this.Value = value; }
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
140
ASC.Xmpp.Core/protocol/Id.cs
Normal file
140
ASC.Xmpp.Core/protocol/Id.cs
Normal file
@ -0,0 +1,140 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region file header
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public enum IdType
|
||||
{
|
||||
/// <summary>
|
||||
/// Numeric Id's are generated by increasing a long value
|
||||
/// </summary>
|
||||
Numeric,
|
||||
|
||||
/// <summary>
|
||||
/// Guid Id's are unique, Guid packet Id's should be used for server and component applications, or apps which very long sessions (multiple days, weeks or years)
|
||||
/// </summary>
|
||||
Guid
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class takes care anout out unique Message Ids
|
||||
/// </summary>
|
||||
public class Id
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static long m_id;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static string m_Prefix = "agsXMPP_";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private static IdType m_Type = IdType.Numeric;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public static IdType Type
|
||||
{
|
||||
get { return m_Type; }
|
||||
|
||||
#if !CF
|
||||
// readyonly on CF1
|
||||
set { m_Type = value; }
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !CF
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public static string GetNextId()
|
||||
{
|
||||
if (m_Type == IdType.Numeric)
|
||||
{
|
||||
m_id++;
|
||||
return m_Prefix + m_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Prefix + Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
|
||||
// On CF 1.0 we have no GUID class, so only increasing numberical id's are supported
|
||||
// We could create GUID's on CF 1.0 with the Crypto API if we want to.
|
||||
public static string GetNextId()
|
||||
{
|
||||
m_id++;
|
||||
return m_Prefix + m_id.ToString();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Reset the id counter to agsXmpp_1 again
|
||||
/// </summary>
|
||||
public static void Reset()
|
||||
{
|
||||
m_id = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to Save Bandwidth on Mobile devices you can change the prefix null is also possible to optimize Bandwidth usage
|
||||
/// </summary>
|
||||
public static string Prefix
|
||||
{
|
||||
get { return m_Prefix; }
|
||||
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
m_Prefix = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Prefix = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
715
ASC.Xmpp.Core/protocol/Jid.cs
Normal file
715
ASC.Xmpp.Core/protocol/Jid.cs
Normal file
@ -0,0 +1,715 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using ASC.Xmpp.Core.utils.Collections;
|
||||
using ASC.Xmpp.Core.utils.Idn;
|
||||
|
||||
#endregion
|
||||
|
||||
#if STRINGPREP
|
||||
|
||||
#endif
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Class for building and handling XMPP Id's (JID's)
|
||||
/// </summary>
|
||||
public class Jid : IComparable
|
||||
#if NET_2 || CF_2
|
||||
,
|
||||
IEquatable<Jid>
|
||||
#endif
|
||||
{
|
||||
/*
|
||||
14 possible invalid forms of JIDs and some variations on valid JIDs with invalid lengths, viz:
|
||||
|
||||
jidforms = [
|
||||
"",
|
||||
"@",
|
||||
"@/resource",
|
||||
"@domain",
|
||||
"@domain/",
|
||||
"@domain/resource",
|
||||
"nodename@",
|
||||
"/",
|
||||
"nodename@domain/",
|
||||
"nodename@/",
|
||||
"@/",
|
||||
"nodename/",
|
||||
"/resource",
|
||||
"nodename@/resource",
|
||||
]
|
||||
|
||||
|
||||
TODO
|
||||
Each allowable portion of a JID (node identifier, domain identifier, and resource identifier) MUST NOT
|
||||
be more than 1023 bytes in length, resulting in a maximum total size
|
||||
(including the '@' and '/' separators) of 3071 bytes.
|
||||
|
||||
stringprep with libIDN
|
||||
m_User ==> nodeprep
|
||||
m_Server ==> nameprep
|
||||
m_Resource ==> resourceprep
|
||||
*/
|
||||
|
||||
// !!!
|
||||
// use this internal variables only if you know what you are doing
|
||||
// !!!
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
internal string m_Jid;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
internal string m_User;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
internal string m_Server;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
internal string m_Resource;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new JID object from a string. The input string must be a valid jabberId and already prepared with stringprep. Otherwise use one of the other constructors with escapes the node and prepares the gives balues with the stringprep profiles
|
||||
/// </summary>
|
||||
/// <param name="jid"> XMPP ID, in string form examples: user@server/Resource, user@server </param>
|
||||
public Jid(string jid)
|
||||
{
|
||||
m_Jid = jid;
|
||||
Parse(jid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// builds a new Jid object
|
||||
/// </summary>
|
||||
/// <param name="user"> XMPP User part </param>
|
||||
/// <param name="server"> XMPP Domain part </param>
|
||||
/// <param name="resource"> XMPP Resource part </param>
|
||||
public Jid(string user, string server, string resource)
|
||||
{
|
||||
#if !STRINGPREP
|
||||
if (user != null)
|
||||
{
|
||||
user = EscapeNode(user);
|
||||
|
||||
m_User = user.ToLower();
|
||||
}
|
||||
|
||||
if (server != null)
|
||||
m_Server = server.ToLower();
|
||||
|
||||
if (resource != null)
|
||||
m_Resource = resource;
|
||||
#else
|
||||
if (user != null)
|
||||
{
|
||||
user = EscapeNode(user);
|
||||
|
||||
m_User = Stringprep.NodePrep(user);
|
||||
}
|
||||
|
||||
if (server != null)
|
||||
{
|
||||
m_Server = Stringprep.NamePrep(server);
|
||||
}
|
||||
|
||||
if (resource != null)
|
||||
{
|
||||
m_Resource = Stringprep.ResourcePrep(resource);
|
||||
}
|
||||
|
||||
#endif
|
||||
BuildJid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a JabberId from a string. If we parse a jid we assume it's correct and already prepared via stringprep.
|
||||
/// </summary>
|
||||
/// <param name="fullJid"> jis to parse as string </param>
|
||||
/// <returns> true if the jid could be parsed, false if an error occured </returns>
|
||||
public bool Parse(string fullJid)
|
||||
{
|
||||
string user = null;
|
||||
string server = null;
|
||||
string resource = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (fullJid == null || fullJid.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Jid = fullJid;
|
||||
|
||||
int atPos = m_Jid.IndexOf('@');
|
||||
int slashPos = m_Jid.IndexOf('/');
|
||||
|
||||
// some more validations
|
||||
// @... or /...
|
||||
if (atPos == 0 || slashPos == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// nodename@
|
||||
if (atPos + 1 == fullJid.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// @/ at followed by resource separator
|
||||
if (atPos + 1 == slashPos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (atPos == -1)
|
||||
{
|
||||
user = null;
|
||||
if (slashPos == -1)
|
||||
{
|
||||
// JID Contains only the Server
|
||||
server = m_Jid;
|
||||
}
|
||||
else
|
||||
{
|
||||
// JID Contains only the Server and Resource
|
||||
server = m_Jid.Substring(0, slashPos);
|
||||
resource = m_Jid.Substring(slashPos + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (slashPos == -1)
|
||||
{
|
||||
// We have no resource
|
||||
// Devide User and Server (user@server)
|
||||
server = m_Jid.Substring(atPos + 1);
|
||||
user = m_Jid.Substring(0, atPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have all
|
||||
user = m_Jid.Substring(0, atPos);
|
||||
server = m_Jid.Substring(atPos + 1, slashPos - atPos - 1);
|
||||
resource = m_Jid.Substring(slashPos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
m_User = user;
|
||||
}
|
||||
|
||||
if (server != null)
|
||||
{
|
||||
m_Server = server;
|
||||
}
|
||||
|
||||
if (resource != null)
|
||||
{
|
||||
m_Resource = resource;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
internal void BuildJid()
|
||||
{
|
||||
m_Jid = BuildJid(m_User, m_Server, m_Resource);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="user"> </param>
|
||||
/// <param name="server"> </param>
|
||||
/// <param name="resource"> </param>
|
||||
/// <returns> </returns>
|
||||
private string BuildJid(string user, string server, string resource)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (user != null)
|
||||
{
|
||||
sb.Append(user);
|
||||
sb.Append("@");
|
||||
}
|
||||
|
||||
sb.Append(server);
|
||||
if (resource != null)
|
||||
{
|
||||
sb.Append("/");
|
||||
sb.Append(resource);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return m_Jid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the user part of the JabberId.
|
||||
/// </summary>
|
||||
public string User
|
||||
{
|
||||
get { return m_User; }
|
||||
|
||||
set
|
||||
{
|
||||
// first Encode the user/node
|
||||
string tmpUser = EscapeNode(value);
|
||||
#if !STRINGPREP
|
||||
if (value != null)
|
||||
m_User = tmpUser.ToLower();
|
||||
else
|
||||
m_User = null;
|
||||
#else
|
||||
if (value != null)
|
||||
{
|
||||
m_User = Stringprep.NodePrep(tmpUser);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_User = null;
|
||||
}
|
||||
|
||||
#endif
|
||||
BuildJid();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only Server
|
||||
/// </summary>
|
||||
public string Server
|
||||
{
|
||||
get { return m_Server; }
|
||||
|
||||
set
|
||||
{
|
||||
#if !STRINGPREP
|
||||
if (value != null)
|
||||
m_Server = value.ToLower();
|
||||
else
|
||||
m_Server = null;
|
||||
#else
|
||||
if (value != null)
|
||||
{
|
||||
m_Server = Stringprep.NamePrep(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Server = null;
|
||||
}
|
||||
|
||||
#endif
|
||||
BuildJid();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only the Resource field. null for none
|
||||
/// </summary>
|
||||
public string Resource
|
||||
{
|
||||
get { return m_Resource; }
|
||||
|
||||
set
|
||||
{
|
||||
#if !STRINGPREP
|
||||
if (value != null)
|
||||
m_Resource = value;
|
||||
else
|
||||
m_Resource = null;
|
||||
#else
|
||||
if (value != null)
|
||||
{
|
||||
m_Resource = Stringprep.ResourcePrep(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Resource = null;
|
||||
}
|
||||
|
||||
#endif
|
||||
BuildJid();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Bare Jid only (user@server).
|
||||
/// </summary>
|
||||
public string Bare
|
||||
{
|
||||
get { return BuildJid(m_User, m_Server, null); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Bare Jid only (user@server).
|
||||
/// </summary>
|
||||
public Jid BareJid
|
||||
{
|
||||
get { return new Jid(Bare); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Jid has not empty User field.
|
||||
/// </summary>
|
||||
public bool HasUser
|
||||
{
|
||||
get { return !string.IsNullOrEmpty(User); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Jid has empty User field.
|
||||
/// </summary>
|
||||
public bool IsServer
|
||||
{
|
||||
get { return !HasUser; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Jid has not empty Resource field.
|
||||
/// </summary>
|
||||
public bool HasResource
|
||||
{
|
||||
get { return !string.IsNullOrEmpty(Resource); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Jid has empty Resource field.
|
||||
/// </summary>
|
||||
public bool IsBare
|
||||
{
|
||||
get { return !HasResource; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Jid has not empty User and not empty Resource fields.
|
||||
/// </summary>
|
||||
public bool IsFull
|
||||
{
|
||||
get { return HasResource && HasUser; }
|
||||
}
|
||||
|
||||
#region << Overrides >>
|
||||
|
||||
/// <summary>
|
||||
/// This compares the full Jid by default
|
||||
/// </summary>
|
||||
/// <param name="obj"> </param>
|
||||
/// <returns> </returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj, new FullJidComparer());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hcode = 0;
|
||||
if (m_User != null)
|
||||
{
|
||||
hcode ^= m_User.GetHashCode();
|
||||
}
|
||||
|
||||
if (m_Server != null)
|
||||
{
|
||||
hcode ^= m_Server.GetHashCode();
|
||||
}
|
||||
|
||||
if (m_Resource != null)
|
||||
{
|
||||
hcode ^= m_Resource.GetHashCode();
|
||||
}
|
||||
|
||||
return hcode;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="other"> </param>
|
||||
/// <param name="comparer"> </param>
|
||||
/// <returns> </returns>
|
||||
public bool Equals(object other, IComparer comparer)
|
||||
{
|
||||
if (comparer.Compare(other, this) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#region IComparable Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="obj"> </param>
|
||||
/// <returns> </returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (obj is Jid)
|
||||
{
|
||||
var comparer = new FullJidComparer();
|
||||
return comparer.Compare(obj, this);
|
||||
}
|
||||
|
||||
throw new ArgumentException("object is not a Jid");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#if NET_2 || CF_2
|
||||
|
||||
#region IEquatable<Jid> Members
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="other"> </param>
|
||||
/// <returns> </returns>
|
||||
public bool Equals(Jid other)
|
||||
{
|
||||
var comparer = new FullJidComparer();
|
||||
if (comparer.Compare(other, this) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(Jid jid1, Jid jid2)
|
||||
{
|
||||
return Equals(jid1, jid2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Jid jid1, Jid jid2)
|
||||
{
|
||||
return !(jid1 == jid2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endif
|
||||
|
||||
#region << XEP-0106: JID Escaping >>
|
||||
|
||||
public static Jid Empty = new Jid(string.Empty);
|
||||
|
||||
public static bool IsNullOrEmpty(Jid jid)
|
||||
{
|
||||
return jid == null || Empty.Equals(jid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Escape a node according to XEP-0106</para> <para>
|
||||
/// <a href="http://www.xmpp.org/extensions/xep-0106.html">http://www.xmpp.org/extensions/xep-0106.html</a>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="node"> </param>
|
||||
/// <returns> </returns>
|
||||
public static string EscapeNode(string node)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
for (int i = 0; i < node.Length; i++)
|
||||
{
|
||||
/*
|
||||
<space> \20
|
||||
" \22
|
||||
& \26
|
||||
' \27
|
||||
/ \2f
|
||||
: \3a
|
||||
< \3c
|
||||
> \3e
|
||||
@ \40
|
||||
\ \5c
|
||||
*/
|
||||
char c = node[i];
|
||||
switch (c)
|
||||
{
|
||||
case ' ':
|
||||
sb.Append(@"\20");
|
||||
break;
|
||||
case '"':
|
||||
sb.Append(@"\22");
|
||||
break;
|
||||
case '&':
|
||||
sb.Append(@"\26");
|
||||
break;
|
||||
case '\'':
|
||||
sb.Append(@"\27");
|
||||
break;
|
||||
case '/':
|
||||
sb.Append(@"\2f");
|
||||
break;
|
||||
case ':':
|
||||
sb.Append(@"\3a");
|
||||
break;
|
||||
case '<':
|
||||
sb.Append(@"\3c");
|
||||
break;
|
||||
case '>':
|
||||
sb.Append(@"\3e");
|
||||
break;
|
||||
case '@':
|
||||
sb.Append(@"\40");
|
||||
break;
|
||||
case '\\':
|
||||
sb.Append(@"\5c");
|
||||
break;
|
||||
default:
|
||||
sb.Append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>unescape a node according to XEP-0106</para> <para>
|
||||
/// <a href="http://www.xmpp.org/extensions/xep-0106.html">http://www.xmpp.org/extensions/xep-0106.html</a>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="node"> </param>
|
||||
/// <returns> </returns>
|
||||
public static string UnescapeNode(string node)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
for (int i = 0; i < node.Length; i++)
|
||||
{
|
||||
char c1 = node[i];
|
||||
if (c1 == '\\' && i + 2 < node.Length)
|
||||
{
|
||||
i += 1;
|
||||
char c2 = node[i];
|
||||
i += 1;
|
||||
char c3 = node[i];
|
||||
if (c2 == '2')
|
||||
{
|
||||
switch (c3)
|
||||
{
|
||||
case '0':
|
||||
sb.Append(' ');
|
||||
break;
|
||||
case '2':
|
||||
sb.Append('"');
|
||||
break;
|
||||
case '6':
|
||||
sb.Append('&');
|
||||
break;
|
||||
case '7':
|
||||
sb.Append('\'');
|
||||
break;
|
||||
case 'f':
|
||||
sb.Append('/');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c2 == '3')
|
||||
{
|
||||
switch (c3)
|
||||
{
|
||||
case 'a':
|
||||
sb.Append(':');
|
||||
break;
|
||||
case 'c':
|
||||
sb.Append('<');
|
||||
break;
|
||||
case 'e':
|
||||
sb.Append('>');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c2 == '4')
|
||||
{
|
||||
if (c3 == '0')
|
||||
{
|
||||
sb.Append("@");
|
||||
}
|
||||
}
|
||||
else if (c2 == '5')
|
||||
{
|
||||
if (c3 == 'c')
|
||||
{
|
||||
sb.Append("\\");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(c1);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
40
ASC.Xmpp.Core/protocol/Stream.cs
Normal file
40
ASC.Xmpp.Core/protocol/Stream.cs
Normal file
@ -0,0 +1,40 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol
|
||||
{
|
||||
/// <summary>
|
||||
/// stream:stream Element This is the first Element we receive from the server. It encloses our whole xmpp session.
|
||||
/// </summary>
|
||||
public class Stream : Base.Stream
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Stream()
|
||||
{
|
||||
Namespace = Uri.STREAM;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
383
ASC.Xmpp.Core/protocol/Uri.cs
Normal file
383
ASC.Xmpp.Core/protocol/Uri.cs
Normal file
@ -0,0 +1,383 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class Uri
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// jabber:component:accept
|
||||
/// </summary>
|
||||
public const string ACCEPT = "jabber:component:accept";
|
||||
|
||||
public const string ADDRESS = "http://jabber.org/protocol/address";
|
||||
|
||||
/// <summary>
|
||||
/// <para></para> <para>http://jabber.org/protocol/amp</para>
|
||||
/// </summary>
|
||||
public const string AMP = "http://jabber.org/protocol/amp";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string BIND = "urn:ietf:params:xml:ns:xmpp-bind";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0065 SOCKS5 bytestreams http://jabber.org/protocol/bytestreams
|
||||
/// </summary>
|
||||
public const string BYTESTREAMS = "http://jabber.org/protocol/bytestreams";
|
||||
|
||||
/// <summary>
|
||||
/// XEP-0115: Entity Capabilities (http://jabber.org/protocol/caps)
|
||||
/// </summary>
|
||||
public const string CAPS = "http://jabber.org/protocol/caps";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0085 Chat State Notifications http://jabber.org/protocol/chatstates
|
||||
/// </summary>
|
||||
public const string CHATSTATES = "http://jabber.org/protocol/chatstates";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string CLIENT = "jabber:client";
|
||||
|
||||
/// <summary>
|
||||
/// Ad-Hoc Commands (http://jabber.org/protocol/commands)
|
||||
/// </summary>
|
||||
public const string COMMANDS = "http://jabber.org/protocol/commands";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0138: Stream Compression
|
||||
/// </summary>
|
||||
public const string COMPRESS = "http://jabber.org/protocol/compress";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string DISCO_INFO = "http://jabber.org/protocol/disco#info";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string DISCO_ITEMS = "http://jabber.org/protocol/disco#items";
|
||||
|
||||
/// <summary>
|
||||
/// XEP-0202: Entity Time urn:xmpp:time
|
||||
/// </summary>
|
||||
public const string ENTITY_TIME = "urn:xmpp:time";
|
||||
|
||||
/// <summary>
|
||||
/// Stream Compression http://jabber.org/features/compress
|
||||
/// </summary>
|
||||
public const string FEATURE_COMPRESS = "http://jabber.org/features/compress";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string FEATURE_IQ_REGISTER = "http://jabber.org/features/iq-register";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string FEATURE_IQ_AUTH = "http://jabber.org/features/iq-auth";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0020: Feature Negotiation http://jabber.org/protocol/feature-neg
|
||||
/// </summary>
|
||||
public const string FEATURE_NEG = "http://jabber.org/protocol/feature-neg";
|
||||
|
||||
/// <summary>
|
||||
/// GeoLoc (http://jabber.org/protocol/geoloc)
|
||||
/// </summary>
|
||||
public const string GEOLOC = "http://jabber.org/protocol/geoloc";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string HTTP_BIND = "http://jabber.org/protocol/httpbind";
|
||||
|
||||
/// <summary>
|
||||
/// <para>XEP-0047: In-Band Bytestreams (IBB)</para> <para>http://jabber.org/protocol/ibb</para>
|
||||
/// </summary>
|
||||
public const string IBB = "http://jabber.org/protocol/ibb";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_AGENTS = "jabber:iq:agents";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_AUTH = "jabber:iq:auth";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_AVATAR = "jabber:iq:avatar";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_BLOCKLIST = "urn:xmpp:blocking";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_BROWSE = "jabber:iq:browse";
|
||||
|
||||
public const string IQ_GOOGLE_JINGLE = "google:jingleinfo";
|
||||
public const string IQ_JINGLE0 = "urn:xmpp:jingle:0";
|
||||
public const string IQ_JINGLE1 = "urn:xmpp:jingle:1";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_LAST = "jabber:iq:last";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_OOB = "jabber:iq:oob";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_PRIVACY = "jabber:iq:privacy";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_PRIVATE = "jabber:iq:private";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_REGISTER = "jabber:iq:register";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_ROSTER = "jabber:iq:roster";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0009: Jabber-RPC
|
||||
/// </summary>
|
||||
public const string IQ_RPC = "jabber:iq:rpc";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_SEARCH = "jabber:iq:search";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_TIME = "jabber:iq:time";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string IQ_VERSION = "jabber:iq:version";
|
||||
|
||||
/// <summary>
|
||||
/// Jingle http://jabber.org/protocol/jingle
|
||||
/// </summary>
|
||||
public const string JINGLE = "http://jabber.org/protocol/jingle";
|
||||
|
||||
/// <summary>
|
||||
/// Jingle audio format description http://jabber.org/protocol/jingle/description/audio
|
||||
/// </summary>
|
||||
public const string JINGLE_AUDIO_DESCRIPTION = "http://jabber.org/protocol/jingle/description/audio";
|
||||
|
||||
/// <summary>
|
||||
/// Jingle Info audio http://jabber.org/protocol/jingle/info/audio;
|
||||
/// </summary>
|
||||
public const string JINGLE_AUDIO_INFO = "http://jabber.org/protocol/jingle/info/audio";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string JINGLE_VIDEO_DESCRIPTION = "http://jabber.org/protocol/jingle/description/video";
|
||||
|
||||
/// <summary>
|
||||
/// Jivesoftware asterisk-im extension (http://jivesoftware.com/xmlns/phone);
|
||||
/// </summary>
|
||||
public const string JIVESOFTWARE_PHONE = "http://jivesoftware.com/xmlns/phone";
|
||||
|
||||
/// <summary>
|
||||
/// <para>XEP-0184: Message Receipts</para> <para>urn:xmpp:receipts</para>
|
||||
/// </summary>
|
||||
public const string MSG_RECEIPT = "urn:xmpp:receipts";
|
||||
|
||||
/// <summary>
|
||||
/// <para>XEP-0333: Chat Markers</para> <para>urn:xmpp:chat-markers:0</para>
|
||||
/// </summary>
|
||||
public const string MSG_CHAT_MARKERS = "urn:xmpp:chat-markers:0";
|
||||
|
||||
/// <summary>
|
||||
/// Multi User Chat (MUC) JEP-0045 http://jabber.org/protocol/muc
|
||||
/// </summary>
|
||||
public const string MUC = "http://jabber.org/protocol/muc";
|
||||
|
||||
/// <summary>
|
||||
/// "http://jabber.org/protocol/muc#admin
|
||||
/// </summary>
|
||||
public const string MUC_ADMIN = "http://jabber.org/protocol/muc#admin";
|
||||
|
||||
/// <summary>
|
||||
/// http://jabber.org/protocol/muc#owner
|
||||
/// </summary>
|
||||
public const string MUC_OWNER = "http://jabber.org/protocol/muc#owner";
|
||||
|
||||
public const string MUC_UNIQUE = "http://jabber.org/protocol/muc#unique";
|
||||
|
||||
/// <summary>
|
||||
/// http://jabber.org/protocol/muc#user
|
||||
/// </summary>
|
||||
public const string MUC_USER = "http://jabber.org/protocol/muc#user";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0172 User nickname http://jabber.org/protocol/nick
|
||||
/// </summary>
|
||||
public const string NICK = "http://jabber.org/protocol/nick";
|
||||
|
||||
/// <summary>
|
||||
/// <para>XMPP ping</para> <para>Namespace: urn:xmpp:ping</para> <para>
|
||||
/// <seealso
|
||||
/// cref="http://www.xmpp.org/extensions/xep-0199.html">http://www.xmpp.org/extensions/xep-0199.html</seealso>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public const string PING = "urn:xmpp:ping";
|
||||
|
||||
/// <summary>
|
||||
/// "stream" namespace prefix
|
||||
/// </summary>
|
||||
public const string PREFIX = "stream";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string PRIMARY = "http://jabber.org/protocol/primary";
|
||||
|
||||
// Pubsub stuff
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string PUBSUB = "http://jabber.org/protocol/pubsub";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string PUBSUB_EVENT = "http://jabber.org/protocol/pubsub#event";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string PUBSUB_OWNER = "http://jabber.org/protocol/pubsub#owner";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string ROSTER_DELIMITER = "roster:delimiter";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string SASL = "urn:ietf:params:xml:ns:xmpp-sasl";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string SERVER = "jabber:server";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string SESSION = "urn:ietf:params:xml:ns:xmpp-session";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string SHIM = "http://jabber.org/protocol/shim";
|
||||
|
||||
/// <summary>
|
||||
/// JEO-0095 http://jabber.org/protocol/si
|
||||
/// </summary>
|
||||
public const string SI = "http://jabber.org/protocol/si";
|
||||
|
||||
/// <summary>
|
||||
/// JEO-0096 http://jabber.org/protocol/si/profile/file-transfer
|
||||
/// </summary>
|
||||
public const string SI_FILE_TRANSFER = "http://jabber.org/protocol/si/profile/file-transfer";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string STANZAS = "urn:ietf:params:xml:ns:xmpp-stanzas";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string STORAGE_AVATAR = "storage:client:avatar";
|
||||
|
||||
// Http-Binding XEP-0124
|
||||
|
||||
/// <summary>
|
||||
/// <para>XEP-0048: Bookmark Storage</para> <para>storage:bookmarks</para>
|
||||
/// </summary>
|
||||
public const string STORAGE_BOOKMARKS = "storage:bookmarks";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string STREAM = "http://etherx.jabber.org/streams";
|
||||
|
||||
/// <summary>
|
||||
/// urn:ietf:params:xml:ns:xmpp-streams
|
||||
/// </summary>
|
||||
public const string STREAMS = "urn:ietf:params:xml:ns:xmpp-streams";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string TLS = "urn:ietf:params:xml:ns:xmpp-tls";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string VCARD = "vcard-temp";
|
||||
|
||||
/// <summary>
|
||||
/// <para>XEP-0153: vCard-Based Avatars</para> <para>vcard-temp:x:update</para>
|
||||
/// </summary>
|
||||
public const string VCARD_UPDATE = "vcard-temp:x:update";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string X_AVATAR = "jabber:x:avatar";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string X_CONFERENCE = "jabber:x:conference";
|
||||
|
||||
/// <summary>
|
||||
/// jabber:x:data
|
||||
/// </summary>
|
||||
public const string X_DATA = "jabber:x:data";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string X_DELAY = "jabber:x:delay";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string X_EVENT = "jabber:x:event";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0144 Roster Item Exchange
|
||||
/// </summary>
|
||||
public const string X_ROSTERX = "http://jabber.org/protocol/rosterx";
|
||||
|
||||
public const string X_TM_IQ_HISTORY = "x:xmpp:tm:history";
|
||||
public const string X_TM_IQ_PRIVATELOG = "x:xmpp:tm:privatelog";
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public const string XHTML = "http://www.w3.org/1999/xhtml";
|
||||
|
||||
/// <summary>
|
||||
/// JEP-0071: XHTML-IM (http://jivesoftware.com/xmlns/phone)
|
||||
/// </summary>
|
||||
public const string XHTML_IM = "http://jabber.org/protocol/xhtml-im";
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
414
ASC.Xmpp.Core/protocol/client/Error.cs
Normal file
414
ASC.Xmpp.Core/protocol/client/Error.cs
Normal file
@ -0,0 +1,414 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
// JEP-0086: Error Condition Mappings
|
||||
|
||||
// <stanza-kind to='sender' type='error'>
|
||||
// [RECOMMENDED to include sender XML here]
|
||||
// <error type='error-type'>
|
||||
// <defined-condition xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
||||
// <text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'
|
||||
// xml:lang='langcode'>
|
||||
// OPTIONAL descriptive text
|
||||
// </text>
|
||||
// [OPTIONAL application-specific condition element]
|
||||
// </error>
|
||||
// </stanza-kind>
|
||||
|
||||
// Legacy Error
|
||||
// <error code="501">Not Implemented</error>
|
||||
|
||||
// XMPP Style Error
|
||||
// <error code='404' type='cancel'>
|
||||
// <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
||||
// </error>
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
// XMPP error condition XMPP error type Legacy error code
|
||||
// <bad-request/> modify 400
|
||||
// <conflict/> cancel 409
|
||||
// <feature-not-implemented/> cancel 501
|
||||
// <forbidden/> auth 403
|
||||
// <gone/> modify 302 (permanent)
|
||||
// <internal-server-error/> wait 500
|
||||
// <item-not-found/> cancel 404
|
||||
// <jid-malformed/> modify 400
|
||||
// <not-acceptable/> modify 406
|
||||
// <not-allowed/> cancel 405
|
||||
// <not-authorized/> auth 401
|
||||
// <payment-required/> auth 402
|
||||
// <recipient-unavailable/> wait 404
|
||||
// <redirect/> modify 302 (temporary)
|
||||
// <registration-required/> auth 407
|
||||
// <remote-server-not-found/> cancel 404
|
||||
// <remote-server-timeout/> wait 504
|
||||
// <resource-constraint/> wait 500
|
||||
// <service-unavailable/> cancel 503
|
||||
// <subscription-required/> auth 407
|
||||
// <undefined-condition/> [any] 500
|
||||
// <unexpected-request/> wait 400
|
||||
|
||||
public enum ErrorCondition
|
||||
{
|
||||
BadRequest,
|
||||
Conflict,
|
||||
FeatureNotImplemented,
|
||||
Forbidden,
|
||||
Gone,
|
||||
InternalServerError,
|
||||
ItemNotFound,
|
||||
JidMalformed,
|
||||
NotAcceptable,
|
||||
NotAllowed,
|
||||
NotAuthorized,
|
||||
PaymentRequired,
|
||||
RecipientUnavailable,
|
||||
Redirect,
|
||||
RegistrationRequired,
|
||||
RemoteServerNotFound,
|
||||
RemoteServerTimeout,
|
||||
ResourceConstraint,
|
||||
ServiceUnavailable,
|
||||
SubscriptionRequired,
|
||||
UndefinedCondition,
|
||||
UnexpectedRequest
|
||||
}
|
||||
|
||||
// The value of the <error/> element's 'type' attribute MUST be one of the following:
|
||||
// * cancel -- do not retry (the error is unrecoverable)
|
||||
// * continue -- proceed (the condition was only a warning)
|
||||
// * modify -- retry after changing the data sent
|
||||
// * auth -- retry after providing credentials
|
||||
// * wait -- retry after waiting (the error is temporary)
|
||||
public enum ErrorType
|
||||
{
|
||||
cancel,
|
||||
@continue,
|
||||
modify,
|
||||
auth,
|
||||
wait
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The legacy Error Code
|
||||
/// </summary>
|
||||
public enum ErrorCode
|
||||
{
|
||||
None = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Bad request
|
||||
/// </summary>
|
||||
BadRequest = 400,
|
||||
|
||||
/// <summary>
|
||||
/// Unauthorized
|
||||
/// </summary>
|
||||
Unauthorized = 401,
|
||||
|
||||
/// <summary>
|
||||
/// Payment required
|
||||
/// </summary>
|
||||
PaymentRequired = 402,
|
||||
|
||||
/// <summary>
|
||||
/// Forbidden
|
||||
/// </summary>
|
||||
Forbidden = 403,
|
||||
|
||||
/// <summary>
|
||||
/// Not found
|
||||
/// </summary>
|
||||
NotFound = 404,
|
||||
|
||||
/// <summary>
|
||||
/// Not allowed
|
||||
/// </summary>
|
||||
NotAllowed = 405,
|
||||
|
||||
/// <summary>
|
||||
/// Not acceptable
|
||||
/// </summary>
|
||||
NotAcceptable = 406,
|
||||
|
||||
/// <summary>
|
||||
/// Registration required
|
||||
/// </summary>
|
||||
RegistrationRequired = 407,
|
||||
|
||||
/// <summary>
|
||||
/// Request timeout
|
||||
/// </summary>
|
||||
RequestTimeout = 408,
|
||||
|
||||
/// <summary>
|
||||
/// Conflict
|
||||
/// </summary>
|
||||
Conflict = 409,
|
||||
|
||||
/// <summary>
|
||||
/// Internal server error
|
||||
/// </summary>
|
||||
InternalServerError = 500,
|
||||
|
||||
/// <summary>
|
||||
/// Not implemented
|
||||
/// </summary>
|
||||
NotImplemented = 501,
|
||||
|
||||
/// <summary>
|
||||
/// Remote server error
|
||||
/// </summary>
|
||||
RemoteServerError = 502,
|
||||
|
||||
/// <summary>
|
||||
/// Service unavailable
|
||||
/// </summary>
|
||||
ServiceUnavailable = 503,
|
||||
|
||||
/// <summary>
|
||||
/// Remote server timeout
|
||||
/// </summary>
|
||||
RemoteServerTimeout = 504,
|
||||
|
||||
/// <summary>
|
||||
/// Disconnected
|
||||
/// </summary>
|
||||
Disconnected = 510
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for Error.
|
||||
/// </summary>
|
||||
public class Error : Element
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
public Error()
|
||||
{
|
||||
Namespace = Uri.CLIENT;
|
||||
TagName = "error";
|
||||
}
|
||||
|
||||
|
||||
public Error(int code) : this()
|
||||
{
|
||||
SetAttribute("code", code.ToString());
|
||||
}
|
||||
|
||||
public Error(ErrorCode code) : this()
|
||||
{
|
||||
SetAttribute("code", (int) code);
|
||||
}
|
||||
|
||||
public Error(ErrorType type) : this()
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an error Element according the the condition The type attrib as added automatically as decribed in the XMPP specs This is the prefered way to create error Elements
|
||||
/// </summary>
|
||||
/// <param name="condition"> </param>
|
||||
public Error(ErrorCondition condition) : this()
|
||||
{
|
||||
Condition = condition;
|
||||
}
|
||||
|
||||
public Error(ErrorType type, ErrorCondition condition) : this(type)
|
||||
{
|
||||
Condition = condition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The error Description
|
||||
/// </summary>
|
||||
public string Message
|
||||
{
|
||||
get { return Value; }
|
||||
set { Value = value; }
|
||||
}
|
||||
|
||||
public ErrorCode Code
|
||||
{
|
||||
get { return (ErrorCode) GetAttributeInt("code"); }
|
||||
set { SetAttribute("code", (int) value); }
|
||||
}
|
||||
|
||||
public ErrorType Type
|
||||
{
|
||||
get { return (ErrorType) GetAttributeEnum("type", typeof (ErrorType)); }
|
||||
set { SetAttribute("type", value.ToString()); }
|
||||
}
|
||||
|
||||
public ErrorCondition Condition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasTag("bad-request")) // <bad-request/>
|
||||
return ErrorCondition.BadRequest;
|
||||
else if (HasTag("conflict")) // <conflict/>
|
||||
return ErrorCondition.Conflict;
|
||||
else if (HasTag("feature-not-implemented")) // <feature-not-implemented/>
|
||||
return ErrorCondition.FeatureNotImplemented;
|
||||
else if (HasTag("forbidden")) // <forbidden/>
|
||||
return ErrorCondition.Forbidden;
|
||||
else if (HasTag("gone")) // <gone/>
|
||||
return ErrorCondition.Gone;
|
||||
else if (HasTag("internal-server-error")) // <internal-server-error/>
|
||||
return ErrorCondition.InternalServerError;
|
||||
else if (HasTag("item-not-found")) // <item-not-found/>
|
||||
return ErrorCondition.ItemNotFound;
|
||||
else if (HasTag("jid-malformed")) // <jid-malformed/>
|
||||
return ErrorCondition.JidMalformed;
|
||||
else if (HasTag("not-acceptable")) // <not-acceptable/>
|
||||
return ErrorCondition.NotAcceptable;
|
||||
else if (HasTag("not-authorized")) // <not-authorized/>
|
||||
return ErrorCondition.NotAuthorized;
|
||||
else if (HasTag("payment-required")) // <payment-required/>
|
||||
return ErrorCondition.PaymentRequired;
|
||||
else if (HasTag("recipient-unavailable")) // <recipient-unavailable/>
|
||||
return ErrorCondition.RecipientUnavailable;
|
||||
else if (HasTag("redirect")) // <redirect/>
|
||||
return ErrorCondition.Redirect;
|
||||
else if (HasTag("registration-required")) // <registration-required/>
|
||||
return ErrorCondition.RegistrationRequired;
|
||||
else if (HasTag("remote-server-not-found")) // <remote-server-not-found/>
|
||||
return ErrorCondition.RemoteServerNotFound;
|
||||
else if (HasTag("remote-server-timeout")) // <remote-server-timeout/>
|
||||
return ErrorCondition.RemoteServerTimeout;
|
||||
else if (HasTag("resource-constraint")) // <resource-constraint/>
|
||||
return ErrorCondition.ResourceConstraint;
|
||||
else if (HasTag("service-unavailable")) // <service-unavailable/>
|
||||
return ErrorCondition.ServiceUnavailable;
|
||||
else if (HasTag("subscription-required")) // <subscription-required/>
|
||||
return ErrorCondition.SubscriptionRequired;
|
||||
else if (HasTag("undefined-condition")) // <undefined-condition/>
|
||||
return ErrorCondition.UndefinedCondition;
|
||||
else if (HasTag("unexpected-request")) // <unexpected-request/>
|
||||
return ErrorCondition.UnexpectedRequest;
|
||||
else
|
||||
return ErrorCondition.UndefinedCondition;
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case ErrorCondition.BadRequest:
|
||||
SetTag("bad-request", "", Uri.STANZAS);
|
||||
Type = ErrorType.modify;
|
||||
break;
|
||||
case ErrorCondition.Conflict:
|
||||
SetTag("conflict", "", Uri.STANZAS);
|
||||
Type = ErrorType.cancel;
|
||||
break;
|
||||
case ErrorCondition.FeatureNotImplemented:
|
||||
SetTag("feature-not-implemented", "", Uri.STANZAS);
|
||||
Type = ErrorType.cancel;
|
||||
break;
|
||||
case ErrorCondition.Forbidden:
|
||||
SetTag("forbidden", "", Uri.STANZAS);
|
||||
Type = ErrorType.auth;
|
||||
break;
|
||||
case ErrorCondition.Gone:
|
||||
SetTag("gone", "", Uri.STANZAS);
|
||||
Type = ErrorType.modify;
|
||||
break;
|
||||
case ErrorCondition.InternalServerError:
|
||||
SetTag("internal-server-error", "", Uri.STANZAS);
|
||||
Type = ErrorType.wait;
|
||||
break;
|
||||
case ErrorCondition.ItemNotFound:
|
||||
SetTag("item-not-found", "", Uri.STANZAS);
|
||||
Type = ErrorType.cancel;
|
||||
break;
|
||||
case ErrorCondition.JidMalformed:
|
||||
SetTag("jid-malformed", "", Uri.STANZAS);
|
||||
Type = ErrorType.modify;
|
||||
break;
|
||||
case ErrorCondition.NotAcceptable:
|
||||
SetTag("not-acceptable", "", Uri.STANZAS);
|
||||
Type = ErrorType.modify;
|
||||
break;
|
||||
case ErrorCondition.NotAllowed:
|
||||
SetTag("not-allowed", "", Uri.STANZAS);
|
||||
Type = ErrorType.cancel;
|
||||
break;
|
||||
case ErrorCondition.NotAuthorized:
|
||||
SetTag("not-authorized", "", Uri.STANZAS);
|
||||
Type = ErrorType.auth;
|
||||
break;
|
||||
case ErrorCondition.PaymentRequired:
|
||||
SetTag("payment-required", "", Uri.STANZAS);
|
||||
Type = ErrorType.auth;
|
||||
break;
|
||||
case ErrorCondition.RecipientUnavailable:
|
||||
SetTag("recipient-unavailable", "", Uri.STANZAS);
|
||||
Type = ErrorType.wait;
|
||||
break;
|
||||
case ErrorCondition.Redirect:
|
||||
SetTag("redirect", "", Uri.STANZAS);
|
||||
Type = ErrorType.modify;
|
||||
break;
|
||||
case ErrorCondition.RegistrationRequired:
|
||||
SetTag("registration-required", "", Uri.STANZAS);
|
||||
Type = ErrorType.auth;
|
||||
break;
|
||||
case ErrorCondition.RemoteServerNotFound:
|
||||
SetTag("remote-server-not-found", "", Uri.STANZAS);
|
||||
Type = ErrorType.cancel;
|
||||
break;
|
||||
case ErrorCondition.RemoteServerTimeout:
|
||||
SetTag("remote-server-timeout", "", Uri.STANZAS);
|
||||
Type = ErrorType.wait;
|
||||
break;
|
||||
case ErrorCondition.ResourceConstraint:
|
||||
SetTag("resource-constraint", "", Uri.STANZAS);
|
||||
Type = ErrorType.wait;
|
||||
break;
|
||||
case ErrorCondition.ServiceUnavailable:
|
||||
SetTag("service-unavailable", "", Uri.STANZAS);
|
||||
Type = ErrorType.cancel;
|
||||
break;
|
||||
case ErrorCondition.SubscriptionRequired:
|
||||
SetTag("subscription-required", "", Uri.STANZAS);
|
||||
Type = ErrorType.auth;
|
||||
break;
|
||||
case ErrorCondition.UndefinedCondition:
|
||||
SetTag("undefined-condition", "", Uri.STANZAS);
|
||||
// could be any
|
||||
break;
|
||||
case ErrorCondition.UnexpectedRequest:
|
||||
SetTag("unexpected-request", "", Uri.STANZAS);
|
||||
Type = ErrorType.wait;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
ASC.Xmpp.Core/protocol/client/Handler.cs
Normal file
41
ASC.Xmpp.Core/protocol/client/Handler.cs
Normal file
@ -0,0 +1,41 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender"> </param>
|
||||
/// <param name="msg"> </param>
|
||||
public delegate void MessageHandler(object sender, Message msg);
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender"> </param>
|
||||
/// <param name="pres"> </param>
|
||||
public delegate void PresenceHandler(object sender, Presence pres);
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sender"> </param>
|
||||
/// <param name="iq"> </param>
|
||||
public delegate void IqHandler(object sender, IQ iq);
|
||||
}
|
243
ASC.Xmpp.Core/protocol/client/IQ.cs
Normal file
243
ASC.Xmpp.Core/protocol/client/IQ.cs
Normal file
@ -0,0 +1,243 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
using ASC.Xmpp.Core.protocol.iq.bind;
|
||||
using ASC.Xmpp.Core.protocol.iq.blocklist;
|
||||
using ASC.Xmpp.Core.protocol.iq.jingle;
|
||||
using ASC.Xmpp.Core.protocol.iq.session;
|
||||
using ASC.Xmpp.Core.protocol.iq.vcard;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
// a i know that i shouldnt use keywords for Enums. But its much easier this way
|
||||
// because of enum.ToString() and enum.Parse() Members
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public enum IqType
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
get,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
set,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
result,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
error
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Iq Stanza.
|
||||
/// </summary>
|
||||
public class IQ : Stanza
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public IQ()
|
||||
{
|
||||
TagName = "iq";
|
||||
Namespace = Uri.CLIENT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="type"> </param>
|
||||
public IQ(IqType type) : this()
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="to"> </param>
|
||||
public IQ(Jid from, Jid to) : this()
|
||||
{
|
||||
From = from;
|
||||
To = to;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="to"> </param>
|
||||
public IQ(IqType type, Jid from, Jid to) : this()
|
||||
{
|
||||
Type = type;
|
||||
From = from;
|
||||
To = to;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Get or Set the Bind ELement if it is a BingIq
|
||||
/// </summary>
|
||||
public virtual Bind Bind
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Bind)) as Bind; }
|
||||
|
||||
set
|
||||
{
|
||||
RemoveTag(typeof (Bind));
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Blocklist Blocklist
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Blocklist)) as Blocklist; }
|
||||
|
||||
set
|
||||
{
|
||||
RemoveTag(typeof (Blocklist));
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Jingle Jingle
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Jingle)) as Jingle; }
|
||||
|
||||
set
|
||||
{
|
||||
RemoveTag(typeof (Jingle));
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error Child Element
|
||||
/// </summary>
|
||||
public Error Error
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Error)) as Error; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Error)))
|
||||
{
|
||||
RemoveTag(typeof (Error));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The query Element. Value can also be null which removes the Query tag when existing
|
||||
/// </summary>
|
||||
public Element Query
|
||||
{
|
||||
get { return SelectSingleElement("query"); }
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
ReplaceChild(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveTag("query");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or Set the Session Element if it is a SessionIq
|
||||
/// </summary>
|
||||
public virtual Session Session
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Session)) as Session; }
|
||||
|
||||
set
|
||||
{
|
||||
RemoveTag(typeof (Session));
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public IqType Type
|
||||
{
|
||||
get { return (IqType) GetAttributeEnum("type", typeof (IqType)); }
|
||||
|
||||
set { SetAttribute("type", value.ToString()); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or Set the VCard if it is a Vcard IQ
|
||||
/// </summary>
|
||||
public virtual Vcard Vcard
|
||||
{
|
||||
get { return SelectSingleElement("vCard") as Vcard; }
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
ReplaceChild(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveTag("vCard");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
585
ASC.Xmpp.Core/protocol/client/Message.cs
Normal file
585
ASC.Xmpp.Core/protocol/client/Message.cs
Normal file
@ -0,0 +1,585 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
using ASC.Xmpp.Core.protocol.extensions.chatstates;
|
||||
using ASC.Xmpp.Core.protocol.extensions.html;
|
||||
using ASC.Xmpp.Core.protocol.extensions.nickname;
|
||||
using ASC.Xmpp.Core.protocol.extensions.shim;
|
||||
using ASC.Xmpp.Core.protocol.x;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// This class represents a XMPP message.
|
||||
/// </summary>
|
||||
public class Message : Stanza
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Message()
|
||||
{
|
||||
TagName = "message";
|
||||
Namespace = Uri.CLIENT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
public Message(Jid to) : this()
|
||||
{
|
||||
To = to;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="body"> </param>
|
||||
public Message(Jid to, string body) : this(to)
|
||||
{
|
||||
Body = body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="from"> </param>
|
||||
public Message(Jid to, Jid from) : this()
|
||||
{
|
||||
To = to;
|
||||
From = from;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="body"> </param>
|
||||
public Message(string to, string body) : this()
|
||||
{
|
||||
To = new Jid(to);
|
||||
Body = body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
public Message(Jid to, string body, string subject) : this()
|
||||
{
|
||||
To = to;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
public Message(string to, string body, string subject) : this()
|
||||
{
|
||||
To = new Jid(to);
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
/// <param name="thread"> </param>
|
||||
public Message(string to, string body, string subject, string thread) : this()
|
||||
{
|
||||
To = new Jid(to);
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
Thread = thread;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
/// <param name="thread"> </param>
|
||||
public Message(Jid to, string body, string subject, string thread) : this()
|
||||
{
|
||||
To = to;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
Thread = thread;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
public Message(string to, MessageType type, string body) : this()
|
||||
{
|
||||
To = new Jid(to);
|
||||
Type = type;
|
||||
Body = body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
public Message(Jid to, MessageType type, string body) : this()
|
||||
{
|
||||
To = to;
|
||||
Type = type;
|
||||
Body = body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
public Message(string to, MessageType type, string body, string subject) : this()
|
||||
{
|
||||
To = new Jid(to);
|
||||
Type = type;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
public Message(Jid to, MessageType type, string body, string subject) : this()
|
||||
{
|
||||
To = to;
|
||||
Type = type;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
/// <param name="thread"> </param>
|
||||
public Message(string to, MessageType type, string body, string subject, string thread) : this()
|
||||
{
|
||||
To = new Jid(to);
|
||||
Type = type;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
Thread = thread;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
/// <param name="thread"> </param>
|
||||
public Message(Jid to, MessageType type, string body, string subject, string thread) : this()
|
||||
{
|
||||
To = to;
|
||||
Type = type;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
Thread = thread;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="body"> </param>
|
||||
public Message(Jid to, Jid from, string body) : this()
|
||||
{
|
||||
To = to;
|
||||
From = from;
|
||||
Body = body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
public Message(Jid to, Jid from, string body, string subject) : this()
|
||||
{
|
||||
To = to;
|
||||
From = from;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
/// <param name="thread"> </param>
|
||||
public Message(Jid to, Jid from, string body, string subject, string thread) : this()
|
||||
{
|
||||
To = to;
|
||||
From = from;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
Thread = thread;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
public Message(Jid to, Jid from, MessageType type, string body) : this()
|
||||
{
|
||||
To = to;
|
||||
From = from;
|
||||
Type = type;
|
||||
Body = body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
public Message(Jid to, Jid from, MessageType type, string body, string subject) : this()
|
||||
{
|
||||
To = to;
|
||||
From = from;
|
||||
Type = type;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="to"> </param>
|
||||
/// <param name="from"> </param>
|
||||
/// <param name="type"> </param>
|
||||
/// <param name="body"> </param>
|
||||
/// <param name="subject"> </param>
|
||||
/// <param name="thread"> </param>
|
||||
public Message(Jid to, Jid from, MessageType type, string body, string subject, string thread)
|
||||
: this()
|
||||
{
|
||||
To = to;
|
||||
From = from;
|
||||
Type = type;
|
||||
Body = body;
|
||||
Subject = subject;
|
||||
Thread = thread;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region << Properties >>
|
||||
|
||||
/// <summary>
|
||||
/// The body of the message. This contains the message text.
|
||||
/// </summary>
|
||||
public string Body
|
||||
{
|
||||
get { return GetTag("body"); }
|
||||
|
||||
set { SetTag("body", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// subject of this message. Its like a subject in a email. The Subject is optional.
|
||||
/// </summary>
|
||||
public string Subject
|
||||
{
|
||||
get { return GetTag("subject"); }
|
||||
|
||||
set { SetTag("subject", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// messages and conversations could be threaded. You can compare this with threads in newsgroups or forums. Threads are optional.
|
||||
/// </summary>
|
||||
public string Thread
|
||||
{
|
||||
get { return GetTag("thread"); }
|
||||
|
||||
set { SetTag("thread", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// message type (chat, groupchat, normal, headline or error).
|
||||
/// </summary>
|
||||
public MessageType Type
|
||||
{
|
||||
get { return (MessageType) GetAttributeEnum("type", typeof (MessageType)); }
|
||||
|
||||
set
|
||||
{
|
||||
if (value == MessageType.normal)
|
||||
{
|
||||
RemoveAttribute("type");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetAttribute("type", value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error Child Element
|
||||
/// </summary>
|
||||
public Error Error
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Error)) as Error; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Error)))
|
||||
{
|
||||
RemoveTag(typeof (Error));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The html part of the message if you want to support the html-im Jep. This part of the message is optional.
|
||||
/// </summary>
|
||||
public Html Html
|
||||
{
|
||||
get { return (Html) SelectSingleElement(typeof (Html)); }
|
||||
|
||||
set
|
||||
{
|
||||
RemoveTag(typeof (Html));
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The event Element for JEP-0022 Message events
|
||||
/// </summary>
|
||||
public Event XEvent
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Event)) as Event; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Event)))
|
||||
{
|
||||
RemoveTag(typeof (Event));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The event Element for JEP-0022 Message events
|
||||
/// </summary>
|
||||
public Delay XDelay
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Delay)) as Delay; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Delay)))
|
||||
{
|
||||
RemoveTag(typeof (Delay));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stanza Headers and Internet Metadata
|
||||
/// </summary>
|
||||
public Headers Headers
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Headers)) as Headers; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Headers)))
|
||||
{
|
||||
RemoveTag(typeof (Headers));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nickname Element
|
||||
/// </summary>
|
||||
public Nickname Nickname
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Nickname)) as Nickname; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Nickname)))
|
||||
{
|
||||
RemoveTag(typeof (Nickname));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region << Chatstate Properties >>
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Chatstate Chatstate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasTag(typeof (Active)))
|
||||
{
|
||||
return Chatstate.active;
|
||||
}
|
||||
else if (HasTag(typeof (Inactive)))
|
||||
{
|
||||
return Chatstate.inactive;
|
||||
}
|
||||
else if (HasTag(typeof (Composing)))
|
||||
{
|
||||
return Chatstate.composing;
|
||||
}
|
||||
else if (HasTag(typeof (Paused)))
|
||||
{
|
||||
return Chatstate.paused;
|
||||
}
|
||||
else if (HasTag(typeof (Gone)))
|
||||
{
|
||||
return Chatstate.gone;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Chatstate.None;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
RemoveChatstate();
|
||||
switch (value)
|
||||
{
|
||||
case Chatstate.active:
|
||||
AddChild(new Active());
|
||||
break;
|
||||
case Chatstate.inactive:
|
||||
AddChild(new Inactive());
|
||||
break;
|
||||
case Chatstate.composing:
|
||||
AddChild(new Composing());
|
||||
break;
|
||||
case Chatstate.paused:
|
||||
AddChild(new Paused());
|
||||
break;
|
||||
case Chatstate.gone:
|
||||
AddChild(new Gone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
private void RemoveChatstate()
|
||||
{
|
||||
RemoveTag(typeof (Active));
|
||||
RemoveTag(typeof (Inactive));
|
||||
RemoveTag(typeof (Composing));
|
||||
RemoveTag(typeof (Paused));
|
||||
RemoveTag(typeof (Gone));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region << Methods and Functions >>
|
||||
|
||||
#if !CF
|
||||
|
||||
/// <summary>
|
||||
/// Create a new unique Thread indendifier
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public string CreateNewThread()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().ToLower();
|
||||
Thread = guid;
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
54
ASC.Xmpp.Core/protocol/client/MessageType.cs
Normal file
54
ASC.Xmpp.Core/protocol/client/MessageType.cs
Normal file
@ -0,0 +1,54 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration that represents the type of a message
|
||||
/// </summary>
|
||||
public enum MessageType
|
||||
{
|
||||
/// <summary>
|
||||
/// This in a normal message, much like an email. You dont expect a fast
|
||||
/// </summary>
|
||||
normal = -1,
|
||||
|
||||
/// <summary>
|
||||
/// a error messages
|
||||
/// </summary>
|
||||
error,
|
||||
|
||||
/// <summary>
|
||||
/// is for chat like messages, person to person. Send this if you expect a fast reply. reply or no reply at all.
|
||||
/// </summary>
|
||||
chat,
|
||||
|
||||
/// <summary>
|
||||
/// is used for sending/receiving messages from/to a chatroom (IRC style chats)
|
||||
/// </summary>
|
||||
groupchat,
|
||||
|
||||
/// <summary>
|
||||
/// Think of this as a news broadcast, or RRS Feed, the message will normally have a URL and Description Associated with it.
|
||||
/// </summary>
|
||||
headline
|
||||
}
|
||||
}
|
255
ASC.Xmpp.Core/protocol/client/Presence.cs
Normal file
255
ASC.Xmpp.Core/protocol/client/Presence.cs
Normal file
@ -0,0 +1,255 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
using ASC.Xmpp.Core.protocol.extensions.nickname;
|
||||
using ASC.Xmpp.Core.protocol.extensions.primary;
|
||||
using ASC.Xmpp.Core.protocol.x;
|
||||
using ASC.Xmpp.Core.protocol.x.muc;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
|
||||
#region usings
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Zusammenfassung f<>r Presence.
|
||||
/// </summary>
|
||||
public class Presence : Stanza
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Presence()
|
||||
{
|
||||
TagName = "presence";
|
||||
Namespace = Uri.CLIENT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="show"> </param>
|
||||
/// <param name="status"> </param>
|
||||
public Presence(ShowType show, string status)
|
||||
: this()
|
||||
{
|
||||
Show = show;
|
||||
Status = status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="show"> </param>
|
||||
/// <param name="status"> </param>
|
||||
/// <param name="priority"> </param>
|
||||
public Presence(ShowType show, string status, int priority)
|
||||
: this(show, status)
|
||||
{
|
||||
Priority = priority;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Error Child Element
|
||||
/// </summary>
|
||||
public Error Error
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Error)) as Error; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Error)))
|
||||
{
|
||||
RemoveTag(typeof (Error));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public bool IsPrimary
|
||||
{
|
||||
get { return GetTag(typeof (Primary)) == null ? false : true; }
|
||||
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
SetTag(typeof (Primary));
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveTag(typeof (Primary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public User MucUser
|
||||
{
|
||||
get { return SelectSingleElement(typeof (User)) as User; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (User)))
|
||||
{
|
||||
RemoveTag(typeof (User));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nickname Element
|
||||
/// </summary>
|
||||
public Nickname Nickname
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Nickname)) as Nickname; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Nickname)))
|
||||
{
|
||||
RemoveTag(typeof (Nickname));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The priority level of the resource. The value MUST be an integer between -128 and +127. If no priority is provided, a server SHOULD consider the priority to be zero.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For information regarding the semantics of priority values in stanza routing within instant messaging and presence applications, refer to Server Rules for Handling XML StanzasServer Rules for Handling XML Stanzas.
|
||||
/// </remarks>
|
||||
public int Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
string tag = GetTag("priority");
|
||||
if (!string.IsNullOrEmpty(tag)) return int.Parse(GetTag("priority"));
|
||||
return 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
set { SetTag("priority", value.ToString()); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The OPTIONAL show element contains non-human-readable XML character data that specifies the particular availability status of an entity or specific resource.
|
||||
/// </summary>
|
||||
public ShowType Show
|
||||
{
|
||||
get { return (ShowType) GetTagEnum("show", typeof (ShowType)); }
|
||||
|
||||
set
|
||||
{
|
||||
if (value != ShowType.NONE)
|
||||
{
|
||||
SetTag("show", value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveAttribute("show");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The OPTIONAL statuc contains a natural-language description of availability status. It is normally used in conjunction with the show element to provide a detailed description of an availability state (e.g., "In a meeting").
|
||||
/// </summary>
|
||||
public string Status
|
||||
{
|
||||
get { return GetTag("status"); }
|
||||
|
||||
set { SetTag("status", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type of a presence stanza is OPTIONAL. A presence stanza that does not possess a type attribute is used to signal to the server that the sender is online and available for communication. If included, the type attribute specifies a lack of availability, a request to manage a subscription to another entity's presence, a request for another entity's current presence, or an error related to a previously-sent presence stanza.
|
||||
/// </summary>
|
||||
public PresenceType Type
|
||||
{
|
||||
get { return (PresenceType) GetAttributeEnum("type", typeof (PresenceType)); }
|
||||
|
||||
set
|
||||
{
|
||||
// dont add type="available"
|
||||
if (value == PresenceType.available)
|
||||
{
|
||||
RemoveAttribute("type");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetAttribute("type", value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Delay XDelay
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Delay)) as Delay; }
|
||||
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Delay)))
|
||||
{
|
||||
RemoveTag(typeof (Delay));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
74
ASC.Xmpp.Core/protocol/client/PresenceType.cs
Normal file
74
ASC.Xmpp.Core/protocol/client/PresenceType.cs
Normal file
@ -0,0 +1,74 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration for the Presence Type structure. This enum is used to describe what type of Subscription Type the current subscription is. When sending a presence or receiving a subscription this type is used to easily identify the type of subscription it is.
|
||||
/// </summary>
|
||||
public enum PresenceType
|
||||
{
|
||||
/// <summary>
|
||||
/// Used when one wants to send presence to someone/server/transport that you<6F>re available.
|
||||
/// </summary>
|
||||
available = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Used to send a subscription request to someone.
|
||||
/// </summary>
|
||||
subscribe,
|
||||
|
||||
/// <summary>
|
||||
/// Used to accept a subscription request.
|
||||
/// </summary>
|
||||
subscribed,
|
||||
|
||||
/// <summary>
|
||||
/// Used to unsubscribe someone from your presence.
|
||||
/// </summary>
|
||||
unsubscribe,
|
||||
|
||||
/// <summary>
|
||||
/// Used to deny a subscription request.
|
||||
/// </summary>
|
||||
unsubscribed,
|
||||
|
||||
/// <summary>
|
||||
/// Used when one wants to send presence to someone/server/transport that you<6F>re unavailable.
|
||||
/// </summary>
|
||||
unavailable,
|
||||
|
||||
/// <summary>
|
||||
/// Used when you want to see your roster, but don't want anyone on you roster to see you
|
||||
/// </summary>
|
||||
invisible,
|
||||
|
||||
/// <summary>
|
||||
/// presence error
|
||||
/// </summary>
|
||||
error,
|
||||
|
||||
/// <summary>
|
||||
/// used in server to server protocol to request presences
|
||||
/// </summary>
|
||||
probe
|
||||
}
|
||||
}
|
58
ASC.Xmpp.Core/protocol/client/ShowType.cs
Normal file
58
ASC.Xmpp.Core/protocol/client/ShowType.cs
Normal file
@ -0,0 +1,58 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.client
|
||||
{
|
||||
// # away -- The entity or resource is temporarily away.
|
||||
// # chat -- The entity or resource is actively interested in chatting.
|
||||
// # dnd -- The entity or resource is busy (dnd = "Do Not Disturb").
|
||||
// # xa -- The entity or resource is away for an extended period (xa = "eXtended Away").
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration that represents the online state.
|
||||
/// </summary>
|
||||
public enum ShowType
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
NONE = -1,
|
||||
|
||||
/// <summary>
|
||||
/// The entity or resource is temporarily away.
|
||||
/// </summary>
|
||||
away,
|
||||
|
||||
/// <summary>
|
||||
/// The entity or resource is actively interested in chatting.
|
||||
/// </summary>
|
||||
chat,
|
||||
|
||||
/// <summary>
|
||||
/// The entity or resource is busy (dnd = "Do Not Disturb").
|
||||
/// </summary>
|
||||
dnd,
|
||||
|
||||
/// <summary>
|
||||
/// The entity or resource is away for an extended period (xa = "eXtended Away").
|
||||
/// </summary>
|
||||
xa,
|
||||
}
|
||||
}
|
64
ASC.Xmpp.Core/protocol/component/Error.cs
Normal file
64
ASC.Xmpp.Core/protocol/component/Error.cs
Normal file
@ -0,0 +1,64 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Error.
|
||||
/// </summary>
|
||||
public class Error : client.Error
|
||||
{
|
||||
public Error()
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Error(int code)
|
||||
: base(code)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Error(ErrorCode code)
|
||||
: base(code)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Error(ErrorType type)
|
||||
: base(type)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an error Element according the the condition The type attrib as added automatically as decribed in the XMPP specs This is the prefered way to create error Elements
|
||||
/// </summary>
|
||||
/// <param name="condition"> </param>
|
||||
public Error(ErrorCondition condition)
|
||||
: base(condition)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
}
|
||||
}
|
29
ASC.Xmpp.Core/protocol/component/Handler.cs
Normal file
29
ASC.Xmpp.Core/protocol/component/Handler.cs
Normal file
@ -0,0 +1,29 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
public delegate void MessageHandler(object sender, Message msg);
|
||||
|
||||
public delegate void PresenceHandler(object sender, Presence pres);
|
||||
|
||||
public delegate void IqHandler(object sender, IQ iq);
|
||||
}
|
59
ASC.Xmpp.Core/protocol/component/Handshake.cs
Normal file
59
ASC.Xmpp.Core/protocol/component/Handshake.cs
Normal file
@ -0,0 +1,59 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
using ASC.Xmpp.Core.utils;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
//<handshake>aaee83c26aeeafcbabeabfcbcd50df997e0a2a1e</handshake>
|
||||
|
||||
/// <summary>
|
||||
/// Handshake Element
|
||||
/// </summary>
|
||||
public class Handshake : Stanza
|
||||
{
|
||||
public Handshake()
|
||||
{
|
||||
TagName = "handshake";
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Handshake(string password, string streamid) : this()
|
||||
{
|
||||
SetAuth(password, streamid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Digest (Hash) for authentication
|
||||
/// </summary>
|
||||
public string Digest
|
||||
{
|
||||
get { return Value; }
|
||||
set { Value = value; }
|
||||
}
|
||||
|
||||
public void SetAuth(string password, string streamId)
|
||||
{
|
||||
Value = Hash.Sha1Hash(streamId + password);
|
||||
}
|
||||
}
|
||||
}
|
75
ASC.Xmpp.Core/protocol/component/IQ.cs
Normal file
75
ASC.Xmpp.Core/protocol/component/IQ.cs
Normal file
@ -0,0 +1,75 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region Using directives
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Iq.
|
||||
/// </summary>
|
||||
public class IQ : client.IQ
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
public IQ()
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public IQ(IqType type) : base(type)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public IQ(Jid from, Jid to) : base(from, to)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public IQ(IqType type, Jid from, Jid to) : base(type, from, to)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Error Child Element
|
||||
/// </summary>
|
||||
public new Error Error
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Error)) as Error; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Error)))
|
||||
RemoveTag(typeof (Error));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
81
ASC.Xmpp.Core/protocol/component/Log.cs
Normal file
81
ASC.Xmpp.Core/protocol/component/Log.cs
Normal file
@ -0,0 +1,81 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
public enum LogType
|
||||
{
|
||||
NONE = -1,
|
||||
warn,
|
||||
info,
|
||||
verbose,
|
||||
debug,
|
||||
notice
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Zusammenfassung f<>r Log.
|
||||
/// </summary>
|
||||
public class Log : Stanza
|
||||
{
|
||||
public Log()
|
||||
{
|
||||
TagName = "log";
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// creates a new Log Packet with the given message
|
||||
/// </summary>
|
||||
/// <param name="message"> </param>
|
||||
public Log(string message) : this()
|
||||
{
|
||||
Value = message;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the logtype
|
||||
/// </summary>
|
||||
public LogType Type
|
||||
{
|
||||
get { return (LogType) GetAttributeEnum("type", typeof (LogType)); }
|
||||
set
|
||||
{
|
||||
if (value == LogType.NONE)
|
||||
RemoveAttribute("type");
|
||||
else
|
||||
SetAttribute("type", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The namespace for logging
|
||||
/// </summary>
|
||||
public string LogNamespace
|
||||
{
|
||||
get { return GetAttribute("ns"); }
|
||||
set { SetAttribute("ns", value); }
|
||||
}
|
||||
}
|
||||
}
|
180
ASC.Xmpp.Core/protocol/component/Message.cs
Normal file
180
ASC.Xmpp.Core/protocol/component/Message.cs
Normal file
@ -0,0 +1,180 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region Using directives
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Message.
|
||||
/// </summary>
|
||||
public class Message : client.Message
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
public Message()
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to)
|
||||
: base(to)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, string body)
|
||||
: base(to, body)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, Jid from)
|
||||
: base(to, from)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(string to, string body)
|
||||
: base(to, body)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, string body, string subject)
|
||||
: base(to, body, subject)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(string to, string body, string subject)
|
||||
: base(to, body, subject)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(string to, string body, string subject, string thread)
|
||||
: base(to, body, subject, thread)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, string body, string subject, string thread)
|
||||
: base(to, body, subject, thread)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(string to, MessageType type, string body)
|
||||
: base(to, type, body)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, MessageType type, string body)
|
||||
: base(to, type, body)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(string to, MessageType type, string body, string subject)
|
||||
: base(to, type, body, subject)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, MessageType type, string body, string subject)
|
||||
: base(to, type, body, subject)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(string to, MessageType type, string body, string subject, string thread)
|
||||
: base(to, type, body, subject, thread)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, MessageType type, string body, string subject, string thread)
|
||||
: base(to, type, body, subject, thread)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, Jid from, string body)
|
||||
: base(to, from, body)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, Jid from, string body, string subject)
|
||||
: base(to, from, body, subject)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, Jid from, string body, string subject, string thread)
|
||||
: base(to, from, body, subject, thread)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, Jid from, MessageType type, string body)
|
||||
: base(to, from,type, body)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, Jid from, MessageType type, string body, string subject)
|
||||
: base(to, from, type, body, subject)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Message(Jid to, Jid from, MessageType type, string body, string subject, string thread)
|
||||
: base(to, from, type, body, subject, thread)
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Error Child Element
|
||||
/// </summary>
|
||||
public new Error Error
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Error)) as Error; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Error)))
|
||||
RemoveTag(typeof (Error));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
71
ASC.Xmpp.Core/protocol/component/Presence.cs
Normal file
71
ASC.Xmpp.Core/protocol/component/Presence.cs
Normal file
@ -0,0 +1,71 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region Using directives
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Presence.
|
||||
/// </summary>
|
||||
public class Presence : client.Presence
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
public Presence()
|
||||
{
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Presence(ShowType show, string status) : this()
|
||||
{
|
||||
Show = show;
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public Presence(ShowType show, string status, int priority) : this(show, status)
|
||||
{
|
||||
Priority = priority;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Error Child Element
|
||||
/// </summary>
|
||||
public new Error Error
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Error)) as Error; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Error)))
|
||||
RemoveTag(typeof (Error));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
96
ASC.Xmpp.Core/protocol/component/Route.cs
Normal file
96
ASC.Xmpp.Core/protocol/component/Route.cs
Normal file
@ -0,0 +1,96 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.component
|
||||
{
|
||||
public enum RouteType
|
||||
{
|
||||
NONE = -1,
|
||||
error,
|
||||
auth,
|
||||
session
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class Route : Stanza
|
||||
{
|
||||
public Route()
|
||||
{
|
||||
TagName = "route";
|
||||
Namespace = Uri.ACCEPT;
|
||||
}
|
||||
|
||||
public Route(Element route) : this()
|
||||
{
|
||||
RouteElement = route;
|
||||
}
|
||||
|
||||
public Route(Element route, Jid from, Jid to) : this()
|
||||
{
|
||||
RouteElement = route;
|
||||
From = from;
|
||||
To = to;
|
||||
}
|
||||
|
||||
public Route(Element route, Jid from, Jid to, RouteType type) : this()
|
||||
{
|
||||
RouteElement = route;
|
||||
From = from;
|
||||
To = to;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the logtype
|
||||
/// </summary>
|
||||
public RouteType Type
|
||||
{
|
||||
get { return (RouteType) GetAttributeEnum("type", typeof (RouteType)); }
|
||||
set
|
||||
{
|
||||
if (value == RouteType.NONE)
|
||||
RemoveAttribute("type");
|
||||
else
|
||||
SetAttribute("type", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets or gets the element to route
|
||||
/// </summary>
|
||||
public Element RouteElement
|
||||
{
|
||||
get { return FirstChild; }
|
||||
set
|
||||
{
|
||||
if (HasChildElements)
|
||||
RemoveAllChildNodes();
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
ASC.Xmpp.Core/protocol/extensions/amp/Action.cs
Normal file
32
ASC.Xmpp.Core/protocol/extensions/amp/Action.cs
Normal file
@ -0,0 +1,32 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.amp
|
||||
{
|
||||
public enum Action
|
||||
{
|
||||
Unknown = -1,
|
||||
alert,
|
||||
drop,
|
||||
error,
|
||||
notify
|
||||
}
|
||||
}
|
103
ASC.Xmpp.Core/protocol/extensions/amp/Amp.cs
Normal file
103
ASC.Xmpp.Core/protocol/extensions/amp/Amp.cs
Normal file
@ -0,0 +1,103 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.Base;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.amp
|
||||
{
|
||||
/*
|
||||
<xs:element name='amp'>
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref='rule' minOccurs='1' maxOccurs='unbounded'/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name='from' usage='optional' type='xs:string'/>
|
||||
<xs:attribute name='per-hop' use='optional' type='xs:bool' default='false'/>
|
||||
<xs:attribute name='status' usage='optional' type='xs:NCName'/>
|
||||
<xs:attribute name='to' usage='optional' type='xs:string'/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
*/
|
||||
|
||||
public class Amp : DirectionalElement
|
||||
{
|
||||
public Amp()
|
||||
{
|
||||
TagName = "amp";
|
||||
Namespace = Uri.AMP;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The 'status' attribute specifies the reason for the amp element. When specifying semantics to be applied (client to server), this attribute MUST NOT be present. When replying to a sending entity regarding a met condition, this attribute MUST be present and SHOULD be the value of the 'action' attribute for the triggered rule. (Note: Individual action definitions MAY provide their own requirements.)
|
||||
/// </summary>
|
||||
public Action Status
|
||||
{
|
||||
get { return (Action) GetAttributeEnum("status", typeof (Action)); }
|
||||
set
|
||||
{
|
||||
if (value == Action.Unknown)
|
||||
RemoveAttribute("status");
|
||||
else
|
||||
SetAttribute("status", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The 'per-hop' attribute flags the contained ruleset for processing at each server in the route between the original sender and original intended recipient. This attribute MAY be present, and MUST be either "true" or "false". If not present, the default is "false".
|
||||
/// </summary>
|
||||
public bool PerHop
|
||||
{
|
||||
get { return GetAttributeBool("per-hop"); }
|
||||
set { SetAttribute("per-hop", value); }
|
||||
}
|
||||
|
||||
public void AddRule(Rule rule)
|
||||
{
|
||||
AddChild(rule);
|
||||
}
|
||||
|
||||
public Rule AddRule()
|
||||
{
|
||||
var rule = new Rule();
|
||||
AddChild(rule);
|
||||
|
||||
return rule;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all form fields
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public Rule[] GetRules()
|
||||
{
|
||||
ElementList nl = SelectElements(typeof (Rule));
|
||||
var items = new Rule[nl.Count];
|
||||
int i = 0;
|
||||
foreach (Element e in nl)
|
||||
{
|
||||
items[i] = (Rule) e;
|
||||
i++;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
31
ASC.Xmpp.Core/protocol/extensions/amp/Condition.cs
Normal file
31
ASC.Xmpp.Core/protocol/extensions/amp/Condition.cs
Normal file
@ -0,0 +1,31 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.amp
|
||||
{
|
||||
public enum Condition
|
||||
{
|
||||
Unknown = -1,
|
||||
Deliver,
|
||||
ExprireAt,
|
||||
MatchResource
|
||||
}
|
||||
}
|
103
ASC.Xmpp.Core/protocol/extensions/amp/Rule.cs
Normal file
103
ASC.Xmpp.Core/protocol/extensions/amp/Rule.cs
Normal file
@ -0,0 +1,103 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.amp
|
||||
{
|
||||
public class Rule : Element
|
||||
{
|
||||
public Rule()
|
||||
{
|
||||
TagName = "rule";
|
||||
Namespace = Uri.AMP;
|
||||
}
|
||||
|
||||
public Rule(Condition condition, string val, Action action)
|
||||
: this()
|
||||
{
|
||||
Condition = condition;
|
||||
Val = val;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The 'value' attribute defines how the condition is matched. This attribute MUST be present, and MUST NOT be an empty string (""). The interpretation of this attribute's value is determined by the 'condition' attribute.
|
||||
/// </summary>
|
||||
public string Val
|
||||
{
|
||||
get { return GetAttribute("value"); }
|
||||
set { SetAttribute("value", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The 'action' attribute defines the result for this rule. This attribute MUST be present, and MUST be either a value defined in the Defined Actions section, or one registered with the XMPP Registrar.
|
||||
/// </summary>
|
||||
public Action Action
|
||||
{
|
||||
get { return (Action) GetAttributeEnum("action", typeof (Action)); }
|
||||
set
|
||||
{
|
||||
if (value == Action.Unknown)
|
||||
RemoveAttribute("action");
|
||||
else
|
||||
SetAttribute("action", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The 'condition' attribute defines the overall condition this rule applies to. This attribute MUST be present, and MUST be either a value defined in the Defined Conditions section, or one registered with the XMPP Registrar.
|
||||
/// </summary>
|
||||
public Condition Condition
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (GetAttribute("condition"))
|
||||
{
|
||||
case "deliver":
|
||||
return Condition.Deliver;
|
||||
case "expire-at":
|
||||
return Condition.ExprireAt;
|
||||
case "match-resource":
|
||||
return Condition.MatchResource;
|
||||
default:
|
||||
return Condition.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case Condition.Deliver:
|
||||
SetAttribute("condition", "deliver");
|
||||
break;
|
||||
case Condition.ExprireAt:
|
||||
SetAttribute("condition", "expire-at");
|
||||
break;
|
||||
case Condition.MatchResource:
|
||||
SetAttribute("condition", "match-resource");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
119
ASC.Xmpp.Core/protocol/extensions/bookmarks/Conference.cs
Normal file
119
ASC.Xmpp.Core/protocol/extensions/bookmarks/Conference.cs
Normal file
@ -0,0 +1,119 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bookmarks
|
||||
{
|
||||
/// <summary>
|
||||
/// One of the most common uses of bookmarks will likely be to bookmark conference rooms on various Jabber servers
|
||||
/// </summary>
|
||||
public class Conference : Element
|
||||
{
|
||||
/*
|
||||
<iq type='result' id='2'>
|
||||
<query xmlns='jabber:iq:private'>
|
||||
<storage xmlns='storage:bookmarks'>
|
||||
<conference name='Council of Oberon'
|
||||
autojoin='true'
|
||||
jid='council@conference.underhill.org'>
|
||||
<nick>Puck</nick>
|
||||
<password>titania</password>
|
||||
</conference>
|
||||
</storage>
|
||||
</query>
|
||||
</iq>
|
||||
*/
|
||||
|
||||
public Conference()
|
||||
{
|
||||
TagName = "conference";
|
||||
Namespace = Uri.STORAGE_BOOKMARKS;
|
||||
}
|
||||
|
||||
public Conference(Jid jid, string name) : this()
|
||||
{
|
||||
Jid = jid;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public Conference(Jid jid, string name, string nickname) : this(jid, name)
|
||||
{
|
||||
Nickname = nickname;
|
||||
}
|
||||
|
||||
public Conference(Jid jid, string name, string nickname, string password) : this(jid, name, nickname)
|
||||
{
|
||||
Password = password;
|
||||
}
|
||||
|
||||
public Conference(Jid jid, string name, string nickname, string password, bool autojoin)
|
||||
: this(jid, name, nickname, password)
|
||||
{
|
||||
AutoJoin = autojoin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A name/description for this bookmarked room
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return GetAttribute("name"); }
|
||||
set { SetAttribute("name", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should the client join this room automatically after successfuil login?
|
||||
/// </summary>
|
||||
public bool AutoJoin
|
||||
{
|
||||
get { return GetAttributeBool("autojoin"); }
|
||||
set { SetAttribute("autojoin", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Jid of the bookmarked room
|
||||
/// </summary>
|
||||
public Jid Jid
|
||||
{
|
||||
get { return GetAttributeJid("jid"); }
|
||||
set { SetAttribute("jid", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Nickname for this room
|
||||
/// </summary>
|
||||
public string Nickname
|
||||
{
|
||||
get { return GetTag("nickname"); }
|
||||
set { SetTag("nickname", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The password for password protected rooms
|
||||
/// </summary>
|
||||
public string Password
|
||||
{
|
||||
get { return GetTag("password"); }
|
||||
set { SetTag("password", value); }
|
||||
}
|
||||
}
|
||||
}
|
185
ASC.Xmpp.Core/protocol/extensions/bookmarks/Storage.cs
Normal file
185
ASC.Xmpp.Core/protocol/extensions/bookmarks/Storage.cs
Normal file
@ -0,0 +1,185 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bookmarks
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class Storage : Element
|
||||
{
|
||||
/*
|
||||
<iq type='result' id='2'>
|
||||
<query xmlns='jabber:iq:private'>
|
||||
<storage xmlns='storage:bookmarks'>
|
||||
<conference name='Council of Oberon'
|
||||
autojoin='true'
|
||||
jid='council@conference.underhill.org'>
|
||||
<nick>Puck</nick>
|
||||
<password>titania</password>
|
||||
</conference>
|
||||
</storage>
|
||||
</query>
|
||||
</iq>
|
||||
*/
|
||||
|
||||
public Storage()
|
||||
{
|
||||
TagName = "storage";
|
||||
Namespace = Uri.STORAGE_BOOKMARKS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a conference bookmark to the storage object
|
||||
/// </summary>
|
||||
/// <param name="conf"> </param>
|
||||
/// <returns> </returns>
|
||||
public Conference AddConference(Conference conf)
|
||||
{
|
||||
AddChild(conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a conference bookmark to the storage object
|
||||
/// </summary>
|
||||
/// <param name="jid"> </param>
|
||||
/// <param name="name"> </param>
|
||||
/// <returns> </returns>
|
||||
public Conference AddConference(Jid jid, string name)
|
||||
{
|
||||
return AddConference(new Conference(jid, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a conference bookmark to the storage object
|
||||
/// </summary>
|
||||
/// <param name="jid"> </param>
|
||||
/// <param name="name"> </param>
|
||||
/// <param name="nickname"> </param>
|
||||
/// <returns> </returns>
|
||||
public Conference AddConference(Jid jid, string name, string nickname)
|
||||
{
|
||||
return AddConference(new Conference(jid, name, nickname));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a conference bookmark to the storage object
|
||||
/// </summary>
|
||||
/// <param name="jid"> </param>
|
||||
/// <param name="name"> </param>
|
||||
/// <param name="nickname"> </param>
|
||||
/// <param name="password"> </param>
|
||||
/// <returns> </returns>
|
||||
public Conference AddConference(Jid jid, string name, string nickname, string password)
|
||||
{
|
||||
return AddConference(new Conference(jid, name, nickname, password));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="jid"> </param>
|
||||
/// <param name="name"> </param>
|
||||
/// <param name="nickname"> </param>
|
||||
/// <param name="password"> </param>
|
||||
/// <param name="autojoin"> </param>
|
||||
/// <returns> </returns>
|
||||
public Conference AddConference(Jid jid, string name, string nickname, string password, bool autojoin)
|
||||
{
|
||||
return AddConference(new Conference(jid, name, nickname, password, autojoin));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add multiple conference bookmarks
|
||||
/// </summary>
|
||||
/// <param name="confs"> </param>
|
||||
public void AddConferences(Conference[] confs)
|
||||
{
|
||||
foreach (Conference conf in confs)
|
||||
{
|
||||
AddConference(conf);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get all conference booksmarks
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public Conference[] GetConferences()
|
||||
{
|
||||
ElementList nl = SelectElements(typeof (Conference));
|
||||
var items = new Conference[nl.Count];
|
||||
int i = 0;
|
||||
foreach (Element e in nl)
|
||||
{
|
||||
items[i] = (Conference) e;
|
||||
i++;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add a url bookmark
|
||||
/// </summary>
|
||||
/// <param name="url"> </param>
|
||||
/// <returns> </returns>
|
||||
public Url AddUrl(Url url)
|
||||
{
|
||||
AddChild(url);
|
||||
return url;
|
||||
}
|
||||
|
||||
public Url AddUrl(string address, string name)
|
||||
{
|
||||
return AddUrl(new Url(address, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add multiple url bookmarks
|
||||
/// </summary>
|
||||
/// <param name="urls"> </param>
|
||||
public void AddUrls(Url[] urls)
|
||||
{
|
||||
foreach (Url url in urls)
|
||||
{
|
||||
AddUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all url bookmarks
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public Url[] GetUrls()
|
||||
{
|
||||
ElementList nl = SelectElements(typeof (Url));
|
||||
var items = new Url[nl.Count];
|
||||
int i = 0;
|
||||
foreach (Element e in nl)
|
||||
{
|
||||
items[i] = (Url) e;
|
||||
i++;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
51
ASC.Xmpp.Core/protocol/extensions/bookmarks/StorageIq.cs
Normal file
51
ASC.Xmpp.Core/protocol/extensions/bookmarks/StorageIq.cs
Normal file
@ -0,0 +1,51 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
using ASC.Xmpp.Core.protocol.iq.@private;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bookmarks
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class StorageIq : PrivateIq
|
||||
{
|
||||
public StorageIq()
|
||||
{
|
||||
Query.AddChild(new Storage());
|
||||
}
|
||||
|
||||
public StorageIq(IqType type) : this()
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public StorageIq(IqType type, Jid to) : this(type)
|
||||
{
|
||||
To = to;
|
||||
}
|
||||
|
||||
public StorageIq(IqType type, Jid to, Jid from) : this(type, to)
|
||||
{
|
||||
From = from;
|
||||
}
|
||||
}
|
||||
}
|
66
ASC.Xmpp.Core/protocol/extensions/bookmarks/Url.cs
Normal file
66
ASC.Xmpp.Core/protocol/extensions/bookmarks/Url.cs
Normal file
@ -0,0 +1,66 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bookmarks
|
||||
{
|
||||
/// <summary>
|
||||
/// URLs are fairly simple, as they only need to store a URL and a title, and the client then can simply launch the appropriate browser.
|
||||
/// </summary>
|
||||
public class Url : Element
|
||||
{
|
||||
/*
|
||||
<url name='Complete Works of Shakespeare'
|
||||
url='http://the-tech.mit.edu/Shakespeare/'/>
|
||||
*/
|
||||
|
||||
public Url()
|
||||
{
|
||||
TagName = "url";
|
||||
Namespace = Uri.STORAGE_BOOKMARKS;
|
||||
}
|
||||
|
||||
public Url(string address, string name) : this()
|
||||
{
|
||||
Address = address;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A description/name for this bookmark
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return GetAttribute("name"); }
|
||||
set { SetAttribute("name", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The url address to store e.g. http://www.ag-software,de/
|
||||
/// </summary>
|
||||
public string Address
|
||||
{
|
||||
get { return GetAttribute("url"); }
|
||||
set { SetAttribute("url", value); }
|
||||
}
|
||||
}
|
||||
}
|
209
ASC.Xmpp.Core/protocol/extensions/bosh/Body.cs
Normal file
209
ASC.Xmpp.Core/protocol/extensions/bosh/Body.cs
Normal file
@ -0,0 +1,209 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bosh
|
||||
{
|
||||
public class Body : Element
|
||||
{
|
||||
public Body()
|
||||
{
|
||||
TagName = "body";
|
||||
Namespace = Uri.HTTP_BIND;
|
||||
}
|
||||
|
||||
/*
|
||||
POST /webclient HTTP/1.1
|
||||
Host: httpcm.jabber.org
|
||||
Accept-Encoding: gzip, deflate
|
||||
Content-Type: text/xml; charset=utf-8
|
||||
Content-Length: 153
|
||||
|
||||
<body rid='1249243564'
|
||||
sid='SomeSID'
|
||||
type='terminate'
|
||||
xmlns='http://jabber.org/protocol/httpbind'>
|
||||
<presence type='unavailable'
|
||||
xmlns='jabber:client'/>
|
||||
</body>
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/xml; charset=utf-8
|
||||
Content-Length: 128
|
||||
|
||||
<body authid='ServerStreamID'
|
||||
wait='60'
|
||||
inactivity='30'
|
||||
polling='5'
|
||||
requests='2'
|
||||
accept='deflate,gzip'
|
||||
sid='SomeSID'
|
||||
secure='true'
|
||||
stream='firstStreamName'
|
||||
charsets='ISO_8859-1 ISO-2022-JP'
|
||||
xmlns='http://jabber.org/protocol/httpbind'/>
|
||||
*/
|
||||
|
||||
public string Sid
|
||||
{
|
||||
get { return GetAttribute("sid"); }
|
||||
set { SetAttribute("sid", value); }
|
||||
}
|
||||
|
||||
public long Rid
|
||||
{
|
||||
get { return GetAttributeLong("rid"); }
|
||||
set { SetAttribute("rid", value); }
|
||||
}
|
||||
|
||||
public long Ack
|
||||
{
|
||||
get { return GetAttributeLong("ack"); }
|
||||
set { SetAttribute("ack", value); }
|
||||
}
|
||||
|
||||
public bool Secure
|
||||
{
|
||||
get { return GetAttributeBool("secure"); }
|
||||
set { SetAttribute("secure", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the longest time (in seconds) that the connection manager is allowed to wait before responding to any request during the session. This enables the client to limit the delay before it discovers any network failure, and to prevent its HTTP/TCP connection from expiring due to inactivity.
|
||||
/// </summary>
|
||||
public int Wait
|
||||
{
|
||||
get { return GetAttributeInt("wait"); }
|
||||
set { SetAttribute("wait", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the connection manager supports session pausing (inactivity) then it SHOULD advertise that to the client by including a 'maxpause' attribute in the session creation response element. The value of the attribute indicates the maximum length of a temporary session pause (in seconds) that a client MAY request.
|
||||
/// </summary>
|
||||
public int MaxPause
|
||||
{
|
||||
get { return GetAttributeInt("maxpause"); }
|
||||
set { SetAttribute("maxpause", value); }
|
||||
}
|
||||
|
||||
public int Inactivity
|
||||
{
|
||||
get { return GetAttributeInt("inactivity"); }
|
||||
set { SetAttribute("inactivity", value); }
|
||||
}
|
||||
|
||||
public int Polling
|
||||
{
|
||||
get { return GetAttributeInt("polling"); }
|
||||
set { SetAttribute("polling", value); }
|
||||
}
|
||||
|
||||
public int Window
|
||||
{
|
||||
get { return GetAttributeInt("window"); }
|
||||
set { SetAttribute("window", value); }
|
||||
}
|
||||
|
||||
public int Requests
|
||||
{
|
||||
get { return GetAttributeInt("requests"); }
|
||||
set { SetAttribute("requests", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the target domain of the first stream.
|
||||
/// </summary>
|
||||
public Jid To
|
||||
{
|
||||
get { return GetAttributeJid("to"); }
|
||||
set { SetAttribute("to", value); }
|
||||
}
|
||||
|
||||
public Jid From
|
||||
{
|
||||
get { return GetAttributeJid("from"); }
|
||||
set { SetAttribute("from", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// specifies the maximum number of requests the connection manager is allowed to keep waiting at any one time during the session. If the client is not able to use HTTP Pipelining then this SHOULD be set to "1".
|
||||
/// </summary>
|
||||
public int Hold
|
||||
{
|
||||
get { return GetAttributeInt("hold"); }
|
||||
set { SetAttribute("hold", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Specifies the highest version of the BOSH protocol that the client supports.
|
||||
/// The numbering scheme is "
|
||||
/// <major>.
|
||||
/// <minor>" (where the minor number MAY be incremented higher than a single digit,
|
||||
/// so it MUST be treated as a separate integer).
|
||||
/// </para>
|
||||
/// <remarks>
|
||||
/// The 'ver' attribute should not be confused with the version of any protocol being transported.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
public string Version
|
||||
{
|
||||
get { return GetAttribute("ver"); }
|
||||
set { SetAttribute("ver", value); }
|
||||
}
|
||||
|
||||
public string NewKey
|
||||
{
|
||||
get { return GetAttribute("newkey"); }
|
||||
set { SetAttribute("newkey", value); }
|
||||
}
|
||||
|
||||
public string Key
|
||||
{
|
||||
get { return GetAttribute("key"); }
|
||||
set { SetAttribute("key", value); }
|
||||
}
|
||||
|
||||
public BoshType Type
|
||||
{
|
||||
get { return (BoshType) GetAttributeEnum("type", typeof (BoshType)); }
|
||||
set
|
||||
{
|
||||
if (value == BoshType.NONE)
|
||||
RemoveAttribute("type");
|
||||
else
|
||||
SetAttribute("type", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public string XmppVersion
|
||||
{
|
||||
get { return GetAttribute("xmpp:version"); }
|
||||
set { SetAttribute("xmpp:version", value); }
|
||||
}
|
||||
|
||||
public bool XmppRestart
|
||||
{
|
||||
get { return GetAttributeBool("xmpp:restart"); }
|
||||
set { SetAttribute("xmpp:restart", value); }
|
||||
}
|
||||
}
|
||||
}
|
30
ASC.Xmpp.Core/protocol/extensions/bosh/BoshType.cs
Normal file
30
ASC.Xmpp.Core/protocol/extensions/bosh/BoshType.cs
Normal file
@ -0,0 +1,30 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bosh
|
||||
{
|
||||
public enum BoshType
|
||||
{
|
||||
NONE = -1,
|
||||
error,
|
||||
terminate
|
||||
}
|
||||
}
|
60
ASC.Xmpp.Core/protocol/extensions/bytestreams/Activate.cs
Normal file
60
ASC.Xmpp.Core/protocol/extensions/bytestreams/Activate.cs
Normal file
@ -0,0 +1,60 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bytestreams
|
||||
{
|
||||
public class Activate : Element
|
||||
{
|
||||
public Activate()
|
||||
{
|
||||
TagName = "activate";
|
||||
Namespace = Uri.BYTESTREAMS;
|
||||
}
|
||||
|
||||
public Activate(Jid jid) : this()
|
||||
{
|
||||
Jid = jid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the full JID of the Target to activate
|
||||
/// </summary>
|
||||
public Jid Jid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Value == null)
|
||||
return null;
|
||||
else
|
||||
return new Jid(Value);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
Value = value.ToString();
|
||||
else
|
||||
Value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
196
ASC.Xmpp.Core/protocol/extensions/bytestreams/ByteStream.cs
Normal file
196
ASC.Xmpp.Core/protocol/extensions/bytestreams/ByteStream.cs
Normal file
@ -0,0 +1,196 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bytestreams
|
||||
{
|
||||
/*
|
||||
<iq type='set'
|
||||
from='initiator@host1/foo'
|
||||
to='proxy.host3'
|
||||
id='activate'>
|
||||
<query xmlns='http://jabber.org/protocol/bytestreams' sid='mySID'>
|
||||
<activate>target@host2/bar</activate>
|
||||
</query>
|
||||
</iq>
|
||||
|
||||
|
||||
<xs:element name='query'>
|
||||
<xs:complexType>
|
||||
<xs:choice>
|
||||
<xs:element ref='streamhost' minOccurs='0' maxOccurs='unbounded'/>
|
||||
<xs:element ref='streamhost-used' minOccurs='0'/>
|
||||
<xs:element name='activate' type='empty' minOccurs='0'/>
|
||||
</xs:choice>
|
||||
<xs:attribute name='sid' type='xs:string' use='optional'/>
|
||||
<xs:attribute name='mode' use='optional' default='tcp'>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base='xs:NCName'>
|
||||
<xs:enumeration value='tcp'/>
|
||||
<xs:enumeration value='udp'/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// ByteStreams
|
||||
/// </summary>
|
||||
public class ByteStream : Element
|
||||
{
|
||||
public ByteStream()
|
||||
{
|
||||
TagName = "query";
|
||||
Namespace = Uri.BYTESTREAMS;
|
||||
}
|
||||
|
||||
public string Sid
|
||||
{
|
||||
set { SetAttribute("sid", value); }
|
||||
get { return GetAttribute("sid"); }
|
||||
}
|
||||
|
||||
public Mode Mode
|
||||
{
|
||||
get { return (Mode) GetAttributeEnum("mode", typeof (Mode)); }
|
||||
set
|
||||
{
|
||||
if (value != Mode.NONE)
|
||||
SetAttribute("mode", value.ToString());
|
||||
else
|
||||
RemoveAttribute("mode");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The activate Element
|
||||
/// </summary>
|
||||
public Activate Activate
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Activate)) as Activate; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Activate)))
|
||||
RemoveTag(typeof (Activate));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
|
||||
public StreamHostUsed StreamHostUsed
|
||||
{
|
||||
get { return SelectSingleElement(typeof (StreamHostUsed)) as StreamHostUsed; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (StreamHostUsed)))
|
||||
RemoveTag(typeof (StreamHostUsed));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a StreamHost
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public StreamHost AddStreamHost()
|
||||
{
|
||||
var sh = new StreamHost();
|
||||
AddChild(sh);
|
||||
return sh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a StreamHost
|
||||
/// </summary>
|
||||
/// <param name="sh"> </param>
|
||||
/// <returns> </returns>
|
||||
public StreamHost AddStreamHost(StreamHost sh)
|
||||
{
|
||||
AddChild(sh);
|
||||
return sh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a StreamHost
|
||||
/// </summary>
|
||||
/// <param name="jid"> </param>
|
||||
/// <param name="host"> </param>
|
||||
/// <returns> </returns>
|
||||
public StreamHost AddStreamHost(Jid jid, string host)
|
||||
{
|
||||
var sh = new StreamHost(jid, host);
|
||||
AddChild(sh);
|
||||
return sh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a StreamHost
|
||||
/// </summary>
|
||||
/// <param name="jid"> </param>
|
||||
/// <param name="host"> </param>
|
||||
/// <param name="port"> </param>
|
||||
/// <returns> </returns>
|
||||
public StreamHost AddStreamHost(Jid jid, string host, int port)
|
||||
{
|
||||
var sh = new StreamHost(jid, host, port);
|
||||
AddChild(sh);
|
||||
return sh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a StreamHost
|
||||
/// </summary>
|
||||
/// <param name="jid"> </param>
|
||||
/// <param name="host"> </param>
|
||||
/// <param name="port"> </param>
|
||||
/// <param name="zeroconf"> </param>
|
||||
/// <returns> </returns>
|
||||
public StreamHost AddStreamHost(Jid jid, string host, int port, string zeroconf)
|
||||
{
|
||||
var sh = new StreamHost(jid, host, port, zeroconf);
|
||||
AddChild(sh);
|
||||
return sh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the list of streamhosts
|
||||
/// </summary>
|
||||
/// <returns> </returns>
|
||||
public StreamHost[] GetStreamHosts()
|
||||
{
|
||||
ElementList nl = SelectElements(typeof (StreamHost));
|
||||
var hosts = new StreamHost[nl.Count];
|
||||
int i = 0;
|
||||
foreach (Element e in nl)
|
||||
{
|
||||
hosts[i] = (StreamHost) e;
|
||||
i++;
|
||||
}
|
||||
return hosts;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bytestreams
|
||||
{
|
||||
/// <summary>
|
||||
/// a Bytestream IQ
|
||||
/// </summary>
|
||||
public class ByteStreamIq : IQ
|
||||
{
|
||||
private readonly ByteStream m_ByteStream = new ByteStream();
|
||||
|
||||
public ByteStreamIq()
|
||||
{
|
||||
base.Query = m_ByteStream;
|
||||
GenerateId();
|
||||
}
|
||||
|
||||
public ByteStreamIq(IqType type) : this()
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public ByteStreamIq(IqType type, Jid to)
|
||||
: this(type)
|
||||
{
|
||||
To = to;
|
||||
}
|
||||
|
||||
public ByteStreamIq(IqType type, Jid to, Jid from)
|
||||
: this(type, to)
|
||||
{
|
||||
From = from;
|
||||
}
|
||||
|
||||
public ByteStreamIq(IqType type, Jid to, Jid from, string Id)
|
||||
: this(type, to, from)
|
||||
{
|
||||
this.Id = Id;
|
||||
}
|
||||
|
||||
public new ByteStream Query
|
||||
{
|
||||
get { return m_ByteStream; }
|
||||
}
|
||||
}
|
||||
}
|
33
ASC.Xmpp.Core/protocol/extensions/bytestreams/Mode.cs
Normal file
33
ASC.Xmpp.Core/protocol/extensions/bytestreams/Mode.cs
Normal file
@ -0,0 +1,33 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bytestreams
|
||||
{
|
||||
/// <summary>
|
||||
/// The Mode for the bytestream socket layer (tcp or udp)
|
||||
/// </summary>
|
||||
public enum Mode
|
||||
{
|
||||
NONE = -1,
|
||||
tcp,
|
||||
udp
|
||||
}
|
||||
}
|
117
ASC.Xmpp.Core/protocol/extensions/bytestreams/StreamHost.cs
Normal file
117
ASC.Xmpp.Core/protocol/extensions/bytestreams/StreamHost.cs
Normal file
@ -0,0 +1,117 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bytestreams
|
||||
{
|
||||
/*
|
||||
<streamhost
|
||||
jid='proxy.host3'
|
||||
host='24.24.24.1'
|
||||
zeroconf='_jabber.bytestreams'/>
|
||||
<xs:element name='streamhost'>
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base='empty'>
|
||||
<xs:attribute name='jid' type='xs:string' use='required'/>
|
||||
<xs:attribute name='host' type='xs:string' use='required'/>
|
||||
<xs:attribute name='zeroconf' type='xs:string' use='optional'/>
|
||||
<xs:attribute name='port' type='xs:string' use='optional'/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
*/
|
||||
|
||||
public class StreamHost : Element
|
||||
{
|
||||
public StreamHost()
|
||||
{
|
||||
TagName = "streamhost";
|
||||
Namespace = Uri.BYTESTREAMS;
|
||||
}
|
||||
|
||||
public StreamHost(Jid jid, string host) : this()
|
||||
{
|
||||
Jid = jid;
|
||||
Host = host;
|
||||
}
|
||||
|
||||
public StreamHost(Jid jid, string host, int port) : this(jid, host)
|
||||
{
|
||||
Port = port;
|
||||
}
|
||||
|
||||
public StreamHost(Jid jid, string host, int port, string zeroconf) : this(jid, host, port)
|
||||
{
|
||||
Zeroconf = zeroconf;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a port associated with the hostname or IP address for SOCKS5 communications over TCP
|
||||
/// </summary>
|
||||
public int Port
|
||||
{
|
||||
get { return GetAttributeInt("port"); }
|
||||
set { SetAttribute("port", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the hostname or IP address of the StreamHost for SOCKS5 communications over TCP
|
||||
/// </summary>
|
||||
public string Host
|
||||
{
|
||||
get { return GetAttribute("host"); }
|
||||
set { SetAttribute("host", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The XMPP/Jabber id of the streamhost
|
||||
/// </summary>
|
||||
public Jid Jid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasAttribute("jid"))
|
||||
return new Jid(GetAttribute("jid"));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
SetAttribute("jid", value.ToString());
|
||||
else
|
||||
RemoveAttribute("jid");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a zeroconf [5] identifier to which an entity may connect, for which the service identifier and protocol name SHOULD be "_jabber.bytestreams".
|
||||
/// </summary>
|
||||
public string Zeroconf
|
||||
{
|
||||
get { return GetAttribute("zeroconf"); }
|
||||
set { SetAttribute("zeroconf", value); }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bytestreams
|
||||
{
|
||||
/*
|
||||
<iq type='result'
|
||||
from='target@host2/bar'
|
||||
to='initiator@host1/foo'
|
||||
id='initiate'>
|
||||
<query xmlns='http://jabber.org/protocol/bytestreams'>
|
||||
<streamhost-used jid='proxy.host3'/>
|
||||
</query>
|
||||
</iq>
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// The <streamhost-used /> element indicates the StreamHost connected to. This element has a single attribute for the JID of the StreamHost to which the Target connected. This element MUST NOT contain any content node. The "jid" attribute specifies the full JID of the StreamHost. This attribute MUST be present, and MUST be a valid JID for use with an <iq/>.
|
||||
/// </summary>
|
||||
public class StreamHostUsed : Element
|
||||
{
|
||||
public StreamHostUsed()
|
||||
{
|
||||
TagName = "streamhost-used";
|
||||
Namespace = Uri.BYTESTREAMS;
|
||||
}
|
||||
|
||||
public StreamHostUsed(Jid jid) : this()
|
||||
{
|
||||
Jid = jid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jid of the streamhost
|
||||
/// </summary>
|
||||
public Jid Jid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HasAttribute("jid"))
|
||||
return new Jid(GetAttribute("jid"));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
SetAttribute("jid", value.ToString());
|
||||
else
|
||||
RemoveAttribute("jid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
ASC.Xmpp.Core/protocol/extensions/bytestreams/UdpSuccess.cs
Normal file
51
ASC.Xmpp.Core/protocol/extensions/bytestreams/UdpSuccess.cs
Normal file
@ -0,0 +1,51 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.bytestreams
|
||||
{
|
||||
/*
|
||||
<message
|
||||
from='proxy.host3'
|
||||
to='target@host2/bar'
|
||||
id='initiate'>
|
||||
<udpsuccess xmlns='http://jabber.org/protocol/bytestreams' dstaddr='Value of Hash'/>
|
||||
</message>
|
||||
*/
|
||||
|
||||
public class UdpSuccess : Element
|
||||
{
|
||||
public UdpSuccess(string dstaddr)
|
||||
{
|
||||
TagName = "udpsuccess";
|
||||
Namespace = Uri.BYTESTREAMS;
|
||||
|
||||
DestinationAddress = dstaddr;
|
||||
}
|
||||
|
||||
public string DestinationAddress
|
||||
{
|
||||
get { return GetAttribute("dstaddr"); }
|
||||
set { SetAttribute("dstaddr", value); }
|
||||
}
|
||||
}
|
||||
}
|
245
ASC.Xmpp.Core/protocol/extensions/caps/Capabilities.cs
Normal file
245
ASC.Xmpp.Core/protocol/extensions/caps/Capabilities.cs
Normal file
@ -0,0 +1,245 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using ASC.Xmpp.Core.protocol.iq.disco;
|
||||
using ASC.Xmpp.Core.utils;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.caps
|
||||
{
|
||||
/*
|
||||
Example 1. Annotated presence sent
|
||||
|
||||
<presence>
|
||||
<c xmlns='http://jabber.org/protocol/caps'
|
||||
node='http://exodus.jabberstudio.org/caps'
|
||||
ver='0.9'/>
|
||||
</presence>
|
||||
|
||||
Example 2. Annotated presence sent, with feature extensions
|
||||
|
||||
<presence>
|
||||
<c xmlns='http://jabber.org/protocol/caps'
|
||||
node='http://exodus.jabberstudio.org/caps'
|
||||
ver='0.9'
|
||||
ext='jingle ftrans xhtml'/>
|
||||
</presence>
|
||||
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// <para>It is often desirable for a Jabber/XMPP application (commonly but not necessarily a client) to take different actions
|
||||
/// depending on the capabilities of another application from which it receives presence information. Examples include:</para> <list
|
||||
/// type="bullet">
|
||||
/// <item>
|
||||
/// <term>Showing a different set of icons depending on the capabilities of other clients.</term>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>Not sending XHTML-IM content to plaintext clients such as cell phones.</term>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>Allowing the initiation of Voice over IP (VoIP) sessions only to clients that support VoIP.</term>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>Not showing a "Send a File" button if another user's client does not support File Transfer.</term>
|
||||
/// </item>
|
||||
/// </list> <para>Recently, some existing Jabber clients have begun sending Software Version requests to each entity from which they
|
||||
/// receive presence. That solution is impractical on a larger scale, particularly for users or applications with large rosters.
|
||||
/// This document proposes a more robust and scalable solution: namely, a presence-based mechanism for exchanging information
|
||||
/// about entity capabilities.</para>
|
||||
/// </summary>
|
||||
public class Capabilities : Element
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Capabilities()
|
||||
{
|
||||
TagName = "c";
|
||||
Namespace = Uri.CAPS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="version"> </param>
|
||||
/// <param name="node"> </param>
|
||||
public Capabilities(string version, string node)
|
||||
: this()
|
||||
{
|
||||
Version = version;
|
||||
Node = node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Required node attribute
|
||||
/// </summary>
|
||||
public string Node
|
||||
{
|
||||
get { return GetAttribute("node"); }
|
||||
set { SetAttribute("node", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Required version attribute
|
||||
/// </summary>
|
||||
public string Version
|
||||
{
|
||||
get { return GetAttribute("ver"); }
|
||||
set { SetAttribute("ver", value); }
|
||||
}
|
||||
|
||||
[Obsolete("This property is deprecated with version 1.4 of XEP-0115. You shouldn't use this propety anymore.")]
|
||||
public string[] Extensions
|
||||
{
|
||||
get { return GetExtensions(); }
|
||||
set { SetExtensions(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds and sets the caps ver attribute from a DiscoInfo object
|
||||
/// </summary>
|
||||
/// <param name="di"> </param>
|
||||
public void SetVersion(DiscoInfo di)
|
||||
{
|
||||
Version = BuildCapsVersion(di);
|
||||
}
|
||||
|
||||
private string BuildCapsVersion(DiscoInfo di)
|
||||
{
|
||||
/*
|
||||
1. Initialize an empty string S.
|
||||
2. Sort the service discovery identities by category and then by type (if it exists), formatted as 'category' '/' 'type'.
|
||||
3. For each identity, append the 'category/type' to S, followed by the '<' character.
|
||||
4. Sort the supported features.
|
||||
5. For each feature, append the feature to S, followed by the '<' character.
|
||||
6. Compute ver by hashing S using the SHA-1 algorithm as specified in RFC 3174 [17] (with binary output) and
|
||||
encoding the hash using Base64 as specified in Section 4 of RFC 4648 [18]
|
||||
(note: the Base64 output MUST NOT include whitespace and MUST set padding bits to zero). [19]
|
||||
*/
|
||||
var features = new ArrayList();
|
||||
var identities = new ArrayList();
|
||||
|
||||
foreach (DiscoIdentity did in di.GetIdentities())
|
||||
identities.Add(did.Type == null ? did.Category : did.Category + "/" + did.Type);
|
||||
|
||||
foreach (DiscoFeature df in di.GetFeatures())
|
||||
features.Add(df.Var);
|
||||
|
||||
identities.Sort();
|
||||
features.Sort();
|
||||
|
||||
var S = new StringBuilder();
|
||||
|
||||
foreach (string s in identities)
|
||||
S.Append(s + "<");
|
||||
|
||||
foreach (string s in features)
|
||||
S.Append(s + "<");
|
||||
|
||||
byte[] sha1 = Hash.Sha1HashBytes(S.ToString());
|
||||
|
||||
#if CF
|
||||
return Convert.ToBase64String(sha1, 0, sha1.Length);
|
||||
#else
|
||||
return Convert.ToBase64String(sha1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#region << Extension Helpers >>
|
||||
|
||||
public void AddExtension(string ext)
|
||||
{
|
||||
string[] extensions = GetExtensions();
|
||||
// check if the extension already exists
|
||||
if (extensions != null &&
|
||||
Array.IndexOf(extensions, ext, extensions.GetLowerBound(0), extensions.Length) >= 0)
|
||||
return;
|
||||
|
||||
int size = extensions == null ? 1 : extensions.Length + 1;
|
||||
var tmpExtensions = new string[size];
|
||||
if (size > 1)
|
||||
extensions.CopyTo(tmpExtensions, 0);
|
||||
|
||||
tmpExtensions[size - 1] = ext;
|
||||
SetExtensions(tmpExtensions);
|
||||
}
|
||||
|
||||
public void RemoveExtension(string ext)
|
||||
{
|
||||
string[] extensions = GetExtensions();
|
||||
if (extensions != null)
|
||||
{
|
||||
if (Array.IndexOf(extensions, ext, extensions.GetLowerBound(0), extensions.Length) >= 0)
|
||||
{
|
||||
int i = 0;
|
||||
var tmpExtensions = new string[extensions.Length - 1];
|
||||
foreach (string s in extensions)
|
||||
{
|
||||
if (s != ext)
|
||||
tmpExtensions[i++] = s;
|
||||
}
|
||||
SetExtensions(tmpExtensions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsExtension(string ext)
|
||||
{
|
||||
string[] extensions = GetExtensions();
|
||||
if (extensions == null)
|
||||
return false;
|
||||
|
||||
if (Array.IndexOf(extensions, ext, extensions.GetLowerBound(0), extensions.Length) >= 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private string[] GetExtensions()
|
||||
{
|
||||
string ext = GetAttribute("ext");
|
||||
return ext != null ? ext.Split(' ') : null;
|
||||
}
|
||||
|
||||
private void SetExtensions(string[] ext)
|
||||
{
|
||||
if (ext != null)
|
||||
{
|
||||
string temp = null;
|
||||
for (int i = 0; i < ext.Length; i++)
|
||||
{
|
||||
temp += ext[i];
|
||||
if (i < ext.Length - 1)
|
||||
temp += " ";
|
||||
}
|
||||
SetAttribute("ext", temp);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
39
ASC.Xmpp.Core/protocol/extensions/chatstates/Active.cs
Normal file
39
ASC.Xmpp.Core/protocol/extensions/chatstates/Active.cs
Normal file
@ -0,0 +1,39 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.chatstates
|
||||
{
|
||||
/// <summary>
|
||||
/// User is actively participating in the chat session. User accepts an initial content message, sends a content message, gives focus to the chat interface, or is otherwise paying attention to the conversation.
|
||||
/// </summary>
|
||||
public class Active : Element
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Active()
|
||||
{
|
||||
TagName = Chatstate.active.ToString();
|
||||
Namespace = Uri.CHATSTATES;
|
||||
}
|
||||
}
|
||||
}
|
59
ASC.Xmpp.Core/protocol/extensions/chatstates/Chatstate.cs
Normal file
59
ASC.Xmpp.Core/protocol/extensions/chatstates/Chatstate.cs
Normal file
@ -0,0 +1,59 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.chatstates
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration of supported Chatstates (JEP-0085)
|
||||
/// </summary>
|
||||
public enum Chatstate
|
||||
{
|
||||
/// <summary>
|
||||
/// No Chatstate at all
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Active Chatstate
|
||||
/// </summary>
|
||||
active,
|
||||
|
||||
/// <summary>
|
||||
/// Inactive Chatstate
|
||||
/// </summary>
|
||||
inactive,
|
||||
|
||||
/// <summary>
|
||||
/// Composing Chatstate
|
||||
/// </summary>
|
||||
composing,
|
||||
|
||||
/// <summary>
|
||||
/// Gone Chatstate
|
||||
/// </summary>
|
||||
gone,
|
||||
|
||||
/// <summary>
|
||||
/// Paused Chatstate
|
||||
/// </summary>
|
||||
paused
|
||||
}
|
||||
}
|
38
ASC.Xmpp.Core/protocol/extensions/chatstates/Composing.cs
Normal file
38
ASC.Xmpp.Core/protocol/extensions/chatstates/Composing.cs
Normal file
@ -0,0 +1,38 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.chatstates
|
||||
{
|
||||
/// <summary>
|
||||
/// User is composing a message. User is interacting with a message input interface specific to this chat session (e.g., by typing in the input area of a chat window).
|
||||
/// </summary>
|
||||
public class Composing : Element
|
||||
{
|
||||
public Composing()
|
||||
{
|
||||
TagName = Chatstate.composing.ToString();
|
||||
;
|
||||
Namespace = Uri.CHATSTATES;
|
||||
}
|
||||
}
|
||||
}
|
40
ASC.Xmpp.Core/protocol/extensions/chatstates/Gone.cs
Normal file
40
ASC.Xmpp.Core/protocol/extensions/chatstates/Gone.cs
Normal file
@ -0,0 +1,40 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.chatstates
|
||||
{
|
||||
/// <summary>
|
||||
/// User has effectively ended their participation in the chat session. User has not interacted with the chat interface, system, or device for a relatively long period of time (e.g., 2 minutes), or has terminated the chat interface (e.g., by closing the chat window).
|
||||
/// </summary>
|
||||
public class Gone : Element
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Gone()
|
||||
{
|
||||
TagName = Chatstate.gone.ToString();
|
||||
;
|
||||
Namespace = Uri.CHATSTATES;
|
||||
}
|
||||
}
|
||||
}
|
40
ASC.Xmpp.Core/protocol/extensions/chatstates/Inactive.cs
Normal file
40
ASC.Xmpp.Core/protocol/extensions/chatstates/Inactive.cs
Normal file
@ -0,0 +1,40 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.chatstates
|
||||
{
|
||||
/// <summary>
|
||||
/// User has not been actively participating in the chat session. User has not interacted with the chat interface for an intermediate period of time (e.g., 30 seconds).
|
||||
/// </summary>
|
||||
public class Inactive : Element
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Inactive()
|
||||
{
|
||||
TagName = Chatstate.inactive.ToString();
|
||||
;
|
||||
Namespace = Uri.CHATSTATES;
|
||||
}
|
||||
}
|
||||
}
|
40
ASC.Xmpp.Core/protocol/extensions/chatstates/Paused.cs
Normal file
40
ASC.Xmpp.Core/protocol/extensions/chatstates/Paused.cs
Normal file
@ -0,0 +1,40 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.chatstates
|
||||
{
|
||||
/// <summary>
|
||||
/// User had been composing but now has stopped. User was composing but has not interacted with the message input interface for a short period of time (e.g., 5 seconds).
|
||||
/// </summary>
|
||||
public class Paused : Element
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Paused()
|
||||
{
|
||||
TagName = Chatstate.paused.ToString();
|
||||
;
|
||||
Namespace = Uri.CHATSTATES;
|
||||
}
|
||||
}
|
||||
}
|
47
ASC.Xmpp.Core/protocol/extensions/commands/Action.cs
Normal file
47
ASC.Xmpp.Core/protocol/extensions/commands/Action.cs
Normal file
@ -0,0 +1,47 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.commands
|
||||
{
|
||||
/*
|
||||
<xs:attribute name='action' use='optional'>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base='xs:NCName'>
|
||||
<xs:enumeration value='cancel'/>
|
||||
<xs:enumeration value='complete'/>
|
||||
<xs:enumeration value='execute'/>
|
||||
<xs:enumeration value='next'/>
|
||||
<xs:enumeration value='prev'/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
*/
|
||||
|
||||
public enum Action
|
||||
{
|
||||
NONE = -1,
|
||||
next = 1,
|
||||
prev = 2,
|
||||
complete = 4,
|
||||
execute = 8,
|
||||
cancel = 16
|
||||
}
|
||||
}
|
152
ASC.Xmpp.Core/protocol/extensions/commands/Actions.cs
Normal file
152
ASC.Xmpp.Core/protocol/extensions/commands/Actions.cs
Normal file
@ -0,0 +1,152 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.commands
|
||||
{
|
||||
/*
|
||||
<xs:element name='actions'>
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name='prev' type='empty' minOccurs='0'/>
|
||||
<xs:element name='next' type='empty' minOccurs='0'/>
|
||||
<xs:element name='complete' type='empty' minOccurs='0'/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name='execute' use='optional'>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base='xs:NCName'>
|
||||
<xs:enumeration value='complete'/>
|
||||
<xs:enumeration value='next'/>
|
||||
<xs:enumeration value='prev'/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<actions execute='complete'>
|
||||
<prev/>
|
||||
<complete/>
|
||||
</actions>
|
||||
*/
|
||||
|
||||
public class Actions : Element
|
||||
{
|
||||
public Actions()
|
||||
{
|
||||
TagName = "actions";
|
||||
Namespace = Uri.COMMANDS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional Execute Action, only complete, next and previous is allowed
|
||||
/// </summary>
|
||||
public Action Execute
|
||||
{
|
||||
get { return (Action) GetAttributeEnum("execute", typeof (Action)); }
|
||||
set
|
||||
{
|
||||
if (value == Action.NONE)
|
||||
RemoveAttribute("execute");
|
||||
else
|
||||
SetAttribute("execute", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public bool Complete
|
||||
{
|
||||
get { return HasTag("complete"); }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
SetTag("complete");
|
||||
else
|
||||
RemoveTag("complete");
|
||||
}
|
||||
}
|
||||
|
||||
public bool Next
|
||||
{
|
||||
get { return HasTag("next"); }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
SetTag("next");
|
||||
else
|
||||
RemoveTag("next");
|
||||
}
|
||||
}
|
||||
|
||||
public bool Previous
|
||||
{
|
||||
get { return HasTag("prev"); }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
SetTag("prev");
|
||||
else
|
||||
RemoveTag("prev");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Actions, only complete, prev and next are allowed here and can be combined
|
||||
/// </summary>
|
||||
public Action Action
|
||||
{
|
||||
get
|
||||
{
|
||||
Action res = 0;
|
||||
|
||||
if (Complete)
|
||||
res |= Action.complete;
|
||||
if (Previous)
|
||||
res |= Action.prev;
|
||||
if (Next)
|
||||
res |= Action.next;
|
||||
|
||||
if (res == 0)
|
||||
return Action.NONE;
|
||||
else
|
||||
return res;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == Action.NONE)
|
||||
{
|
||||
Complete = false;
|
||||
Previous = false;
|
||||
Next = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Complete = ((value & Action.complete) == Action.complete);
|
||||
Previous = ((value & Action.prev) == Action.prev);
|
||||
Next = ((value & Action.next) == Action.next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
159
ASC.Xmpp.Core/protocol/extensions/commands/Command.cs
Normal file
159
ASC.Xmpp.Core/protocol/extensions/commands/Command.cs
Normal file
@ -0,0 +1,159 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.x.data;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.commands
|
||||
{
|
||||
public class Command : Element
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
public Command()
|
||||
{
|
||||
TagName = "command";
|
||||
Namespace = Uri.COMMANDS;
|
||||
}
|
||||
|
||||
public Command(string node) : this()
|
||||
{
|
||||
Node = node;
|
||||
}
|
||||
|
||||
public Command(Action action) : this()
|
||||
{
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public Command(Status status) : this()
|
||||
{
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public Command(string node, string sessionId) : this(node)
|
||||
{
|
||||
SessionId = sessionId;
|
||||
}
|
||||
|
||||
public Command(string node, string sessionId, Action action) : this(node, sessionId)
|
||||
{
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public Command(string node, string sessionId, Status status) : this(node, sessionId)
|
||||
{
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public Command(string node, string sessionId, Action action, Status status) : this(node, sessionId, action)
|
||||
{
|
||||
Status = status;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public Action Action
|
||||
{
|
||||
get { return (Action) GetAttributeEnum("action", typeof (Action)); }
|
||||
set
|
||||
{
|
||||
if (value == Action.NONE)
|
||||
RemoveAttribute("action");
|
||||
else
|
||||
SetAttribute("action", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public Status Status
|
||||
{
|
||||
get { return (Status) GetAttributeEnum("status", typeof (Status)); }
|
||||
set
|
||||
{
|
||||
if (value == Status.NONE)
|
||||
RemoveAttribute("status");
|
||||
else
|
||||
SetAttribute("status", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// <xs:attribute name='node' type='xs:string' use='required'/>
|
||||
|
||||
/// <summary>
|
||||
/// Node is Required
|
||||
/// </summary>
|
||||
public string Node
|
||||
{
|
||||
get { return GetAttribute("node"); }
|
||||
set { SetAttribute("node", value); }
|
||||
}
|
||||
|
||||
// <xs:attribute name='sessionid' type='xs:string' use='optional'/>
|
||||
public string SessionId
|
||||
{
|
||||
get { return GetAttribute("sessionid"); }
|
||||
set { SetAttribute("sessionid", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The X-Data Element
|
||||
/// </summary>
|
||||
public x.data.Data Data
|
||||
{
|
||||
get { return SelectSingleElement(typeof (x.data.Data)) as x.data.Data; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (x.data.Data)))
|
||||
RemoveTag(typeof (x.data.Data));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Note Note
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Note)) as Note; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Note)))
|
||||
RemoveTag(typeof (Note));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Actions Actions
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Actions)) as Actions; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Actions)))
|
||||
RemoveTag(typeof (Actions));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
ASC.Xmpp.Core/protocol/extensions/commands/Note.cs
Normal file
82
ASC.Xmpp.Core/protocol/extensions/commands/Note.cs
Normal file
@ -0,0 +1,82 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.commands
|
||||
{
|
||||
/*
|
||||
<note type='info'>Service 'httpd' has been configured.</note>
|
||||
|
||||
<xs:element name='note'>
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base='xs:string'>
|
||||
<xs:attribute name='type' use='required'>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base='xs:NCName'>
|
||||
<xs:enumeration value='error'/>
|
||||
<xs:enumeration value='info'/>
|
||||
<xs:enumeration value='warn'/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
*/
|
||||
|
||||
public class Note : Element
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public Note()
|
||||
{
|
||||
TagName = "note";
|
||||
Namespace = Uri.COMMANDS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="type"> </param>
|
||||
public Note(NoteType type) : this()
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="text"> </param>
|
||||
/// <param name="type"> </param>
|
||||
public Note(string text, NoteType type) : this(type)
|
||||
{
|
||||
Value = text;
|
||||
}
|
||||
|
||||
public NoteType Type
|
||||
{
|
||||
get { return (NoteType) GetAttributeEnum("type", typeof (NoteType)); }
|
||||
set { SetAttribute("type", value.ToString()); }
|
||||
}
|
||||
}
|
||||
}
|
30
ASC.Xmpp.Core/protocol/extensions/commands/NoteType.cs
Normal file
30
ASC.Xmpp.Core/protocol/extensions/commands/NoteType.cs
Normal file
@ -0,0 +1,30 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.commands
|
||||
{
|
||||
public enum NoteType
|
||||
{
|
||||
error,
|
||||
info,
|
||||
warn
|
||||
}
|
||||
}
|
43
ASC.Xmpp.Core/protocol/extensions/commands/Status.cs
Normal file
43
ASC.Xmpp.Core/protocol/extensions/commands/Status.cs
Normal file
@ -0,0 +1,43 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.commands
|
||||
{
|
||||
/*
|
||||
* <xs:attribute name='status' use='optional'>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base='xs:NCName'>
|
||||
<xs:enumeration value='canceled'/>
|
||||
<xs:enumeration value='completed'/>
|
||||
<xs:enumeration value='executing'/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
*/
|
||||
|
||||
public enum Status
|
||||
{
|
||||
NONE = -1,
|
||||
canceled,
|
||||
completed,
|
||||
executing
|
||||
}
|
||||
}
|
64
ASC.Xmpp.Core/protocol/extensions/compression/Compress.cs
Normal file
64
ASC.Xmpp.Core/protocol/extensions/compression/Compress.cs
Normal file
@ -0,0 +1,64 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.compression
|
||||
{
|
||||
// <compress xmlns="http://jabber.org/protocol/compress">
|
||||
// <method>zlib</method>
|
||||
// </compress>
|
||||
|
||||
public class Compress : Element
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
public Compress()
|
||||
{
|
||||
TagName = "compress";
|
||||
Namespace = Uri.COMPRESS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with a given method/algorithm for Stream compression
|
||||
/// </summary>
|
||||
/// <param name="method"> method/algorithm used to compressing the stream </param>
|
||||
public Compress(CompressionMethod method) : this()
|
||||
{
|
||||
Method = method;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// method/algorithm used to compressing the stream
|
||||
/// </summary>
|
||||
public CompressionMethod Method
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value != CompressionMethod.Unknown)
|
||||
SetTag("method", value.ToString());
|
||||
}
|
||||
get { return (CompressionMethod) GetTagEnum("method", typeof (CompressionMethod)); }
|
||||
}
|
||||
}
|
||||
}
|
39
ASC.Xmpp.Core/protocol/extensions/compression/Compressed.cs
Normal file
39
ASC.Xmpp.Core/protocol/extensions/compression/Compressed.cs
Normal file
@ -0,0 +1,39 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.compression
|
||||
{
|
||||
/*
|
||||
* Example 5. Receiving Entity Acknowledges Stream Compression
|
||||
* <compressed xmlns='http://jabber.org/protocol/compress'/>
|
||||
*/
|
||||
|
||||
public class Compressed : Element
|
||||
{
|
||||
public Compressed()
|
||||
{
|
||||
TagName = "compressed";
|
||||
Namespace = Uri.COMPRESS;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.compression
|
||||
{
|
||||
public enum CompressionMethod
|
||||
{
|
||||
Unknown = -1,
|
||||
zlib,
|
||||
lzw
|
||||
}
|
||||
}
|
56
ASC.Xmpp.Core/protocol/extensions/compression/Failure.cs
Normal file
56
ASC.Xmpp.Core/protocol/extensions/compression/Failure.cs
Normal file
@ -0,0 +1,56 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.compression
|
||||
{
|
||||
/*
|
||||
*
|
||||
* Note: If the initiating entity did not understand any of the advertised compression methods,
|
||||
* it SHOULD ignore the compression option and proceed as if no compression methods were advertised.
|
||||
*
|
||||
* If the initiating entity requests a stream compression method that is not supported by the
|
||||
* receiving entity, the receiving entity MUST return an <unsupported-method/> error:
|
||||
*
|
||||
* Example 3. Receiving Entity Reports That Method is Unsupported
|
||||
* <failure xmlns='http://jabber.org/protocol/compress'>
|
||||
* <unsupported-method/>
|
||||
* </failure>
|
||||
*
|
||||
* If the receiving entity cannot establish compression using the requested method for any
|
||||
* other reason, it MUST return a <setup-failed/> error:
|
||||
*
|
||||
* Example 4. Receiving Entity Reports That Compression Setup Failed
|
||||
* <failure xmlns='http://jabber.org/protocol/compress'>
|
||||
* <setup-failed/>
|
||||
* </failure>
|
||||
*/
|
||||
|
||||
public class Failure : Element
|
||||
{
|
||||
public Failure()
|
||||
{
|
||||
TagName = "failure";
|
||||
Namespace = Uri.COMPRESS;
|
||||
}
|
||||
}
|
||||
}
|
83
ASC.Xmpp.Core/protocol/extensions/featureneg/FeatureNeg.cs
Normal file
83
ASC.Xmpp.Core/protocol/extensions/featureneg/FeatureNeg.cs
Normal file
@ -0,0 +1,83 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.x.data;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.featureneg
|
||||
{
|
||||
/// <summary>
|
||||
/// JEP-0020: Feature Negotiation This JEP defines a A protocol that enables two Jabber entities to mutually negotiate feature options.
|
||||
/// </summary>
|
||||
public class FeatureNeg : Element
|
||||
{
|
||||
/*
|
||||
<iq type='get'
|
||||
from='romeo@montague.net/orchard'
|
||||
to='juliet@capulet.com/balcony'
|
||||
id='neg1'>
|
||||
<feature xmlns='http://jabber.org/protocol/feature-neg'>
|
||||
<x xmlns='jabber:x:data' type='form'>
|
||||
<field type='list-single' var='places-to-meet'>
|
||||
<option><value>Lover's Lane</value></option>
|
||||
<option><value>Secret Grotto</value></option>
|
||||
<option><value>Verona Park</value></option>
|
||||
</field>
|
||||
<field type='list-single' var='times-to-meet'>
|
||||
<option><value>22:00</value></option>
|
||||
<option><value>22:30</value></option>
|
||||
<option><value>23:00</value></option>
|
||||
<option><value>23:30</value></option>
|
||||
</field>
|
||||
</x>
|
||||
</feature>
|
||||
</iq>
|
||||
*/
|
||||
|
||||
public FeatureNeg()
|
||||
{
|
||||
TagName = "feature";
|
||||
Namespace = Uri.FEATURE_NEG;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// data form of type "form" which defines the available options for one or more features. Each feature is represented as an x-data "field", which MUST be of type "list-single".
|
||||
/// </summary>
|
||||
public x.data.Data Data
|
||||
{
|
||||
get
|
||||
{
|
||||
Element data = SelectSingleElement(typeof (x.data.Data));
|
||||
if (data != null)
|
||||
return data as x.data.Data;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (x.data.Data)))
|
||||
RemoveTag(typeof (x.data.Data));
|
||||
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
72
ASC.Xmpp.Core/protocol/extensions/featureneg/FeatureNegIq.cs
Normal file
72
ASC.Xmpp.Core/protocol/extensions/featureneg/FeatureNegIq.cs
Normal file
@ -0,0 +1,72 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.featureneg
|
||||
{
|
||||
/// <summary>
|
||||
/// JEP-0020: Feature Negotiation This JEP defines a A protocol that enables two Jabber entities to mutually negotiate feature options.
|
||||
/// </summary>
|
||||
public class FeatureNegIq : IQ
|
||||
{
|
||||
/*
|
||||
<iq type='get'
|
||||
from='romeo@montague.net/orchard'
|
||||
to='juliet@capulet.com/balcony'
|
||||
id='neg1'>
|
||||
<feature xmlns='http://jabber.org/protocol/feature-neg'>
|
||||
<x xmlns='jabber:x:data' type='form'>
|
||||
<field type='list-single' var='places-to-meet'>
|
||||
<option><value>Lover's Lane</value></option>
|
||||
<option><value>Secret Grotto</value></option>
|
||||
<option><value>Verona Park</value></option>
|
||||
</field>
|
||||
<field type='list-single' var='times-to-meet'>
|
||||
<option><value>22:00</value></option>
|
||||
<option><value>22:30</value></option>
|
||||
<option><value>23:00</value></option>
|
||||
<option><value>23:30</value></option>
|
||||
</field>
|
||||
</x>
|
||||
</feature>
|
||||
</iq>
|
||||
*/
|
||||
|
||||
private readonly FeatureNeg m_FeatureNeg = new FeatureNeg();
|
||||
|
||||
public FeatureNegIq()
|
||||
{
|
||||
AddChild(m_FeatureNeg);
|
||||
GenerateId();
|
||||
}
|
||||
|
||||
public FeatureNegIq(IqType type) : this()
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public FeatureNeg FeatureNeg
|
||||
{
|
||||
get { return m_FeatureNeg; }
|
||||
}
|
||||
}
|
||||
}
|
142
ASC.Xmpp.Core/protocol/extensions/filetransfer/File.cs
Normal file
142
ASC.Xmpp.Core/protocol/extensions/filetransfer/File.cs
Normal file
@ -0,0 +1,142 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.utils;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.filetransfer
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for File.
|
||||
/// </summary>
|
||||
public class File : Element
|
||||
{
|
||||
/*
|
||||
Example 1:
|
||||
<file xmlns='http://jabber.org/protocol/si/profile/file-transfer'
|
||||
name='test.txt'
|
||||
size='1022'/>
|
||||
|
||||
Example 2:
|
||||
<file xmlns='http://jabber.org/protocol/si/profile/file-transfer'
|
||||
name='test.txt'
|
||||
size='1022'
|
||||
hash='552da749930852c69ae5d2141d3766b1'
|
||||
date='1969-07-21T02:56:15Z'>
|
||||
|
||||
<desc>This is a test. If this were a real file...</desc>
|
||||
</file>
|
||||
|
||||
Example 3:
|
||||
<file xmlns='http://jabber.org/protocol/si/profile/file-transfer'>
|
||||
<range offset='252' length='179'/>
|
||||
</file>
|
||||
|
||||
<xs:element name='file'>
|
||||
<xs:complexType>
|
||||
<xs:sequence minOccurs='0'>
|
||||
<xs:element name='desc' type='xs:string'/>
|
||||
<xs:element ref='range'/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name='date' type='xs:dateTime' use='optional'/>
|
||||
<xs:attribute name='hash' type='xs:string' use='optional'/>
|
||||
<xs:attribute name='name' type='xs:string' use='required'/>
|
||||
<xs:attribute name='size' type='xs:integer' use='required'/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
*/
|
||||
|
||||
public File()
|
||||
{
|
||||
TagName = "file";
|
||||
Namespace = Uri.SI_FILE_TRANSFER;
|
||||
}
|
||||
|
||||
public File(string name, long size) : this()
|
||||
{
|
||||
Name = name;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The file name. Its required
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return GetAttribute("name"); }
|
||||
set { SetAttribute("name", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Size of the file. This is required
|
||||
/// </summary>
|
||||
public long Size
|
||||
{
|
||||
get { return GetAttributeLong("size"); }
|
||||
set { SetAttribute("size", value.ToString()); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a Hash checksum of the file
|
||||
/// </summary>
|
||||
public string Hash
|
||||
{
|
||||
get { return GetAttribute("hash"); }
|
||||
set { SetAttribute("hash", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// file date
|
||||
/// </summary>
|
||||
public DateTime Date
|
||||
{
|
||||
get { return Time.ISO_8601Date(GetAttribute("date")); }
|
||||
set { SetAttribute("date", Time.ISO_8601Date(value)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// is used to provide a sender-generated description of the file so the receiver can better understand what is being sent. It MUST NOT be sent in the result.
|
||||
/// </summary>
|
||||
public string Description
|
||||
{
|
||||
get { return GetTag("desc"); }
|
||||
set { SetTag("desc", value); }
|
||||
}
|
||||
|
||||
public Range Range
|
||||
{
|
||||
get
|
||||
{
|
||||
Element range = SelectSingleElement(typeof (Range));
|
||||
if (range != null)
|
||||
return range as Range;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
RemoveTag(typeof (Range));
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
65
ASC.Xmpp.Core/protocol/extensions/filetransfer/Range.cs
Normal file
65
ASC.Xmpp.Core/protocol/extensions/filetransfer/Range.cs
Normal file
@ -0,0 +1,65 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.filetransfer
|
||||
{
|
||||
/// <summary>
|
||||
/// When range is sent in the offer, it should have no attributes. This signifies that the sender can do ranged transfers. When no range element is sent in the Stream Initiation result, the Sender MUST send the complete file starting at offset 0. More generally, data is sent over the stream byte for byte starting at the offset position for the length specified.
|
||||
/// </summary>
|
||||
public class Range : Element
|
||||
{
|
||||
/*
|
||||
<range offset='252' length='179'/>
|
||||
*/
|
||||
|
||||
public Range()
|
||||
{
|
||||
TagName = "range";
|
||||
Namespace = Uri.SI_FILE_TRANSFER;
|
||||
}
|
||||
|
||||
public Range(long offset, long length) : this()
|
||||
{
|
||||
Offset = offset;
|
||||
Length = length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the position, in bytes, to start transferring the file data from. This defaults to zero (0) if not specified.
|
||||
/// </summary>
|
||||
public long Offset
|
||||
{
|
||||
get { return GetAttributeLong("offset"); }
|
||||
set { SetAttribute("offset", value.ToString()); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the number of bytes to retrieve starting at offset. This defaults to the length of the file from offset to the end.
|
||||
/// </summary>
|
||||
public long Length
|
||||
{
|
||||
get { return GetAttributeLong("length"); }
|
||||
set { SetAttribute("length", value.ToString()); }
|
||||
}
|
||||
}
|
||||
}
|
142
ASC.Xmpp.Core/protocol/extensions/geoloc/GeoLoc.cs
Normal file
142
ASC.Xmpp.Core/protocol/extensions/geoloc/GeoLoc.cs
Normal file
@ -0,0 +1,142 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using System;
|
||||
using ASC.Xmpp.Core.utils;
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.geoloc
|
||||
{
|
||||
/*
|
||||
|
||||
Element Name Inclusion Datatype Definition
|
||||
|
||||
alt MAY xs:decimal Altitude in meters above or below sea level
|
||||
bearing MAY xs:decimal GPS bearing (direction in which the entity is heading to reach its next waypoint), measured in decimal degrees relative to true north [2]
|
||||
datum MAY xs:string GPS datum [3]
|
||||
description MAY xs:string A natural-language description of the location
|
||||
error MAY xs:decimal Horizontal GPS error in arc minutes
|
||||
lat MUST xs:decimal Latitude in decimal degrees North
|
||||
lon MUST xs:decimal Longitude in decimal degrees East
|
||||
timestamp MAY xs:datetime UTC timestamp specifying the moment when the reading was taken (MUST conform to the DateTime profile of Jabber Date and Time Profiles [4])
|
||||
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// XEP-0080 Geographical Location (GeoLoc) This JEP defines a format for capturing data about an entity's geographical location (geoloc). The namespace defined herein is intended to provide a semi-structured format for describing a geographical location that may change fairly frequently, where the geoloc information is provided as Global Positioning System (GPS) coordinates.
|
||||
/// </summary>
|
||||
public class GeoLoc : Element
|
||||
{
|
||||
#region << Constructors >>
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public GeoLoc()
|
||||
{
|
||||
TagName = "geoloc";
|
||||
Namespace = Uri.GEOLOC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="Latitude"> </param>
|
||||
/// <param name="Longitude"> </param>
|
||||
public GeoLoc(double latitude, double longitude) : this()
|
||||
{
|
||||
Latitude = latitude;
|
||||
Longitude = longitude;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// A natural-language description of the location
|
||||
/// </summary>
|
||||
public string Description
|
||||
{
|
||||
get { return GetTag("description"); }
|
||||
set { SetTag("description", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GPS datum
|
||||
/// </summary>
|
||||
public string Datum
|
||||
{
|
||||
get { return GetTag("datum"); }
|
||||
set { SetTag("datum", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Latitude in decimal degrees North
|
||||
/// </summary>
|
||||
public double Latitude
|
||||
{
|
||||
get { return GetTagDouble("lat"); }
|
||||
set { SetTag("lat", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Longitude in decimal degrees East
|
||||
/// </summary>
|
||||
public double Longitude
|
||||
{
|
||||
get { return GetTagDouble("lon"); }
|
||||
set { SetTag("lon", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Altitude in meters above or below sea level
|
||||
/// </summary>
|
||||
public double Altitude
|
||||
{
|
||||
get { return GetTagDouble("alt"); }
|
||||
set { SetTag("alt", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GPS bearing (direction in which the entity is heading to reach its next waypoint), measured in decimal degrees relative to true north
|
||||
/// </summary>
|
||||
public double Bearing
|
||||
{
|
||||
get { return GetTagDouble("bearing"); }
|
||||
set { SetTag("bearing", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal GPS error in arc minutes
|
||||
/// </summary>
|
||||
public double Error
|
||||
{
|
||||
get { return GetTagDouble("error"); }
|
||||
set { SetTag("error", value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UTC timestamp specifying the moment when the reading was taken
|
||||
/// </summary>
|
||||
public DateTime Timestamp
|
||||
{
|
||||
get { return Time.ISO_8601Date(GetTag("timestamp")); }
|
||||
set { SetTag("timestamp", Time.ISO_8601Date(value)); }
|
||||
}
|
||||
}
|
||||
}
|
59
ASC.Xmpp.Core/protocol/extensions/geoloc/GeoLocIq.cs
Normal file
59
ASC.Xmpp.Core/protocol/extensions/geoloc/GeoLocIq.cs
Normal file
@ -0,0 +1,59 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.protocol.client;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.geoloc
|
||||
{
|
||||
/// <summary>
|
||||
/// a GeoLoc InfoQuery
|
||||
/// </summary>
|
||||
public class GeoLocIq : IQ
|
||||
{
|
||||
private readonly GeoLoc m_GeoLoc = new GeoLoc();
|
||||
|
||||
public GeoLocIq()
|
||||
{
|
||||
base.Query = m_GeoLoc;
|
||||
GenerateId();
|
||||
}
|
||||
|
||||
public GeoLocIq(IqType type) : this()
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public GeoLocIq(IqType type, Jid to) : this(type)
|
||||
{
|
||||
To = to;
|
||||
}
|
||||
|
||||
public GeoLocIq(IqType type, Jid to, Jid from) : this(type, to)
|
||||
{
|
||||
From = from;
|
||||
}
|
||||
|
||||
public new GeoLoc Query
|
||||
{
|
||||
get { return m_GeoLoc; }
|
||||
}
|
||||
}
|
||||
}
|
53
ASC.Xmpp.Core/protocol/extensions/html/Body.cs
Normal file
53
ASC.Xmpp.Core/protocol/extensions/html/Body.cs
Normal file
@ -0,0 +1,53 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.html
|
||||
{
|
||||
/// <summary>
|
||||
/// The Body Element of a XHTML message
|
||||
/// </summary>
|
||||
public class Body : Element
|
||||
{
|
||||
public Body()
|
||||
{
|
||||
TagName = "body";
|
||||
Namespace = Uri.XHTML;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public string InnerHtml
|
||||
{
|
||||
get
|
||||
{
|
||||
// Thats a HACK
|
||||
string xml = ToString();
|
||||
|
||||
int start = xml.IndexOf(">");
|
||||
int end = xml.LastIndexOf("</" + TagName + ">");
|
||||
|
||||
return xml.Substring(start + 1, end - start - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
61
ASC.Xmpp.Core/protocol/extensions/html/Html.cs
Normal file
61
ASC.Xmpp.Core/protocol/extensions/html/Html.cs
Normal file
@ -0,0 +1,61 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.html
|
||||
{
|
||||
/*
|
||||
* <message>
|
||||
* <body>hi!</body>
|
||||
* <html xmlns='http://jabber.org/protocol/xhtml-im'>
|
||||
* <body xmlns='http://www.w3.org/1999/xhtml'>
|
||||
* <p style='font-weight:bold'>hi!</p>
|
||||
* </body>
|
||||
* </html>
|
||||
* </message>
|
||||
*/
|
||||
|
||||
public class Html : Element
|
||||
{
|
||||
public Html()
|
||||
{
|
||||
TagName = "html";
|
||||
Namespace = Uri.XHTML_IM;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Body Element of the XHTML Message
|
||||
/// </summary>
|
||||
public Body Body
|
||||
{
|
||||
get { return SelectSingleElement(typeof (Body)) as Body; }
|
||||
set
|
||||
{
|
||||
if (HasTag(typeof (Body)))
|
||||
RemoveTag(typeof (Body));
|
||||
|
||||
if (value != null)
|
||||
AddChild(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
ASC.Xmpp.Core/protocol/extensions/ibb/Base.cs
Normal file
45
ASC.Xmpp.Core/protocol/extensions/ibb/Base.cs
Normal file
@ -0,0 +1,45 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
using ASC.Xmpp.Core.utils.Xml.Dom;
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.ibb
|
||||
{
|
||||
/// <summary>
|
||||
/// IBB base class
|
||||
/// </summary>
|
||||
public abstract class Base : Element
|
||||
{
|
||||
public Base()
|
||||
{
|
||||
Namespace = Uri.IBB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sid
|
||||
/// </summary>
|
||||
public string Sid
|
||||
{
|
||||
get { return GetAttribute("sid"); }
|
||||
set { SetAttribute("sid", value); }
|
||||
}
|
||||
}
|
||||
}
|
47
ASC.Xmpp.Core/protocol/extensions/ibb/Close.cs
Normal file
47
ASC.Xmpp.Core/protocol/extensions/ibb/Close.cs
Normal file
@ -0,0 +1,47 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.ibb
|
||||
{
|
||||
/*
|
||||
<close xmlns='http://jabber.org/protocol/ibb' sid='mySID'/>
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class Close : Base
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Close()
|
||||
{
|
||||
TagName = "close";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sid"> </param>
|
||||
public Close(string sid) : this()
|
||||
{
|
||||
Sid = sid;
|
||||
}
|
||||
}
|
||||
}
|
75
ASC.Xmpp.Core/protocol/extensions/ibb/Data.cs
Normal file
75
ASC.Xmpp.Core/protocol/extensions/ibb/Data.cs
Normal file
@ -0,0 +1,75 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Copyright (c) 2003-2008 by AG-Software *
|
||||
* All Rights Reserved. *
|
||||
* Contact information for AG-Software is available at http://www.ag-software.de *
|
||||
* *
|
||||
* Licence: *
|
||||
* The agsXMPP SDK is released under a dual licence *
|
||||
* agsXMPP can be used under either of two licences *
|
||||
* *
|
||||
* A commercial licence which is probably the most appropriate for commercial *
|
||||
* corporate use and closed source projects. *
|
||||
* *
|
||||
* The GNU Public License (GPL) is probably most appropriate for inclusion in *
|
||||
* other open source projects. *
|
||||
* *
|
||||
* See README.html for details. *
|
||||
* *
|
||||
* For general enquiries visit our website at: *
|
||||
* http://www.ag-software.de *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
namespace ASC.Xmpp.Core.protocol.extensions.ibb
|
||||
{
|
||||
/*
|
||||
<data xmlns='http://jabber.org/protocol/ibb' sid='mySID' seq='0'>
|
||||
qANQR1DBwU4DX7jmYZnncmUQB/9KuKBddzQH+tZ1ZywKK0yHKnq57kWq+RFtQdCJ
|
||||
WpdWpR0uQsuJe7+vh3NWn59/gTc5MDlX8dS9p0ovStmNcyLhxVgmqS8ZKhsblVeu
|
||||
IpQ0JgavABqibJolc3BKrVtVV1igKiX/N7Pi8RtY1K18toaMDhdEfhBRzO/XB0+P
|
||||
AQhYlRjNacGcslkhXqNjK5Va4tuOAPy2n1Q8UUrHbUd0g+xJ9Bm0G0LZXyvCWyKH
|
||||
kuNEHFQiLuCY6Iv0myq6iX6tjuHehZlFSh80b5BVV9tNLwNR5Eqz1klxMhoghJOA
|
||||
</data>
|
||||
|
||||
<xs:element name='data'>
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base='xs:string'>
|
||||
<xs:attribute name='sid' type='xs:string' use='required'/>
|
||||
<xs:attribute name='seq' type='xs:string' use='required'/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class Data : Base
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public Data()
|
||||
{
|
||||
TagName = "data";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="sid"> </param>
|
||||
/// <param name="seq"> </param>
|
||||
public Data(string sid, int seq) : this()
|
||||
{
|
||||
Sid = sid;
|
||||
Sequence = seq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the sequence
|
||||
/// </summary>
|
||||
public int Sequence
|
||||
{
|
||||
get { return GetAttributeInt("seq"); }
|
||||
set { SetAttribute("seq", value); }
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user