diff options
author | Jan Synacek <jsynacek@redhat.com> | 2014-05-05 15:28:58 +0200 |
---|---|---|
committer | Jan Synacek <jsynacek@redhat.com> | 2014-05-06 08:31:20 +0200 |
commit | 08a3b7128e27f474046afa3f78b55df221c59dd9 (patch) | |
tree | f59578a238b6086c31904bf925567f96eef0280a /src/libs | |
parent | 55f63d29f5d2b4e82979d71386df58394e87ef5a (diff) | |
download | openlmi-providers-08a3b7128e27f474046afa3f78b55df221c59dd9.tar.gz openlmi-providers-08a3b7128e27f474046afa3f78b55df221c59dd9.tar.xz openlmi-providers-08a3b7128e27f474046afa3f78b55df221c59dd9.zip |
libopenlmi: minor fixes and improvements
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/libopenlmi/openlmi.c | 48 | ||||
-rw-r--r-- | src/libs/libopenlmi/openlmi.h | 65 |
2 files changed, 75 insertions, 38 deletions
diff --git a/src/libs/libopenlmi/openlmi.c b/src/libs/libopenlmi/openlmi.c index 6257520..1259fbc 100644 --- a/src/libs/libopenlmi/openlmi.c +++ b/src/libs/libopenlmi/openlmi.c @@ -388,46 +388,44 @@ void _lmi_debug(int level, const char *file, int line, const char *format, ...) -CMPIStatus lmi_check_required( - const CMPIBroker *b, +CMPIStatus lmi_check_required_properties( + const CMPIBroker *cb, const CMPIContext *ctx, - const CMPIObjectPath *o) + const CMPIObjectPath *o, + const char *csccn_prop_name, + const char *csn_prop_name) { CMPIStatus st; CMPIData data; - const char *prop; /* check computer system creation class name */ - data = CMGetKey(o, "CSCreationClassName", &st); - lmi_check_status(st); - + data = CMGetKey(o, csccn_prop_name, &st); + lmi_return_if_status_not_ok(st); if (CMIsNullValue(data)) { - CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "CSCreationClassName is empty"); + lmi_return_with_chars(cb, CMPI_RC_ERR_FAILED, "%s is empty", csccn_prop_name); } - prop = lmi_get_string_property_from_objectpath(o, "CSCreationClassName"); - if (strcmp(prop, lmi_get_system_creation_class_name()) != 0) { - CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "Wrong CSCreationClassName"); + if (strcmp(KChars(data.value.string), lmi_get_system_creation_class_name()) != 0) { + lmi_return_with_chars(cb, CMPI_RC_ERR_FAILED, "Wrong %s", csccn_prop_name); } /* check fqdn */ - data = CMGetKey(o, "CSName", &st); - lmi_check_status(st); + data = CMGetKey(o, csn_prop_name, &st); + lmi_return_if_status_not_ok(st); if (CMIsNullValue(data)) { - CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "CSName is empty"); + lmi_return_with_chars(cb, CMPI_RC_ERR_FAILED, "%s is empty", csn_prop_name); } - prop = lmi_get_string_property_from_objectpath(o, "CSName"); - if (strcmp(prop, lmi_get_system_name()) != 0) { - CMReturnWithChars(b, CMPI_RC_ERR_FAILED, "Wrong CSName"); + if (strcmp(KChars(data.value.string), lmi_get_system_name()) != 0) { + lmi_return_with_chars(cb, CMPI_RC_ERR_FAILED, "Wrong %s", csn_prop_name); } CMReturn(CMPI_RC_OK); } -CMPIStatus lmi_check_assoc_class( +CMPIStatus lmi_class_path_is_a( const CMPIBroker *cb, const char *namespace, - const char *assocClass, - const char *class) + const char *class, + const char *class_type) { CMPIObjectPath *o; CMPIStatus st = {.rc = CMPI_RC_OK}; @@ -440,9 +438,9 @@ CMPIStatus lmi_check_assoc_class( CMRelease(o); return st; } - if (assocClass && !CMClassPathIsA(cb, o, assocClass, &st)) { - CMRelease(o); + if (class_type && !CMClassPathIsA(cb, o, class_type, &st)) { st.rc = LMI_RC_ERR_CLASS_CHECK_FAILED; + CMRelease(o); return st; } CMRelease(o); @@ -462,3 +460,9 @@ const char *lmi_get_string_property_from_instance(const CMPIInstance *i, const c d = CMGetProperty(i, prop, NULL); return KChars(d.value.string); } + +/* vi: set et: */ +/* Local Variables: */ +/* indent-tabs-mode: nil */ +/* c-basic-offset: 4 */ +/* End: */ diff --git a/src/libs/libopenlmi/openlmi.h b/src/libs/libopenlmi/openlmi.h index 7f151cd..a35e01e 100644 --- a/src/libs/libopenlmi/openlmi.h +++ b/src/libs/libopenlmi/openlmi.h @@ -182,8 +182,7 @@ void lmi_set_log_level(int level); * @retval true if succeeds * @retval false if addition fails */ -/* TODO: Rename. Looks like a class. */ -#define LMI_ReturnInstance(cr, w) KOkay(__KReturnInstance((cr), &(w).__base)) +#define lmi_return_instance(cr, w) KOkay(__KReturnInstance((cr), &(w).__base)) enum { _LMI_DEBUG_NONE=0, _LMI_DEBUG_ERROR, _LMI_DEBUG_WARN, @@ -196,28 +195,32 @@ void _lmi_debug(int level, const char *file, int line, const char *format, ...); #define lmi_info(...) _lmi_debug(_LMI_DEBUG_INFO, __FILE__, __LINE__, __VA_ARGS__) #define lmi_warn(...) _lmi_debug(_LMI_DEBUG_WARN, __FILE__, __LINE__, __VA_ARGS__) #define lmi_error(...) _lmi_debug(_LMI_DEBUG_ERROR, __FILE__, __LINE__, __VA_ARGS__) -#define lmi_dump_objectpath(o, lvl) \ +#define lmi_dump_objectpath(o, lvl) \ lmi_##lvl("OP: %s", CMGetCharsPtr((o)->ft->toString(o, NULL), NULL)) -/* Shortcuts for functions and macros from openlmicommon library. */ -#define get_system_creation_class_name lmi_get_system_creation_class_name -#define get_system_name lmi_get_system_name + +#define lmi_return_with_chars(b, code, ...) \ + do { \ + char errmsg[BUFLEN]; \ + snprintf(errmsg, BUFLEN - 1, __VA_ARGS__); \ + CMReturnWithChars(b, code, errmsg); \ + } while (0) /* Status checking helpers. Beware of the returns! */ -#define lmi_check_status(st) \ +#define lmi_return_if_status_not_ok(st) \ do { \ - if (st.rc != CMPI_RC_OK) { \ - return st; \ + if ((st).rc != CMPI_RC_OK) { \ + return (st); \ } \ } while (0) -#define lmi_check_class_check_status(st) \ +#define lmi_return_if_class_check_not_ok(st) \ do { \ - if (st.rc == LMI_RC_ERR_CLASS_CHECK_FAILED) { \ + if ((st).rc == LMI_RC_ERR_CLASS_CHECK_FAILED) { \ CMReturn(CMPI_RC_OK); \ } \ - lmi_check_status(st); \ + lmi_return_if_status_not_ok(st); \ } while (0) #define lmi_return_with_status(b, st, code, msg) \ @@ -227,10 +230,40 @@ void _lmi_debug(int level, const char *file, int line, const char *format, ...); } while(0) -CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIContext *, const CMPIObjectPath *); -CMPIStatus lmi_check_assoc_class(const CMPIBroker *, const char *, const char *, const char *); +/** + * Check required properties and their values. currently, only computer system + * creation class name and computer system name are checked. + * + * @param cb CMPIBroker + * @param ctx CMPIContext + * @param o Objectpath to be checked + * @param csccn_prop_name Computer system creation class name property name + * @param csn_prop_name Computer system name property name + */ +CMPIStatus lmi_check_required_properties(const CMPIBroker *cb, const CMPIContext *ctx, + const CMPIObjectPath *o, + const char *csccn_prop_name, + const char *csn_prop_name); + +/** + * Determine whether a CIM class is of <class_type> or any of <class_type> + * subclasses. + * + * @param cb CMPIBroker + * @param namespace CIMOM namespace + * @param class Class to be checked + * @param class_type Class to be checked against + */ +CMPIStatus lmi_class_path_is_a(const CMPIBroker *cb, const char *namespace, + const char *class, const char *class_type); -const char *lmi_get_string_property_from_objectpath(const CMPIObjectPath *, const char *); -const char *lmi_get_string_property_from_instance(const CMPIInstance *, const char *); +const char *lmi_get_string_property_from_objectpath(const CMPIObjectPath *o, const char *prop); +const char *lmi_get_string_property_from_instance(const CMPIInstance *i, const char *prop); #endif /* OPENLMI_H */ + +/* vi: set et: */ +/* Local Variables: */ +/* indent-tabs-mode: nil */ +/* c-basic-offset: 4 */ +/* End: */ |