/*============================================================================
 * OpcUa_MemoryStream_Read
 *===========================================================================*/
OpcUa_StatusCode OpcUa_MemoryStream_Read(
    struct _OpcUa_InputStream*     istrm,
    OpcUa_Byte*                    buffer,
    OpcUa_UInt32*                  count,
    OpcUa_Stream_PfnOnReadyToRead* callback,
    OpcUa_Void*                    callbackData)
{
    OpcUa_MemoryStream* handle = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream);

    OpcUa_ReturnErrorIfArgumentNull(istrm);
    OpcUa_ReturnErrorIfArgumentNull(buffer);
    OpcUa_ReturnErrorIfArgumentNull(count);
    OpcUa_ReturnErrorIfInvalidStream(istrm, Read);
    OpcUa_ReferenceParameter(callback);
    OpcUa_ReferenceParameter(callbackData);

    handle = (OpcUa_MemoryStream*)istrm->Handle;

    if (handle->Closed)
    {
        return OpcUa_BadInvalidState;
    }

    return OpcUa_Buffer_Read(handle->pBuffer, buffer, count);
}
/*============================================================================
 * GetStringFromGuid
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Guid_ToString(   OpcUa_Guid*     a_pGuid,
                                        OpcUa_String**  a_ppString)
{
    OpcUa_CharA pRawString[OPCUA_GUID_LEXICAL_LENGTH + 1] = {0};

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Guid);

    OpcUa_ReturnErrorIfArgumentNull(a_ppString);
    OpcUa_ReturnErrorIfArgumentNull(a_pGuid);

    *a_ppString = OpcUa_Null;

#if 1
    OpcUa_SPrintfA( pRawString,
#if OPCUA_USE_SAFE_FUNCTIONS
                    OPCUA_GUID_LEXICAL_LENGTH,
#endif /* OPCUA_USE_SAFE_FUNCTIONS */
                    "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
                    a_pGuid->Data1,
                    a_pGuid->Data2,
                    a_pGuid->Data3,
                    a_pGuid->Data4[0], a_pGuid->Data4[1],
                    a_pGuid->Data4[2], a_pGuid->Data4[3], a_pGuid->Data4[4],
                    a_pGuid->Data4[5], a_pGuid->Data4[6], a_pGuid->Data4[7]);
#endif

    return OpcUa_String_CreateNewString(pRawString,
                                        OPCUA_GUID_LEXICAL_LENGTH,
                                        0,
                                        OpcUa_True,
                                        OpcUa_True,
                                        a_ppString);
}
/*============================================================================
 * OpcUa_MemoryStream_Close
 *===========================================================================*/
static
OpcUa_StatusCode OpcUa_MemoryStream_Close(
    OpcUa_Stream*       strm)
{
    OpcUa_MemoryStream* handle  = OpcUa_Null;
    OpcUa_StatusCode    uStatus = OpcUa_Good;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream);

    OpcUa_ReturnErrorIfArgumentNull(strm);
    OpcUa_ReturnErrorIfInvalidStream(strm, Close);

    handle = (OpcUa_MemoryStream*)strm->Handle;

    if (handle->Closed)
    {
        return OpcUa_BadInvalidState;
    }

    if(strm->Type == OpcUa_StreamType_Output)
    {
        /* flush content when stream gets closed */
        uStatus = OpcUa_MemoryStream_Flush( (OpcUa_OutputStream*)strm,
                                            OpcUa_True);
    }

    handle->Closed = OpcUa_True;

    return uStatus;
}
/*============================================================================
 * OpcUa_MemoryStream_GetBuffer
 *===========================================================================*/
OPCUA_EXPORT OpcUa_StatusCode OpcUa_MemoryStream_GetBuffer(
    OpcUa_OutputStream* a_pOstrm,
    OpcUa_Byte**        a_ppBuffer,
    OpcUa_UInt32*       a_puBufferSize)
{
    OpcUa_MemoryStream* handle = OpcUa_Null;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream);

    OpcUa_ReturnErrorIfNull(a_pOstrm,       OpcUa_BadInvalidArgument);
    OpcUa_ReturnErrorIfNull(a_ppBuffer,     OpcUa_BadInvalidArgument);
    OpcUa_ReturnErrorIfNull(a_puBufferSize, OpcUa_BadInvalidArgument);

    if (a_pOstrm->Type != OpcUa_StreamType_Output || a_pOstrm->Write != OpcUa_MemoryStream_Write)
    {
        return OpcUa_BadInvalidArgument;
    }

    handle = (OpcUa_MemoryStream*)a_pOstrm->Handle;

    if (!handle->Closed)
    {
        return OpcUa_BadInvalidState;
    }

    return OpcUa_Buffer_GetData(handle->pBuffer, a_ppBuffer, a_puBufferSize);
}
/*============================================================================
 * OpcUa_Crypto_CreateCertificate
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Crypto_CreateCertificate(
    struct _OpcUa_CryptoProvider*       a_pProvider,
    const OpcUa_Int32                   a_serialNumber,
    OpcUa_DateTime                      a_validFrom,
    OpcUa_DateTime                      a_validTo,
    OpcUa_Crypto_NameEntry*             a_pNameEntries,      /* will be used for issuer and subject thus it's selfigned cert */
    OpcUa_UInt                          a_nameEntriesCount,  /* will be used for issuer and subject thus it's selfigned cert */
    OpcUa_Key                           a_pSubjectPublicKey, /* EVP_PKEY* - type defines also public key algorithm */
    OpcUa_Crypto_Extension*             a_pExtensions,
    OpcUa_UInt                          a_extensionsCount,
    const OpcUa_UInt                    a_signatureHashAlgorithm, /* EVP_sha1(),... */
    OpcUa_Certificate*                  a_pIssuerCertificate,
    OpcUa_Key                           a_pIssuerPrivateKey, /* EVP_PKEY* - type defines also signature algorithm */
    OpcUa_Certificate**                 a_ppCertificate)     /* this has to be changed to OpcUa_Certificate** */
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->CreateCertificate, OpcUa_BadNotSupported);

    return a_pProvider->CreateCertificate(a_pProvider,
                                          a_serialNumber,
                                          a_validFrom,
                                          a_validTo,
                                          a_pNameEntries,
                                          a_nameEntriesCount,
                                          a_pSubjectPublicKey,
                                          a_pExtensions,
                                          a_extensionsCount,
                                          a_signatureHashAlgorithm,
                                          a_pIssuerCertificate,
                                          a_pIssuerPrivateKey,
                                          a_ppCertificate);
}
Exemple #6
0
/**
  @brief Set the cursor to the element with the given data

  @return OpcUa_Null if no element is found
  @return OpcUa_Null if a_pList is null
  @return OpcUa_Null if a_pElementData is null
  @return a pointer to the user data that was found

  This function should use currtElement instead of tempElement so that
  when it returns the cursor is left pointing at the found element

  @param a_plist            [in]    Location of the list
  @param a_pElementData     [in]    Data to find
*/
OpcUa_Void* OpcUa_List_GetElement(OpcUa_List* a_pList, OpcUa_Void* a_pElementData)
{
    OpcUa_StatusCode   uStatus      = OpcUa_Good;
    OpcUa_ListElement* tempElement  = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);

    OpcUa_GotoErrorIfArgumentNull(a_pList);
    OpcUa_GotoErrorIfArgumentNull(a_pElementData);

    tempElement = a_pList->firstElement;

    while(tempElement != OpcUa_Null)
    {
        if(tempElement->data == a_pElementData)
        {

            return tempElement->data;
        }

        tempElement = tempElement->nextElement;
    }


Error:
    return OpcUa_Null;
}
Exemple #7
0
/**
  @brief Deletes the current element performing all necessary list management
  However, the list element is added to a temporary list and must be removed manually

  QueueFirst and QueueLast have to be initialized to null before first use

  Takes no action if a_pList is null
  Takes no action if a_pList->currtElement is null

  @param a_pList        [in]    Location of the list
  @param a_ppQueueFirst [in]    First Element of the queue
  @param a_ppQueueLast  [in]    Last Element of the queue
*/
OPCUA_EXPORT
OpcUa_Void          OpcUa_List_EnQueueCurrentElement(OpcUa_List*         a_pList,
                                                     OpcUa_ListElement** a_ppQueueFirst,
                                                     OpcUa_ListElement** a_ppQueueLast)

{
    OpcUa_StatusCode    uStatus         = OpcUa_Good;
    OpcUa_ListElement*  deleteElement   = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);

    OpcUa_GotoErrorIfArgumentNull(a_pList);
    OpcUa_GotoErrorIfArgumentNull(a_pList->currtElement);
    OpcUa_GotoErrorIfArgumentNull(a_ppQueueFirst);
    OpcUa_GotoErrorIfArgumentNull(a_ppQueueLast);

    deleteElement = a_pList->currtElement;

    if(deleteElement->prevElement)
    {
        deleteElement->prevElement->nextElement = deleteElement->nextElement;
    }

    if(deleteElement->nextElement)
    {
        deleteElement->nextElement->prevElement = deleteElement->prevElement;
    }

    a_pList->currtElement = deleteElement->nextElement;

    if(deleteElement == a_pList->firstElement)
    {
        a_pList->firstElement = deleteElement->nextElement;
    }

    if(deleteElement == a_pList->lastElement)
    {
        a_pList->lastElement = deleteElement->prevElement;
    }

    a_pList->uintNbElements--;

    deleteElement->prevElement = *a_ppQueueLast;
    deleteElement->nextElement = OpcUa_Null;

    if(*a_ppQueueFirst == OpcUa_Null)
    {
        *a_ppQueueFirst = deleteElement;
    }
    else
    {
        (*a_ppQueueLast)->nextElement = deleteElement;
    }

    *a_ppQueueLast = deleteElement;

Error:
    return;
}
Exemple #8
0
/**
  @brief Moves the cursor to the first element in list.

  @return OpcUa_Good on success
  @return OpcUa_BadInvalidArgument if a_pList is null

  @param a_pList    [in]    Location of the list
*/
OpcUa_StatusCode OpcUa_List_ResetCurrent(OpcUa_List* a_pList)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);
    OpcUa_ReturnErrorIfArgumentNull(a_pList);

    a_pList->currtElement = a_pList->firstElement;

    return OpcUa_Good;
}
Exemple #9
0
/*============================================================================*/
OpcUa_StatusCode OpcUa_DateTime_GetTimeOfDay(OpcUa_TimeVal* a_pValue)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_DateTime);
    OpcUa_ReturnErrorIfArgumentNull(a_pValue);

    OpcUa_P_DateTime_GetTimeOfDay(a_pValue);

    return OpcUa_Good;
}
Exemple #10
0
/*============================================================================*/
OpcUa_StatusCode OpcUa_DateTime_GetDateTimeFromString(  OpcUa_StringA   a_pchDateTimeString,
                                                        OpcUa_DateTime* a_pDateTime)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_DateTime);
    OpcUa_ReturnErrorIfArgumentNull(a_pchDateTimeString);
    OpcUa_ReturnErrorIfArgumentNull(a_pDateTime);

    return OpcUa_P_DateTime_GetDateTimeFromString(a_pchDateTimeString, a_pDateTime);
}
/*============================================================================
 * OpcUa_MemoryStream_CreateReadable
 *===========================================================================*/
OpcUa_StatusCode OpcUa_MemoryStream_CreateReadable(
    OpcUa_Byte*         buffer,
    OpcUa_UInt32        bufferSize,
    OpcUa_InputStream** istrm)
{
    OpcUa_StatusCode uStatus = OpcUa_Good;
    OpcUa_MemoryStream* handle = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream);

    OpcUa_ReturnErrorIfNull(istrm, OpcUa_BadInvalidArgument);
    *istrm = OpcUa_Null;

    handle = (OpcUa_MemoryStream*)OpcUa_Alloc(sizeof(OpcUa_MemoryStream));
    OpcUa_GotoErrorIfAllocFailed(handle);
    OpcUa_MemSet(handle, 0, sizeof(OpcUa_MemoryStream));

    handle->SanityCheck = OpcUa_MemoryStream_SanityCheck;
    handle->pBuffer     = OpcUa_Null;
    handle->Closed      = OpcUa_False;

    uStatus = OpcUa_Buffer_Create(buffer, bufferSize, bufferSize, bufferSize, OpcUa_False, (OpcUa_Buffer**)&handle->pBuffer);
    OpcUa_GotoErrorIfBad(uStatus);

    *istrm = (OpcUa_InputStream*)OpcUa_Alloc(sizeof(OpcUa_InputStream));
    OpcUa_GotoErrorIfAllocFailed(*istrm);

    (*istrm)->Type              = OpcUa_StreamType_Input;
    (*istrm)->Handle            = handle;
    (*istrm)->GetPosition       = OpcUa_MemoryStream_GetPosition;
    (*istrm)->SetPosition       = OpcUa_MemoryStream_SetPosition;
    (*istrm)->Close             = OpcUa_MemoryStream_Close;
    (*istrm)->Delete            = OpcUa_MemoryStream_Delete;
    (*istrm)->Read              = OpcUa_MemoryStream_Read;
    (*istrm)->AttachBuffer      = OpcUa_MemoryStream_AttachBuffer;
    (*istrm)->DetachBuffer      = OpcUa_MemoryStream_DetachBuffer;
    (*istrm)->GetChunkLength    = OpcUa_MemoryStream_GetChunkLength;
    (*istrm)->NonBlocking       = OpcUa_False;
    (*istrm)->CanSeek           = OpcUa_True;

    return OpcUa_Good;

Error:

    if (handle != OpcUa_Null && handle->pBuffer != OpcUa_Null)
    {
        OpcUa_Buffer_Delete((OpcUa_Buffer**)&handle->pBuffer);
    }

    OpcUa_Free(handle);
    OpcUa_Free(*istrm);

    *istrm = OpcUa_Null;

    return uStatus;
}
Exemple #12
0
/**
  @brief Returns the number of elements currently in the list.

  @return OpcUa_BadInvalidArgument if a_pList is null
  @return OpcUa_BadInvalidArgument if a_uintElementCount is null
  @return OpcUa_Good otherwise

  @param a_pList            [in]    Location of the list
  @param a_uintElementCount [out]   Location of an OpcUa_UInt32 to store the size of the list
*/
OpcUa_StatusCode OpcUa_List_GetNumberOfElements(OpcUa_List* a_pList, OpcUa_UInt32 *a_uintElementCount)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);
    OpcUa_ReturnErrorIfArgumentNull(a_pList);
    OpcUa_ReturnErrorIfArgumentNull(a_uintElementCount);

    *a_uintElementCount = a_pList->uintNbElements;

    return OpcUa_Good;
}
/*============================================================================
 * OpcUa_Crypto_GenerateKey
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Crypto_GenerateKey(
    struct _OpcUa_CryptoProvider*    a_pProvider,
    OpcUa_Int32                      a_keyLen,
    OpcUa_Key*                       a_pKey)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->GenerateKey, OpcUa_BadNotSupported);

    return a_pProvider->GenerateKey(a_pProvider, a_keyLen, a_pKey);
}
/*============================================================================
 * OpcUa_Crypto_GetAsymmetricKeyLength
 *===========================================================================*/
OPCUA_EXPORT OpcUa_StatusCode OpcUa_Crypto_GetAsymmetricKeyLength(
    struct _OpcUa_CryptoProvider*   a_pProvider,
    OpcUa_Key                       a_publicKey,
    OpcUa_UInt32*                   a_pBits)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->GetAsymmetricKeyLength, OpcUa_BadNotSupported);

    return a_pProvider->GetAsymmetricKeyLength(a_pProvider, a_publicKey, a_pBits);
}
/*============================================================================
 * OpcUa_Crypto_GetCertificateThumbprint
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Crypto_GetCertificateThumbprint(
    struct _OpcUa_CryptoProvider*       a_pProvider,
    OpcUa_ByteString*                   a_pCertificate,
    OpcUa_ByteString*                   a_pCertificateThumbprint)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->GetCertificateThumbprint, OpcUa_BadNotSupported);

    return a_pProvider->GetCertificateThumbprint(a_pProvider, a_pCertificate, a_pCertificateThumbprint);
}
/*============================================================================
 * OpcUa_Crypto_GetPublicKeyFromCert
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Crypto_GetPublicKeyFromCert(
    struct _OpcUa_CryptoProvider*       a_pProvider,
    OpcUa_ByteString*                   a_pCertificate,
    OpcUa_StringA                       a_password,             /* this could be optional */
    OpcUa_Key*                          a_pPublicKey)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->GetPublicKeyFromCert, OpcUa_BadNotSupported);

    return a_pProvider->GetPublicKeyFromCert(a_pProvider, a_pCertificate, a_password, a_pPublicKey);
}
/*============================================================================
 * OpcUa_Crypto_GenerateAsymmetricKeypair
 *===========================================================================*/
OPCUA_EXPORT OpcUa_StatusCode OpcUa_Crypto_GenerateAsymmetricKeypair(
    struct _OpcUa_CryptoProvider*   a_pProvider,
    OpcUa_UInt                      a_type,
    OpcUa_UInt32                    a_bits,
    OpcUa_Key*                      a_pPublicKey,
    OpcUa_Key*                      a_pPrivateKey)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->GenerateAsymmetricKeypair, OpcUa_BadNotSupported);

    return a_pProvider->GenerateAsymmetricKeypair(a_pProvider, a_type, a_bits, a_pPublicKey, a_pPrivateKey);
}
/*============================================================================
 * OpcUa_Crypto_SymmetricSign
 *============================================================================*/
OpcUa_StatusCode OpcUa_Crypto_SymmetricSign(
    struct _OpcUa_CryptoProvider* a_pProvider,
    OpcUa_Byte*                   a_pData,
    OpcUa_UInt32                  a_dataLen,
    OpcUa_Key*                    a_key,
    OpcUa_ByteString*             a_pSignature)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->SymmetricSign, OpcUa_BadNotSupported);

    return a_pProvider->SymmetricSign(a_pProvider, a_pData, a_dataLen, a_key, a_pSignature);
}
Exemple #19
0
/**
  @brief Creates and initializes a new list element

  @return OpcUa_Good on success

  @param a_ppNewElement [in/out]    Location of a pointer to the new List Element
*/
OpcUa_StatusCode OpcUa_ListElement_Create(OpcUa_ListElement** a_ppNewElement)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);
    OpcUa_ReturnErrorIfArgumentNull(a_ppNewElement);

    *a_ppNewElement = (OpcUa_ListElement*)OpcUa_Alloc(sizeof(OpcUa_ListElement));

    OpcUa_ReturnErrorIfAllocFailed(*a_ppNewElement);

    OpcUa_ListElement_Initialize(*a_ppNewElement);

    return OpcUa_Good;
}
/*============================================================================
 * OpcUa_Crypto_DeriveKey
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Crypto_DeriveKey(
    struct _OpcUa_CryptoProvider* a_pProvider,
    OpcUa_ByteString              a_secret, /* clientnonce | servernonce, servernonce | clientnonce */
    OpcUa_ByteString              a_seed,
    OpcUa_Int32                   a_keyLen, /* output len */
    OpcUa_Key*                    a_pKey)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->DeriveKey, OpcUa_BadNotSupported);

    return a_pProvider->DeriveKey(a_pProvider, a_secret, a_seed, a_keyLen, a_pKey);
}
Exemple #21
0
/*============================================================================*/
OpcUa_StatusCode OpcUa_DateTime_GetStringFromDateTime(  OpcUa_DateTime  a_dateTime,
                                                        OpcUa_StringA   a_pBuffer,
                                                        OpcUa_UInt32    a_uLength)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_DateTime);
    OpcUa_ReturnErrorIfArgumentNull(a_pBuffer);

    if(a_uLength < 25)
    {
        return OpcUa_BadInvalidArgument;
    }

    return OpcUa_P_DateTime_GetStringFromDateTime(a_dateTime, a_pBuffer, a_uLength);
}
/*============================================================================
 * OpcUa_Crypto_AsymmetricVerify
 *============================================================================*/
OpcUa_StatusCode OpcUa_Crypto_AsymmetricVerify(
    struct _OpcUa_CryptoProvider*   a_pProvider,
    OpcUa_ByteString                a_data,
    OpcUa_Key*                      a_publicKey,
    OpcUa_ByteString*               a_pSignature)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Crypto);
    OpcUa_ReturnErrorIfArgumentNull(a_pProvider);
    OpcUa_ReturnErrorIfNull(a_pProvider->AsymmetricVerify, OpcUa_BadNotSupported);

    return a_pProvider->AsymmetricVerify(
                                            a_pProvider,
                                            a_data,
                                            a_publicKey,
                                            a_pSignature);
}
/*============================================================================
 * OpcUa_MemoryStream_GetPosition
 *===========================================================================*/
OpcUa_StatusCode OpcUa_MemoryStream_GetPosition(
    struct _OpcUa_Stream* strm,
    OpcUa_UInt32*         position)
{
    OpcUa_MemoryStream* handle = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream);

    OpcUa_ReturnErrorIfArgumentNull(strm);
    OpcUa_ReturnErrorIfArgumentNull(position);
    OpcUa_ReturnErrorIfInvalidStream(strm, GetPosition);

    handle = (OpcUa_MemoryStream*)strm->Handle;

    return OpcUa_Buffer_GetPosition(handle->pBuffer, position);
}
Exemple #24
0
/**
  @brief Moves the cursor to the previous element if existing and returns the userdata.

  @return OpcUa_Null if the cursor was pointing to the first element
  @return OpcUa_Null if a_pList is null
  @return OpcUa_Null if a_pList->currtElement is null
  @return the data from the previous element otherwise

  @param a_pList    [in]    Location of the list
*/
OpcUa_Void* OpcUa_List_GetPrevElement(OpcUa_List* a_pList)
{
    OpcUa_StatusCode uStatus = OpcUa_Good;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);
    OpcUa_GotoErrorIfArgumentNull(a_pList);
    OpcUa_GotoErrorIfArgumentNull(a_pList->currtElement);

    if(a_pList->currtElement->prevElement)
    {
        a_pList->currtElement = a_pList->currtElement->prevElement;
        return a_pList->currtElement->data;
    }

Error:
    return OpcUa_Null;
}
Exemple #25
0
/**
  @brief Removes the element containing the specified user data from the list.
  The data itself is not deleted.

  @return OpcUa_BadInternalError if a_pList is null
  @return OpcUa_BadInternalError if a_pElementData is null
  @return OpcUa_Good on success;

  @param a_pList            [in]    Location of the list
  @param a_pElementData     [in]    Location of the data to remove from the list
*/
OpcUa_StatusCode OpcUa_List_DeleteElement(OpcUa_List* a_pList, OpcUa_Void* a_pElementData)
{
    OpcUa_StatusCode    uStatus             = OpcUa_BadNotFound; /* initialise with error */

    OpcUa_ListElement*  safeCurrentElement  = OpcUa_Null;
    OpcUa_Void*         currentElementData  = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);

    OpcUa_GotoErrorIfArgumentNull(a_pList);
    OpcUa_GotoErrorIfArgumentNull(a_pElementData);

    /* current element is target */
    if((a_pList->currtElement != OpcUa_Null) && (a_pElementData == a_pList->currtElement->data))
    {
        OpcUa_List_DeleteCurrentElement(a_pList);
        return OpcUa_Good;
    }

    /* target may be elsewhere in the list */
    safeCurrentElement = a_pList->currtElement;

    /* begin search from start of list */
    OpcUa_List_ResetCurrent(a_pList);

    currentElementData = OpcUa_List_GetCurrentElement(a_pList);

    while(currentElementData != OpcUa_Null)
    {
        if(currentElementData == a_pElementData)
        {
            OpcUa_List_DeleteCurrentElement(a_pList);
            uStatus = OpcUa_Good;
            break;
        }
        else
        {
            currentElementData = OpcUa_List_GetNextElement(a_pList);
        }
    }

    /* restore prior cursor */
    a_pList->currtElement = safeCurrentElement;

Error:
    return uStatus;
}
/**
* @brief Allocate and initialize a new OpcUa_TcpListener_Connection object.
*
* @return Bad status on fail; Good status on success;
*/
OpcUa_StatusCode OpcUa_TcpListener_Connection_Create(OpcUa_TcpListener_Connection** a_ppConnection)
{
    OpcUa_TcpListener_Connection*   pConnection = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_TcpListener);

    pConnection = (OpcUa_TcpListener_Connection*) OpcUa_Alloc(sizeof(OpcUa_TcpListener_Connection));
    OpcUa_ReturnErrorIfAllocFailed(pConnection);
    OpcUa_MemSet(pConnection, 0, sizeof(OpcUa_TcpListener_Connection));

    pConnection->uCurrentChunk  = 0;

    OpcUa_TcpListener_Connection_Initialize(pConnection);

    *a_ppConnection = pConnection;
    return OpcUa_Good;
}
/**
 * @brief Initialize an allocated connection manager.
 */
OpcUa_StatusCode OpcUa_TcpListener_ConnectionManager_Initialize(
    OpcUa_TcpListener_ConnectionManager* a_pConnectionManager)
{
    OpcUa_StatusCode uStatus    = OpcUa_Good;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_TcpListener);

    if(a_pConnectionManager == OpcUa_Null)
    {
        return OpcUa_BadInvalidArgument;
    }

    OpcUa_MemSet(a_pConnectionManager, 0, sizeof(OpcUa_TcpListener_ConnectionManager));

    uStatus = OpcUa_List_Create(    &(a_pConnectionManager->Connections));
    OpcUa_ReturnErrorIfBad(uStatus);

    return uStatus;
}
Exemple #28
0
/*============================================================================
 * Create
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Thread_Create(   OpcUa_Thread*           a_pThread,
                                        OpcUa_PfnThreadMain*    a_pThreadMain,
                                        OpcUa_Void*             a_pThreadArgument)
{
    OpcUa_StatusCode        uStatus = OpcUa_Good;
    OpcUa_ThreadInternal*   pThread = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Thread);

    OpcUa_ReturnErrorIfArgumentNull(a_pThread);
    OpcUa_ReturnErrorIfArgumentNull(a_pThreadMain);

    pThread = (OpcUa_ThreadInternal*)OpcUa_Alloc(sizeof(OpcUa_ThreadInternal));

    OpcUa_ReturnErrorIfAllocFailed(pThread);

    OpcUa_MemSet(pThread, 0, sizeof(OpcUa_ThreadInternal));

    pThread->IsRunning      = OpcUa_False;
    pThread->ThreadMain     = a_pThreadMain;
    pThread->ThreadData     = a_pThreadArgument;
    pThread->Mutex          = OpcUa_Null;
    pThread->ShutdownEvent  = OpcUa_Null;

    uStatus = OpcUa_P_Thread_Create(&(pThread->RawThread));
    OpcUa_GotoErrorIfBad(uStatus);

    uStatus = OPCUA_P_SEMAPHORE_CREATE( &(pThread->ShutdownEvent),
                                        1,  /* the initial value is 1 (signalled, 1 free resource) */
                                        1); /* the maximum value is 1 */
    OpcUa_GotoErrorIfBad(uStatus);

    uStatus = OPCUA_P_MUTEX_CREATE(&(pThread->Mutex));
    OpcUa_GotoErrorIfBad(uStatus);

    *a_pThread = pThread;

    return OpcUa_Good;

Error:

    return uStatus;
}
Exemple #29
0
/* conversion is done internally, the parameter must be filled with a value representing milliseconds */
OpcUa_StatusCode OpcUa_Thread_WaitForShutdown(  OpcUa_Thread a_Thread,
                                                OpcUa_UInt32 a_msecTimeout)
{
    OpcUa_StatusCode        uStatus = OpcUa_Good;
    OpcUa_ThreadInternal*   Thread  = OpcUa_Null;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Thread);

    Thread = (OpcUa_ThreadInternal*)a_Thread;

    OpcUa_ReturnErrorIfArgumentNull(Thread);

    OPCUA_P_MUTEX_LOCK(Thread->Mutex);
    if(Thread->IsRunning == OpcUa_False)
    {
        /* printf("wait for shutdown: thread is not running\n");*/
        OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);
        return OpcUa_Good;
    }
    OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);

    uStatus = OPCUA_P_SEMAPHORE_TIMEDWAIT(Thread->ShutdownEvent, a_msecTimeout);
    if(OpcUa_IsBad(uStatus))
    {
        return uStatus;
    }

    OPCUA_P_MUTEX_LOCK(Thread->Mutex);
    if(Thread->IsRunning == OpcUa_False)
    {
        /* Release the semaphore again to enable other threads waiting on it to get unlocked. */
        uStatus = OPCUA_P_SEMAPHORE_POST(   Thread->ShutdownEvent,
                                            1);
        /*printf("wait for shutdown: thread stopped\n");*/
        OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);
        return OpcUa_Good;
    }

    OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);

    /* printf("wait for shutdown: thread is still running\n");*/

    return OpcUa_GoodNonCriticalTimeout;
}
Exemple #30
0
/**
  @brief Initializes all internal variables of the list.

  Do not call this function twice. Memory leaks will be created.

  @return OpcUa_BadInvalidArgument if a_pList is null
  @return OpcUa_Good on success

  @param a_pList    [in]    Location of the list
*/
OpcUa_StatusCode OpcUa_List_Initialize(OpcUa_List* a_pList)
{
    OpcUa_StatusCode    uStatus = OpcUa_Good;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);
    OpcUa_ReturnErrorIfArgumentNull(a_pList);

    a_pList->pMutex = OpcUa_Null;

    a_pList->currtElement   = OpcUa_Null;
    a_pList->firstElement   = OpcUa_Null;
    a_pList->lastElement    = OpcUa_Null;

    a_pList->uintNbElements = 0;

    uStatus = OPCUA_P_MUTEX_CREATE(&(a_pList->pMutex));
    OpcUa_ReturnErrorIfBad(uStatus);

    return OpcUa_Good;
}