Skip to content

Commit

Permalink
Merge pull request #1684 from mrsuciu/1.4.367roleset
Browse files Browse the repository at this point in the history
Initialize well known nodes to default values
ctt fixes (#1685) 
Assign a default value to any variable in namespace 0
Set status code Good for all BaseVariableState in namespace 0
  • Loading branch information
mrsuciu committed Jan 27, 2022
2 parents 03c9936 + f9a6509 commit cc7fded
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 37 deletions.
11 changes: 11 additions & 0 deletions Libraries/Opc.Ua.Server/Diagnostics/CustomNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ protected virtual void AddPredefinedNode(ISystemContext context, NodeState node)
m_predefinedNodes = new NodeIdDictionary<NodeState>();
}

// assign a default value to any variable in namespace 0
if (node is BaseVariableState nodeStateVar)
{
if (nodeStateVar.NodeId.NamespaceIndex == 0 && nodeStateVar.Value == null)
{
nodeStateVar.Value = TypeInfo.GetDefaultValue(nodeStateVar.DataType,
nodeStateVar.ValueRank,
Server.TypeTree);
}
}

NodeState activeNode = AddBehaviourToPredefinedNode(context, node);
m_predefinedNodes[activeNode.NodeId] = activeNode;

Expand Down
24 changes: 21 additions & 3 deletions Libraries/Opc.Ua.Server/Diagnostics/DiagnosticsNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> e
Server.CoreNodeManager.ImportNodes(SystemContext, PredefinedNodes.Values, true);

// hook up the server GetMonitoredItems method.
MethodState getMonitoredItems = (MethodState)FindPredefinedNode(
GetMonitoredItemsMethodState getMonitoredItems = (GetMonitoredItemsMethodState)FindPredefinedNode(
MethodIds.Server_GetMonitoredItems,
typeof(MethodState));
typeof(GetMonitoredItemsMethodState));

if (getMonitoredItems != null)
{
Expand All @@ -169,11 +169,29 @@ public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> e
getMonitoredItemsOutputArguments.ClearChangeMasks(SystemContext, false);
}
}

// Subscription Durable mode not supported by the server.
ServerObjectState serverObject = (ServerObjectState)FindPredefinedNode(
ObjectIds.Server,
typeof(ServerObjectState));

if (serverObject != null)
{
NodeState setSubscriptionDurableNode = serverObject.FindChild(
SystemContext,
BrowseNames.SetSubscriptionDurable);

if (setSubscriptionDurableNode != null)
{
DeleteNode(SystemContext, MethodIds.Server_SetSubscriptionDurable);
serverObject.SetSubscriptionDurable = null;
}
}
}
}

/// <summary>
/// Called when a client locks the server.
/// Called when a client gets the monitored items of a subscription.
/// </summary>
public ServiceResult OnGetMonitoredItems(
ISystemContext context,
Expand Down
14 changes: 14 additions & 0 deletions Libraries/Opc.Ua.Server/Server/ServerInternalData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,20 @@ private void CreateServerObject()
operationLimits.MaxMonitoredItemsPerCall = null;
}

// setup PublishSubscribe Status State value
PubSubState pubSubState = PubSubState.Disabled;

var default_PubSubState = (BaseVariableState)m_diagnosticsNodeManager.FindPredefinedNode(
VariableIds.PublishSubscribe_Status_State,
typeof(BaseVariableState));
default_PubSubState.Value = pubSubState;

// setup value for SupportedTransportProfiles
var default_SupportedTransportProfiles = (BaseVariableState)m_diagnosticsNodeManager.FindPredefinedNode(
VariableIds.PublishSubscribe_SupportedTransportProfiles,
typeof(BaseVariableState));
default_SupportedTransportProfiles.Value = "uadp";

// setup callbacks for dynamic values.
serverObject.NamespaceArray.OnSimpleReadValue = OnReadNamespaceArray;
serverObject.NamespaceArray.MinimumSamplingInterval = 1000;
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Opc.Ua.Server/Subscription/SubscriptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ public StatusCode DeleteSubscription(OperationContext context, uint subscription

if (!NodeId.IsNull(sessionId))
{
// check that the subscrition is the owner.
// check that the subscription is the owner.
if (context != null && !Object.ReferenceEquals(context.Session, subscription.Session))
{
throw new ServiceResultException(StatusCodes.BadSessionIdInvalid);
throw new ServiceResultException(StatusCodes.BadSubscriptionIdInvalid);
}

SessionPublishQueue queue = null;
Expand Down
22 changes: 7 additions & 15 deletions Stack/Opc.Ua.Core/Stack/Server/ServerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,12 @@ private static string GetBestDiscoveryUrl(Uri clientUrl, BaseAddress baseAddress
continue;
}

if (endpointUrl.Port != baseAddress.Url.Port)
{
continue;
}


EndpointDescription translation = new EndpointDescription();

translation.EndpointUrl = baseAddress.Url.ToString();
Expand All @@ -1094,22 +1100,8 @@ private static string GetBestDiscoveryUrl(Uri clientUrl, BaseAddress baseAddress
translation.UserIdentityTokens = endpoint.UserIdentityTokens;
translation.Server = application;

// skip duplicates.
bool duplicateFound = false;
translations.Add(translation);

foreach (EndpointDescription existingTranslation in translations)
{
if (existingTranslation.IsEqual(translation))
{
duplicateFound = true;
break;
}
}

if (!duplicateFound)
{
translations.Add(translation);
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Stack/Opc.Ua.Core/Stack/State/MethodState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,16 @@ public PropertyState<Argument[]> OutputArguments
expectedCount = InputArguments.Value.Length;
}

if (expectedCount != inputArguments.Count)
if (expectedCount > inputArguments.Count)
{
return StatusCodes.BadArgumentsMissing;
}

if (expectedCount < inputArguments.Count)
{
return StatusCodes.BadTooManyArguments;
}

// validate individual arguements.
bool error = false;

Expand Down
21 changes: 18 additions & 3 deletions Stack/Opc.Ua.Core/Stack/State/NodeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3454,7 +3454,12 @@ protected virtual void PopulateBrowser(ISystemContext context, NodeBrowser brows
value = description;
}

return result;
if (value != null)
{
return result;
}

break;
}

case Attributes.WriteMask:
Expand Down Expand Up @@ -3505,7 +3510,12 @@ protected virtual void PopulateBrowser(ISystemContext context, NodeBrowser brows
value = rolePermissions;
}

return result;
if (value != null)
{
return result;
}

break;
}

case Attributes.UserRolePermissions:
Expand All @@ -3522,7 +3532,12 @@ protected virtual void PopulateBrowser(ISystemContext context, NodeBrowser brows
value = userRolePermissions;
}

return result;
if (value != null)
{
return result;
}

break;
}

case Attributes.AccessRestrictions:
Expand Down
55 changes: 43 additions & 12 deletions Stack/Opc.Ua.Core/Types/BuiltIn/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,24 @@ public string ToString(string format, IFormatProvider formatProvider)
throw new FormatException(Utils.Format("Invalid format string: '{0}'.", format));
}

/// <summary>
/// Append a ByteString as a hex string.
/// </summary>
private void AppendByteString(StringBuilder buffer, byte[] bytes, IFormatProvider formatProvider)
{
if (bytes != null)
{
for (int ii = 0; ii < bytes.Length; ii++)
{
buffer.AppendFormat(formatProvider, "{0:X2}", bytes[ii]);
}
}
else
{
buffer.Append("(null)");
}
}

/// <summary>
/// Formats a value as a string.
/// </summary>
Expand All @@ -877,12 +895,7 @@ private void AppendFormat(StringBuilder buffer, object value, IFormatProvider fo
if (m_typeInfo.BuiltInType == BuiltInType.ByteString && m_typeInfo.ValueRank < 0)
{
byte[] bytes = (byte[])value;

for (int ii = 0; ii < bytes.Length; ii++)
{
buffer.AppendFormat(formatProvider, "{0:X2}", bytes[ii]);
}

AppendByteString(buffer, bytes, formatProvider);
return;
}

Expand All @@ -901,15 +914,33 @@ private void AppendFormat(StringBuilder buffer, object value, IFormatProvider fo
{
buffer.Append('{');

if (array.Length > 0)
if (m_typeInfo.BuiltInType == BuiltInType.ByteString)
{
AppendFormat(buffer, array.GetValue(0), formatProvider);
}
if (array.Length > 0)
{
byte[] bytes = (byte[])array.GetValue(0);
AppendByteString(buffer, bytes, formatProvider);
}

for (int ii = 1; ii < array.Length; ii++)
for (int ii = 1; ii < array.Length; ii++)
{
buffer.Append('|');
byte[] bytes = (byte[])array.GetValue(ii);
AppendByteString(buffer, bytes, formatProvider);
}
}
else
{
buffer.Append(" |");
AppendFormat(buffer, array.GetValue(ii), formatProvider);
if (array.Length > 0)
{
AppendFormat(buffer, array.GetValue(0), formatProvider);
}

for (int ii = 1; ii < array.Length; ii++)
{
buffer.Append('|');
AppendFormat(buffer, array.GetValue(ii), formatProvider);
}
}

buffer.Append('}');
Expand Down
2 changes: 1 addition & 1 deletion Stack/Opc.Ua.Core/Types/Encoders/BinaryDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ private Variant ReadVariantValue(string fieldName)
}
else
{
value = new Variant(array);
value = new Variant(array, new TypeInfo(builtInType, 1));
}
}
}
Expand Down

0 comments on commit cc7fded

Please sign in to comment.