Beispiel #1
0
//--------------------------------------------------------------------------------------------------
void ni_SetNodeValueString
(
    ni_IteratorRef_t iteratorRef,  ///< [IN] The iterator object to access.
    const char* pathPtr,           ///< [IN] Optional path to another node in the tree.
    const char* valuePtr           ///< [IN] Write this value into the tree.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_TryCreateNode(iteratorRef, pathPtr);

    if (nodeRef)
    {
        tdb_SetValueAsString(nodeRef, valuePtr);
    }
}
Beispiel #2
0
//--------------------------------------------------------------------------------------------------
void ni_SetNodeValueBool
(
    ni_IteratorRef_t iteratorRef,  ///< [IN] The iterator object to access.
    const char* pathPtr,           ///< [IN] Optional path to another node in the tree.
    bool value                     ///< [IN] The value to write.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_TryCreateNode(iteratorRef, pathPtr);

    if (nodeRef)
    {
        tdb_SetValueAsBool(nodeRef, value);
    }
}
Beispiel #3
0
//--------------------------------------------------------------------------------------------------
void ni_SetEmpty
(
    ni_IteratorRef_t iteratorRef,  ///< [IN] The iterator object to access.
    const char* newPathPtr         ///< [IN] Optional, can be used to specify a node relative to the
                                   ///< [IN] current one.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_TryCreateNode(iteratorRef, newPathPtr);

    if (nodeRef)
    {
        tdb_SetEmpty(nodeRef);
        tdb_EnsureExists(nodeRef);
    }
}
// -------------------------------------------------------------------------------------------------
void le_cfgAdmin_ImportTree
(
    le_cfgAdmin_ServerCmdRef_t commandRef,  ///< [IN] Reference used to generate a reply for this
                                            ///<      request.
    le_cfg_IteratorRef_t externalRef,       ///< [IN] Write iterator that is being used for the
                                            ///<      import.
    const char* filePathPtr,                ///< [IN] Import the tree data from the this file.
    const char* nodePathPtr                 ///< [IN] Where in the tree should this import happen?
                                            ///<      Leave as an empty string to use the iterator's
                                            ///<      current node.
)
// -------------------------------------------------------------------------------------------------
{
    LE_DEBUG("** Importing a tree from '%s' onto node '%s', using iterator, '%p'.",
             filePathPtr, nodePathPtr, externalRef);

    ni_IteratorRef_t iteratorRef = GetIteratorFromRef(externalRef);

    if (iteratorRef == NULL)
    {
        le_cfgAdmin_ImportTreeRespond(commandRef, LE_OK);
        return;
    }

    tdb_NodeRef_t nodeRef = ni_TryCreateNode(iteratorRef, nodePathPtr);

    if (nodeRef == NULL)
    {
        le_cfgAdmin_ImportTreeRespond(commandRef, LE_NOT_FOUND);
    }
    else
    {
        // Open the requested file.
        LE_DEBUG("Opening file '%s'.", filePathPtr);

        FILE* filePtr = NULL;

        filePtr = fopen(filePathPtr, "r");

        if (!filePtr)
        {
            LE_ERROR("File '%s' could not be opened.", filePathPtr);
            le_cfgAdmin_ImportTreeRespond(commandRef, LE_FAULT);

            return;
        }

        // Now, attempt to import the requested data.
        LE_DEBUG("Importing config data.");

        le_result_t result;

        if (tdb_ReadTreeNode(nodeRef, filePtr))
        {
            result = LE_OK;
        }
        else
        {
            result = LE_FORMAT_ERROR;
        }

        // Let the caller know we're done.
        le_cfgAdmin_ImportTreeRespond(commandRef, result);

        // Close up the file and we're done.
        fclose(filePtr);
    }
}
Beispiel #5
0
//--------------------------------------------------------------------------------------------------
le_result_t ni_SetNodeName
(
    ni_IteratorRef_t iteratorRef,  ///< [IN] The iterator object to access.
    const char* pathPtr,           ///< [IN] Optional path to another node in the tree.
    const char* namePtr            ///< [IN] The new name to use.
)
//--------------------------------------------------------------------------------------------------
{
    // Try to get or create the requested node.  If the optional sub-path results in a new path that
    // overflows, then the node get will fail.
    tdb_NodeRef_t nodeRef = ni_TryCreateNode(iteratorRef, pathPtr);
    le_result_t result = LE_OK;

    if (nodeRef)
    {
        // Ok, the existing path is ok.  Cache the existing node name, in case we have to revert it
        // later, then set the new name.  We may have to revert the name later, because, while the
        // new name itself may be ok.  The name may actually be too long for the path limit.
        char oldName[LE_CFG_NAME_LEN_BYTES] = "";
        LE_ASSERT(tdb_GetNodeName(nodeRef, oldName, sizeof(oldName)) == LE_OK);

        result = tdb_SetNodeName(nodeRef, namePtr);

        if (result == LE_OK)
        {
            // The new name passed validation, now we have to make sure that the full path to the
            // node is still ok.  So, first we have to check, was a relative path used.
            if (strcmp(pathPtr, "") == 0)
            {
                // Looks like the caller was using the iterator's current node.  So, remove the old
                // name from the end of the iterator's current path, and append the new name.  If
                // this fails, it's because the new absolute path is too long, so name change fails,
                // and we have to revert the changes.
                LE_ASSERT(le_pathIter_Append(iteratorRef->pathIterRef, "..") == LE_OK);
                result = le_pathIter_Append(iteratorRef->pathIterRef, namePtr);

                if (result != LE_OK)
                {
                    LE_ASSERT(le_pathIter_Append(iteratorRef->pathIterRef, oldName) == LE_OK);
                }
            }
            else
            {
                // The user is accessing a node relative to the iterator's current node.  So, we
                // need too build up a new path and validate that the new name still fits within our
                // limits.  The new path ref is for validation only and can be safely discarded once
                // the check is complete.
                le_pathIter_Ref_t newPathRef = le_pathIter_Clone(iteratorRef->pathIterRef);
                result = le_pathIter_Append(newPathRef, pathPtr);

                if (result == LE_OK)
                {
                    LE_ASSERT(le_pathIter_Append(newPathRef, "..") == LE_OK);
                    result = le_pathIter_Append(newPathRef, namePtr);
                }

                le_pathIter_Delete(newPathRef);
            }

            // If we got to this point and everything is ok, then we know that the name set was ok,
            // and that the resultant path with the new name is also ok.  So, make sure that this
            // node exists in the next commit.  Otherwise, revert the node to it's old name and
            // report the error to the caller.
            if (result == LE_OK)
            {
                tdb_EnsureExists(nodeRef);
            }
            else
            {
                LE_ASSERT(tdb_SetNodeName(nodeRef, oldName) == LE_OK);
            }
        }
    }

    return result;
}