Пример #1
0
TreeNode Xml_FindChildWithGrandchildValue(const TreeNode parentNode, const char * childName, const char * grandchildName, const char * grandchildValue)
{
    TreeNode child;
    int index = 0;
    while ((child = TreeNode_GetChild(parentNode, index)))
    {
        if (strcmp(childName, TreeNode_GetName(child)) == 0)
        {
            TreeNode grandchild;
            if ((grandchild = Xml_Find(child, grandchildName)) != NULL)
            {
                const char * value = (const char * )TreeNode_GetValue(grandchild);
                if (value != NULL)
                {
                    if (strcmp(grandchildValue, value) == 0)
                    {
                        //found
                        break;
                    }
                }
            }
        }
        index++;
    }
    return child;
}
Пример #2
0
const char * xmlif_GetOpaque(TreeNode content, const char * name)
{
    TreeNode node = TreeNode_Navigate(content, (char*)name);
    if (node != NULL)
    {
        return (const char *)TreeNode_GetValue(node);
    }
    return NULL;
}
AwaError ResponseCommon_CheckForErrors(const ResponseCommon * response)
{
    AwaError result = AwaError_Success;
    if (response != NULL)
    {
        if (response->ObjectsNode != NULL)
        {
            TreeNode currentNode = response->ObjectsNode;
            if (currentNode != NULL)
            {
                while ((currentNode = ObjectsTree_GetNextLeafNode(currentNode)) != NULL)
                {
                    // check for a Result tag
                    TreeNode resultNode = Xml_Find(currentNode, "Result");
                    if (resultNode != NULL)
                    {
                        TreeNode errorNode = Xml_Find(resultNode, "Error");
                        if (errorNode != NULL)
                        {
                            AwaError error = Error_FromString((const char *)TreeNode_GetValue(errorNode));
                            if (error != AwaError_Success)
                            {
                                result = AwaError_Response;
                            }
                            // keep looking; examine all leaf nodes
                        }
                        else
                        {
                            // result without error node - error
                            result = LogErrorWithEnum(AwaError_ResponseInvalid, "Response Result has missing Error node");
                            break;
                        }
                    }
                    else
                    {
                        // leaf without result node - error
                        result = LogErrorWithEnum(AwaError_ResponseInvalid, "Response has missing Result node");
                        break;
                    }
                }
            }
            else
            {
                result = LogErrorWithEnum(AwaError_Internal, "Response has no objects tree");
            }
        }
        else
        {
            result = LogErrorWithEnum(AwaError_Internal, "Response has no objects node");
        }
    }
    else
    {
        result = LogErrorWithEnum(AwaError_ResponseInvalid, "response is NULL");
    }
    return result;
}
Пример #4
0
int xmlif_GetInteger(TreeNode content, const char * name)
{
    TreeNode node = TreeNode_Navigate(content, (char*)name);
    if (node != NULL)
    {
        const uint8_t * value = TreeNode_GetValue(node);
        if (value != NULL)
        {
            return atoi((const char*)value);
        }
    }
    return -1;
}
Пример #5
0
static int _TreeToString(const TreeNode node, char * buffer, size_t bufferSize, int level)
{
    const char * name = TreeNode_GetName(node);
    int pos = 0;
    int rc;

    if (TreeNode_GetChild(node, 0) != NULL)
    {
        TreeNode child;
        int idx = 0;

        rc = snprintf(buffer, bufferSize, "%*s<%s>\n", level, "", name);
        if ((rc == -1) || (rc >= bufferSize))
        {
            return -1;
        }
        pos += rc;

        while ((child = TreeNode_GetChild(node, idx++)) != NULL)
        {
            rc = _TreeToString(child, &buffer[pos], bufferSize - pos, level + 1);
            if (rc < 0)
            {
                return -1;
            }
            pos += rc;
        }

        rc = snprintf(&buffer[pos], bufferSize - pos, "%*s</%s>\n", level, "", name);
        if ((rc == -1) || (rc >= bufferSize - pos))
        {
            return -1;
        }
        pos += rc;
    }
    else
    {
        const char * value = (const char *)TreeNode_GetValue(node);

        rc = snprintf(buffer, bufferSize, "%*s<%s>%s</%s>\n", level, "", name, value ? value : "", name);
        if ((rc == -1) || (rc >= bufferSize))
        {
            return -1;
        }
        pos += rc;
    }

    return pos;
}