# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1199971251 -3600
# Node ID a45042de9fd40ef1cb150c854f506baf03690ed5
# Parent b69727ddc9a45a32c75547a90364759500280398
Add function to validate the client given object path o ComputerSystem
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r b69727ddc9a4 -r a45042de9fd4 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Thu Jan 10 11:04:39 2008 +0100
+++ b/src/Virt_ComputerSystem.c Thu Jan 10 14:20:51 2008 +0100
@@ -285,7 +285,7 @@ CMPIInstance *instance_from_name(const C
dom = virDomainLookupByName(conn, name);
if (dom == NULL)
- return 0;
+ return NULL;
instance = get_typed_instance(broker,
pfx_from_conn(conn),
@@ -374,45 +374,62 @@ static CMPIStatus return_enum_domains(co
return s;
}
-static CMPIStatus get_domain(const CMPIObjectPath *reference,
- const CMPIResult *results,
- const char *name)
-{
- CMPIInstance *inst;
- CMPIStatus s;
+static CMPIStatus get_domain(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ CMPIInstance **inst)
+{
+ CMPIInstance *_inst;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
virConnectPtr conn = NULL;
- const char *prop = NULL;
-
- if (!provider_is_responsible(_BROKER, reference, &s)) {
- CMSetStatus(&s, CMPI_RC_ERR_NOT_FOUND);
+ const char *name;
+
+ if (!provider_is_responsible(broker, reference, &s))
return s;
- }
-
- conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
+
+ if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "No domain name specified");
+ return s;
+ }
+
+ conn = connect_by_classname(broker, CLASSNAME(reference), &s);
if (conn == NULL)
return s;
- inst = instance_from_name(_BROKER, conn, name, reference);
- if (inst == NULL) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Unable to find `%s'", name);
- goto out;
- }
-
- prop = cu_compare_ref(reference, inst);
+ _inst = instance_from_name(broker, conn, name, reference);
+ if (_inst == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)", name);
+ goto out;
+ }
+
+ out:
+ virConnectClose(conn);
+ *inst = _inst;
+
+ return s;
+}
+
+CMPIStatus validate_domain_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *ref)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
+ const char *prop;
+
+ s = get_domain(broker, ref, &inst);
+ if (s.rc != CMPI_RC_OK)
+ return s;
+
+ prop = cu_compare_ref(ref, inst);
if (prop != NULL) {
- cu_statusf(_BROKER, &s,
+ cu_statusf(broker, &s,
CMPI_RC_ERR_NOT_FOUND,
"No such instance (%s)", prop);
- goto out;
- }
-
- CMReturnInstance(results, inst);
- CMSetStatus(&s, CMPI_RC_OK);
- out:
- virConnectClose(conn);
-
+ }
+
return s;
}
@@ -440,19 +457,25 @@ static CMPIStatus GetInstance(CMPIInstan
const CMPIObjectPath *reference,
const char **properties)
{
- const char *name;
-
- if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) {
- CMPIStatus s;
-
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "No domain name specified");
-
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
+ const char *prop = NULL;
+
+ s = get_domain(_BROKER, reference, &inst);
+ if (s.rc != CMPI_RC_OK)
return s;
- }
-
- return get_domain(reference, results, name);
+
+ prop = cu_compare_ref(reference, inst);
+ if (prop != NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)", prop);
+ return s;
+ }
+
+ CMReturnInstance(results, inst);
+
+ return s;
}
DEFAULT_CI();
diff -r b69727ddc9a4 -r a45042de9fd4 src/Virt_ComputerSystem.h
--- a/src/Virt_ComputerSystem.h Thu Jan 10 11:04:39 2008 +0100
+++ b/src/Virt_ComputerSystem.h Thu Jan 10 14:20:51 2008 +0100
@@ -52,6 +52,16 @@ int enum_domains(const CMPIBroker *broke
const char *ns,
struct inst_list *instlist);
+/**
+ * Validate the client given domain object path
+ *
+ * @param broker A pointer to the current broker
+ * @param ref The client given object path
+ * @returns CMPIStatus
+ */
+CMPIStatus validate_domain_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *ref);
+
#endif