From 48a5b0a2081b20bbe092967708a687450b96f4c2 Mon Sep 17 00:00:00 2001 From: Klaus Kämpf Date: Mon, 13 Sep 2010 16:01:27 +0200 Subject: Enhance enumerate with association filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Enhance enumerate with association filter to have the ability to specify the optional elements namely: AssociationClassName, Role, ResultClassName, ResultRole and IncludeResultProperty. (IncludeResultProperty is a list, specify it as a comma separated list in the “U” option. (Chris Poblete) (This patch was in svn but missing from git :-/) --- src/wsman.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'src/wsman.c') diff --git a/src/wsman.c b/src/wsman.c index e066c7f..438d05c 100644 --- a/src/wsman.c +++ b/src/wsman.c @@ -542,6 +542,45 @@ static int wsman_read_client_config(dictionary * ini) return 1; } +static void free_include_result_property(char **resultProps) +{ + if (NULL != resultProps) { + char **tmp = resultProps; + while (*tmp != NULL) { // iterate until list terminator + u_free(*tmp); + tmp++; + } + u_free(resultProps); + } +} + +static char ** get_include_result_property(int *propNum) +{ + char **resultProps = NULL; + char *tok, *val, *copy; + int idx = 0; + + *propNum = 0; + if (NULL != enum_context) { + copy = u_strdup(enum_context); + for (tok = copy ; NULL != tok ; (*propNum)++, tok = strchr(tok, ',')) { // get count + tok++; + } + resultProps = (char **)u_calloc((*propNum + 1), sizeof(char *)); // 1 more for list terminator + val = copy; + while (val) { + tok = strchr(val, ','); + if (NULL != tok) { + *tok++ = '\0'; + } + resultProps[idx++] = u_strdup(val); + val = tok; + } + resultProps[idx] = NULL; // list terminator + u_free(copy); + } + return resultProps; +} int main(int argc, char **argv) { @@ -773,7 +812,24 @@ int main(int argc, char **argv) epr_add_selector_text(epr, CIM_NAMESPACE_SELECTOR, options->cim_ns); } if (epr) { - filter = filter_create_assoc(epr, (op == WSMAN_ACTION_REFERENCES )?0:1, NULL, NULL, NULL, NULL, NULL, 0 ); + char **resultProperties = NULL; + const char *assocClass, *resultClass, *role, *resultRole; + int propNum; + + if (NULL != (assocClass = wsman_epr_selector_by_name(epr, "AssociationClassName"))) + epr_delete_selector(epr, "AssociationClassName"); + if (NULL != (resultClass = wsman_epr_selector_by_name(epr, "ResultClassName"))) + epr_delete_selector(epr, "ResultClassName"); + if (NULL != (role = wsman_epr_selector_by_name(epr, "Role"))) + epr_delete_selector(epr, "Role"); + if (NULL != (resultRole = wsman_epr_selector_by_name(epr, "ResultRole"))) + epr_delete_selector(epr, "ResultRole"); + resultProperties = get_include_result_property(&propNum); + + filter = filter_create_assoc(epr, (op == WSMAN_ACTION_REFERENCES )?0:1, + assocClass, resultClass, role, resultRole, resultProperties, propNum); + + free_include_result_property(resultProperties); } } else { error("Filter Requied"); -- cgit