Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function __internalRegisterServer(RegisterServerXResponse, discoveryServer, server, discoveryConfiguration) {
function sendError(statusCode) {
///Xx xconsole.log(chalk.red("_on_RegisterServerRequest error"), statusCode.toString());
const response = new RegisterServerXResponse({responseHeader: {serviceResult: statusCode}});
return response;
}
// check serverType is valid
if (!_isValidServerType(server.serverType)) {
return sendError(StatusCodes.BadInvalidArgument);
}
// BadServerUriInvalid
// TODO
// BadServerNameMissing
if (server.serverNames.length === 0) {
return sendError(StatusCodes.BadServerNameMissing);
}
// BadDiscoveryUrlMissing
if (server.discoveryUrls.length === 0) {
return sendError(StatusCodes.BadDiscoveryUrlMissing);
}
const key = server.serverUri;
// it is possible to not provide inputArguments when method has no arguments
return {statusCode: StatusCodes.Good};
}
if (methodInputArguments.length > 0 && !inputArguments) {
return {statusCode: StatusCodes.BadArgumentsMissing};
}
inputArguments = inputArguments ||[];
if (methodInputArguments.length > inputArguments.length) {
// istanbul ignore next
if (doDebug) {
console.log("xxxxxxxx verifyArguments_ArgumentList " +
"\n The client did specify too many input arguments for the method. " +
"\n expected : " +methodInputArguments.length + "" +
"\n actual : " + inputArguments.length );
}
return {statusCode: StatusCodes.BadInvalidArgument};
}
if (methodInputArguments.length < inputArguments.length) {
// istanbul ignore next
if (doDebug) {
console.log("xxxxxxxx verifyArguments_ArgumentList " +
"\n The client did not specify all of the input arguments for the method. " +
"\n expected : " + methodInputArguments.length + "" +
"\n actual : " + inputArguments.length);
}
return {statusCode: StatusCodes.BadArgumentsMissing};
}
let errorCount = 0;
for (let i = 0; i < methodInputArguments.length; i++) {
delete previousConfMap[discoveryConfiguration.mdnsServerName!];
(discoveryConfiguration as any).bonjourHolder = prevConf.bonjourHolder;
}
// let's announce the server on the multicast DNS
await _announcedOnMulticastSubnet(discoveryConfiguration, announcement);
return StatusCodes.Good;
}
// check serverType is valid
if (!_isValidServerType(server.serverType)) {
return sendError(StatusCodes.BadInvalidArgument);
}
if (!server.serverUri) {
return sendError(StatusCodes.BadInvalidArgument);
}
// BadServerUriInvalid
// TODO
server.serverNames = server.serverNames || [];
// BadServerNameMissing
if (server.serverNames.length === 0) {
return sendError(StatusCodes.BadServerNameMissing);
}
// BadDiscoveryUrlMissing
server.discoveryUrls = server.discoveryUrls || [];
if (server.discoveryUrls.length === 0) {
return sendError(StatusCodes.BadDiscoveryUrlMissing);
}
if (doDebug) {
console.log("xxxxxxxx verifyArguments_ArgumentList \n" +
" The client did specify a argument with the wrong data type.\n" +
" expected : ".white + argDefinition.dataType + "\n" +
" actual :".cyan + arg.dataType);
}
inputArgumentResults.push(StatusCodes.BadTypeMismatch);
errorCount += 1;
} else {
inputArgumentResults.push(StatusCodes.Good);
}
}
assert(inputArgumentResults.length === methodInputArguments.length);
const ret = {
statusCode: errorCount === 0 ? StatusCodes.Good : StatusCodes.BadInvalidArgument,
inputArgumentResults: inputArgumentResults
};
return ret;
}
const nonceVariant = inputArguments[4];
if (!expected(certificateGroupIdVariant, DataType.NodeId, VariantArrayType.Scalar)) {
return { statusCode: StatusCodes.BadInvalidArgument };
}
if (!expected(certificateTypeIdVariant, DataType.NodeId, VariantArrayType.Scalar)) {
return { statusCode: StatusCodes.BadInvalidArgument };
}
if (!expected(subjectNameVariant, DataType.String, VariantArrayType.Scalar)) {
return { statusCode: StatusCodes.BadInvalidArgument };
}
if (!expected(regeneratePrivateKeyVariant, DataType.Boolean, VariantArrayType.Scalar)) {
return { statusCode: StatusCodes.BadInvalidArgument };
}
if (!expected(regeneratePrivateKeyVariant, DataType.Boolean, VariantArrayType.Scalar)) {
return { statusCode: StatusCodes.BadInvalidArgument };
}
if (!hasEncryptedChannel(context)) {
return { statusCode: StatusCodes.BadSecurityModeInsufficient };
}
if (!hasExpectedUserAccess(context)) {
return { statusCode: StatusCodes.BadUserAccessDenied };
}
const certificateGroupId = certificateGroupIdVariant.value as NodeId;
const certificateTypeId = certificateTypeIdVariant.value as NodeId;
const subjectName = subjectNameVariant.value as string;
const regeneratePrivateKey = regeneratePrivateKeyVariant.value as boolean;
const nonce = nonceVariant.value as Buffer;
debugLog("verifyArguments_ArgumentList \n" +
" The client did specify a argument with the wrong data type.\n" +
chalk.white(" expected : ") + argDefinition.dataType + "\n" +
chalk.cyan(" actual :") + arg.dataType);
}
inputArgumentResults.push(StatusCodes.BadTypeMismatch);
errorCount += 1;
} else {
inputArgumentResults.push(StatusCodes.Good);
}
}
assert(inputArgumentResults.length === methodInputArguments.length);
const ret = {
inputArgumentResults,
statusCode: errorCount === 0 ? StatusCodes.Good : StatusCodes.BadInvalidArgument
};
return ret;
}
async function _setPositionFile(
this: UAMethod,
inputArguments: Variant[],
context: SessionContext
): Promise {
const addressSpace = this.addressSpace;
const fileHandle: UInt32 = inputArguments[0].value as UInt32;
const position: UInt64 = inputArguments[1].value as UInt64;
const _fileInfo = _getFileInfo(addressSpace, context, fileHandle);
if (!_fileInfo) {
return { statusCode: StatusCodes.BadInvalidArgument };
}
_fileInfo.position = position;
return { statusCode: StatusCodes.Good };
}