Skip to content

Commit 83d3929

Browse files
committed
Merge branch 'eventengine-poc' into eventengine/handshake-handler
2 parents 5aae315 + 839dda5 commit 83d3929

23 files changed

+191
-101
lines changed

.pubnub.yml

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: c-sharp
2-
version: "6.16.0"
2+
version: "6.17.0"
33
schema: 1
44
scm: github.com/pubnub/c-sharp
55
changelog:
6+
- date: 2023-07-10
7+
version: v6.17.0
8+
changes:
9+
- type: improvement
10+
text: "Validate json string before deserialization."
611
- date: 2023-05-18
712
version: v6.16.0
813
changes:
@@ -720,7 +725,7 @@ features:
720725
- QUERY-PARAM
721726
supported-platforms:
722727
-
723-
version: Pubnub 'C#' 6.16.0
728+
version: Pubnub 'C#' 6.17.0
724729
platforms:
725730
- Windows 10 and up
726731
- Windows Server 2008 and up
@@ -730,7 +735,7 @@ supported-platforms:
730735
- .Net Framework 4.5
731736
- .Net Framework 4.6.1+
732737
-
733-
version: PubnubPCL 'C#' 6.16.0
738+
version: PubnubPCL 'C#' 6.17.0
734739
platforms:
735740
- Xamarin.Android
736741
- Xamarin.iOS
@@ -750,7 +755,7 @@ supported-platforms:
750755
- .Net Core
751756
- .Net 6.0
752757
-
753-
version: PubnubUWP 'C#' 6.16.0
758+
version: PubnubUWP 'C#' 6.17.0
754759
platforms:
755760
- Windows Phone 10
756761
- Universal Windows Apps
@@ -774,7 +779,7 @@ sdks:
774779
distribution-type: source
775780
distribution-repository: GitHub
776781
package-name: Pubnub
777-
location: https://github.com/pubnub/c-sharp/releases/tag/v6.16.0.0
782+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.17.0.0
778783
requires:
779784
-
780785
name: ".Net"
@@ -1057,7 +1062,7 @@ sdks:
10571062
distribution-type: source
10581063
distribution-repository: GitHub
10591064
package-name: PubNubPCL
1060-
location: https://github.com/pubnub/c-sharp/releases/tag/v6.16.0.0
1065+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.17.0.0
10611066
requires:
10621067
-
10631068
name: ".Net Core"
@@ -1416,7 +1421,7 @@ sdks:
14161421
distribution-type: source
14171422
distribution-repository: GitHub
14181423
package-name: PubnubUWP
1419-
location: https://github.com/pubnub/c-sharp/releases/tag/v6.16.0.0
1424+
location: https://github.com/pubnub/c-sharp/releases/tag/v6.17.0.0
14201425
requires:
14211426
-
14221427
name: "Universal Windows Platform Development"

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v6.17.0 - July 10 2023
2+
-----------------------------
3+
- Modified: validate json string before deserialization.
4+
15
v6.16.0 - May 18 2023
26
-----------------------------
37
- Modified: replaced ConcurrentDictionary class file with System.Collections.Concurrent package for all target frameworks except .net 3.5/4.0.

src/Api/PubnubApi/Builder/StatusBuilder.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public PNStatus CreateStatusResponse<T>(PNOperationType type, PNStatusCategory c
5555
}
5656
else
5757
{
58-
Dictionary<string, object> deserializeStatus = jsonLibrary.DeserializeToDictionaryOfObject(targetException.Message);
58+
Dictionary<string, object> deserializeStatus = null;
59+
if (jsonLibrary.IsDictionaryCompatible(targetException.Message, type))
60+
{
61+
deserializeStatus = jsonLibrary.DeserializeToDictionaryOfObject(targetException.Message);
62+
}
5963
if (deserializeStatus != null && deserializeStatus.Count >= 1
6064
&& deserializeStatus.ContainsKey("error") && string.Equals(deserializeStatus["error"].ToString(), "true", StringComparison.OrdinalIgnoreCase)
6165
&& deserializeStatus.ContainsKey("status") && Int32.TryParse(deserializeStatus["status"].ToString(), out serverErrorStatusCode))

src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using PubnubApi.EventEngine.Subscribe.Common;
33

44
namespace PubnubApi.EventEngine.Subscribe.Events {
5+
public class UnsubscribeAllEvent : Core.IEvent {
6+
}
7+
58
public class SubscriptionChangedEvent : Core.IEvent {
69
public IEnumerable<string> Channels;
710
public IEnumerable<string> ChannelGroups;

src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeFailedState.cs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public override TransitionResult Transition(IEvent e)
1414
{
1515
return e switch
1616
{
17+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
18+
{
19+
},
20+
1721
Events.SubscriptionChangedEvent subscriptionChanged => new HandshakingState()
1822
{
1923
Channels = subscriptionChanged.Channels, ChannelGroups = subscriptionChanged.ChannelGroups,

src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeReconnectingState.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ internal class HandshakeReconnectingState : Core.State
1313
public int MaxConnectionRetry;
1414
public int AttemptedRetries;
1515

16-
1716
public override IEnumerable<IEffectInvocation> OnEntry => new HandshakeReconnectInvocation()
1817
{ Channels = this.Channels, ChannelGroups = this.ChannelGroups, Policy = this.RetryPolicy, MaxConnectionRetry = this.MaxConnectionRetry, AttemptedRetries = this.AttemptedRetries }.AsArray();
1918
public override IEnumerable<IEffectInvocation> OnExit { get; } = new CancelHandshakeReconnectInvocation().AsArray();
@@ -22,6 +21,10 @@ public override TransitionResult Transition(IEvent e)
2221
{
2322
return e switch
2423
{
24+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
25+
{
26+
},
27+
2528
Events.SubscriptionChangedEvent subscriptionChanged => new HandshakingState()
2629
{
2730
Channels = subscriptionChanged.Channels, ChannelGroups = subscriptionChanged.ChannelGroups,

src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeStoppedState.cs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public override TransitionResult Transition(IEvent e)
1414
{
1515
return e switch
1616
{
17+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
18+
{
19+
},
20+
1721
Events.SubscriptionChangedEvent subscriptionChanged => new HandshakingState()
1822
{
1923
Channels = subscriptionChanged.Channels, ChannelGroups = subscriptionChanged.ChannelGroups,

src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakingState.cs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public override TransitionResult Transition(IEvent e)
1919
{
2020
return e switch
2121
{
22+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
23+
{
24+
},
25+
2226
Events.SubscriptionChangedEvent subscriptionChanged => new States.HandshakingState()
2327
{
2428
Channels = subscriptionChanged.Channels, ChannelGroups = subscriptionChanged.ChannelGroups

src/Api/PubnubApi/EventEngine/Subscribe/States/ReceiveFailedState.cs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public override TransitionResult Transition(IEvent e)
1919
{
2020
return e switch
2121
{
22+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
23+
{
24+
},
25+
2226
Events.SubscriptionChangedEvent subscriptionChanged => new ReceivingState()
2327
{
2428
Channels = subscriptionChanged.Channels,

src/Api/PubnubApi/EventEngine/Subscribe/States/ReceiveReconnectingState.cs

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public override TransitionResult Transition(IEvent e)
2222
{
2323
return e switch
2424
{
25+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
26+
{
27+
},
28+
2529
Events.SubscriptionChangedEvent subscriptionChanged => new ReceivingState()
2630
{
2731
Channels = subscriptionChanged.Channels,

src/Api/PubnubApi/EventEngine/Subscribe/States/ReceiveStoppedState.cs

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public override TransitionResult Transition(IEvent e)
1616
{
1717
return e switch
1818
{
19+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
20+
{
21+
},
22+
1923
Events.SubscriptionChangedEvent subscriptionChanged => new ReceivingState()
2024
{
2125
Channels = subscriptionChanged.Channels,

src/Api/PubnubApi/EventEngine/Subscribe/States/ReceivingState.cs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public override TransitionResult Transition(IEvent e)
2121
{
2222
return e switch
2323
{
24+
Events.UnsubscribeAllEvent unsubscribeAll => new UnsubscribedState()
25+
{
26+
},
27+
2428
Events.ReceiveSuccessEvent receiveSuccess => new ReceivingState()
2529
{
2630
Channels = receiveSuccess.Channels,

src/Api/PubnubApi/NewtonsoftJsonDotNet.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public object BuildJsonObject(string jsonString)
100100
public bool IsDictionaryCompatible(string jsonString, PNOperationType operationType)
101101
{
102102
bool ret = false;
103-
if (IsValidJson(jsonString, operationType))
103+
if (JsonFastCheck(jsonString) && IsValidJson(jsonString, operationType))
104104
{
105105
try
106106
{
@@ -1234,14 +1234,19 @@ public virtual T DeserializeToObject<T>(List<object> listObject)
12341234

12351235
public Dictionary<string, object> DeserializeToDictionaryOfObject(string jsonString)
12361236
{
1237+
Dictionary<string, object> result = null;
12371238
try
12381239
{
1239-
return JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
1240+
if (JsonFastCheck(jsonString))
1241+
{
1242+
result = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
1243+
}
12401244
}
12411245
catch
12421246
{
1243-
return null;
1247+
//ignore
12441248
}
1249+
return result;
12451250
}
12461251

12471252
public Dictionary<string, object> ConvertToDictionaryObject(object localContainer)
@@ -1369,6 +1374,10 @@ public object[] ConvertToObjectArray(object localContainer)
13691374
return ret;
13701375
}
13711376

1377+
public static bool JsonFastCheck(string rawJson) {
1378+
var c = rawJson.TrimStart()[0];
1379+
return c == '[' || c == '{';
1380+
}
13721381
private static object ConvertJTokenToObject(JToken token)
13731382
{
13741383
if (token == null)

src/Api/PubnubApi/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
[assembly: AssemblyProduct("Pubnub C# SDK")]
1212
[assembly: AssemblyCopyright("Copyright © 2021")]
1313
[assembly: AssemblyTrademark("")]
14-
[assembly: AssemblyVersion("6.16.0.0")]
15-
[assembly: AssemblyFileVersion("6.16.0.0")]
14+
[assembly: AssemblyVersion("6.17.0.0")]
15+
[assembly: AssemblyFileVersion("6.17.0.0")]
1616
// Setting ComVisible to false makes the types in this assembly not visible
1717
// to COM components. If you need to access a type in this assembly from
1818
// COM, set the ComVisible attribute to true on that type.

src/Api/PubnubApi/PubnubCoreBase.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,11 @@ private PNStatus GetStatusIfError<T>(RequestState<T> asyncRequestState, string j
14141414
else if (deserializeStatus.Count >= 1 && deserializeStatus.ContainsKey("error") && deserializeStatus.ContainsKey("status") && Int32.TryParse(deserializeStatus["status"].ToString(), out statusCode) && statusCode > 0)
14151415
{
14161416
string errorMessageJson = deserializeStatus["error"].ToString();
1417-
Dictionary<string, object> errorDic = jsonLib.DeserializeToDictionaryOfObject(errorMessageJson);
1417+
Dictionary<string, object> errorDic = null;
1418+
if (jsonLib.IsDictionaryCompatible(errorMessageJson, type))
1419+
{
1420+
errorDic = jsonLib.DeserializeToDictionaryOfObject(errorMessageJson);
1421+
}
14181422
if (errorDic != null && errorDic.Count > 0 && errorDic.ContainsKey("message")
14191423
&& statusCode != 200 && pubnubConfig.TryGetValue(PubnubInstance.InstanceId, out currentConfig))
14201424
{
@@ -1425,8 +1429,12 @@ private PNStatus GetStatusIfError<T>(RequestState<T> asyncRequestState, string j
14251429
}
14261430
else if (deserializeStatus.Count >= 1 && deserializeStatus.ContainsKey("status") && string.Equals(deserializeStatus["status"].ToString(), "error", StringComparison.OrdinalIgnoreCase) && deserializeStatus.ContainsKey("error"))
14271431
{
1432+
Dictionary<string, object> errorDic = null;
14281433
string errorMessageJson = deserializeStatus["error"].ToString();
1429-
Dictionary<string, object> errorDic = jsonLib.DeserializeToDictionaryOfObject(errorMessageJson);
1434+
if (jsonLib.IsDictionaryCompatible(errorMessageJson, type))
1435+
{
1436+
errorDic = jsonLib.DeserializeToDictionaryOfObject(errorMessageJson);
1437+
}
14301438
if (errorDic != null && errorDic.Count > 0 && errorDic.ContainsKey("code") && errorDic.ContainsKey("message"))
14311439
{
14321440
statusCode = PNStatusCodeHelper.GetHttpStatusCode(errorDic["code"].ToString());

src/Api/PubnubApiPCL/PubnubApiPCL.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515

1616
<PropertyGroup>
1717
<PackageId>PubnubPCL</PackageId>
18-
<PackageVersion>6.16.0.0</PackageVersion>
18+
<PackageVersion>6.17.0.0</PackageVersion>
1919
<Title>PubNub C# .NET - Web Data Push API</Title>
2020
<Authors>Pandu Masabathula</Authors>
2121
<Owners>PubNub</Owners>
2222
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2323
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2424
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2525
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
26-
<PackageReleaseNotes>Replaced ConcurrentDictionary class file with System.Collections.Concurrent package for all target frameworks except .net 3.5/4.0.
27-
Addressed threading issue on reading ConcurrentDictionary keys.</PackageReleaseNotes>
26+
<PackageReleaseNotes>Validate json string before deserialization.</PackageReleaseNotes>
2827
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
2928
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
3029
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/Api/PubnubApiUWP/PubnubApiUWP.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717
<PropertyGroup>
1818
<PackageId>PubnubUWP</PackageId>
19-
<PackageVersion>6.16.0.0</PackageVersion>
19+
<PackageVersion>6.17.0.0</PackageVersion>
2020
<Title>PubNub C# .NET - Web Data Push API</Title>
2121
<Authors>Pandu Masabathula</Authors>
2222
<Owners>PubNub</Owners>
2323
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2424
<PackageIconUrl>http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png</PackageIconUrl>
2525
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2626
<RepositoryUrl>https://github.com/pubnub/c-sharp/</RepositoryUrl>
27-
<PackageReleaseNotes>Replaced ConcurrentDictionary class file with System.Collections.Concurrent package for all target frameworks except .net 3.5/4.0.
28-
Addressed threading issue on reading ConcurrentDictionary keys.</PackageReleaseNotes>
27+
<PackageReleaseNotes>Validate json string before deserialization.</PackageReleaseNotes>
2928
<PackageTags>Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing</PackageTags>
3029
<!--<Summary>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Summary>-->
3130
<Description>PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously</Description>

src/UnitTests/AcceptanceTests/Steps/GrantTokenSteps.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public async Task WhenIGrantATokenSpecifyingThosePermissions()
393393
.ExecuteAsync();
394394
grantResult = pamGrantResult.Result;
395395
pnStatus = pamGrantResult.Status;
396-
if (pnStatus.Error)
396+
if (pnStatus != null && pnStatus.Error)
397397
{
398398
pnError = pn.JsonPluggableLibrary.DeserializeToObject<PubnubError>(pnStatus.ErrorData.Information);
399399
}
@@ -421,7 +421,7 @@ public async Task WhenIAttemptToGrantATokenSpecifyingThosePermissions()
421421
.ExecuteAsync();
422422
grantResult = pamGrantResult.Result;
423423
pnStatus = pamGrantResult.Status;
424-
if (pnStatus.Error)
424+
if (pnStatus != null && pnStatus.Error)
425425
{
426426
pnError = pn.JsonPluggableLibrary.DeserializeToObject<PubnubError>(pnStatus.ErrorData.Information);
427427
}

0 commit comments

Comments
 (0)