Skip to content

Commit

Permalink
Bump version to v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan130200 committed Apr 17, 2024
1 parent 9c10ba3 commit 3838f32
Show file tree
Hide file tree
Showing 96 changed files with 5,077 additions and 4,750 deletions.
36 changes: 36 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
root = true

[*]
indent_style = tab
encoding = utf-8

[*.{xml,csproj,json}]
indent_size = 4
tab_size = 4

[*.cs]
indent_size = 4
tab_size = 4

dotnet_style_qualification_for_field = true
dotnet_style_qualification_for_property = true
dotnet_style_qualification_for_method = true
dotnet_style_qualification_for_event = true
csharp_prefer_simple_using_statement = false
dotnet_style_require_accessibility_modifiers = true
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true
dotnet_style_prefer_collection_expression = false

csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = false:silent
csharp_style_conditional_delegate_call = true:silent
csharp_style_prefer_primary_constructors = false:silent
csharp_style_prefer_top_level_statements = false:silent

dotnet_diagnostic.CS1998.severity = error
dotnet_diagnostic.CS1591.severity = none
dotnet_diagnostic.CA2255.severity = none
dotnet_diagnostic.IDE0060.severity = none
dotnet_diagnostic.IDE0280.severity = error
73 changes: 21 additions & 52 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,24 @@

[![github](https://img.shields.io/badge/XmppSharp-1?style=plastic&logo=github&label=Github)](https://github.com/nathan130200/XmppSharp) [![nuget](https://img.shields.io/badge/XmppSharp-1?style=plastic&logo=nuget&label=NuGet&color=blue)](https://www.nuget.org/packages/XmppSharp/)

A manipulation library and utility for XMPP inspired by the classic agsXMPP library (developed by [AG-Software](https://www.ag-software.net)). The main objective of this library is to reduce the level of unnecessary verbosity for constructing XML tags.

# Changelog

### 1.4.0

- **Breaking changes**: Some types renamed or will be moved to another files/namespaces!
- Added target support for .NET 6.
- Add service discovery elements.
- Enhance JID construction.
- Make JID records types again, but keep setters instead init-only.
- `Jid.Empty` now provide a empty jid instance.
- `Jid(string jid)` contructor will try parse as full jid before set domain component.
- Added `ReadOnlyJid` that wraps Jid instance into a read-only struct for immutable/exposing.
- Added `ReadOnlyJid.Empty` static helper to fast create its instance.
- `ReadOnlyJid` has proper ways to cast between `Jid` and other `ReadOnlyJid` instances.
- Added helper method to convert `XElement` objects into Xmpp Sharp `Element` objects.
- Begin add XML docstrings in types/methods/fields/properties etc.

### 1.4.1

- Fix NRE while setting attribute with `SetAttributeValue`

### 1.4.2

- Minor changes & fixes.
- Added helper methods to fast get functions to parse primitive types.

### 2.0.0

- 2.0 is here! I was finally able to migrate to an improved system using `XElement`.
- First of all, removed ALL AI-generated docstrings. I think it was one of the most bizarre ideas I've ever had and it didn't work out very well, it generated a lot of redundant things that weren't well explained. Then soon I will calmly document everything.
- Some things **_may_** break! For example, how to create/declare your elements. But I did everything I could to maintain the compatibility layer between old `Element` class and `XElement` class!
- By the way, most of the xmpp elements remained the same, the way to access/define data also remained almost the same.
- `CDATA` and `Comment` nodes are supported now when parsing (Even though it is not recommended to use these types of nodes in the XMPP protocol standards, this depends on each developer and the needs of each project.).
- Added extra helper methods around XElement class.
- All XMPP elements are now around `XElement` class and all `System.Xml.Linq` related.

### 2.0.1

- Minor bug fixes around `XmppSharp.Jid` equality comparer.

### 3.0

- Rollback using builtin .NET xml types in `System.Xml.Linq`

> I'm so sorry for reverting this change). I've found a critical issue around namespace declarations in XElement, so i've decided to do not keep using. Instead i've reimplemente again `Element` classes now with support for `Cdata`, `Text` and `Comment` nodes.

- All other features still the same (extend to `Element` class and etc...)

### Notes
I ask users to report any bugs that may exist. Even though I carry out internal tests on my XMPP server, there may be some bug or other that goes unnoticed during the tests.
A manipulation library and utility with the main objective to reduce the level of unnecessary verbosity for constructing XML tags for XMPP protocol.

<hr/>

<b>Updates</b>

- 1.4
- Last stable version before rework.

- 2.0
- Mistakenly changed to `XElement` and rolled back after discovering critical problem when declaring/replacing namespaces.

- 3.0
- Bring back own XML specific classes, now supporting `Element` with extra nodes `Comment`, `Cdata`, `Text`.

- 3.1
- Add enhanced utilities & helper methods to interact with element and nodes.

<hr/>

Don't forget to report __XMPP#__ bugs & crashes on github even with unit tests we can encounter some unexpected bug!
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# XMPP#
A manipulation library and utility for XMPP inspired by the classic agsXMPP library (developed by [AG-Software](https://www.ag-software.net))

The main objective of this library is to reduce the level of unnecessary verbosity for constructing XML tags.
A manipulation library and utility with the main objective to reduce the level of unnecessary verbosity for constructing XML tags for XMPP protocol.

<hr/>

### XMPP Parser

Expand Down
110 changes: 110 additions & 0 deletions XmppSharp.Test/AttributeHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Security.Authentication;
using XmppSharp.Dom;
using XmppSharp.Protocol.Sasl;
using XmppSharp.Protocol.ServiceDiscovery.IdentityValues;
using XmppSharp.Protocol.Tls;

namespace XmppSharp.Test;

[TestClass]
public class AttributeHelperTests
{
Element element = default!;

[TestInitialize]
public void Initialize()
=> element = new("root");

[TestCleanup]
public void Cleanup()
=> element = null!;

[TestMethod]
public void WithXmppEnum()
{
WithXmppEnum(TlsPolicy.Required, "required");
WithXmppEnum(TlsPolicy.Optional, "optional");
WithXmppEnum(MechanismType.Plain, "PLAIN");
WithXmppEnum(MechanismType.DigestMD5, "DIGEST-MD5");
WithXmppEnum(ConferenceValues.Text, "text");
WithXmppEnum(PubSubValues.Owned, "pep");
WithXmppEnum(PubSubValues.Service, "service");
WithXmppEnum(GatewayValues.Discord, "discord");
WithXmppEnum(GatewayValues.Facebook, "facebook");
WithXmppEnum(GatewayValues.AIM, "aim");
}

void WithXmppEnum<T>(T value, string rawValue) where T : struct, Enum
{
Debug.WriteLine($"WithXmppEnum<{typeof(T).Name}>: raw value={rawValue}");

element.SetAttribute("data", value.ToXmppName());
Assert.AreEqual(rawValue, element.GetAttribute("data"));

var actual = XmppEnum.ParseOrThrow<T>(element.GetAttribute("data")!);
Assert.AreEqual(value, actual);

Debug.WriteLine($" {typeof(T).Name}.{actual}: parsed? {value.Equals(actual)}");
ParserTests.PrintResult(element);
Debug.WriteLine(" ---------------------------------\n");
}

enum EnumTestType
{
CSharp,
VisualBasic
}

[TestMethod]
public void WithBitwise()
{
WithBitwise(FileAccess.ReadWrite, true);
WithBitwise(SslProtocols.Tls12 | SslProtocols.Tls13, true);
}

[TestMethod]
public void WithBitwiseAsString()
{
WithBitwise(FileAccess.ReadWrite, false);
WithBitwise(SslProtocols.Tls12 | SslProtocols.Tls13, false);
}

[TestMethod]
public void WithString()
{
WithBitwise(EnumTestType.CSharp, false);
WithBitwise(EnumTestType.VisualBasic, false);
WithBitwise(ConferenceValues.Text, false);
WithBitwise(TestTimeout.Infinite, false);
WithBitwise(TestIdGenerationStrategy.FullyQualified, false);
WithBitwise(ThreadWaitReason.ExecutionDelay, false);
WithBitwise(ThreadWaitReason.LpcReply, false);
WithBitwise(ThreadPriority.AboveNormal, false);
WithBitwise(ThreadPriority.Highest, false);
}

void WithBitwise<T>(T value, bool isNumber, [CallerMemberName] string func = default!) where T : struct, Enum
{
var typeName = typeof(T).Name;
object rawValue = Convert.ChangeType(value, Enum.GetUnderlyingType(typeof(T)));

element.SetAttributeEnum("data", (T?)value, isNumber);
Assert.AreEqual(isNumber ? rawValue.ToString() : value.ToString(), element.GetAttribute("data"));

var actual = element.GetAttributeEnum<T>("data", isNumber: isNumber);
Debug.WriteLine($"{func}<{typeName}>: {value} ({rawValue} @ {rawValue.GetType().Name})");

var isParsed = value.Equals(actual);

Debug.WriteLine($" {typeName}.{actual}: parsed? {isParsed}\n");

ParserTests.PrintResult(element);

Debug.WriteLine("\n---------------------------------\n");

if (!isParsed)
Assert.Fail();
}
}
Loading

0 comments on commit 3838f32

Please sign in to comment.