Skip to content

Commit

Permalink
Refactor: libs: Deprecate crm_str_eq, safe_str_eq, and safe_str_neq.
Browse files Browse the repository at this point in the history
  • Loading branch information
clumens committed Aug 12, 2020
1 parent 8c493d8 commit 1d3ce85
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 40 deletions.
3 changes: 1 addition & 2 deletions devel/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ EXTRA_DIST = $(EXTRA_SCRIPTS) \
# ref-passed-variables-inited.cocci seems to be returning some false positives around
# GHashTableIters, so it is disabled for the moment.
COCCI_FILES ?= coccinelle/string-empty.cocci \
coccinelle/string-null-matches.cocci \
coccinelle/string-replacements.cocci
coccinelle/string-null-matches.cocci

cocci:
for f in $(COCCI_FILES); do \
Expand Down
12 changes: 9 additions & 3 deletions include/crm/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ long long crm_parse_ll(const char *text, const char *default_text);
int crm_parse_int(const char *text, const char *default_text);
long long crm_get_msec(const char *input);
char * crm_strip_trailing_newline(char *str);
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
gboolean safe_str_neq(const char *a, const char *b);
gboolean crm_strcase_equal(gconstpointer a, gconstpointer b);
guint crm_strcase_hash(gconstpointer v);
guint g_str_hash_traditional(gconstpointer v);
char *crm_strdup_printf(char const *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
int pcmk_numeric_strcasecmp(const char *s1, const char *s2);

# define safe_str_eq(a, b) pcmk__str_eq(a, b, pcmk__str_casei)
# define crm_str_hash g_str_hash_traditional

static inline char *
Expand Down Expand Up @@ -220,6 +217,15 @@ bool pcmk_str_is_minus_infinity(const char *s);
//! \deprecated Use pcmk_get_ra_caps() instead
bool crm_provider_required(const char *standard);

//! \deprecated Use pcmk__str_eq() instead
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);

//! \deprecated Use pcmk__str_eq() instead
gboolean safe_str_neq(const char *a, const char *b);

//! \deprecated Use pcmk__str_eq() instead
#define safe_str_eq(a, b) pcmk__str_eq(a, b, pcmk__str_casei)

#endif // PCMK__NO_COMPAT

#ifdef __cplusplus
Expand Down
78 changes: 43 additions & 35 deletions lib/common/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,6 @@ crm_get_msec(const char *input)
return msec;
}

gboolean
safe_str_neq(const char *a, const char *b)
{
if (a == b) {
return FALSE;

} else if (a == NULL || b == NULL) {
return TRUE;

} else if (strcasecmp(a, b) == 0) {
return FALSE;
}
return TRUE;
}

gboolean
crm_is_true(const char *s)
{
Expand Down Expand Up @@ -324,26 +309,6 @@ crm_strip_trailing_newline(char *str)
return str;
}

gboolean
crm_str_eq(const char *a, const char *b, gboolean use_case)
{
if (use_case) {
return g_strcmp0(a, b) == 0;

/* TODO - Figure out which calls, if any, really need to be case independent */
} else if (a == b) {
return TRUE;

} else if (a == NULL || b == NULL) {
/* shouldn't be comparing NULLs */
return FALSE;

} else if (strcasecmp(a, b) == 0) {
return TRUE;
}
return FALSE;
}

/*!
* \brief Check whether a string starts with a certain sequence
*
Expand Down Expand Up @@ -850,3 +815,46 @@ pcmk__strcmp(const char *s1, const char *s2, uint32_t flags)
return strcmp(s1, s2);
}
}

// Deprecated functions kept only for backward API compatibility

gboolean safe_str_neq(const char *a, const char *b);

gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);

//! \deprecated Use pcmk__str_eq() instead
gboolean
safe_str_neq(const char *a, const char *b)
{
if (a == b) {
return FALSE;

} else if (a == NULL || b == NULL) {
return TRUE;

} else if (strcasecmp(a, b) == 0) {
return FALSE;
}
return TRUE;
}

//! \deprecated Use pcmk__str_eq() instead
gboolean
crm_str_eq(const char *a, const char *b, gboolean use_case)
{
if (use_case) {
return g_strcmp0(a, b) == 0;

/* TODO - Figure out which calls, if any, really need to be case independent */
} else if (a == b) {
return TRUE;

} else if (a == NULL || b == NULL) {
/* shouldn't be comparing NULLs */
return FALSE;

} else if (strcasecmp(a, b) == 0) {
return TRUE;
}
return FALSE;
}

0 comments on commit 1d3ce85

Please sign in to comment.