Browse Source

improve documentation, get rid of a duplicate function for string comparison

Julius Pfrommer 9 years ago
parent
commit
bc5151e65d
4 changed files with 43 additions and 50 deletions
  1. 34 37
      include/ua_types.h
  2. 1 2
      src/server/ua_services_attribute.c
  3. 8 6
      src/server/ua_services_session.c
  4. 0 5
      src/ua_types.c

+ 34 - 37
include/ua_types.h

@@ -111,8 +111,8 @@ typedef double UA_Double;
 
 /** @brief A sequence of Unicode characters. */
 typedef struct {
-    UA_Int32 length;
-    UA_Byte *data;
+    UA_Int32 length; ///< The length of the string
+    UA_Byte *data; ///< The string's content (not null-terminated)
 } UA_String;
 
 /** @brief An instance in time.
@@ -138,26 +138,26 @@ typedef UA_String UA_XmlElement;
 /** @brief An identifier for a node in the address space of an OPC UA Server. */
 /* The shortened numeric types are introduced during encoding. */
 typedef struct {
-    UA_UInt16 namespaceIndex;
-    enum {
+    UA_UInt16 namespaceIndex; ///< The namespace index of the node
+    enum UA_NodeIdType {
         UA_NODEIDTYPE_NUMERIC    = 2,
         UA_NODEIDTYPE_STRING     = 3,
         UA_NODEIDTYPE_GUID       = 4,
         UA_NODEIDTYPE_BYTESTRING = 5
-    } identifierType;
+    } identifierType; ///< The type of the node identifier
     union {
         UA_UInt32     numeric;
         UA_String     string;
         UA_Guid       guid;
         UA_ByteString byteString;
-    } identifier;
+    } identifier; ///< The node identifier
 } UA_NodeId;
 
 /** @brief A NodeId that allows the namespace URI to be specified instead of an index. */
 typedef struct {
-    UA_NodeId nodeId;
-    UA_String namespaceUri; // not encoded if length=-1
-    UA_UInt32 serverIndex;  // not encoded if 0
+    UA_NodeId nodeId; ///< The nodeid without extensions
+    UA_String namespaceUri; ///< The Uri of the namespace (tindex in the nodeId is ignored)
+    UA_UInt32 serverIndex;  ///< The index of the server
 } UA_ExpandedNodeId;
 
 #include "ua_statuscodes.h"
@@ -166,43 +166,31 @@ typedef enum UA_StatusCode UA_StatusCode; // StatusCodes aren't an enum(=int) si
 
 /** @brief A name qualified by a namespace. */
 typedef struct {
-    UA_UInt16 namespaceIndex;
-    UA_String name;
+    UA_UInt16 namespaceIndex; ///< The namespace index
+    UA_String name; ///< The actual name
 } UA_QualifiedName;
 
 /** @brief Human readable text with an optional locale identifier. */
 typedef struct {
-    UA_String locale;
-    UA_String text;
+    UA_String locale; ///< The locale (e.g. "en-US")
+    UA_String text; ///< The actual text
 } UA_LocalizedText;
 
 /** @brief A structure that contains an application specific data type that may
     not be recognized by the receiver. */
 typedef struct {
-    UA_NodeId typeId;
+    UA_NodeId typeId; ///< The nodeid of the datatype
     enum {
         UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED  = 0,
         UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING = 1,
         UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISXML        = 2
-    } encoding;
-    UA_ByteString body; // contains either the bytestring or a pointer to the memory-object
+    } encoding; ///< The encoding of the contained data
+    UA_ByteString body; ///< The bytestring of the encoded data
 } UA_ExtensionObject;
 
 struct UA_DataType;
 typedef struct UA_DataType UA_DataType; 
 
-/** @brief NumericRanges are used select a subset in a (multidimensional) variant array.
-    NumericRange has no official type structure in the standard. Officially, it only exists as an
-    encoded string, such as "1:2,0:3,5". The colon separates min/max index and the comma separates
-    dimensions. A single value indicates a range with a single element (min==max). */
-typedef struct {
-    UA_Int32 dimensionsSize;
-    struct UA_NumericRangeDimension {
-        UA_UInt32 min;
-        UA_UInt32 max;
-    } *dimensions;
-} UA_NumericRange;
-
 /** @brief Variants store (arrays of) any data type. Either they provide a pointer to the data in
  *   memory, or functions from which the data can be accessed. Variants are replaced together with
  *   the data they store (exception: use a data source).
@@ -215,14 +203,14 @@ typedef struct {
  */
 
 typedef struct {
-    const UA_DataType *type;
+    const UA_DataType *type; ///< The nodeid of the datatype
     enum {
         UA_VARIANT_DATA, ///< The data is "owned" by this variant (copied and deleted together)
         UA_VARIANT_DATA_NODELETE, /**< The data is "borrowed" by the variant and shall not be
                                        deleted at the end of this variant's lifecycle. It is not
                                        possible to overwrite borrowed data due to concurrent access.
                                        Use a custom datasource with a mutex. */
-    } storageType;
+    } storageType; ///< Shall the data be deleted together with the variant
     UA_Int32  arrayLength;  ///< the number of elements in the data-pointer
     void     *data; ///< points to the scalar or array data
     UA_Int32  arrayDimensionsSize; ///< the number of dimensions the data-array has
@@ -322,18 +310,15 @@ UA_TYPE_HANDLING_FUNCTIONS(UA_DiagnosticInfo)
     allocated. If the memory cannot be allocated, a null-string is returned. */
 UA_String UA_EXPORT UA_String_fromChars(char const src[]);
 
-#define UA_STRING_ALLOC(CHARS) UA_String_fromChars(CHARS)
-#define UA_STRING(CHARS) (UA_String) {strlen(CHARS), (UA_Byte*)CHARS }
 #define UA_STRING_NULL (UA_String) {-1, (UA_Byte*)0 }
-
-/** Printf a char-array into a UA_String. Memory for the string data is allocated. */
-UA_StatusCode UA_EXPORT UA_String_copyprintf(char const fmt[], UA_String *dst, ...);
+#define UA_STRING(CHARS) (UA_String) {strlen(CHARS), (UA_Byte*)CHARS }
+#define UA_STRING_ALLOC(CHARS) UA_String_fromChars(CHARS)
 
 /** Compares two strings */
 UA_Boolean UA_EXPORT UA_String_equal(const UA_String *string1, const UA_String *string2);
 
-/** Compares an UA String with a char array */
-UA_Boolean UA_EXPORT UA_String_equalchars(const UA_String *string1, char *charString);
+/** Printf a char-array into a UA_String. Memory for the string data is allocated. */
+UA_StatusCode UA_EXPORT UA_String_copyprintf(char const fmt[], UA_String *dst, ...);
 
 /* DateTime */
 /** Returns the current time */
@@ -472,6 +457,18 @@ UA_StatusCode UA_EXPORT UA_Variant_setArray(UA_Variant *v, void *array, UA_Int32
 UA_StatusCode UA_EXPORT UA_Variant_setArrayCopy(UA_Variant *v, const void *array, UA_Int32 noElements,
                                                 const UA_DataType *type);
 
+/** @brief NumericRanges are used select a subset in a (multidimensional) variant array.
+    NumericRange has no official type structure in the standard. Officially, it only exists as an
+    encoded string, such as "1:2,0:3,5". The colon separates min/max index and the comma separates
+    dimensions. A single value indicates a range with a single element (min==max). */
+typedef struct {
+    UA_Int32 dimensionsSize;
+    struct UA_NumericRangeDimension {
+        UA_UInt32 min;
+        UA_UInt32 max;
+    } *dimensions;
+} UA_NumericRange;
+
 /**
  * Copy the variant, but use only a subset of the (multidimensional) array into a variant. Returns
  * an error code if the variant is not an array or if the indicated range does not fit.

+ 1 - 2
src/server/ua_services_attribute.c

@@ -95,8 +95,7 @@ static void handleSourceTimestamps(UA_TimestampsToReturn timestamps, UA_DataValu
 #ifndef BUILD_UNIT_TESTS
 static
 #endif
-void readValue(UA_Server *server, UA_TimestampsToReturn timestamps,
-                      const UA_ReadValueId *id, UA_DataValue *v) {
+void readValue(UA_Server *server, UA_TimestampsToReturn timestamps, const UA_ReadValueId *id, UA_DataValue *v) {
     UA_String binEncoding = UA_STRING("DefaultBinary");
     UA_String xmlEncoding = UA_STRING("DefaultXml");
 	if(id->dataEncoding.name.length >= 0){

+ 8 - 6
src/server/ua_services_session.c

@@ -59,19 +59,19 @@ void Service_ActivateSession(UA_Server *server, UA_SecureChannel *channel,
     UA_UserNameIdentityToken username_token;
     UA_UserNameIdentityToken_init(&username_token);
 
+    UA_String ap = UA_STRING(ANONYMOUS_POLICY);
+    UA_String up = UA_STRING(USERNAME_POLICY);
     if(token.policyId.data == UA_NULL) {
         /* 1) no policy defined */
         response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
-    } else if(server->config.Login_enableAnonymous &&
-              UA_String_equalchars(&token.policyId, ANONYMOUS_POLICY)) {
+    } else if(server->config.Login_enableAnonymous && UA_String_equal(&token.policyId, &ap)) {
         /* 2) anonymous logins */
         if(foundSession->channel && foundSession->channel != channel)
             UA_SecureChannel_detachSession(foundSession->channel, foundSession);
         UA_SecureChannel_attachSession(channel, foundSession);
         foundSession->activated = UA_TRUE;
         UA_Session_updateLifetime(foundSession);
-    } else if(server->config.Login_enableUsernamePassword &&
-              UA_String_equalchars(&token.policyId, USERNAME_POLICY)) {
+    } else if(server->config.Login_enableUsernamePassword && UA_String_equal(&token.policyId, &up)) {
         /* 3) username logins */
         offset = 0;
         UA_UserNameIdentityToken_decodeBinary(&request->userIdentityToken.body, &offset, &username_token);
@@ -85,8 +85,10 @@ void Service_ActivateSession(UA_Server *server, UA_SecureChannel *channel,
             /* 3.3) ok, trying to match the username */
             UA_UInt32 i = 0;
             for(; i < server->config.Login_loginsCount; ++i) {
-                if(UA_String_equalchars(&username_token.userName, server->config.Login_usernames[i])
-                    && UA_String_equalchars(&username_token.password, server->config.Login_passwords[i])) {
+                UA_String user = UA_STRING(server->config.Login_usernames[i]);
+                UA_String pw = UA_STRING(server->config.Login_passwords[i]);
+                if(UA_String_equal(&username_token.userName, &user) &&
+                   UA_String_equal(&username_token.password, &pw)) {
                     /* success - activate */
                     if(foundSession->channel && foundSession->channel != channel)
                         UA_SecureChannel_detachSession(foundSession->channel, foundSession);

+ 0 - 5
src/ua_types.c

@@ -159,11 +159,6 @@ UA_Boolean UA_String_equal(const UA_String *string1, const UA_String *string2) {
     return (is == 0) ? UA_TRUE : UA_FALSE;
 }
 
-UA_Boolean UA_String_equalchars(const UA_String *string1, char *charString) {
-    UA_String string2 = UA_STRING(charString);
-    return UA_String_equal(string1, &string2);
-}
-
 /* DateTime */
 #define UNIX_EPOCH_BIAS_SEC 11644473600LL // Number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
 #define HUNDRED_NANOSEC_PER_USEC 10LL