static UA_StatusCode EndpointsHandshake(UA_Client *client) { 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; UA_String profileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary"); request.profileUris = &profileUri; request.profileUrisSize = 1; UA_GetEndpointsResponse response; UA_GetEndpointsResponse_init(&response); __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_GETENDPOINTSREQUEST], &response, &UA_TYPES[UA_TYPES_GETENDPOINTSRESPONSE]); UA_Boolean endpointFound = UA_FALSE; UA_Boolean tokenFound = UA_FALSE; UA_String securityNone = UA_STRING("http://opcfoundation.org/UA/SecurityPolicy#None"); for(UA_Int32 i = 0; i < response.endpointsSize; i++) { UA_EndpointDescription* endpoint = &response.endpoints[i]; /* look out for an endpoint without security */ if(!UA_String_equal(&endpoint->securityPolicyUri, &securityNone)) continue; endpointFound = UA_TRUE; /* endpoint with no security found */ /* look for a user token policy with an anonymous token */ for(UA_Int32 j=0; j<endpoint->userIdentityTokensSize; ++j) { UA_UserTokenPolicy* userToken = &endpoint->userIdentityTokens[j]; if(userToken->tokenType != UA_USERTOKENTYPE_ANONYMOUS) continue; tokenFound = UA_TRUE; UA_UserTokenPolicy_copy(userToken, &client->token); break; } } UA_GetEndpointsResponse_deleteMembers(&response); if(!endpointFound) { UA_LOG_ERROR(client->logger, UA_LOGCATEGORY_CLIENT, "No suitable endpoint found"); return UA_STATUSCODE_BADINTERNALERROR; } if(!tokenFound) { UA_LOG_ERROR(client->logger, UA_LOGCATEGORY_CLIENT, "No anonymous token found"); return UA_STATUSCODE_BADINTERNALERROR; } return response.responseHeader.serviceResult; }
static UA_StatusCode requestGetEndpoints(UA_Client *client, UA_UInt32 *requestId) { UA_GetEndpointsRequest request; UA_GetEndpointsRequest_init(&request); request.requestHeader.timestamp = UA_DateTime_now(); request.requestHeader.timeoutHint = 10000; /* assume the endpointurl outlives the service call */ UA_String_copy(&client->endpointUrl, &request.endpointUrl); client->connectStatus = UA_Client_sendAsyncRequest( client, &request, &UA_TYPES[UA_TYPES_GETENDPOINTSREQUEST], (UA_ClientAsyncServiceCallback) responseGetEndpoints, &UA_TYPES[UA_TYPES_GETENDPOINTSRESPONSE], NULL, requestId); UA_GetEndpointsRequest_deleteMembers(&request); return client->connectStatus; }
static UA_StatusCode GetEndpoints(UA_Client *client, const UA_String* endpointUrl, size_t* endpointDescriptionsSize, UA_EndpointDescription** endpointDescriptions, const char* filterTransportProfileUri) { UA_GetEndpointsRequest request; UA_GetEndpointsRequest_init(&request); //request.requestHeader.authenticationToken = client->authenticationToken; request.requestHeader.timestamp = UA_DateTime_now(); request.requestHeader.timeoutHint = 10000; request.endpointUrl = *endpointUrl; // assume the endpointurl outlives the service call if (filterTransportProfileUri) { request.profileUrisSize = 1; request.profileUris = (UA_String*)UA_malloc(sizeof(UA_String)); request.profileUris[0] = UA_String_fromChars(filterTransportProfileUri); } UA_GetEndpointsResponse response; UA_GetEndpointsResponse_init(&response); __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_GETENDPOINTSREQUEST], &response, &UA_TYPES[UA_TYPES_GETENDPOINTSRESPONSE]); if (filterTransportProfileUri) { UA_Array_delete(request.profileUris, request.profileUrisSize, &UA_TYPES[UA_TYPES_STRING]); } ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD); *endpointDescriptionsSize = response.endpointsSize; *endpointDescriptions = (UA_EndpointDescription*)UA_Array_new(response.endpointsSize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); for(size_t i=0;i<response.endpointsSize;i++) { UA_EndpointDescription_init(&(*endpointDescriptions)[i]); UA_EndpointDescription_copy(&response.endpoints[i], &(*endpointDescriptions)[i]); } UA_GetEndpointsResponse_deleteMembers(&response); return UA_STATUSCODE_GOOD; }