From 76d4396d3e9d2593d76116b6275b1d7edc83e5d1 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 1 Feb 2015 10:36:18 +0100 Subject: [PATCH] error utils: Add sdb_error_parse_priority(). --- src/include/utils/error.h | 11 +++++++++++ src/utils/error.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/include/utils/error.h b/src/include/utils/error.h index 49034eb..ae653af 100644 --- a/src/include/utils/error.h +++ b/src/include/utils/error.h @@ -131,6 +131,17 @@ sdb_error_get(void); int sdb_error_get_prio(void); +/* + * sdb_error_parse_priority: + * Parse the name of a log priority. + * + * Returns: + * - the numeric log priority on success + * - a negative value else + */ +int +sdb_error_parse_priority(char *prio); + /* * sdb_strerror: * This is a wrapper around the system's strerror function which ensures that diff --git a/src/utils/error.c b/src/utils/error.c index f940be6..2bc9901 100644 --- a/src/utils/error.c +++ b/src/utils/error.c @@ -276,6 +276,24 @@ sdb_error_get_prio(void) return ctx->prio; } /* sdb_error_get_prio */ +int +sdb_error_parse_priority(char *prio) +{ + if (! strcasecmp(prio, "EMERG")) + return SDB_LOG_EMERG; + else if (! strcasecmp(prio, "ERROR")) + return SDB_LOG_ERR; + else if (! strcasecmp(prio, "WARNING")) + return SDB_LOG_WARNING; + else if (! strcasecmp(prio, "NOTICE")) + return SDB_LOG_NOTICE; + else if (! strcasecmp(prio, "INFO")) + return SDB_LOG_INFO; + else if (! strcasecmp(prio, "DEBUG")) + return SDB_LOG_DEBUG; + return -1; +} /* sdb_error_parse_priority */ + char * sdb_strerror(int errnum, char *strerrbuf, size_t buflen) { -- 2.30.2