diff --git a/src/Api/PubnubApi/ClientNetworkStatus.cs b/src/Api/PubnubApi/ClientNetworkStatus.cs index c2e879dd8..c38cf9b36 100644 --- a/src/Api/PubnubApi/ClientNetworkStatus.cs +++ b/src/Api/PubnubApi/ClientNetworkStatus.cs @@ -35,11 +35,11 @@ internal static bool CheckInternetStatus(bool systemActive, PNOperationType } catch (AggregateException ae) { foreach (var ie in ae.InnerExceptions) { - PubnubConfiguation?.Logger?.Error($"AggregateException CheckInternetStatus : {ie.GetType().Name} {ie.Message}"); + PubnubConfiguation?.Logger?.Warn($"AggregateException CheckInternetStatus : {ie.GetType().Name} {ie.Message}"); } } catch (Exception ex) { - PubnubConfiguation?.Logger?.Error($"CheckInternetStatus Exception: {ex.Message}"); + PubnubConfiguation?.Logger?.Warn($"CheckInternetStatus Exception: {ex.Message}"); } return networkStatus; diff --git a/src/Api/PubnubApi/EndPoint/TokenManager.cs b/src/Api/PubnubApi/EndPoint/TokenManager.cs index 3be92c002..a82270271 100644 --- a/src/Api/PubnubApi/EndPoint/TokenManager.cs +++ b/src/Api/PubnubApi/EndPoint/TokenManager.cs @@ -1,12 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; using System.Text.RegularExpressions; -using System.Collections; -using System.Reflection; -using Newtonsoft.Json; -using PeterO.Cbor; +// using PeterO.Cbor; using System.Globalization; #if !NET35 && !NET40 using System.Collections.Concurrent; @@ -67,113 +63,9 @@ private static string GetDisplayableBytes(byte[] currentBytes) public PNTokenContent ParseToken(string token) { PNTokenContent result = null; - try - { - if (!string.IsNullOrEmpty(token) && token.Trim().Length > 0) - { - string refinedToken = token.Replace('_', '/').Replace('-', '+'); - byte[] tokenByteArray = Convert.FromBase64String(refinedToken); - logger?.Debug($"TokenManager Token Bytes = {GetDisplayableBytes(tokenByteArray)}"); - using (System.IO.MemoryStream ms = new System.IO.MemoryStream(tokenByteArray)) - { - CBORObject cborObj = CBORObject.DecodeFromBytes(tokenByteArray); - logger?.Debug($"RAW CBOR {cborObj.ToJSONString()}"); - - if (cborObj != null) - { - result = new PNTokenContent(); - result.Meta = new Dictionary(); - result.Resources = new PNTokenResources { - Channels = new Dictionary(), - ChannelGroups = new Dictionary(), - Uuids = new Dictionary(), - Users = new Dictionary(), - Spaces = new Dictionary() - }; - result.Patterns = new PNTokenPatterns { - Channels = new Dictionary(), - ChannelGroups = new Dictionary(), - Uuids = new Dictionary(), - Users = new Dictionary(), - Spaces = new Dictionary() - }; - ParseCBOR(cborObj, "", ref result); - } - - } - } - } - catch (Exception ex) - { - logger?.Error($"Error parsing token: {ex.Message} \n {ex.StackTrace}"); - } return result; } - private void ParseCBOR(CBORObject cbor, string parent, ref PNTokenContent pnGrantTokenDecoded) - { - foreach (KeyValuePair kvp in cbor.Entries) - { - if (kvp.Key.Type.ToString().Equals("ByteString", StringComparison.OrdinalIgnoreCase)) - { -#if NETSTANDARD10 || NETSTANDARD11 - UTF8Encoding utf8 = new UTF8Encoding(true, true); - byte[] keyBytes = kvp.Key.GetByteString(); - string key = utf8.GetString(keyBytes, 0, keyBytes.Length); -#else - string key = Encoding.ASCII.GetString(kvp.Key.GetByteString()); -#endif - ParseCBORValue(key, parent, kvp, ref pnGrantTokenDecoded); - } - else if (kvp.Key.Type.ToString().Equals("TextString", StringComparison.OrdinalIgnoreCase)) - { - logger?.Debug($"ParseCBOR TextString Key {kvp.Key}-{kvp.Value}-{kvp.Value.Type}"); - ParseCBORValue(kvp.Key.ToString(), parent, kvp, ref pnGrantTokenDecoded); - } - else - { - logger?.Debug($"Others Key {kvp.Key}-{kvp.Key.Type}-{kvp.Value}-{kvp.Value.Type}"); - } - - } - } - - private void ParseCBORValue(string key, string parent, KeyValuePair kvp, ref PNTokenContent pnGrantTokenDecoded) - { - if (kvp.Value.Type.ToString().Equals("Map", StringComparison.OrdinalIgnoreCase)) - { - logger?.Debug($"ParseCBORValue Map Key {key}"); - var p = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", parent, string.IsNullOrEmpty(parent) ? "" : ":", key); - ParseCBOR(kvp.Value, p, ref pnGrantTokenDecoded); - } - else if (kvp.Value.Type.ToString().Equals("ByteString", StringComparison.OrdinalIgnoreCase)) - { -#if NETSTANDARD10 || NETSTANDARD11 - UTF8Encoding utf8 = new UTF8Encoding(true, true); - byte[] valBytes = kvp.Value.GetByteString(); - string val = utf8.GetString(valBytes, 0, valBytes.Length); -#else - string val = Encoding.ASCII.GetString(kvp.Value.GetByteString()); -#endif - logger?.Debug($"ByteString Value {key}-{val}"); - FillGrantToken(parent, key, kvp.Value, typeof(string), ref pnGrantTokenDecoded); - } - else if (kvp.Value.Type.ToString().Equals("Integer", StringComparison.OrdinalIgnoreCase)) - { - logger?.Debug($" Integer Value {key}-{kvp.Value}"); - FillGrantToken(parent, key, kvp.Value, typeof(int), ref pnGrantTokenDecoded); - } - else if (kvp.Value.Type.ToString().Equals("TextString", StringComparison.OrdinalIgnoreCase)) - { - logger?.Debug($"TextString Value {key}-{kvp.Value}"); - FillGrantToken(parent, key, kvp.Value, typeof(string), ref pnGrantTokenDecoded); - } - else - { - logger?.Debug($"Others Key Value {kvp.Key.Type}-{kvp.Value.Type}-{key}-{kvp.Value}"); - } - } - private string ReplaceBoundaryQuotes(string key) { if (key != null && !string.IsNullOrEmpty(key) && key.Length >= 2 @@ -185,149 +77,6 @@ private string ReplaceBoundaryQuotes(string key) } return key; } - - private void FillGrantToken(string parent, string key, object val, Type type, ref PNTokenContent pnGrantTokenDecoded) - { - key = ReplaceBoundaryQuotes(key); - int i = 0; - long l = 0; - switch (type.Name) - { - case "Int32": - if (!int.TryParse(val.ToString(), out i)) - { - //do nothing. - } - break; - case "Int64": - if (!long.TryParse(val.ToString(), out l)) - { - //do nothing - } - break; - case "String": - // do nothing - break; - default: - break; - } - switch (key) - { - case "v": - pnGrantTokenDecoded.Version = i; - break; - case "t": - pnGrantTokenDecoded.Timestamp = i; - break; - case "ttl": - pnGrantTokenDecoded.TTL = i; - break; - case "meta": - pnGrantTokenDecoded.Meta = val as Dictionary; - break; - case "uuid": - pnGrantTokenDecoded.AuthorizedUuid = ((CBORObject)val).AsString(); - break; - case "sig": -#if NETSTANDARD10 || NETSTANDARD11 - UTF8Encoding utf8 = new UTF8Encoding(true, true); - byte[] keyBytes = (byte[])val; - pnGrantTokenDecoded.Signature = utf8.GetString(keyBytes, 0, keyBytes.Length); -#else - byte[] sigBytes = ((CBORObject)val).GetByteString(); - string base64String = Convert.ToBase64String(sigBytes); - pnGrantTokenDecoded.Signature = base64String; -#endif - break; - default: - PNTokenAuthValues rp = GetResourcePermission(i); - switch (parent) - { - case "meta": - if (!pnGrantTokenDecoded.Meta.ContainsKey(key)) - { - switch (type.Name) - { - case "Int32": - pnGrantTokenDecoded.Meta.Add(key, ((CBORObject)val).AsInt32()); - break; - case "Int64": - pnGrantTokenDecoded.Meta.Add(key, ((CBORObject)val).ToObject()); - break; - case "String": - pnGrantTokenDecoded.Meta.Add(key, ((CBORObject)val).AsString()); - break; - default: - break; - } - } - break; - case "res:spc": - if (!pnGrantTokenDecoded.Resources.Spaces.ContainsKey(key)) - { - pnGrantTokenDecoded.Resources.Spaces.Add(key, rp); - } - break; - case "res:usr": - if (!pnGrantTokenDecoded.Resources.Users.ContainsKey(key)) - { - pnGrantTokenDecoded.Resources.Users.Add(key, rp); - } - break; - case "res:uuid": - if (!pnGrantTokenDecoded.Resources.Uuids.ContainsKey(key)) - { - pnGrantTokenDecoded.Resources.Uuids.Add(key, rp); - } - break; - case "res:chan": - if (!pnGrantTokenDecoded.Resources.Channels.ContainsKey(key)) - { - pnGrantTokenDecoded.Resources.Channels.Add(key, rp); - } - break; - case "res:grp": - if (!pnGrantTokenDecoded.Resources.ChannelGroups.ContainsKey(key)) - { - pnGrantTokenDecoded.Resources.ChannelGroups.Add(key, rp); - } - break; - case "pat:spc": - if (!pnGrantTokenDecoded.Patterns.Spaces.ContainsKey(key)) - { - pnGrantTokenDecoded.Patterns.Spaces.Add(key, rp); - } - break; - case "pat:usr": - if (!pnGrantTokenDecoded.Patterns.Users.ContainsKey(key)) - { - pnGrantTokenDecoded.Patterns.Users.Add(key, rp); - } - break; - case "pat:uuid": - if (!pnGrantTokenDecoded.Patterns.Uuids.ContainsKey(key)) - { - pnGrantTokenDecoded.Patterns.Uuids.Add(key, rp); - } - break; - case "pat:chan": - if (!pnGrantTokenDecoded.Patterns.Channels.ContainsKey(key)) - { - pnGrantTokenDecoded.Patterns.Channels.Add(key, rp); - } - break; - case "pat:grp": - if (!pnGrantTokenDecoded.Patterns.ChannelGroups.ContainsKey(key)) - { - pnGrantTokenDecoded.Patterns.ChannelGroups.Add(key, rp); - } - break; - default: - break; - } - break; - } - } public void SetAuthToken(string token) { dToken.AddOrUpdate(pubnubInstanceId, token, (k, o) => token); diff --git a/src/Api/PubnubApi/EventEngine/Common/EventEmitter.cs b/src/Api/PubnubApi/EventEngine/Common/EventEmitter.cs index 519f5c807..bb7a8f109 100644 --- a/src/Api/PubnubApi/EventEngine/Common/EventEmitter.cs +++ b/src/Api/PubnubApi/EventEngine/Common/EventEmitter.cs @@ -165,7 +165,7 @@ public void EmitEvent(object e) catch (Exception ex) { decryptMessage = "**DECRYPT ERROR**"; - configuration?.Logger?.Error("Failed to decrypt message on channel {currentMessageChannel} due to exception={ex}.\n Message might be not encrypted"); + configuration?.Logger?.Warn("Failed to decrypt message on channel {currentMessageChannel} due to exception={ex}.\n Message might be not encrypted"); } object decodeMessage = jsonLibrary.DeserializeToObject((decryptMessage == "**DECRYPT ERROR**") ? jsonLibrary.SerializeToJsonString(payload) : decryptMessage); diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index aa160d28c..873f65984 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -66,7 +66,6 @@ None - diff --git a/src/Api/PubnubApi/Transport/HttpClientService.cs b/src/Api/PubnubApi/Transport/HttpClientService.cs index 5b643630f..11c39ddea 100644 --- a/src/Api/PubnubApi/Transport/HttpClientService.cs +++ b/src/Api/PubnubApi/Transport/HttpClientService.cs @@ -79,7 +79,7 @@ public async Task GetRequest(TransportRequest transportReques } catch (Exception e) { - logger?.Error( + logger?.Warn( $"HttpClient Service: Exception for http call url {transportRequest.RequestUrl}, exception message: {e.Message}, stacktrace: {e.StackTrace}"); transportResponse = new TransportResponse() { @@ -149,7 +149,7 @@ public async Task PostRequest(TransportRequest transportReque } catch (Exception e) { - logger?.Error( + logger?.Warn( $"Exception for http call url {transportRequest.RequestUrl}, exception message: {e.Message}, stacktrace: {e.StackTrace}"); transportResponse = new TransportResponse() { @@ -228,7 +228,7 @@ public async Task PutRequest(TransportRequest transportReques } catch (Exception e) { - logger?.Error( + logger?.Warn( $"Exception for http call url {transportRequest.RequestUrl}, exception message: {e.Message}, stacktrace: {e.StackTrace}"); transportResponse = new TransportResponse() { @@ -291,7 +291,7 @@ public async Task DeleteRequest(TransportRequest transportReq } catch (Exception e) { - logger?.Error( + logger?.Warn( $"Exception for http call url {transportRequest.RequestUrl}, exception message: {e.Message}, stacktrace: {e.StackTrace}"); transportResponse = new TransportResponse() { @@ -371,7 +371,7 @@ public async Task PatchRequest(TransportRequest transportRequ } catch (Exception e) { - logger?.Error( + logger?.Warn( $"Exception for http call url {transportRequest.RequestUrl}, exception message: {e.Message}, stacktrace: {e.StackTrace}"); transportResponse = new TransportResponse() { diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 5f95ff31b..dbd940e93 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -637,7 +637,6 @@ None - diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 3b7446838..53fcf66f8 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -777,7 +777,6 @@ 13.0.3 - 4.3.0 diff --git a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj index 53c2e5075..aeb41b24d 100644 --- a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj +++ b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj @@ -717,7 +717,6 @@ -