Exemplo n.º 1
0
void Array_FreeItem(ArrayItem * valueItem, AwaResourceType resourceType)
{
    if (resourceType == AwaResourceType_OpaqueArray)
    {
        AwaOpaque * opaque = (AwaOpaque *)valueItem->Value;
        LogFree("AwaArray.OpaqueData", opaque->Data);
        Awa_MemSafeFree(opaque->Data);
    }
    Array_FreeItemValue(valueItem);
    LogFree("AwaArray.Item", valueItem);
    Awa_MemSafeFree(valueItem);
}
Exemplo n.º 2
0
AwaClientSubscribeOperation * AwaClientSubscribeOperation_New(const AwaClientSession * session)
{
    AwaClientSubscribeOperation * operation = NULL;

    if (session != NULL)
    {
        if (ClientSession_IsConnected(session) != false)
        {
            operation = Awa_MemAlloc(sizeof(*operation));
            if (operation != NULL)
            {
                memset(operation, 0, sizeof(*operation));
                operation->Common = OperationCommon_NewWithClientSession(session);
                if (operation->Common != NULL)
                {
                    operation->Subscribers = Map_New();

                    if (operation->Subscribers != NULL)
                    {
                        LogNew("AwaClientSubscribeOperation", operation);
                    }
                    else
                    {
                        LogErrorWithEnum(AwaError_OutOfMemory, "Could not create subscriber list.");
                        Awa_MemSafeFree(operation);
                        operation = NULL;
                    }
                }
                else
                {
                    LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation.");
                    Awa_MemSafeFree(operation);
                    operation = NULL;
                }
            }
            else
            {
                LogErrorWithEnum(AwaError_OutOfMemory);
            }
        }
        else
        {
            LogError("Session is not connected");
        }
    }
    else
    {
        LogError("Session is NULL");
    }
    return operation;
}
Exemplo n.º 3
0
OperationCommon * OperationCommon_NewWithExistingObjectsTree(const Session * session, SessionType sessionType, TreeNode objectsTree)
{
    OperationCommon * operation = NULL;
    if (session != NULL)
    {
        operation = Awa_MemAlloc(sizeof(*operation));
        if (operation != NULL)
        {
            memset(operation, 0, sizeof(*operation));
            operation->Session = session;
            operation->SessionType = sessionType;
            operation->ObjectsTree = objectsTree;
            if (operation->ObjectsTree != NULL)
            {
                LogNew("OperationCommon", operation);
            }
            else
            {
                LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation");
                Awa_MemSafeFree(operation);
                operation = NULL;
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_OutOfMemory);
        }
    }
    else
    {
        LogErrorWithEnum(AwaError_SessionInvalid, "Session is NULL");
    }
    return operation;
}
Exemplo n.º 4
0
AwaChangeSet * ChangeSet_NewWithClientID(Session * session, SessionType sessionType, TreeNode objectsTree, const char * clientID)
{
    AwaChangeSet * changeSet = NULL;
    if (objectsTree != NULL)
    {
        changeSet = Awa_MemAlloc(sizeof(*changeSet));
        if (changeSet != NULL)
        {
            memset(changeSet, 0, sizeof(*changeSet));

            changeSet->OperationCommon = OperationCommon_New(session, sessionType);

            if (changeSet->OperationCommon != NULL)
            {
                changeSet->ResponseCommon = ResponseCommon_New(changeSet->OperationCommon, objectsTree);
                if (changeSet->ResponseCommon != NULL)
                {
                    changeSet->ClientID = clientID;
                    LogNew("AwaChangeSet New", changeSet);
                }
                else
                {
                    LogErrorWithEnum(AwaError_OutOfMemory);
                    OperationCommon_Free(&changeSet->OperationCommon);
                    Awa_MemSafeFree(changeSet);
                    changeSet = NULL;
                }
            }
            else
            {
                LogErrorWithEnum(AwaError_OutOfMemory);
                Awa_MemSafeFree(changeSet);
                changeSet = NULL;
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_OutOfMemory);
        }
    }
    else
    {
        LogErrorWithEnum(AwaError_OperationInvalid, "Objects tree is NULL");
    }
    return changeSet;
}
Exemplo n.º 5
0
static AwaClientSubscription * ClientSubscription_New(const char * path, void * callback, void * context, AwaSubscribeType subscribeType)
{
    AwaClientSubscription * subscription = NULL;

    if ((path != NULL) && (callback != NULL))
    {
        subscription = Awa_MemAlloc(sizeof(*subscription));

        if (subscription != NULL)
        {
            subscription->Path = strdup(path);
            if (subscription->Path != NULL)
            {
                subscription->Operations = List_New();
                if (subscription->Operations != NULL)
                {
                    subscription->Callback = (void *)callback;
                    subscription->Context = context;
                    subscription->Session = NULL;
                    subscription->Type = subscribeType;
                }
                else
                {
                    free((void *)subscription->Path);
                    Awa_MemSafeFree(subscription);
                    LogErrorWithEnum(AwaError_OutOfMemory);
                    subscription = NULL;
                }
            }
            else
            {
                Awa_MemSafeFree(subscription);
                LogErrorWithEnum(AwaError_OutOfMemory);
                subscription = NULL;
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_OutOfMemory);
        }
    }
    return subscription;
}
Exemplo n.º 6
0
void StringIterator_Free(StringIterator ** iterator)
{
    if ((iterator != NULL) && (*iterator != NULL))
    {
        // free memory managed by iterator:
        Iterator_FreeValues((*iterator)->Iterator);
        Iterator_Free(&(*iterator)->Iterator);
        LogFree("StringIterator", *iterator);
        Awa_MemSafeFree(*iterator);
        *iterator = NULL;
    }
}
Exemplo n.º 7
0
AwaError AwaServerExecuteOperation_Free(AwaServerExecuteOperation ** operation)
{
    AwaError result = AwaError_OperationInvalid;
    if ((operation != NULL) && (*operation != NULL))
    {
        ServerOperation_Free(&(*operation)->ServerOperation);
        ServerResponse_Free(&(*operation)->Response);
        LogFree("AwaServerExecuteOperation", *operation);
        Awa_MemSafeFree(*operation);
        *operation = NULL;
        result = AwaError_Success;
    }
    return result;
}
Exemplo n.º 8
0
AwaError AwaServerExecuteOperation_AddPath(AwaServerExecuteOperation * operation, const char * clientID, const char * path, const AwaExecuteArguments * arguments)
{
    AwaError result = AwaError_Unspecified;

    if (operation != NULL)
    {
        if (Path_IsValidForResource(path))
        {
            TreeNode resultNode = NULL;
            if ((result = ServerOperation_AddPath(operation->ServerOperation, clientID, path, &resultNode)) == AwaError_Success)
            {
                if (resultNode != NULL)
                {
                    char * encodedValue = NULL;
                    if (arguments != NULL && arguments->Size > 0)
                    {
                        encodedValue = xmlif_EncodeValue(AwaResourceType_Opaque, arguments->Data, arguments->Size);
                    }

                    if (encodedValue == NULL || SetWriteCommon_SetResourceNodeValue(resultNode, encodedValue) == InternalError_Success)
                    {
                        result = AwaError_Success;
                    }
                    else
                    {
                        result = LogErrorWithEnum(AwaError_Internal, "Failed to set resource value");
                    }

                    if (encodedValue)
                    {
                        Awa_MemSafeFree(encodedValue);
                    }
                }
                else
                {
                    result = LogErrorWithEnum(AwaError_Internal, "AddPath failed to return result node");
                }
            }
        }
        else
        {
            result = LogErrorWithEnum(AwaError_PathInvalid, "%s is not a valid path to an executable resource", path);
        }
    }
    else
    {
        result = LogErrorWithEnum(AwaError_OperationInvalid, "Operation is NULL");
    }
    return result;
}
Exemplo n.º 9
0
void OperationCommon_Free(OperationCommon ** operation)
{
    if ((operation != NULL) && (*operation != NULL))
    {
        // do not free the session, it is not owned by the operation

        Tree_DetachNode((*operation)->ObjectsTree);
        ObjectsTree_Free((*operation)->ObjectsTree);

        LogFree("OperationCommon", operation);
        Awa_MemSafeFree(*operation);
        *operation = NULL;
    }
}
Exemplo n.º 10
0
AwaError ChangeSet_Free(AwaChangeSet ** changeSet)
{
    AwaError result = AwaError_OperationInvalid;
    if ((changeSet != NULL) && (*changeSet != NULL))
    {
        LogFree("AwaChangeSet", *changeSet);
        ResponseCommon_Free(&(*changeSet)->ResponseCommon);
        OperationCommon_Free(&(*changeSet)->OperationCommon);
        Awa_MemSafeFree(*changeSet);
        *changeSet = NULL;
        result = AwaError_Success;
    }
    return result;
}
Exemplo n.º 11
0
AwaServerSession * AwaServerSession_New(void)
{
    AwaServerSession * session = Awa_MemAlloc(sizeof(*session));
    if (session != NULL)
    {
        memset(session, 0, sizeof(*session));

        session->SessionCommon = SessionCommon_New(SessionType_Server);
        if (session->SessionCommon != NULL)
        {
            session->Observers = Map_New();
            if (session->Observers)
            {
                session->NotificationQueue = Queue_New();
            }
            else
            {
                LogErrorWithEnum(AwaError_OutOfMemory, "Could not create observer list");
                SessionCommon_Free(&session->SessionCommon);
                Awa_MemSafeFree(session);
                session = NULL;
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_OutOfMemory, "Could not create common session");
            SessionCommon_Free(&session->SessionCommon);
            Awa_MemSafeFree(session);
            session = NULL;
        }
    }
    else
    {
        LogErrorWithEnum(AwaError_OutOfMemory, "Could not create ServerSession");
    }
    return session;
}
AwaError AwaServerListClientsOperation_Free(AwaServerListClientsOperation ** operation)
{
    AwaError result = AwaError_OperationInvalid;
    if ((operation != NULL) && (*operation != NULL))
    {
        ServerResponse_Free(&(*operation)->ServerResponse);
        ServerOperation_Free(&(*operation)->ServerOperation);

        Map_FreeValues((*operation)->ClientResponseMap);
        Map_Free(&((*operation)->ClientResponseMap));

        LogFree("AwaServerListClientsOperation", *operation);
        Awa_MemSafeFree(*operation);
        *operation = NULL;
        result = AwaError_Success;
    }
    return result;
}
Exemplo n.º 13
0
AwaServerExecuteOperation * AwaServerExecuteOperation_New(const AwaServerSession * session)
{
    // AwaServerExecuteResponse is an alias for ResponseCommon
    AwaServerExecuteOperation * operation = NULL;

    if (session != NULL)
    {
        if (ServerSession_IsConnected(session) != false)
        {
            operation = Awa_MemAlloc(sizeof(*operation));
            if (operation != NULL)
            {
                memset(operation, 0, sizeof(*operation));
                operation->ServerOperation = ServerOperation_New(session);
                if (operation->ServerOperation != NULL)
                {
                    LogNew("AwaServerExecuteOperation", operation);
                }
                else
                {
                    LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation");
                    Awa_MemSafeFree(operation);
                    operation = NULL;
                }
            }
            else
            {
                LogErrorWithEnum(AwaError_OutOfMemory);
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_SessionInvalid);

        }
    }
    else
    {
        LogErrorWithEnum(AwaError_SessionInvalid, "Session is NULL");
    }

    return operation;
}
Exemplo n.º 14
0
AwaError AwaClientSetOperation_Free(AwaClientSetOperation ** operation)
{
    AwaError result = AwaError_OperationInvalid;
    if ((operation != NULL) && (*operation != NULL))
    {
        OperationCommon_Free(&(*operation)->Common);

        if ((*operation)->Response != NULL)
        {
            ResponseCommon_Free(&(*operation)->Response);
        }

        LogFree("AwaClientSetOperation", *operation);
        Awa_MemSafeFree(*operation);
        *operation = NULL;
        result = AwaError_Success;
    }
    return result;
}
AwaServerListClientsOperation * AwaServerListClientsOperation_New(const AwaServerSession * session)
{
    AwaServerListClientsOperation * operation = NULL;

    if (session != NULL)
    {
        if (ServerSession_IsConnected(session) != false)
        {
            operation = Awa_MemAlloc(sizeof(*operation));
            if (operation != NULL)
            {
                memset(operation, 0, sizeof(*operation));
                operation->ServerResponse = NULL;
                operation->ServerOperation = ServerOperation_New(session);
                if (operation->ServerOperation != NULL)
                {
                    operation->ClientResponseMap = Map_New();
                    LogNew("AwaServerListClientsOperation", operation);
                }
                else
                {
                    LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation");
                    Awa_MemSafeFree(operation);
                    operation = NULL;
                }
            }
            else
            {
                LogErrorWithEnum(AwaError_OutOfMemory);
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_SessionNotConnected);
        }
    }
    else
    {
        LogError("Session is NULL");
    }
    return operation;
}
AwaError ResponseCommon_Free(ResponseCommon ** response)
{
    AwaError result = AwaError_Unspecified;
    if ((response != NULL) && (*response != NULL))
    {
        LogFree("ResponseCommon", *response);
        FreeSimpleMap(&((*response)->PathResults));
        FreeSimpleMap(&((*response)->NulledValues));
        FreeValues(&((*response)->Values));
        Tree_Delete((*response)->ObjectsNode);
        Awa_MemSafeFree(*response);
        *response = NULL;
        result = AwaError_Success;
    }
    else
    {
        result = AwaError_OperationInvalid;
    }
    return result;
}
Exemplo n.º 17
0
AwaError AwaClientSubscribeOperation_Free(AwaClientSubscribeOperation ** operation)
{
    AwaError result = AwaError_OperationInvalid;
    if (operation != NULL && *operation != NULL)
    {
        OperationCommon_Free(&(*operation)->Common);
        Map_ForEach((*operation)->Subscribers, RemoveSubscriptionLinkToOperation, *operation);
        Map_Free(&(*operation)->Subscribers);

        if ((*operation)->Response != NULL)
        {
            SubscribeResponse_Free(&(*operation)->Response);
        }

        LogFree("AwaClientSubscribeOperation", *operation);
        Awa_MemSafeFree(*operation);
        *operation = NULL;
        result = AwaError_Success;
    }
    return result;
}
Exemplo n.º 18
0
static AwaError ClientSubscription_Free(AwaClientSubscription ** subscription)
{
    AwaError result = AwaError_SubscriptionInvalid;

    if ((subscription != NULL) && (*subscription != NULL))
    {
        List_ForEach((*subscription)->Operations, RemoveSubscriptionFromOperation, *subscription);
        List_Free(&(*subscription)->Operations);

        if ((*subscription)->Session != NULL)
        {
            Map_Remove(ClientSession_GetSubscribers((*subscription)->Session), (*subscription)->Path);
        }

        free((void *)(*subscription)->Path);
        Awa_MemSafeFree(*subscription);
        *subscription = NULL;

        result = AwaError_Success;
    }
    return result;
}
Exemplo n.º 19
0
AwaError AwaServerSession_Free(AwaServerSession ** session)
{
    AwaError result = AwaError_Success;
    if ((session != NULL) && (*session != NULL))
    {
        SessionCommon_Free(&((*session)->SessionCommon));
        (*session)->SessionCommon = NULL;

        Map_ForEach((*session)->Observers, RemoveObservationLinkToSession, NULL);
        Map_Free(&(*session)->Observers);
        Queue_Free(&((*session)->NotificationQueue));

        // Free the session itself
        LogFree("AwaServerSession", *session);
        Awa_MemSafeFree(*session);
        *session = NULL;
    }
    else
    {
        result = LogErrorWithEnum(AwaError_SessionInvalid, "Session is NULL");
    }
    return result;
}
Exemplo n.º 20
0
void Array_FreeItemValue(ArrayItem * valueItem)
{
    LogFree("AwaArray.Item.Value",  valueItem->Value);
    Awa_MemSafeFree(valueItem->Value);
    valueItem->Value = NULL;
}
Exemplo n.º 21
0
AwaError AwaClientSetOperation_Perform(AwaClientSetOperation * operation, AwaTimeout timeout)
{
    AwaError result = AwaError_Unspecified;

    if (timeout >= 0)
    {
        if (operation != NULL)
        {
            const AwaClientSession * session = OperationCommon_GetSession(operation->Common, NULL);
            if (session != NULL)
            {
                if (ClientSession_IsConnected(session))
                {
                    TreeNode objectsTree = OperationCommon_GetObjectsTree(operation->Common);
                    if (objectsTree != NULL)
                    {
                        if (TreeNode_GetChildCount(objectsTree) > 0)
                        {
                            IPCMessage * setRequest = IPCMessage_NewPlus(IPC_MESSAGE_TYPE_REQUEST, IPC_MESSAGE_SUB_TYPE_SET, OperationCommon_GetSessionID(operation->Common));
                            IPCMessage_AddContent(setRequest, objectsTree);

                            // Serialise message
                            char * requestBuffer = IPC_SerialiseMessageToXML(setRequest);
                            Awa_MemSafeFree(requestBuffer);

                            // Send via IPC
                            IPCMessage * setResponse = NULL;
                            result = IPC_SendAndReceive(ClientSession_GetChannel(session), setRequest, &setResponse, timeout);

                            // Process the response
                            if (result == AwaError_Success)
                            {
                                // Free an old Read response record if it exists
                                if (operation->Response != NULL)
                                {
                                    ResponseCommon_Free(&operation->Response);
                                }

                                TreeNode contentNode = IPCMessage_GetContentNode(setResponse);
                                TreeNode objectsNode = Xml_Find(contentNode, "Objects");
                                operation->Response = ResponseCommon_New(operation->Common, objectsNode);

                                result = ResponseCommon_CheckForErrors(operation->Response);

                                LogDebug("Perform Set Operation successful");
                            }
                            // Free allocated memory
                            IPCMessage_Free(&setRequest);
                            IPCMessage_Free(&setResponse);
                        }
                        else
                        {
                            result = LogErrorWithEnum(AwaError_OperationInvalid, "No paths specified");
                        }
                    }
                    else
                    {
                        result = LogErrorWithEnum(AwaError_Internal, "objectsTree is NULL");
                    }
                }
                else
                {
                    result = LogErrorWithEnum(AwaError_SessionNotConnected, "session is not connected");
                }
            }
            else
            {
                result = LogErrorWithEnum(AwaError_SessionInvalid, "session is NULL");
            }
        }
        else
        {
            result = LogErrorWithEnum(AwaError_OperationInvalid, "operation is NULL");
        }
    }
    else
    {
        result = LogErrorWithEnum(AwaError_OperationInvalid, "Invalid timeout specified");
    }
    return result;
}
// TODO: is maintaining a separate ClientResponseMap unnecessary? Can the ServerResponse's own Map be used instead?
const AwaServerListClientsResponse * AwaServerListClientsOperation_GetResponse(const AwaServerListClientsOperation * operation, const char * clientID)
{
    AwaServerListClientsResponse * listClientsResponse = NULL;
    if (operation != NULL)
    {
        if (clientID != NULL)
        {
            if (operation->ServerResponse != NULL)
            {
                // check that client response exists:
                const ResponseCommon * clientResponse = ServerResponse_GetClientResponse(operation->ServerResponse, clientID);
                if (clientResponse != NULL)
                {
                    // look up existing Response in map, return it.
                    // if it doesn't exist, create new Response and add to map, return it.
                    Map_Get(operation->ClientResponseMap, clientID, (void *)&listClientsResponse);
                    if (listClientsResponse == NULL)
                    {
                        LogDebug("Create new AwaServerListClientsResponse");
                        listClientsResponse = Awa_MemAlloc(sizeof(*listClientsResponse));
                        if (listClientsResponse != NULL)
                        {
                            memset(listClientsResponse, 0, sizeof(*listClientsResponse));
                            listClientsResponse->Response = clientResponse;

                            // cache the listClientsResponse
                            if (Map_Put(operation->ClientResponseMap, clientID, (void *)listClientsResponse) == false)
                            {
                                // do not return the response if we can't retain it, as it will eventually leak
                                LogErrorWithEnum(AwaError_Internal, "Map put failed");
                                Awa_MemSafeFree(listClientsResponse);
                                listClientsResponse = NULL;
                            }
                        }
                        else
                        {
                            LogErrorWithEnum(AwaError_OutOfMemory);
                        }
                    }
                    else
                    {
                        LogDebug("Retrieved cached AwaServerListClientsResponse");
                    }
                }
                else
                {
                    LogErrorWithEnum(AwaError_ClientNotFound, "Client ID %s not found", clientID);
                }
            }
            else
            {
                LogErrorWithEnum(AwaError_ResponseInvalid, "operation response is NULL");
            }
        }
        else
        {
            LogErrorWithEnum(AwaError_ClientIDInvalid, "clientID is NULL");
        }
    }
    else
    {
        LogErrorWithEnum(AwaError_OperationInvalid, "operation is NULL");
    }
    return listClientsResponse;
}