Exemplo n.º 1
0
/*
 * Search all the data sources for matches to our query.  We look for
 * dynamic hints first as overrides for static or fallback hints.
 */
static int
resource_find(int *line, int *startln,
    const char *name, int *unit, const char *resname, const char *value,
    const char **ret_name, int *ret_namelen, int *ret_unit,
    const char **ret_resname, int *ret_resnamelen, const char **ret_value)
{
	int i;
	int un;

	*line = 0;

	/* Search for exact unit matches first */
	i = res_find(line, startln, name, unit, resname, value,
	    ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
	    ret_value);
	if (i == 0)
		return 0;
	if (unit == NULL)
		return ENOENT;
	/* If we are still here, search for wildcard matches */
	un = -1;
	i = res_find(line, startln, name, &un, resname, value,
	    ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
	    ret_value);
	if (i == 0)
		return 0;
	return ENOENT;
}
Exemplo n.º 2
0
int getconflict(char *restriction, char *cont, resource *res1)
{
	resource *res2;
	resourcetype *restype;
	int n;

	restype=res1->restype;

	res2=res_find(restype, cont);

	if(res2==NULL) {
		error(_("Can't find resource '%s', resource type '%s' in "
			"'conflicts-with' restriction"), cont, restype->type);
		return(-1);
	}

	if(recursive) {
		for(n=0;n<restype->resnum;n++) {
			if(res_get_conflict(restype, n, res1->resid)) {
				res_set_conflict(&restype->res[n], res2);
				res_set_conflict(res2, &restype->res[n]);
			}
		}
	} else {
		res_set_conflict(res1, res2);
		res_set_conflict(res2, res1);
	}

	return 0;
}
Exemplo n.º 3
0
/** @brief Get a resource definition for an event from the XML tree.
 *
 * @param cur Pointer to the \<event\> node.
 * @param restype Get a resource definition for this resource type. */
static resource *parser_event_get_res(xmlNodePtr cur, resourcetype *restype)
{
    resource *res;
    xmlChar *type, *name;

    assert(restype!=NULL);
    assert(cur!=NULL);

    res=NULL;

    cur=cur->children;
    while(cur!=NULL) {
        if(!xmlStrcmp(cur->name, XMLCHAR "resource")) {
            type=parser_getprop_str(cur, XMLCHAR "type");

            if(xmlStrcmp(type, XMLCHAR restype->type)) {
                free(type);
                cur=cur->next;
                continue;
            }

            name=parser_getprop_str(cur, XMLCHAR "name");

            if(res!=NULL) {
                fatal(_("Definition of event has multiple "
                        "definitions for resource type '%s' (line %d)"),
                      restype->type, xmlGetLineNo(cur));
            }

            res=res_find(restype, CHAR name);
            if(res==NULL) INVPROP("name", cur);

            xmlFree(type);
            xmlFree(name);
        }
        cur=cur->next;
    }

    return(res);
}