mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-29 23:21:36 +00:00 
			
		
		
		
	Updated to support IIP v3.3
This commit is contained in:
		| @@ -1,4 +1,29 @@ | ||||
| using System; | ||||
|  | ||||
| /* | ||||
|   | ||||
| Copyright (c) 2017 Ahmed Kh. Zamil | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  | ||||
| */ | ||||
|  | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| @@ -218,7 +243,7 @@ namespace Esiur.Net.Packets | ||||
|                         return postSize - (data.Length - headerSize); | ||||
|                      | ||||
|  | ||||
|                     if (Headers["content-type"] == "application/x-www-form-urlencoded" | ||||
|                     if (Headers["content-type"].StartsWith("application/x-www-form-urlencoded") | ||||
|                         || Headers["content-type"] == "" | ||||
|                         || Headers["content-type"] == null) | ||||
|                     { | ||||
|   | ||||
| @@ -1,4 +1,27 @@ | ||||
| using System; | ||||
| /* | ||||
|   | ||||
| Copyright (c) 2017 Ahmed Kh. Zamil | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  | ||||
| */ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
|   | ||||
| @@ -1,4 +1,28 @@ | ||||
|  using Esiur.Data; | ||||
| /* | ||||
|   | ||||
| Copyright (c) 2017 Ahmed Kh. Zamil | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  | ||||
| */ | ||||
|  | ||||
| using Esiur.Data; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
|   | ||||
| @@ -1,4 +1,28 @@ | ||||
|  using Esiur.Data; | ||||
| /* | ||||
|   | ||||
| Copyright (c) 2017 Ahmed Kh. Zamil | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  | ||||
| */ | ||||
|  | ||||
| using Esiur.Data; | ||||
| using Esiur.Engine; | ||||
| using Esiur.Misc; | ||||
| using Esiur.Net.Packets; | ||||
| @@ -12,12 +36,39 @@ namespace Esiur.Net.Packets | ||||
| { | ||||
|     class IIPPacket : Packet | ||||
|     { | ||||
|  | ||||
|         public override string ToString() | ||||
|         { | ||||
|             var rt = Command.ToString(); | ||||
|  | ||||
|             if (Command == IIPPacketCommand.Event) | ||||
|             { | ||||
|                 rt += " " + Event.ToString(); | ||||
|                 //if (Event == IIPPacketEvent.AttributesUpdated) | ||||
|                 //  rt +=  | ||||
|             } | ||||
|             else if (Command == IIPPacketCommand.Request) | ||||
|             { | ||||
|                 rt += " " + Action.ToString(); | ||||
|                 if (Action == IIPPacketAction.AttachResource) | ||||
|                 { | ||||
|                     rt += " CID: " + CallbackId + " RID: " + ResourceId;  | ||||
|                 } | ||||
|             } | ||||
|             else if (Command == IIPPacketCommand.Reply) | ||||
|                 rt += " " + Action.ToString(); | ||||
|             else if (Command == IIPPacketCommand.Report) | ||||
|                 rt += " " + Report.ToString(); | ||||
|  | ||||
|             return rt; | ||||
|         } | ||||
|  | ||||
|         public enum IIPPacketCommand : byte | ||||
|         { | ||||
|             Event = 0, | ||||
|             Request, | ||||
|             Reply, | ||||
|             Error, | ||||
|             Report, | ||||
|         } | ||||
|  | ||||
|         public enum IIPPacketEvent: byte | ||||
| @@ -25,10 +76,15 @@ namespace Esiur.Net.Packets | ||||
|             // Event Manage | ||||
|             ResourceReassigned = 0, | ||||
|             ResourceDestroyed, | ||||
|              | ||||
|             ChildAdded, | ||||
|             ChildRemoved, | ||||
|             Renamed, | ||||
|             // Event Invoke | ||||
|             PropertyUpdated = 0x10, | ||||
|             EventOccured, | ||||
|             EventOccurred, | ||||
|  | ||||
|             // Attribute | ||||
|             AttributesUpdated = 0x18 | ||||
|         } | ||||
|  | ||||
|         public enum IIPPacketAction : byte | ||||
| @@ -39,22 +95,49 @@ namespace Esiur.Net.Packets | ||||
|             DetachResource, | ||||
|             CreateResource, | ||||
|             DeleteResource, | ||||
|             AddChild, | ||||
|             RemoveChild, | ||||
|             RenameResource, | ||||
|  | ||||
|             // Request Inquire | ||||
|             TemplateFromClassName = 0x8, | ||||
|             TemplateFromClassId, | ||||
|             TemplateFromResourceLink, | ||||
|             TemplateFromResourceId, | ||||
|             ResourceIdFromResourceLink, | ||||
|             QueryLink, | ||||
|             ResourceHistory, | ||||
|             ResourceChildren, | ||||
|             ResourceParents, | ||||
|  | ||||
|             // Request Invoke | ||||
|             InvokeFunction = 0x10, | ||||
|             GetProperty, | ||||
|             GetPropertyIfModified, | ||||
|             SetProperty, | ||||
|  | ||||
|             // Request Attribute | ||||
|             GetAllAttributes = 0x18, | ||||
|             UpdateAllAttributes, | ||||
|             ClearAllAttributes, | ||||
|             GetAttributes, | ||||
|             UpdateAttributes, | ||||
|             ClearAttributes | ||||
|         } | ||||
|  | ||||
|         public enum IIPPacketReport: byte | ||||
|         { | ||||
|             ManagementError, | ||||
|             ExecutionError, | ||||
|             ProgressReport = 0x8, | ||||
|             ChunkStream = 0x9 | ||||
|         } | ||||
|           | ||||
|  | ||||
|         public IIPPacketReport Report | ||||
|         { | ||||
|             get; | ||||
|             set; | ||||
|         } | ||||
|  | ||||
|   | ||||
|         public IIPPacketCommand Command | ||||
|         { | ||||
|             get; | ||||
| @@ -72,13 +155,33 @@ namespace Esiur.Net.Packets | ||||
|             set; | ||||
|         } | ||||
|  | ||||
|       | ||||
|         public IIPPacketCommand PreviousCommand | ||||
|         { | ||||
|             get; | ||||
|             set; | ||||
|         } | ||||
|         public IIPPacketAction PreviousAction | ||||
|         { | ||||
|             get; | ||||
|             set; | ||||
|         } | ||||
|  | ||||
|         public IIPPacketEvent PreviousEvent | ||||
|         { | ||||
|             get; | ||||
|             set; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         public uint ResourceId { get; set; } | ||||
|         public uint NewResourceId { get; set; } | ||||
|         //public uint ParentId { get; set; } | ||||
|         public uint ChildId { get; set; } | ||||
|         public uint StoreId { get; set; } | ||||
|  | ||||
|         public uint ResourceAge { get; set; } | ||||
|         public ulong ResourceAge { get; set; } | ||||
|         public byte[] Content { get; set; } | ||||
|         public byte ErrorCode { get; set; } | ||||
|         public ushort ErrorCode { get; set; } | ||||
|         public string ErrorMessage { get; set; } | ||||
|         public string ClassName { get; set; } | ||||
|         public string ResourceLink { get; set; } | ||||
| @@ -86,8 +189,15 @@ namespace Esiur.Net.Packets | ||||
|         public byte MethodIndex { get; set; } | ||||
|         public string MethodName { get; set; } | ||||
|         public uint CallbackId { get; set; } | ||||
|         public int ProgressValue { get; set; } | ||||
|         public int ProgressMax { get; set; } | ||||
|         public DateTime FromDate { get; set; } | ||||
|         public DateTime ToDate { get; set; } | ||||
|         public ulong FromAge { get; set; } | ||||
|         public ulong ToAge { get; set; } | ||||
|  | ||||
|         private uint dataLengthNeeded; | ||||
|         private uint originalOffset; | ||||
|  | ||||
|         public override bool Compose() | ||||
|         { | ||||
| @@ -98,7 +208,9 @@ namespace Esiur.Net.Packets | ||||
|         { | ||||
|             if (offset + needed > ends) | ||||
|             { | ||||
|                 dataLengthNeeded = needed - (ends - offset); | ||||
|                 //dataLengthNeeded = needed - (ends - offset); | ||||
|                 dataLengthNeeded = needed - (ends - originalOffset); | ||||
|  | ||||
|                 return true; | ||||
|             } | ||||
|             else | ||||
| @@ -107,13 +219,15 @@ namespace Esiur.Net.Packets | ||||
|  | ||||
|         public override long Parse(byte[] data, uint offset, uint ends) | ||||
|         { | ||||
|             var oOffset = offset; | ||||
|             originalOffset = offset; | ||||
|  | ||||
|             if (NotEnough(offset, ends, 1)) | ||||
|                 return -dataLengthNeeded; | ||||
|  | ||||
|             Command = (IIPPacketCommand)(data[offset] >> 6); | ||||
|             PreviousCommand = Command; | ||||
|  | ||||
|             Command = (IIPPacketCommand)(data[offset] >> 6); | ||||
|              | ||||
|             if (Command == IIPPacketCommand.Event) | ||||
|             { | ||||
|                 Event = (IIPPacketEvent)(data[offset++] & 0x3f); | ||||
| @@ -124,8 +238,19 @@ namespace Esiur.Net.Packets | ||||
|                 ResourceId = data.GetUInt32(offset); | ||||
|                 offset += 4; | ||||
|             } | ||||
|             else if (Command == IIPPacketCommand.Report) | ||||
|             { | ||||
|                 Report = (IIPPacketReport)(data[offset++] & 0x3f); | ||||
|  | ||||
|                 if (NotEnough(offset, ends, 4)) | ||||
|                     return -dataLengthNeeded; | ||||
|  | ||||
|                 CallbackId = data.GetUInt32(offset); | ||||
|                 offset += 4; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 PreviousAction = Action; | ||||
|                 Action = (IIPPacketAction)(data[offset++] & 0x3f); | ||||
|  | ||||
|                 if (NotEnough(offset, ends, 4)) | ||||
| @@ -150,6 +275,30 @@ namespace Esiur.Net.Packets | ||||
|                 { | ||||
|                     // nothing to parse | ||||
|                 } | ||||
|                 else if (Event == IIPPacketEvent.ChildAdded | ||||
|                         || Event == IIPPacketEvent.ChildRemoved) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 4)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ChildId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                 } | ||||
|                 else if(Event == IIPPacketEvent.Renamed) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 2)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     var cl = data.GetUInt16(offset); | ||||
|                     offset += 2; | ||||
|  | ||||
|                     if (NotEnough(offset, ends, cl)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     Content = data.Clip(offset, cl); | ||||
|  | ||||
|                     offset += cl; | ||||
|                 } | ||||
|                 else if (Event == IIPPacketEvent.PropertyUpdated) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 2)) | ||||
| @@ -183,7 +332,7 @@ namespace Esiur.Net.Packets | ||||
|                         offset += (uint)size; | ||||
|                     } | ||||
|                 } | ||||
|                 else if (Event == IIPPacketEvent.EventOccured) | ||||
|                 else if (Event == IIPPacketEvent.EventOccurred) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 5))  | ||||
|                         return -dataLengthNeeded; | ||||
| @@ -197,6 +346,22 @@ namespace Esiur.Net.Packets | ||||
|                     offset += cl; | ||||
|  | ||||
|                 } | ||||
|                 // Attribute | ||||
|                 else if (Event == IIPPacketEvent.AttributesUpdated) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 4)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     var cl = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|  | ||||
|                     if (NotEnough(offset, ends, cl)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     Content = data.Clip(offset, cl); | ||||
|  | ||||
|                     offset += cl; | ||||
|                 } | ||||
|             } | ||||
|             else if (Command == IIPPacketCommand.Request) | ||||
|             { | ||||
| @@ -210,14 +375,14 @@ namespace Esiur.Net.Packets | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.ReattachResource) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 8)) | ||||
|                     if (NotEnough(offset, ends, 12)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|  | ||||
|                     ResourceAge = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                     ResourceAge = data.GetUInt64(offset); | ||||
|                     offset += 8; | ||||
|  | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.DetachResource) | ||||
| @@ -231,16 +396,21 @@ namespace Esiur.Net.Packets | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.CreateResource) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 1)) | ||||
|                     if (NotEnough(offset, ends, 12)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     var cl = data[offset++]; | ||||
|                     StoreId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|  | ||||
|                     var cl = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|  | ||||
|                     if (NotEnough(offset, ends, cl)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ClassName = data.GetString(offset, cl); | ||||
|                     offset += cl; | ||||
|                     this.Content = data.Clip(offset, cl); | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.DeleteResource) | ||||
|                 { | ||||
| @@ -251,6 +421,33 @@ namespace Esiur.Net.Packets | ||||
|                     offset += 4; | ||||
|  | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.AddChild | ||||
|                         || Action == IIPPacketAction.RemoveChild) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 8)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                     ChildId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.RenameResource) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 6)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                     var cl = data.GetUInt16(offset); | ||||
|                     offset += 2; | ||||
|  | ||||
|                     if (NotEnough(offset, ends, cl)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     Content = data.Clip(offset, cl); | ||||
|                     offset += cl; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.TemplateFromClassName) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 1)) | ||||
| @@ -274,20 +471,6 @@ namespace Esiur.Net.Packets | ||||
|                     offset += 16; | ||||
|  | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.TemplateFromResourceLink) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 2)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     var cl = data.GetUInt16(offset); | ||||
|                     offset += 2; | ||||
|  | ||||
|                     if (NotEnough(offset, ends, cl)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ResourceLink = data.GetString(offset, cl); | ||||
|                     offset += cl; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.TemplateFromResourceId) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 4)) | ||||
| @@ -296,7 +479,7 @@ namespace Esiur.Net.Packets | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.ResourceIdFromResourceLink) | ||||
|                 else if (Action == IIPPacketAction.QueryLink) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 2)) | ||||
|                         return -dataLengthNeeded; | ||||
| @@ -310,6 +493,30 @@ namespace Esiur.Net.Packets | ||||
|                     ResourceLink = data.GetString(offset, cl); | ||||
|                     offset += cl; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.ResourceChildren | ||||
|                         || Action == IIPPacketAction.ResourceParents) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 4)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.ResourceHistory) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 20)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|  | ||||
|                     FromDate = data.GetDateTime(offset); | ||||
|                     offset += 8; | ||||
|  | ||||
|                     ToDate = data.GetDateTime(offset); | ||||
|                     offset += 8; | ||||
|  | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.InvokeFunction) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 9)) | ||||
| @@ -351,8 +558,8 @@ namespace Esiur.Net.Packets | ||||
|  | ||||
|                     MethodIndex = data[offset++]; | ||||
|  | ||||
|                     ResourceAge = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                     ResourceAge = data.GetUInt64(offset); | ||||
|                     offset += 8; | ||||
|  | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.SetProperty) | ||||
| @@ -392,6 +599,26 @@ namespace Esiur.Net.Packets | ||||
|                         offset += (uint)size; | ||||
|                     } | ||||
|                 } | ||||
|                 // Attributes | ||||
|                 else if (Action == IIPPacketAction.UpdateAllAttributes | ||||
|                         || Action == IIPPacketAction.GetAttributes | ||||
|                         || Action == IIPPacketAction.UpdateAttributes | ||||
|                         || Action == IIPPacketAction.ClearAttributes) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 8)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                     var cl = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|  | ||||
|                     if (NotEnough(offset, ends, cl)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     Content = data.Clip(offset, cl); | ||||
|                     offset += cl; | ||||
|                 } | ||||
|             } | ||||
|             else if (Command == IIPPacketCommand.Reply) | ||||
|             { | ||||
| @@ -405,8 +632,8 @@ namespace Esiur.Net.Packets | ||||
|                     ClassId = data.GetGuid(offset); | ||||
|                     offset += 16; | ||||
|  | ||||
|                     ResourceAge = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                     ResourceAge = data.GetUInt64(offset); | ||||
|                     offset += 8; | ||||
|  | ||||
|                     uint cl = data.GetUInt16(offset); | ||||
|                     offset += 2; | ||||
| @@ -438,8 +665,8 @@ namespace Esiur.Net.Packets | ||||
|                     if (NotEnough(offset, ends, 20)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ClassId = data.GetGuid(offset); | ||||
|                     offset += 16; | ||||
|                     //ClassId = data.GetGuid(offset); | ||||
|                     //offset += 16; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
| @@ -449,10 +676,17 @@ namespace Esiur.Net.Packets | ||||
|                 { | ||||
|                     // nothing to do | ||||
|                 } | ||||
|                         // Inquire | ||||
|                 else if (Action == IIPPacketAction.TemplateFromClassName | ||||
|                         || Action == IIPPacketAction.TemplateFromClassId | ||||
|                         || Action == IIPPacketAction.TemplateFromResourceLink | ||||
|                         || Action == IIPPacketAction.TemplateFromResourceId) | ||||
|                         || Action == IIPPacketAction.TemplateFromResourceId | ||||
|                         || Action == IIPPacketAction.QueryLink | ||||
|                         || Action == IIPPacketAction.ResourceChildren | ||||
|                         || Action == IIPPacketAction.ResourceParents | ||||
|                         || Action == IIPPacketAction.ResourceHistory | ||||
|                         // Attribute | ||||
|                         || Action == IIPPacketAction.GetAllAttributes | ||||
|                         || Action == IIPPacketAction.GetAttributes) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 4)) | ||||
|                         return -dataLengthNeeded; | ||||
| @@ -466,20 +700,6 @@ namespace Esiur.Net.Packets | ||||
|                     Content = data.Clip(offset, cl); | ||||
|                     offset += cl; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.ResourceIdFromResourceLink) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 24)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     ClassId = data.GetGuid(offset); | ||||
|                     offset += 16; | ||||
|  | ||||
|                     ResourceId = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|  | ||||
|                     ResourceAge = data.GetUInt32(offset); | ||||
|                     offset += 4; | ||||
|                 } | ||||
|                 else if (Action == IIPPacketAction.InvokeFunction  | ||||
|                     || Action == IIPPacketAction.GetProperty | ||||
|                     || Action == IIPPacketAction.GetPropertyIfModified) | ||||
| @@ -518,33 +738,80 @@ namespace Esiur.Net.Packets | ||||
|                     // nothing to do | ||||
|                 } | ||||
|             } | ||||
|             else if (Command == IIPPacketCommand.Error) | ||||
|             else if (Command == IIPPacketCommand.Report) | ||||
|             { | ||||
|                 // Error | ||||
|                 if (NotEnough(offset, ends, 4)) | ||||
|                     return -dataLengthNeeded; | ||||
|                 if (Report == IIPPacketReport.ManagementError) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 2)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                 CallbackId = data.GetUInt32(offset); | ||||
|                     ErrorCode = data.GetUInt16(offset); | ||||
|                     offset += 2; | ||||
|                 } | ||||
|                 else if (Report == IIPPacketReport.ExecutionError) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 2)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                 if (NotEnough(offset, ends, 1)) | ||||
|                     return -dataLengthNeeded; | ||||
|                     ErrorCode = data.GetUInt16(offset); | ||||
|                     offset += 2; | ||||
|  | ||||
|                 ErrorCode = data[offset++]; | ||||
|                     if (NotEnough(offset, ends, 2)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                 if (NotEnough(offset, ends, 4)) | ||||
|                     return -dataLengthNeeded; | ||||
|                     var cl = data.GetUInt16(offset); | ||||
|                     offset += 2; | ||||
|  | ||||
|                 var cl = data.GetUInt32(offset); | ||||
|                 offset += 4; | ||||
|                     if (NotEnough(offset, ends, cl)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                 if (NotEnough(offset, ends, cl)) | ||||
|                     return -dataLengthNeeded; | ||||
|                     ErrorMessage = data.GetString(offset, cl); | ||||
|                     offset += cl; | ||||
|                 } | ||||
|                 else if (Report == IIPPacketReport.ProgressReport) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 8)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                 ErrorMessage = data.GetString(offset, cl); | ||||
|                 offset += cl; | ||||
|                     ProgressValue = data.GetInt32(offset); | ||||
|                     offset += 4; | ||||
|                     ProgressMax = data.GetInt32(offset); | ||||
|                     offset += 4; | ||||
|                 } | ||||
|                 else if (Report == IIPPacketReport.ChunkStream) | ||||
|                 { | ||||
|                     if (NotEnough(offset, ends, 1)) | ||||
|                         return -dataLengthNeeded; | ||||
|  | ||||
|                     var dt = (DataType)data[offset++]; | ||||
|                     var size = dt.Size();// Codec.SizeOf(dt); | ||||
|  | ||||
|                     if (size < 0) | ||||
|                     { | ||||
|                         if (NotEnough(offset, ends, 4)) | ||||
|                             return -dataLengthNeeded; | ||||
|  | ||||
|                         var cl = data.GetUInt32(offset); | ||||
|                         offset += 4; | ||||
|  | ||||
|                         if (NotEnough(offset, ends, cl)) | ||||
|                             return -dataLengthNeeded; | ||||
|  | ||||
|                         Content = data.Clip(offset - 5, cl + 5); | ||||
|                         offset += cl; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         if (NotEnough(offset, ends, (uint)size)) | ||||
|                             return -dataLengthNeeded; | ||||
|  | ||||
|                         Content = data.Clip(offset - 1, (uint)size + 1); | ||||
|                         offset += (uint)size; | ||||
|                     } | ||||
|                 } | ||||
|             }  | ||||
|  | ||||
|             return offset - oOffset; | ||||
|             return offset - originalOffset; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,28 @@ | ||||
| using System; | ||||
| /* | ||||
|   | ||||
| Copyright (c) 2017 Ahmed Kh. Zamil | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  | ||||
| */ | ||||
|  | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| @@ -138,9 +162,10 @@ namespace Esiur.Net.Packets | ||||
|                     offset += 8; | ||||
|                 } | ||||
|  | ||||
|                 /* | ||||
|                 if (Mask) | ||||
|                 { | ||||
|                     MaskKey = new byte[4]; | ||||
|                                     MaskKey = new byte[4]; | ||||
|                     MaskKey[0] = data[offset++]; | ||||
|                     MaskKey[1] = data[offset++]; | ||||
|                     MaskKey[2] = data[offset++]; | ||||
| @@ -149,6 +174,7 @@ namespace Esiur.Net.Packets | ||||
|                     //MaskKey = DC.GetUInt32(data, offset); | ||||
|                     //offset += 4; | ||||
|                 } | ||||
|                 */ | ||||
|  | ||||
|                 needed += PayloadLength; | ||||
|                 if (length < needed) | ||||
| @@ -156,23 +182,26 @@ namespace Esiur.Net.Packets | ||||
|                     //Console.WriteLine("stage 4"); | ||||
|                     return length - needed; | ||||
|                 } | ||||
|  | ||||
|                 //                if ((int)PayloadLength > (ends - offset)) | ||||
|                 //              { | ||||
|                 //                return -((int)PayloadLength - (ends - offset)); | ||||
|                 //          } | ||||
|                 else | ||||
|                 { | ||||
|                     Message = DC.Clip(data, offset, (uint)PayloadLength); | ||||
|  | ||||
|                     if (Mask) | ||||
|                     { | ||||
|                         MaskKey = new byte[4]; | ||||
|                         MaskKey[0] = data[offset++]; | ||||
|                         MaskKey[1] = data[offset++]; | ||||
|                         MaskKey[2] = data[offset++]; | ||||
|                         MaskKey[3] = data[offset++]; | ||||
|  | ||||
|                         Message = DC.Clip(data, offset, (uint)PayloadLength); | ||||
|  | ||||
|                         //var aMask = BitConverter.GetBytes(MaskKey); | ||||
|                         for (int i = 0; i < Message.Length; i++) | ||||
|                         { | ||||
|                             Message[i] = (byte)(Message[i] ^ MaskKey[i % 4]); | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                         Message = DC.Clip(data, offset, (uint)PayloadLength); | ||||
|  | ||||
|  | ||||
|                     return (offset - oOffset) + (int)PayloadLength; | ||||
|                 } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user