Skip to content

Commit

Permalink
ctt fixes (#1685)
Browse files Browse the repository at this point in the history
* remove the SetDurableSubscription method, to skip the test cases
* DeleteSubscription returns BadSubscriptionIdInvalid
* MethodState return also BadTooManyArguments
* return AttributeIdInvalid for null attributes (fix UA Expert display)
* fix ToString of Variant array of ByteString
* fix Variant decoding 1-dim array of bytestring
  • Loading branch information
mregen committed Jan 27, 2022
1 parent 8d3e393 commit 079148f
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 22 deletions.
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
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 @@ -443,10 +443,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
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 @@ -2205,7 +2205,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 079148f

Please sign in to comment.