/**
* @brief Initializes the given parameter and allocates embedded objects.
* If embedded objects cannot be allocated, the given pointer is set to OpcUa_Null.
*
* @return Bad status on fail; Good status on success;
*/
OpcUa_StatusCode OpcUa_TcpListener_Connection_Initialize(OpcUa_TcpListener_Connection* a_pConnection)
{
    OpcUa_StatusCode uStatus    = OpcUa_Good;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_TcpListener);

    OpcUa_ReturnErrorIfArgumentNull(a_pConnection);

    OpcUa_MemSet(&(a_pConnection->ConnectTime), 0, sizeof(OpcUa_DateTime));
    OpcUa_MemSet(&(a_pConnection->DisconnectTime), 0, sizeof(OpcUa_DateTime));

    a_pConnection->Socket                   = OpcUa_Null;

#if OPCUA_P_SOCKETGETPEERINFO_V2
    OpcUa_MemSet(a_pConnection->achPeerInfo, 0, OPCUA_P_PEERINFO_MIN_SIZE);
#else /* OPCUA_P_SOCKETGETPEERINFO_V2 */
    a_pConnection->PeerPort                 = 0;
    a_pConnection->PeerIp                   = 0;
#endif /* OPCUA_P_SOCKETGETPEERINFO_V2 */

    a_pConnection->pListenerHandle          = OpcUa_Null;
    a_pConnection->pInputStream             = OpcUa_Null;
    a_pConnection->uNoOfRequestsTotal       = 0;
    a_pConnection->bConnected               = OpcUa_False;

    OpcUa_String_Initialize(&a_pConnection->sURL);

    uStatus = OPCUA_P_MUTEX_CREATE(&(a_pConnection->Mutex));
    OpcUa_ReturnErrorIfBad(uStatus);

    a_pConnection->ReceiveBufferSize        = 0;
    a_pConnection->SendBufferSize           = 0;
    a_pConnection->pSendQueue               = OpcUa_Null;
    a_pConnection->bCloseWhenDone           = OpcUa_False;
    a_pConnection->bNoRcvUntilDone          = OpcUa_False;
    a_pConnection->bRcvDataPending          = OpcUa_False;

    return OpcUa_Good;
}
Esempio n. 2
0
/*============================================================================
 * OpcUa_TcpSecureChannel_Create
 *===========================================================================*/
OpcUa_StatusCode OpcUa_TcpSecureChannel_Create(OpcUa_SecureChannel** a_ppSecureChannel)
{
    OpcUa_TcpSecureChannel* pTcpSecureChannel = OpcUa_Null;

OpcUa_InitializeStatus(OpcUa_Module_SecureChannel, "Create");

    *a_ppSecureChannel = OpcUa_Null;

    pTcpSecureChannel = (OpcUa_TcpSecureChannel*)OpcUa_Alloc(sizeof(OpcUa_TcpSecureChannel));
    OpcUa_ReturnErrorIfAllocFailed(pTcpSecureChannel);
    OpcUa_MemSet(pTcpSecureChannel, 0, sizeof(OpcUa_TcpSecureChannel));

    *a_ppSecureChannel = (OpcUa_SecureChannel*)OpcUa_Alloc(sizeof(OpcUa_SecureChannel));
    OpcUa_GotoErrorIfAllocFailed(*a_ppSecureChannel);
    OpcUa_MemSet(*a_ppSecureChannel, 0, sizeof(OpcUa_SecureChannel));

    (*a_ppSecureChannel)->SecureChannelId           = OPCUA_SECURECHANNEL_ID_INVALID;
    (*a_ppSecureChannel)->NextTokenId               = 1;
    (*a_ppSecureChannel)->uLastSequenceNumberRcvd   = 0xFFFFFFFFU;
    (*a_ppSecureChannel)->uLastSequenceNumberSent   = OPCUA_SECURECHANNEL_STARTING_SEQUENCE_NUMBER;
    (*a_ppSecureChannel)->Handle                    = pTcpSecureChannel;
    (*a_ppSecureChannel)->Open                      = OpcUa_TcpSecureChannel_Open;
    (*a_ppSecureChannel)->Renew                     = OpcUa_TcpSecureChannel_Renew;
    (*a_ppSecureChannel)->Close                     = OpcUa_TcpSecureChannel_Close;
    (*a_ppSecureChannel)->GenerateSecurityToken     = OpcUa_TcpSecureChannel_GenerateSecurityToken;
    (*a_ppSecureChannel)->RenewSecurityToken        = OpcUa_TcpSecureChannel_RenewSecurityToken;
    (*a_ppSecureChannel)->GetSecuritySet            = OpcUa_TcpSecureChannel_GetSecuritySet;
    (*a_ppSecureChannel)->GetCurrentSecuritySet     = OpcUa_TcpSecureChannel_GetCurrentSecuritySet;
    (*a_ppSecureChannel)->ReleaseSecuritySet        = OpcUa_TcpSecureChannel_ReleaseSecuritySet;
    (*a_ppSecureChannel)->GetSequenceNumber         = OpcUa_TcpSecureChannel_GetSequenceNumber;
    (*a_ppSecureChannel)->CheckSequenceNumber       = OpcUa_TcpSecureChannel_CheckSequenceNumber;
    (*a_ppSecureChannel)->LockWriteMutex            = OpcUa_TcpSecureChannel_LockWriteMutex;
    (*a_ppSecureChannel)->UnlockWriteMutex          = OpcUa_TcpSecureChannel_UnlockWriteMutex;
    (*a_ppSecureChannel)->IsOpen                    = OpcUa_SecureChannel_IsOpen;
    (*a_ppSecureChannel)->DiscoveryOnly             = OpcUa_False;
    (*a_ppSecureChannel)->MessageSecurityMode       = OpcUa_MessageSecurityMode_None;

    uStatus = OPCUA_P_MUTEX_CREATE(&((*a_ppSecureChannel)->hSyncAccess));
    OpcUa_GotoErrorIfBad(uStatus);
    uStatus = OPCUA_P_MUTEX_CREATE(&((*a_ppSecureChannel)->hWriteMutex));
    OpcUa_GotoErrorIfBad(uStatus);
    OpcUa_String_Initialize(&((*a_ppSecureChannel)->SecurityPolicyUri));
    OpcUa_String_Initialize(&((*a_ppSecureChannel)->sPeerInfo));

OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;

    if (*a_ppSecureChannel != OpcUa_Null)
    {
        if((*a_ppSecureChannel)->hSyncAccess != OpcUa_Null)
        {
            OPCUA_P_MUTEX_DELETE(&((*a_ppSecureChannel)->hSyncAccess));
        }

        if((*a_ppSecureChannel)->hWriteMutex != OpcUa_Null)
        {
            OPCUA_P_MUTEX_DELETE(&((*a_ppSecureChannel)->hWriteMutex));
        }

        OpcUa_Free(*a_ppSecureChannel);
        *a_ppSecureChannel = OpcUa_Null;
    }

    OpcUa_Free(pTcpSecureChannel);

OpcUa_FinishErrorHandling;
}