# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1200052158 -3600
# Node ID ec66d30629f4584ca30751ce3e079f5561f2985a
# Parent b69727ddc9a45a32c75547a90364759500280398
Add function to validate the client given object path of a ComputerSystem
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r b69727ddc9a4 -r ec66d30629f4 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Thu Jan 10 11:04:39 2008 +0100
+++ b/src/Virt_ComputerSystem.c Fri Jan 11 12:49:18 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,46 +374,66 @@ 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);
- if (prop != NULL) {
- cu_statusf(_BROKER, &s,
+ _inst = instance_from_name(broker, conn, name, reference);
+ if (_inst == NULL) {
+ cu_statusf(broker, &s,
CMPI_RC_ERR_NOT_FOUND,
- "No such instance (%s)", prop);
- goto out;
- }
-
- CMReturnInstance(results, inst);
- CMSetStatus(&s, CMPI_RC_OK);
+ "No such instance (%s)", name);
+ goto out;
+ }
+
+ s = cu_validate_ref(broker, reference, _inst);
+
out:
virConnectClose(conn);
-
- return s;
+ if (inst)
+ *inst = _inst;
+
+ return s;
+}
+
+static CMPIStatus return_domain(const CMPIObjectPath *reference,
+ const CMPIResult *results)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
+
+ s = get_domain(_BROKER, reference, &inst);
+ if (s.rc != CMPI_RC_OK)
+ return s;
+
+ CMReturnInstance(results, inst);
+
+ return s;
+}
+
+CMPIStatus validate_domain_ref(const CMPIBroker *broker,
+ const CMPIObjectPath *ref)
+{
+ return get_domain(broker, ref, NULL);
}
static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self,
@@ -440,19 +460,7 @@ 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");
-
- return s;
- }
-
- return get_domain(reference, results, name);
+ return return_domain(reference, results);
}
DEFAULT_CI();
diff -r b69727ddc9a4 -r ec66d30629f4 src/Virt_ComputerSystem.h
--- a/src/Virt_ComputerSystem.h Thu Jan 10 11:04:39 2008 +0100
+++ b/src/Virt_ComputerSystem.h Fri Jan 11 12:49:18 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