[Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path o ComputerSystem
Kaitlin Rupert
kaitlin at linux.vnet.ibm.com
Thu Jan 10 18:14:10 UTC 2008
Heidi Eckhart wrote:
I like the idea of a validate function. But the body of GetInstance()
is almost identical to the body of validate_domain_ref() - the only
exception is that one returns an instance and the other returns a status.
Could these functions be consolidated? You could change get_domain() to
something like _get_domain(). Then get_domain() could call
_get_domain() and validate_domain_ref(). When you need the instance
returned, you can use get_domain(), otherwise you can just call
validate_domain_ref() directly to validate.
> -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;
> }
--
Kaitlin Rupert
IBM Linux Technology Center
karupert at us.ibm.com
More information about the Libvirt-cim
mailing list