Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const dataEncoding = nodeToRead.dataEncoding;
const continuationPoint = nodeToRead.continuationPoint;
assert(engine.addressSpace instanceof AddressSpace); // initialize not called
if (timestampsToReturn === TimestampsToReturn.Invalid) {
return new DataValue({statusCode: StatusCodes.BadTimestampsToReturnInvalid});
}
timestampsToReturn = (_.isObject(timestampsToReturn)) ? timestampsToReturn : TimestampsToReturn.Neither;
const obj = engine.__findObject(nodeId);
if (!obj) {
// may be return BadNodeIdUnknown in dataValue instead ?
// Object Not Found
callback(null, new HistoryReadResult({statusCode: StatusCodes.BadNodeIdUnknown}));
} else {
if (!obj.historyRead) {
// note : Object and View may also support historyRead to provide Event historical data
// todo implement historyRead for Object and View
const msg = " this node doesn't provide historyRead! probably not a UAVariable\n "
+ obj.nodeId.toString() + " " + obj.browseName.toString() + "\n"
+ "with " + nodeToRead.toString() + "\n"
+ "HistoryReadDetails " + historyReadDetails.toString();
if (doDebug) {
console.log("ServerEngine#_historyReadSingleNode ".cyan, msg.white.bold);
}
const err = new Error(msg);
// object has no historyRead method
return setImmediate(callback.bind(null, err));
}
function getMethodDeclaration_ArgumentList(addressSpace, objectId, methodId) {
assert(objectId instanceof NodeId);
assert(methodId instanceof NodeId);
// find object in address space
const obj = addressSpace.findNode(objectId);
if (!obj) {
// istanbul ignore next
if(doDebug) {
console.warn("cannot find node ",objectId.toString());
}
return {statusCode: StatusCodes.BadNodeIdUnknown};
}
if (!obj.hasMethods) {
return {statusCode: StatusCodes.BadNodeIdInvalid};
}
let objectMethod = obj.getMethodById(methodId);
if (!objectMethod) {
// the method doesn't belong to the object, nevertheless
// the method can be called
objectMethod = addressSpace.findNode(methodId);
if (!objectMethod || !(objectMethod instanceof UAMethod)) {
return {statusCode: StatusCodes.BadMethodInvalid};
}
}
const methodDeclarationId = objectMethod.methodDeclarationId;
assert(context instanceof SessionContext);
assert(callback instanceof Function);
const nodeId = nodeToRead.nodeId;
const indexRange = nodeToRead.indexRange;
const dataEncoding = nodeToRead.dataEncoding;
const continuationPoint = nodeToRead.continuationPoint;
timestampsToReturn = (_.isObject(timestampsToReturn)) ? timestampsToReturn : TimestampsToReturn.Neither;
const obj = this.__findObject(nodeId) as UAVariable;
if (!obj) {
// may be return BadNodeIdUnknown in dataValue instead ?
// Object Not Found
callback(null, new HistoryReadResult({ statusCode: StatusCodes.BadNodeIdUnknown }));
return;
} else {
if (!obj.historyRead) {
// note : Object and View may also support historyRead to provide Event historical data
// todo implement historyRead for Object and View
const msg = " this node doesn't provide historyRead! probably not a UAVariable\n "
+ obj.nodeId.toString() + " " + obj.browseName.toString() + "\n"
+ "with " + nodeToRead.toString() + "\n"
+ "HistoryReadDetails " + historyReadDetails.toString();
if (doDebug) {
console.log(chalk.cyan("ServerEngine#_historyReadSingleNode "),
chalk.white.bold(msg));
}
const err = new Error(msg);
addressSpace: AddressSpace,
objectId: NodeId,
methodId: NodeId
): any {
assert(objectId instanceof NodeId);
assert(methodId instanceof NodeId);
// find object in address space
const obj = addressSpace.findNode(objectId) as UAObject;
if (!obj) {
// istanbul ignore next
if (doDebug) {
debugLog("cannot find node ", objectId.toString());
}
return { statusCode: StatusCodes.BadNodeIdUnknown };
}
let objectMethod = obj.getMethodById(methodId) as UAMethod;
if (!objectMethod) {
// the method doesn't belong to the object, nevertheless
// the method can be called
objectMethod = addressSpace.findNode(methodId) as UAMethod;
if (!objectMethod || objectMethod.nodeClass !== NodeClass.Method) {
return { statusCode: StatusCodes.BadMethodInvalid };
}
}
const methodDeclarationId = (objectMethod as any).methodDeclarationId;
const methodDeclaration = addressSpace.findNode(methodDeclarationId);
if (!methodDeclaration) {
AddressSpace.prototype.browsePath = function (browsePath) {
const self = this;
assert(browsePath instanceof translate_service.BrowsePath);
const startingNode = self.findNode(browsePath.startingNode);
if (!startingNode) {
return new BrowsePathResult({statusCode: StatusCodes.BadNodeIdUnknown});
}
if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
return new BrowsePathResult({
statusCode: StatusCodes.BadNothingToDo,
targets: []
});
}
const elements_length = browsePath.relativePath.elements.length;
//-------------------------------------------------------------------------------------------------------
// verify standard RelativePath construction
// from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
// TargetName The BrowseName of the target node.
// The final element may have an empty targetName. In this situation all targets of the
public browsePath(browsePath: BrowsePath): BrowsePathResult {
assert(browsePath instanceof BrowsePath);
const startingNode = this.findNode(browsePath.startingNode);
if (!startingNode) {
return new BrowsePathResult({ statusCode: StatusCodes.BadNodeIdUnknown });
}
if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
return new BrowsePathResult({
statusCode: StatusCodes.BadNothingToDo,
targets: []
});
}
const elements_length = browsePath.relativePath.elements.length;
// -------------------------------------------------------------------------------------------------------
// verify standard RelativePath construction
// from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
// TargetName The BrowseName of the target node.
// The final element may have an empty targetName. In this situation all targets of the
// references identified by the referenceTypeId are the targets of the RelativePath.
Subscription.prototype.createMonitoredItem = function (addressSpace, timestampsToReturn, monitoredItemCreateRequest) {
const subscription = this;
assert(addressSpace.constructor.name === "AddressSpace");
assert(monitoredItemCreateRequest instanceof MonitoredItemCreateRequest);
function handle_error(statusCode) {
return new subscription_service.MonitoredItemCreateResult({statusCode: statusCode});
}
const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;
const node = addressSpace.findNode(itemToMonitor.nodeId);
if (!node) {
return handle_error(StatusCodes.BadNodeIdUnknown);
}
if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
// AttributeIds.Value is only valid for monitoring value of UAVariables.
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (itemToMonitor.attributeId === AttributeIds.INVALID) {
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (!itemToMonitor.indexRange.isValid()) {
return handle_error(StatusCodes.BadIndexRangeInvalid);
}
addressSpace: AddressSpace,
timestampsToReturn: TimestampsToReturn,
monitoredItemCreateRequest: MonitoredItemCreateRequest
): MonitoredItemCreateResult {
assert(monitoredItemCreateRequest instanceof MonitoredItemCreateRequest);
function handle_error(statusCode: StatusCode): MonitoredItemCreateResult {
return new MonitoredItemCreateResult({ statusCode });
}
const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;
const node = addressSpace.findNode(itemToMonitor.nodeId);
if (!node) {
return handle_error(StatusCodes.BadNodeIdUnknown);
}
if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
// AttributeIds.Value is only valid for monitoring value of UAVariables.
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (itemToMonitor.attributeId === AttributeIds.INVALID) {
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (!itemToMonitor.indexRange.isValid()) {
return handle_error(StatusCodes.BadIndexRangeInvalid);
}
// check dataEncoding applies only on Values
session.read(nodesToRead, 1, function (err, dataValues) {
if (!err) {
if (dataValues[0].statusCode === StatusCodes.BadNodeIdUnknown) {
//xx console.log(" INVALID NODE ", nodeId.toString());
return callback(new Error("Invalid Node " + nodeId.toString()));
}
clientObject = new ProxyObject(proxyManager, nodeId);
///x console.log("xxxx ,s",results.map(function(a){ return a.toString();}));
clientObject.browseName = dataValues[0].value.value;
clientObject.description = (dataValues[1].value ? dataValues[1].value.value : "");
clientObject.nodeClass = dataValues[2].value.value;
//xx console.log("xxx nodeClass = ",clientObject.nodeClass.toString());
if (clientObject.nodeClass === NodeClass.Variable) {
return read_accessLevels(clientObject, callback);
}
assert(context instanceof SessionContext);
assert(_.isFunction(callback));
assert(writeValue.schema.name === "WriteValue");
assert(writeValue.value instanceof DataValue);
if (writeValue.value.value === null) {
return callback(null, StatusCodes.BadTypeMismatch);
}
assert(writeValue.value.value instanceof Variant);
const nodeId = writeValue.nodeId;
const obj = engine.__findObject(nodeId);
if (!obj) {
return callback(null, StatusCodes.BadNodeIdUnknown);
} else {
obj.writeAttribute(context, writeValue, callback);
}
}