Esempio n. 1
0
/**************************************************************
 * constructor/destructor
 **************************************************************/
v_cfElement
v_cfElementNew (
    v_configuration config,
    const c_char *tagName)
{
    v_cfElement el;

    assert(C_TYPECHECK(config, v_configuration));
    assert(tagName != NULL);

    el = v_cfElement(v_cfNodeNew(config, V_CFELEMENT));
    v_cfElementInit(el, config, tagName);

    return el;
}
Esempio n. 2
0
c_iter
u_cfElementXPath(
    u_cfElement element,
    const c_char *xpathExpr)
{
    u_result      r;
    v_cfElement   ke;
    v_cfNode      vChild;
    c_iter        vChildren;
    c_iter        children;
    u_participant p;
    u_cfNode      proxy;

    children = c_iterNew(NULL);
    if ((element != NULL) && (xpathExpr != NULL)) {
        r = u_cfNodeReadClaim(u_cfNode(element), (v_cfNode*)(&ke));
        if (r == U_RESULT_OK) {
            p = u_cfNodeParticipant(u_cfNode(element));
            vChildren = v_cfElementXPath(ke, xpathExpr);
            vChild = c_iterTakeFirst(vChildren);
            while (vChild != NULL) {
                switch(v_cfNodeKind(vChild)) {
                case V_CFELEMENT:
                    proxy = u_cfNode(u_cfElementNew(p, v_cfElement(vChild)));
                break;
                case V_CFATTRIBUTE:
                    proxy = u_cfNode(u_cfAttributeNew(p, v_cfAttribute(vChild)));
                break;
                case V_CFDATA:
                    proxy = u_cfNode(u_cfDataNew(p,v_cfData(vChild)));
                break;
                default:
                    proxy = NULL;
                break;
                }
                children = c_iterInsert(children, proxy);
                vChild = c_iterTakeFirst(vChildren);
            }
            c_iterFree(vChildren);
            u_cfNodeRelease(u_cfNode(element));
        }
    }
    return children;
}
Esempio n. 3
0
c_iter
u_cfElementGetChildren(
    u_cfElement element)
{
    u_result      r;
    v_cfElement   ke;
    v_cfNode      child;
    u_cfNode      proxy;
    c_iter        kc;
    c_iter        children;
    u_participant p;

    children = c_iterNew(NULL);
    if (element != NULL) {
        r = u_cfNodeReadClaim(u_cfNode(element), (v_cfNode*)(&ke));
        if (r == U_RESULT_OK) {
            p = u_cfNodeParticipant(u_cfNode(element));
            kc = v_cfElementGetChildren(ke);
            child = c_iterTakeFirst(kc);
            while (child != NULL) {
                switch(v_cfNodeKind(child)) {
                case V_CFELEMENT:
                    proxy = u_cfNode(u_cfElementNew(p, v_cfElement(child)));
                break;
                case V_CFATTRIBUTE:
                    proxy = u_cfNode(u_cfAttributeNew(p, v_cfAttribute(child)));
                break;
                case V_CFDATA:
                    proxy = u_cfNode(u_cfDataNew(p,v_cfData(child)));
                break;
                default:
                    proxy = NULL;
                break;
                }
                c_iterInsert(children, proxy);
                child = c_iterTakeFirst(kc);
            }
            c_iterFree(kc);
            u_cfNodeRelease(u_cfNode(element));
        }
    }
    return children;
}
Esempio n. 4
0
static c_bool
getChildren(
    c_object o,
    c_voidp arg)
{
    struct getChildrenArg *a = (struct getChildrenArg *)arg;
    c_value value;
    c_bool isEqual;

    if (a->tagName == NULL) {
        a->children = c_iterInsert(a->children, o);
    } else {
        if (strcmp(v_cfNodeGetName(v_cfNode(o)), a->tagName) == 0) {
            if (a->attribName == NULL) {
                a->children = c_iterInsert(a->children, o);
            } else {
                value = v_cfElementAttributeValue(v_cfElement(o), a->attribName);
                if (value.kind == V_STRING) {
                    isEqual = (strcmp(a->attribValue, value.is.String) == 0);
                    if (isEqual != a->attribNegate) {
                        /* Add if isEqual && !a->attribNegate or
                               if !isEqual && a->attribNegate (XOR) */
                        a->children = c_iterInsert(a->children, o);
                    }
                } else {
                    assert(value.kind == V_UNDEFINED);
                    /* If this is a not-relationship,
                       add the element to the result */
                    if (a->attribNegate) {
                        a->children = c_iterInsert(a->children, o);
                    }
                }
            }
        }
    }
    return TRUE; /* always finish the walk */
}
Esempio n. 5
0
static int
lockPages(
    v_kernel k,
    const c_char *name)
{
    v_configuration cfg;
    v_cfElement root;
    v_cfElement service;
    v_cfData data;
    int lock;
    c_char *path;
    c_iter iter;
    int iterLength;
    c_value value;

    assert(k);

    lock = 0;
    cfg = v_getConfiguration(k);
    if (cfg != NULL) {
        root = v_configurationGetRoot(cfg);
        if (root != NULL) {
            path = (c_char *)os_malloc(strlen(SERVICE_PATH) + strlen(name));
            /* NULL terminator is covered by '%s' in SERVICE_PATH constant */
            os_sprintf(path, SERVICE_PATH, name);
            iter = v_cfElementXPath(root, path);
            iterLength = c_iterLength(iter);
            os_free(path);
            if (iterLength == 1) {
                service = v_cfElement(c_iterTakeFirst(iter));
                c_iterFree(iter);
                iter = v_cfElementXPath(service, "Locking/#text");
                iterLength = c_iterLength(iter);
                if (iterLength == 1) {
                    data = v_cfData(c_iterTakeFirst(iter));
                    if (u_cfValueScan(v_cfDataValue(data), V_BOOLEAN, &value)) {
                        if (value.is.Boolean) {
                            lock = 1;
                            OS_REPORT_1(OS_INFO,"lockPages", 0,
                                "service '%s': Locking enabled", name);
                        }
                    } else {
                        OS_REPORT_1(OS_WARNING,"lockPages", 0,
                            "Failed to retrieve Locking for service '%s': Locking disabled", name);
                    }
                }
            } else if (iterLength > 1) {
                OS_REPORT_2(OS_WARNING,"lockPages", 0,
                    "Multiple configuration found for service '%s' (too many: %d): Locking disabled",
                    name, iterLength);
            } else {
                OS_REPORT_1(OS_WARNING,"lockPages", 0,
                    "Could not get configuration for service '%s' (non-existent): Locking disabled",
                    name);
            }
            c_iterFree(iter);
            c_free(root);
        }
    }

    return lock;
}
Esempio n. 6
0
c_iter
v_cfElementXPath(
    v_cfElement element,
    const c_char *xpathExpr)
{
    c_iter result;
    const c_char *posInExpr;
    const c_char *slash;
    char *attribEnd;
    c_ulong length;
    struct getChildrenArg arg;
    c_long nrToProcess;
    v_cfNode node;

    assert(C_TYPECHECK(element, v_cfElement));
    assert(xpathExpr != NULL);
 
    result = c_iterNew(element);
    nrToProcess = 1;
    posInExpr = xpathExpr;
    slash = strchr(posInExpr, XPATH_SEPERATOR);
    while (nrToProcess > 0) {
        node = c_iterTakeFirst(result);
        nrToProcess--;
        if (node->kind == V_CFELEMENT) { /* do not process data elements */
            if (slash) {

            	length = C_ADDRESS(slash) - C_ADDRESS(posInExpr);
            } else {
                length = strlen(posInExpr);
            }
            arg.children = c_iterNew(NULL);
            arg.tagName = (c_char *)os_malloc(length + 1U);
            os_strncpy(arg.tagName, posInExpr, length);
            arg.tagName[length] = 0;
            
            /* Look for selection criteria based on attribute value
             * Example XPath expression:
             * /aaa/bbb[@name='value']/ccc or /aaa/bbb[@name!='value']/ccc */
            arg.attribName = strchr(arg.tagName, '[');
            if (arg.attribName != NULL) {
                *arg.attribName = '\0';
                arg.attribName = &(arg.attribName[1]);
                assert(*arg.attribName == '@');
                arg.attribName = &(arg.attribName[1]);
                arg.attribValue = strchr(arg.attribName, '!');
                if (arg.attribValue != NULL) {
                    arg.attribNegate = TRUE;
                    *arg.attribValue = '\0';
                    arg.attribValue = &arg.attribValue[1];
                    assert(*arg.attribValue == '=');
                } else {
                    arg.attribNegate = FALSE;
                    arg.attribValue = strchr(arg.attribName, '=');
                }
                assert(arg.attribValue != NULL);
                *arg.attribValue = '\0';
                arg.attribValue = &arg.attribValue[1];
                assert(*arg.attribValue == '\'');
                arg.attribValue = &(arg.attribValue[1]);
                attribEnd = strchr(arg.attribValue, '\'');
                assert(attribEnd != NULL);
                *attribEnd = '\0';
                assert(attribEnd[1] == ']');
            }
        
            c_walk(v_cfElement(node)->children, getChildren, &arg);
            os_free(arg.tagName);
            if (slash) { 
                nrToProcess += c_iterLength(arg.children);
            }
            /* now append */
            node = v_cfNode(c_iterTakeFirst(arg.children));
            while (node != NULL) {
                c_iterAppend(result, node);
                node = v_cfNode(c_iterTakeFirst(arg.children));
            }
            c_iterFree(arg.children);

            if (slash) {

                posInExpr = (const c_char *)(C_ADDRESS(slash) + 1U);
                slash = strchr(posInExpr, XPATH_SEPERATOR);
            }
        }
    }

    return result;
}
Esempio n. 7
0
/*
 * ES, dds1576: This method consults the configuration info stored in the kernel
 * to determine the access policy for this partition
 */
v_accessMode
v_kernelPartitionAccessMode(
    v_kernel _this,
    v_partitionPolicy partition)
{
    v_configuration config;
    v_cfElement root;
    v_cfElement element;
    c_iter iter;
    v_accessMode retVal = V_ACCESS_MODE_UNDEFINED;
    c_value expression;
    c_value accessMode;
    c_iter partitionsSplit;
    c_char* partitionName;

    config = v_getConfiguration(_this);
    if(config)
    {
        root = v_configurationGetRoot(config);
        /* Iterate over all partitionAccess elements */
        iter = v_cfElementXPath(root, "Domain/PartitionAccess");
        while(c_iterLength(iter) > 0)
        {
            element = v_cfElement(c_iterTakeFirst(iter));
            /* Get the partition expression value, it should be a string */
            expression = v_cfElementAttributeValue(element, "partition_expression");
            if(expression.kind == V_STRING)
            {
                /* iterate over partitions, if one matches, exit and return */
                partitionsSplit = v_partitionPolicySplit(partition);
                while(c_iterLength(partitionsSplit) > 0)
                {
                    partitionName = (c_char*)c_iterTakeFirst(partitionsSplit);
                    if(v_partitionStringMatchesExpression(partitionName, expression.is.String))
                    {
                        /* The partition matches the expression.*/
                        accessMode = v_cfElementAttributeValue(element, "access_mode");
                        if(accessMode.kind == V_STRING)
                        {
                            /* A correct solution space can be realized between multiple
                             * expressions having an AND relationship by specifying the
                             * following rules R&W=RW, R&N=N, W&N=N, RW&N=N.
                             */
                            switch(retVal)
                            {
                                case V_ACCESS_MODE_UNDEFINED: /* start state */
                                    if(strcmp(accessMode.is.String, "none") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_NONE;
                                    } else if(strcmp(accessMode.is.String, "write") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_WRITE;
                                    } else if(strcmp(accessMode.is.String, "read") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_READ;
                                    } else if(strcmp(accessMode.is.String, "readwrite") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_READ_WRITE;
                                    }
                                    break;
                                case V_ACCESS_MODE_WRITE:
                                    if(strcmp(accessMode.is.String, "read") == 0 ||
                                       strcmp(accessMode.is.String, "readwrite") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_READ_WRITE;
                                    } else if(strcmp(accessMode.is.String, "none") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_NONE;
                                    }
                                    break;
                                case V_ACCESS_MODE_READ:
                                    if(strcmp(accessMode.is.String, "write") == 0 ||
                                       strcmp(accessMode.is.String, "readwrite") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_READ_WRITE;
                                    } else if(strcmp(accessMode.is.String, "none") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_NONE;
                                    }
                                    break;
                                case V_ACCESS_MODE_READ_WRITE:
                                    if(strcmp(accessMode.is.String, "none") == 0)
                                    {
                                        retVal = V_ACCESS_MODE_NONE;
                                    }
                                    break;
                                default: /* case V_ACCESS_MODE_NONE > none always remains none */
                                    break;
                            }
                        }
                    }
                    os_free(partitionName);
                }
                c_iterFree(partitionsSplit);
            }
        }
        if(iter)
        {
            c_iterFree(iter);
        }
        if(root)
        {
            c_free(root);
        }
    }
    if(retVal == V_ACCESS_MODE_UNDEFINED)
    {
        /* No specific rights defined, fall back to default */
        retVal = V_ACCESS_MODE_READ_WRITE;
    }
    return retVal;
}