Browse Source

cosmetic improvements

Julius Pfrommer 9 years ago
parent
commit
9f9c66b413
4 changed files with 23 additions and 28 deletions
  1. 1 2
      examples/client.c
  2. 1 1
      examples/server.c
  3. 20 24
      src/client/ua_client.c
  4. 1 1
      src/server/ua_server.c

+ 1 - 2
examples/client.c

@@ -46,8 +46,7 @@ int main(int argc, char *argv[]) {
     UA_Array_delete(endpointArray,endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
 
     //connect to a server
-    retval = UA_Client_connect(client, UA_ClientConnectionTCP,
-                                             "opc.tcp://localhost:16664");
+    retval = UA_Client_connect(client, UA_ClientConnectionTCP, "opc.tcp://localhost:16664");
 
     if(retval != UA_STATUSCODE_GOOD) {
         UA_Client_delete(client);

+ 1 - 1
examples/server.c

@@ -452,5 +452,5 @@ int main(int argc, char** argv) {
 #endif
 
     UA_ByteString_deleteMembers(&config.serverCertificate);
-    return retval;
+    return (int)retval;
 }

+ 20 - 24
src/client/ua_client.c

@@ -177,11 +177,10 @@ static UA_StatusCode SecureChannelHandshake(UA_Client *client, UA_Boolean renew)
 
     UA_SecureConversationMessageHeader messageHeader;
     messageHeader.messageHeader.messageTypeAndFinal = UA_MESSAGETYPEANDFINAL_OPNF;
-    if(renew){
+    if(renew)
         messageHeader.secureChannelId = client->channel.securityToken.channelId;
-    }else{
+    else
         messageHeader.secureChannelId = 0;
-    }
 
     UA_SequenceHeader seqHeader;
     seqHeader.sequenceNumber = ++client->channel.sequenceNumber;
@@ -277,8 +276,7 @@ static UA_StatusCode SecureChannelHandshake(UA_Client *client, UA_Boolean renew)
         UA_ByteString_deleteMembers(&reply);
         
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_SECURECHANNEL,
-                     "Decoding OpenSecureChannelResponse failed");
+        UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_SECURECHANNEL, "Decoding OpenSecureChannelResponse failed");
         UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&asymHeader);
         UA_OpenSecureChannelResponse_init(&response);
         response.responseHeader.serviceResult = retval;
@@ -287,18 +285,22 @@ static UA_StatusCode SecureChannelHandshake(UA_Client *client, UA_Boolean renew)
 
     //response.securityToken.revisedLifetime is UInt32 we need to cast it to DateTime=Int64
     //we take 75% of lifetime to start renewing as described in standard
-    client->scRenewAt = UA_DateTime_now() + (UA_DateTime)(response.securityToken.revisedLifetime * (UA_Double)UA_MSEC_TO_DATETIME * 0.75);
+    client->scRenewAt = UA_DateTime_now() +
+        (UA_DateTime)(response.securityToken.revisedLifetime * (UA_Double)UA_MSEC_TO_DATETIME * 0.75);
     retval = response.responseHeader.serviceResult;
 
     if(retval != UA_STATUSCODE_GOOD)
-        UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_SECURECHANNEL,
-                     "SecureChannel could not be opened / renewed");
+        UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_SECURECHANNEL, "SecureChannel could not be opened / renewed");
     else {
+        UA_ChannelSecurityToken_deleteMembers(&client->channel.securityToken);
         UA_ChannelSecurityToken_copy(&response.securityToken, &client->channel.securityToken);
         /* if the handshake is repeated, replace the old nonce */
         UA_ByteString_deleteMembers(&client->channel.serverNonce);
         UA_ByteString_copy(&response.serverNonce, &client->channel.serverNonce);
-        UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_SECURECHANNEL, "SecureChannel opened/renewed");
+        if(renew)
+            UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_SECURECHANNEL, "SecureChannel renewed");
+        else
+            UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_SECURECHANNEL, "SecureChannel opened");
     }
     UA_OpenSecureChannelResponse_deleteMembers(&response);
     UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&asymHeader);
@@ -337,18 +339,15 @@ static UA_StatusCode ActivateSession(UA_Client *client) {
  * Gets a list of endpoints
  * Memory is allocated for endpointDescription array
  */
-static UA_StatusCode GetEndpoints(UA_Client *client, size_t* endpointDescriptionsSize, UA_EndpointDescription** endpointDescriptions) {
+static UA_StatusCode
+GetEndpoints(UA_Client *client, size_t* endpointDescriptionsSize, UA_EndpointDescription** endpointDescriptions) {
     UA_GetEndpointsRequest request;
     UA_GetEndpointsRequest_init(&request);
     request.requestHeader.authenticationToken = client->authenticationToken;
     request.requestHeader.timestamp = UA_DateTime_now();
     request.requestHeader.timeoutHint = 10000;
+    request.endpointUrl = client->endpointUrl; // assume the endpointurl outlives the service call
     
-    request.endpointUrl = client->endpointUrl; //here we assume the endpointUrl is on the stack
-    
-    //no filter for endpoints
-    request.profileUrisSize = 0;
-
     UA_GetEndpointsResponse response;
     UA_GetEndpointsResponse_init(&response);
     __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_GETENDPOINTSREQUEST],
@@ -356,18 +355,16 @@ static UA_StatusCode GetEndpoints(UA_Client *client, size_t* endpointDescription
 
     if(response.responseHeader.serviceResult != UA_STATUSCODE_GOOD) {
         UA_LOG_ERROR(client->logger, UA_LOGCATEGORY_CLIENT, "GetEndpointRequest failed");
+        UA_GetEndpointsResponse_deleteMembers(&response);
         return response.responseHeader.serviceResult;
     }
 
     *endpointDescriptionsSize = response.endpointsSize;
     *endpointDescriptions = UA_Array_new(response.endpointsSize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
-    for(size_t i=0;i<response.endpointsSize;i++){
+    for(size_t i=0;i<response.endpointsSize;i++)
         UA_EndpointDescription_copy(&response.endpoints[i], &(*endpointDescriptions)[i]);
-    }
-
     UA_GetEndpointsResponse_deleteMembers(&response);
-
-    return response.responseHeader.serviceResult;
+    return UA_STATUSCODE_GOOD;
 }
 
 static UA_StatusCode EndpointsHandshake(UA_Client *client) {
@@ -524,7 +521,7 @@ UA_Client_getEndpoints(UA_Client *client, UA_ConnectClientConnection connectFunc
     }
 
     client->endpointUrl = UA_STRING_ALLOC(serverUrl);
-    if(client->endpointUrl.data == NULL) {
+    if(!client->endpointUrl.data) {
         retval = UA_STATUSCODE_BADOUTOFMEMORY;
         goto cleanup;
     }
@@ -557,7 +554,7 @@ UA_StatusCode UA_Client_connect(UA_Client *client, UA_ConnectClientConnection co
     }
 
     client->endpointUrl = UA_STRING_ALLOC(endpointUrl);
-    if(client->endpointUrl.data == NULL) {
+    if(!client->endpointUrl.data) {
         retval = UA_STATUSCODE_BADOUTOFMEMORY;
         goto cleanup;
     }
@@ -699,6 +696,5 @@ void __UA_Client_Service(UA_Client *client, const void *r, const UA_DataType *re
         client->state = UA_CLIENTSTATE_ERRORED;
         respHeader->serviceResult = retval;
     }
-    UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_CLIENT,
-                 "Received a response of type %i", responseId.identifier.numeric);
+    UA_LOG_DEBUG(client->logger, UA_LOGCATEGORY_CLIENT, "Received a response of type %i", responseId.identifier.numeric);
 }

+ 1 - 1
src/server/ua_server.c

@@ -496,7 +496,7 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     /**********************/
 
     server->startTime = UA_DateTime_now();
-    
+
     /**************/
     /* References */
     /**************/