mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-06-27 14:53:11 +00:00
1.0
This commit is contained in:
278
bin/Net/Packets/IIPAuthPacket.dart
Normal file
278
bin/Net/Packets/IIPAuthPacket.dart
Normal file
@ -0,0 +1,278 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2019 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.
|
||||
|
||||
*/
|
||||
import '../../Data/DC.dart';
|
||||
import 'IIPAuthPacketAction.dart';
|
||||
import 'IIPAuthPacketCommand.dart';
|
||||
import 'IIPAuthPacketMethod.dart';
|
||||
|
||||
class IIPAuthPacket
|
||||
{
|
||||
|
||||
int command;
|
||||
int action;
|
||||
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
|
||||
int localMethod;
|
||||
|
||||
DC sourceInfo;
|
||||
|
||||
DC hash;
|
||||
|
||||
DC sessionId;
|
||||
|
||||
int remoteMethod;
|
||||
|
||||
String domain;
|
||||
|
||||
int certificateId;
|
||||
|
||||
String localUsername;
|
||||
|
||||
String remoteUsername;
|
||||
|
||||
DC localPassword;
|
||||
|
||||
DC remotePassword;
|
||||
|
||||
DC localToken;
|
||||
|
||||
DC remoteToken;
|
||||
|
||||
DC asymetricEncryptionKey;
|
||||
|
||||
DC localNonce;
|
||||
|
||||
DC remoteNonce;
|
||||
|
||||
int _dataLengthNeeded;
|
||||
|
||||
bool _notEnough(int offset, int ends, int needed)
|
||||
{
|
||||
if (offset + needed > ends)
|
||||
{
|
||||
_dataLengthNeeded = needed - (ends - offset);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
return command.toString() + " " + action.toString();
|
||||
}
|
||||
|
||||
int parse(DC data, int offset, int ends)
|
||||
{
|
||||
var oOffset = offset;
|
||||
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
command = (data[offset] >> 6);
|
||||
|
||||
if (command == IIPAuthPacketCommand.Action)
|
||||
{
|
||||
action = (data[offset++] & 0x3f);
|
||||
|
||||
if (action == IIPAuthPacketAction.AuthenticateHash)
|
||||
{
|
||||
if (_notEnough(offset, ends, 32))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
hash = data.clip(offset, 32);
|
||||
|
||||
//var hash = new byte[32];
|
||||
//Buffer.BlockCopy(data, (int)offset, hash, 0, 32);
|
||||
//Hash = hash;
|
||||
|
||||
offset += 32;
|
||||
}
|
||||
else if (action == IIPAuthPacketAction.NewConnection)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var length = data.getUint16(offset);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, length))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
sourceInfo = data.clip(offset, length);
|
||||
|
||||
//var sourceInfo = new byte[length];
|
||||
//Buffer.BlockCopy(data, (int)offset, sourceInfo, 0, length);
|
||||
//SourceInfo = sourceInfo;
|
||||
|
||||
offset += 32;
|
||||
}
|
||||
else if (action == IIPAuthPacketAction.ResumeConnection
|
||||
|| action == IIPAuthPacketAction.ConnectionEstablished)
|
||||
{
|
||||
//var sessionId = new byte[32];
|
||||
|
||||
if (_notEnough(offset, ends, 32))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
sessionId = data.clip(offset, 32);
|
||||
|
||||
//Buffer.BlockCopy(data, (int)offset, sessionId, 0, 32);
|
||||
//SessionId = sessionId;
|
||||
|
||||
offset += 32;
|
||||
}
|
||||
}
|
||||
else if (command == IIPAuthPacketCommand.Declare)
|
||||
{
|
||||
remoteMethod = ((data[offset] >> 4) & 0x3);
|
||||
localMethod = ((data[offset] >> 2) & 0x3);
|
||||
var encrypt = ((data[offset++] & 0x2) == 0x2);
|
||||
|
||||
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var domainLength = data[offset++];
|
||||
if (_notEnough(offset, ends, domainLength))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var domain = data.getString(offset, domainLength);
|
||||
|
||||
this.domain = domain;
|
||||
|
||||
offset += domainLength;
|
||||
|
||||
|
||||
if (remoteMethod == IIPAuthPacketMethod.Credentials)
|
||||
{
|
||||
if (localMethod == IIPAuthPacketMethod.None)
|
||||
{
|
||||
if (_notEnough(offset, ends, 33))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
|
||||
remoteNonce = data.clip(offset, 32);
|
||||
|
||||
offset += 32;
|
||||
|
||||
var length = data[offset++];
|
||||
|
||||
if (_notEnough(offset, ends, length))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
remoteUsername = data.getString(offset, length);
|
||||
|
||||
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
|
||||
if (encrypt)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var keyLength = data.getUint16(offset);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, keyLength))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
|
||||
asymetricEncryptionKey = data.clip(offset, keyLength);
|
||||
|
||||
offset += keyLength;
|
||||
}
|
||||
}
|
||||
else if (command == IIPAuthPacketCommand.Acknowledge)
|
||||
{
|
||||
remoteMethod = ((data[offset] >> 4) & 0x3);
|
||||
localMethod = ((data[offset] >> 2) & 0x3);
|
||||
var encrypt = ((data[offset++] & 0x2) == 0x2);
|
||||
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
|
||||
if (remoteMethod == IIPAuthPacketMethod.Credentials)
|
||||
{
|
||||
if (localMethod == IIPAuthPacketMethod.None)
|
||||
{
|
||||
if (_notEnough(offset, ends, 32))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
remoteNonce = data.clip(offset, 32);
|
||||
offset += 32;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (encrypt)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var keyLength = data.getUint16(offset);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, keyLength))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
asymetricEncryptionKey = data.clip(offset, keyLength);
|
||||
|
||||
offset += keyLength;
|
||||
}
|
||||
}
|
||||
else if (command == IIPAuthPacketCommand.Error)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
offset++;
|
||||
errorCode = data[offset++];
|
||||
|
||||
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
errorMessage = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return offset - oOffset;
|
||||
|
||||
}
|
||||
|
||||
}
|
16
bin/Net/Packets/IIPAuthPacketAction.dart
Normal file
16
bin/Net/Packets/IIPAuthPacketAction.dart
Normal file
@ -0,0 +1,16 @@
|
||||
class IIPAuthPacketAction
|
||||
{
|
||||
// Authenticate
|
||||
static const int AuthenticateHash = 0;
|
||||
|
||||
|
||||
//Challenge,
|
||||
//CertificateRequest,
|
||||
//CertificateReply,
|
||||
//EstablishRequest,
|
||||
//EstablishReply
|
||||
|
||||
static const int NewConnection = 0x20;
|
||||
static const int ResumeConnection = 0x21;
|
||||
static const int ConnectionEstablished = 0x28;
|
||||
}
|
7
bin/Net/Packets/IIPAuthPacketCommand.dart
Normal file
7
bin/Net/Packets/IIPAuthPacketCommand.dart
Normal file
@ -0,0 +1,7 @@
|
||||
class IIPAuthPacketCommand
|
||||
{
|
||||
static const int Action = 0;
|
||||
static const int Declare = 1;
|
||||
static const int Acknowledge = 2;
|
||||
static const int Error = 3;
|
||||
}
|
8
bin/Net/Packets/IIPAuthPacketMethod.dart
Normal file
8
bin/Net/Packets/IIPAuthPacketMethod.dart
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
class IIPAuthPacketMethod
|
||||
{
|
||||
static const int None = 0;
|
||||
static const int Certificate = 1;
|
||||
static const int Credentials = 2;
|
||||
static const int Token = 3;
|
||||
}
|
727
bin/Net/Packets/IIPPacket.dart
Normal file
727
bin/Net/Packets/IIPPacket.dart
Normal file
@ -0,0 +1,727 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2019 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.
|
||||
|
||||
*/
|
||||
import '../../Data/DC.dart';
|
||||
import '../../Data/Guid.dart';
|
||||
|
||||
import 'IIPPacketAction.dart';
|
||||
import 'IIPPacketCommand.dart';
|
||||
import 'IIPPacketEvent.dart';
|
||||
import 'IIPPacketReport.dart';
|
||||
import '../../Data/Codec.dart';
|
||||
import '../../Data/DataType.dart';
|
||||
|
||||
class IIPPacket
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int report;
|
||||
|
||||
int command;
|
||||
|
||||
int action;
|
||||
|
||||
int event;
|
||||
|
||||
int previousCommand;
|
||||
|
||||
|
||||
int previousAction;
|
||||
|
||||
int previousEvent;
|
||||
|
||||
|
||||
int resourceId;
|
||||
int newResourceId;
|
||||
|
||||
int childId;
|
||||
int storeId;
|
||||
|
||||
int resourceAge;
|
||||
DC content;
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
String className ;
|
||||
String resourceLink ;
|
||||
Guid classId ;
|
||||
int methodIndex ;
|
||||
String methodName;
|
||||
int callbackId ;
|
||||
int progressValue;
|
||||
int progressMax ;
|
||||
DateTime fromDate ;
|
||||
DateTime toDate;
|
||||
int fromAge;
|
||||
int toAge;
|
||||
|
||||
int _dataLengthNeeded;
|
||||
int _originalOffset;
|
||||
|
||||
|
||||
bool _notEnough(int offset, int ends, int needed)
|
||||
{
|
||||
if (offset + needed > ends)
|
||||
{
|
||||
//dataLengthNeeded = needed - (ends - offset);
|
||||
_dataLengthNeeded = needed - (ends - _originalOffset);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
int parse(DC data, int offset, int ends)
|
||||
{
|
||||
_originalOffset = offset;
|
||||
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
previousCommand = command;
|
||||
|
||||
command = (data[offset] >> 6);
|
||||
|
||||
if (command == IIPPacketCommand.Event)
|
||||
{
|
||||
event = (data[offset++] & 0x3f);
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (command == IIPPacketCommand.Report)
|
||||
{
|
||||
report = (data[offset++] & 0x3f);
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
callbackId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
previousAction = action;
|
||||
action = (data[offset++] & 0x3f);
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
callbackId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
if (command == IIPPacketCommand.Event)
|
||||
{
|
||||
if (event == IIPPacketEvent.ResourceReassigned)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
newResourceId = data.getUint32( offset);
|
||||
offset += 4;
|
||||
|
||||
}
|
||||
else if (event == IIPPacketEvent.ResourceDestroyed)
|
||||
{
|
||||
// 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))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(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, size))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
else if (event == IIPPacketEvent.EventOccurred)
|
||||
{
|
||||
if (_notEnough(offset, ends, 5))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
var cl = data.getUint32( offset);
|
||||
offset += 4;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
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)
|
||||
{
|
||||
if (action == IIPPacketAction.AttachResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (action == IIPPacketAction.ReattachResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 12))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
resourceAge = data.getUint64(offset);
|
||||
offset += 8;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.DetachResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.CreateResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 12))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
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;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
}
|
||||
else if (action == IIPPacketAction.DeleteResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
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))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var cl = data[offset++];
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
className = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.TemplateFromClassId)
|
||||
{
|
||||
if (_notEnough(offset, ends, 16))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
classId = data.getGuid(offset);
|
||||
offset += 16;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.TemplateFromResourceId)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (action == IIPPacketAction.QueryLink)
|
||||
{
|
||||
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.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.InvokeFunctionArrayArguments
|
||||
|| action == IIPPacketAction.InvokeFunctionNamedArguments)
|
||||
{
|
||||
if (_notEnough(offset, ends, 9))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.GetProperty)
|
||||
{
|
||||
if (_notEnough(offset, ends, 5))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.GetPropertyIfModified)
|
||||
{
|
||||
if (_notEnough(offset, ends, 9))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
resourceAge = data.getUint64(offset);
|
||||
offset += 8;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.SetProperty)
|
||||
{
|
||||
if (_notEnough(offset, ends, 6))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(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, size))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset-1, size + 1);
|
||||
offset += 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)
|
||||
{
|
||||
if (action == IIPPacketAction.AttachResource
|
||||
|| action == IIPPacketAction.ReattachResource)
|
||||
{
|
||||
|
||||
if (_notEnough(offset, ends, 26))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
classId = data.getGuid(offset);
|
||||
offset += 16;
|
||||
|
||||
resourceAge = data.getUint64(offset);
|
||||
offset += 8;
|
||||
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
resourceLink = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
else if (action == IIPPacketAction.DetachResource)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
else if (action == IIPPacketAction.CreateResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 20))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
//ClassId = data.GetGuid(offset);
|
||||
//offset += 16;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.DetachResource)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
// Inquire
|
||||
else if (action == IIPPacketAction.TemplateFromClassName
|
||||
|| action == IIPPacketAction.TemplateFromClassId
|
||||
|| 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;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
else if (action == IIPPacketAction.InvokeFunctionArrayArguments
|
||||
|| action == IIPPacketAction.InvokeFunctionNamedArguments
|
||||
|| action == IIPPacketAction.GetProperty
|
||||
|| action == IIPPacketAction.GetPropertyIfModified)
|
||||
{
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(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, size))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
else if (action == IIPPacketAction.SetProperty)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
else if (command == IIPPacketCommand.Report)
|
||||
{
|
||||
if (report == IIPPacketReport.ManagementError)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
errorCode = data.getUint16(offset);
|
||||
offset += 2;
|
||||
}
|
||||
else if (report == IIPPacketReport.ExecutionError)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
errorCode = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
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;
|
||||
|
||||
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 = data[offset++];
|
||||
var size = DataType.size(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, size))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return offset - _originalOffset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
toString()
|
||||
{
|
||||
var rt = command.toString();
|
||||
|
||||
if (command == IIPPacketCommand.Event)
|
||||
{
|
||||
rt += " " + event.toString();
|
||||
}
|
||||
else if (command == IIPPacketCommand.Request)
|
||||
{
|
||||
rt += " " + action.toString();
|
||||
if (action == IIPPacketAction.AttachResource)
|
||||
{
|
||||
rt += " CID: " + callbackId.toString() + " RID: " + resourceId.toString();
|
||||
}
|
||||
}
|
||||
else if (command == IIPPacketCommand.Reply)
|
||||
rt += " " + action.toString();
|
||||
else if (command == IIPPacketCommand.Report)
|
||||
rt += " " + report.toString();
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
}
|
36
bin/Net/Packets/IIPPacketAction.dart
Normal file
36
bin/Net/Packets/IIPPacketAction.dart
Normal file
@ -0,0 +1,36 @@
|
||||
class IIPPacketAction
|
||||
{
|
||||
// Request Manage
|
||||
static const int AttachResource = 0x0;
|
||||
static const int ReattachResource = 0x1;
|
||||
static const int DetachResource = 0x2;
|
||||
static const int CreateResource = 0x3;
|
||||
static const int DeleteResource = 0x4;
|
||||
static const int AddChild = 0x5;
|
||||
static const int RemoveChild = 0x6;
|
||||
static const int RenameResource = 0x7;
|
||||
|
||||
// Request Inquire
|
||||
static const int TemplateFromClassName = 0x8;
|
||||
static const int TemplateFromClassId = 0x9;
|
||||
static const int TemplateFromResourceId = 0xA;
|
||||
static const int QueryLink = 0xB;
|
||||
static const int ResourceHistory = 0xC;
|
||||
static const int ResourceChildren = 0xD;
|
||||
static const int ResourceParents = 0xE;
|
||||
|
||||
// Request Invoke
|
||||
static const int InvokeFunctionArrayArguments = 0x10;
|
||||
static const int GetProperty = 0x11;
|
||||
static const int GetPropertyIfModified = 0x12;
|
||||
static const int SetProperty = 0x13;
|
||||
static const int InvokeFunctionNamedArguments = 0x14;
|
||||
|
||||
// Request Attribute
|
||||
static const int GetAllAttributes = 0x18;
|
||||
static const int UpdateAllAttributes = 0x19;
|
||||
static const int ClearAllAttributes = 0x1A;
|
||||
static const int GetAttributes = 0x1B;
|
||||
static const int UpdateAttributes = 0x1C;
|
||||
static const int ClearAttributes = 0x1D;
|
||||
}
|
7
bin/Net/Packets/IIPPacketCommand.dart
Normal file
7
bin/Net/Packets/IIPPacketCommand.dart
Normal file
@ -0,0 +1,7 @@
|
||||
class IIPPacketCommand
|
||||
{
|
||||
static const int Event = 0;
|
||||
static const int Request = 1;
|
||||
static const int Reply = 2;
|
||||
static const int Report = 3;
|
||||
}
|
15
bin/Net/Packets/IIPPacketEvent.dart
Normal file
15
bin/Net/Packets/IIPPacketEvent.dart
Normal file
@ -0,0 +1,15 @@
|
||||
class IIPPacketEvent
|
||||
{
|
||||
// Event Manage
|
||||
static const int ResourceReassigned = 0;
|
||||
static const int ResourceDestroyed = 1;
|
||||
static const int ChildAdded = 2;
|
||||
static const int ChildRemoved = 3;
|
||||
static const int Renamed = 4;
|
||||
// Event Invoke
|
||||
static const int PropertyUpdated = 0x10;
|
||||
static const int EventOccurred = 0x11;
|
||||
|
||||
// Attribute
|
||||
static const int AttributesUpdated = 0x18;
|
||||
}
|
7
bin/Net/Packets/IIPPacketReport.dart
Normal file
7
bin/Net/Packets/IIPPacketReport.dart
Normal file
@ -0,0 +1,7 @@
|
||||
class IIPPacketReport
|
||||
{
|
||||
static const int ManagementError = 0;
|
||||
static const int ExecutionError = 1;
|
||||
static const int ProgressReport = 0x8;
|
||||
static const int ChunkStream = 0x9;
|
||||
}
|
Reference in New Issue
Block a user