From 1d419618b0c36a0d363f30e336ec5ddaa850c60b Mon Sep 17 00:00:00 2001 From: mk722 Date: Wed, 4 Jan 2023 14:40:25 +0100 Subject: [PATCH 01/11] added prival function --- include/stumpless/prival.h | 271 +++++++++++++++++++++++++++++++++++++ src/prival.c | 46 +++++++ 2 files changed, 317 insertions(+) create mode 100644 include/stumpless/prival.h create mode 100644 src/prival.c diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h new file mode 100644 index 000000000..c5daeefc2 --- /dev/null +++ b/include/stumpless/prival.h @@ -0,0 +1,271 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* + * Copyright 2018-2022 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** @file + * Severity codes for classifying log entries. See RFC 5424 section 6.2.1 for + * details on these values. Severities are defined to be compatible with the + * syslog.h header if it is found on the system. Otherwise, they are defined as + * closely as possible to the RFC 5424 specification. + */ + +#ifndef __STUMPLESS_PRIVAL_H +# define __STUMPLESS_PRIVAL_H + +# include +# include + +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# include +# endif + +/** Creates a severity mask for the provided severity. */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_MASK( SEVERITY ) ( LOG_MASK( SEVERITY ) ) +# else +# define STUMPLESS_SEVERITY_MASK( SEVERITY ) ( 1 << ( SEVERITY ) ) +# endif + +/** Creates a severity mask from EMERG up to the provided severity. */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_MASK_UPTO( SEVERITY ) ( LOG_UPTO( SEVERITY ) ) +# else +# define STUMPLESS_SEVERITY_MASK_UPTO( SEVERITY ) \ +( ( 1 << ( ( SEVERITY ) + 1 ) ) - 1 ) +# endif + +/** + * Severity code value for EMERG log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_EMERG_VALUE LOG_EMERG +# else +# define STUMPLESS_SEVERITY_EMERG_VALUE 0 +# endif + +/** + * Severity code value for ALERT log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_ALERT_VALUE LOG_ALERT +# else +# define STUMPLESS_SEVERITY_ALERT_VALUE 1 +# endif + +/** + * Severity code value for CRIT log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_CRIT_VALUE LOG_CRIT +# else +# define STUMPLESS_SEVERITY_CRIT_VALUE 2 +# endif + +/** + * Severity code value for ERR log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_ERR_VALUE LOG_ERR +# else +# define STUMPLESS_SEVERITY_ERR_VALUE 3 +# endif + +/** + * Severity code value for WARNING log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_WARNING_VALUE LOG_WARNING +# else +# define STUMPLESS_SEVERITY_WARNING_VALUE 4 +# endif + +/** + * Severity code value for NOTICE log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_NOTICE_VALUE LOG_NOTICE +# else +# define STUMPLESS_SEVERITY_NOTICE_VALUE 5 +# endif + +/** + * Severity code value for INFO log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_INFO_VALUE LOG_INFO +# else +# define STUMPLESS_SEVERITY_INFO_VALUE 6 +# endif + +/** + * Severity code value for DEBUG log entries. + * + * @since release v2.0.0. + */ +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# define STUMPLESS_SEVERITY_DEBUG_VALUE LOG_DEBUG +# else +# define STUMPLESS_SEVERITY_DEBUG_VALUE 7 +# endif + +/** + * Equivalent to the DEBUG severity code value. Trace level messages include + * extra information, but do not have a distinct severity value in log entries. + * + * @since release v2.1.0 + */ +# define STUMPLESS_SEVERITY_TRACE_VALUE STUMPLESS_SEVERITY_DEBUG_VALUE + +/** + * A macro function that runs the provided action once for each severity, + * providing the symbol and value. The action must take two arguments, the + * first being the symbol name of the severity, and the second the numeric + * value of the severity. + * + * @since release v2.0.0. + */ +# define STUMPLESS_FOREACH_SEVERITY( ACTION ) \ +/** Emergency: system is unusable. */ \ +ACTION( STUMPLESS_SEVERITY_EMERG, STUMPLESS_SEVERITY_EMERG_VALUE ) \ +/** Alert: action must be taken immediately. */ \ +ACTION( STUMPLESS_SEVERITY_ALERT, STUMPLESS_SEVERITY_ALERT_VALUE ) \ +/** Critical: critical conditions. */ \ +ACTION( STUMPLESS_SEVERITY_CRIT, STUMPLESS_SEVERITY_CRIT_VALUE ) \ +/** Error: error conditions. */ \ +ACTION( STUMPLESS_SEVERITY_ERR, STUMPLESS_SEVERITY_ERR_VALUE ) \ +/** Warning: warning conditions. */ \ +ACTION( STUMPLESS_SEVERITY_WARNING, STUMPLESS_SEVERITY_WARNING_VALUE ) \ +/** Notice: normal but significant condition. */ \ +ACTION( STUMPLESS_SEVERITY_NOTICE, STUMPLESS_SEVERITY_NOTICE_VALUE ) \ +/** Informational: informational messages. */ \ +ACTION( STUMPLESS_SEVERITY_INFO, STUMPLESS_SEVERITY_INFO_VALUE ) \ +/** Debug: debug-level messages. */ \ +ACTION( STUMPLESS_SEVERITY_DEBUG, STUMPLESS_SEVERITY_DEBUG_VALUE ) + +# ifdef __cplusplus +extern "C" { +# endif + +/** + * All possible severity codes available to log entries. + * + * In versions prior to 2.0.0, these values were simply #define symbols. They + * have been changed to an enum to clearly convey proper usage. + * + * @since release v2.0.0. + */ +enum stumpless_severity { + STUMPLESS_FOREACH_SEVERITY( STUMPLESS_GENERATE_ENUM ) +}; + +/** + * Equivalent to the DEBUG severity. Trace level messages include extra + * information, but do not have a distinct severity value in log entries. + * + * @since release v2.1.0 + */ +# define STUMPLESS_SEVERITY_TRACE STUMPLESS_SEVERITY_DEBUG + +/** + * Gets the string representation of the given severity. + * + * This is a string literal that should not be modified or freed by the caller. + * + * **Thread Safety: MT-Safe** + * This function is thread safe. + * + * **Async Signal Safety: AS-Safe** + * This function is safe to call from signal handlers. + * + * **Async Cancel Safety: AC-Safe** + * This function is safe to call from threads that may be asynchronously + * cancelled. + * + * @param severity The severity to get the string from. + * + * @return The string representation of the given severity. + */ +STUMPLESS_PUBLIC_FUNCTION +const char * +stumpless_get_severity_string( enum stumpless_severity severity ); + +/** + * Gets the enum value corresponding to the given severity string. + * + * **Thread Safety: MT-Safe** + * This function is thread safe. + * + * **Async Signal Safety: AS-Safe** + * This function is safe to call from signal handlers. + * + * **Async Cancel Safety: AC-Safe** + * This function is safe to call from threads that may be asynchronously + * cancelled. + * + * @since release v2.1.0. + * + * @param severity_string The severity name to get the enum from. + * + * @return The enum integer corresponding to the given severity or -1 if + * the string is not a valid severity name. + */ +STUMPLESS_PUBLIC_FUNCTION +enum stumpless_severity +stumpless_get_severity_enum( const char *severity_string ); + +/** + * Gets the string corresponding to the given int prival value. + * + * **Thread Safety: MT-Safe** + * This function is thread safe. + * + * **Async Signal Safety: AS-Safe** + * This function is safe to call from signal handlers. + * + * **Async Cancel Safety: AC-Safe** + * This function is safe to call from threads that may be asynchronously + * cancelled. + * + * @since release v2.1.0. + * + * @param prival The prival name to get the string from. + * + * @return +*/ +STUMPLESS_PUBLIC_FUNCTION +const char * +stumpless_get_prival_string( int prival ); + +# ifdef __cplusplus +} /* extern "C" */ +# endif + +#endif /* __STUMPLESS_PRIVAL_H */ diff --git a/src/prival.c b/src/prival.c new file mode 100644 index 000000000..cf4197eee --- /dev/null +++ b/src/prival.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright 2018-2022 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + + +const char * +stumpless_get_prival_string(int prival) { + const char *prival_string; + int severity = get_severity(prival); + int facility = get_facility(prival); + + asprintf(&prival_string,"%s | %s", stumpless_get_severity_string((enum)*severity), + stumpless_get_facility_string((enum)*facility)); + return prival_string; +} + +/* private functions */ + +int +get_severity( int prival ) { + return prival & 0x7; +} + +int +get_facility( int prival ) { + return prival & 0xf8; +} \ No newline at end of file From 68ba4c23d9d77dd540503aef6c6cde411ccabbf4 Mon Sep 17 00:00:00 2001 From: mk722 Date: Thu, 5 Jan 2023 16:50:37 +0100 Subject: [PATCH 02/11] add test, edit prival function and CMake --- CMakeLists.txt | 6 + include/stumpless/prival.h | 221 +----------------------------- src/prival.c | 24 ++-- src/windows/stumpless.def | 2 + test/function/prival.cpp | 34 +++++ tools/check_headers/stumpless.yml | 1 + 6 files changed, 54 insertions(+), 234 deletions(-) create mode 100644 test/function/prival.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e6eacf15..1c6e2b4fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,7 @@ set(STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/log.c ${PROJECT_SOURCE_DIR}/src/memory.c ${PROJECT_SOURCE_DIR}/src/param.c + ${PROJECT_SOURCE_DIR}/src/prival.c ${PROJECT_SOURCE_DIR}/src/severity.c ${PROJECT_SOURCE_DIR}/src/strbuilder.c ${PROJECT_SOURCE_DIR}/src/strhelper.c @@ -950,6 +951,7 @@ install(FILES ${PROJECT_SOURCE_DIR}/include/stumpless/memory.h ${PROJECT_SOURCE_DIR}/include/stumpless/option.h ${PROJECT_SOURCE_DIR}/include/stumpless/param.h + ${PROJECT_SOURCE_DIR}/include/stumpless/prival.h ${PROJECT_SOURCE_DIR}/include/stumpless/severity.h ${PROJECT_SOURCE_DIR}/include/stumpless/target.h ${PROJECT_SOURCE_DIR}/include/stumpless/version.h @@ -1218,6 +1220,10 @@ add_function_test(perror SOURCES test/function/startup/perror.cpp ) +add_function_test(facility + SOURCES test/function/prival.cpp +) + add_function_test(severity SOURCES test/function/severity.cpp ) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index c5daeefc2..d20717fe2 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -17,10 +17,7 @@ */ /** @file - * Severity codes for classifying log entries. See RFC 5424 section 6.2.1 for - * details on these values. Severities are defined to be compatible with the - * syslog.h header if it is found on the system. Otherwise, they are defined as - * closely as possible to the RFC 5424 specification. + * Prival codes for function to create severity and facility string from prival int value. */ #ifndef __STUMPLESS_PRIVAL_H @@ -29,218 +26,6 @@ # include # include -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# include -# endif - -/** Creates a severity mask for the provided severity. */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_MASK( SEVERITY ) ( LOG_MASK( SEVERITY ) ) -# else -# define STUMPLESS_SEVERITY_MASK( SEVERITY ) ( 1 << ( SEVERITY ) ) -# endif - -/** Creates a severity mask from EMERG up to the provided severity. */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_MASK_UPTO( SEVERITY ) ( LOG_UPTO( SEVERITY ) ) -# else -# define STUMPLESS_SEVERITY_MASK_UPTO( SEVERITY ) \ -( ( 1 << ( ( SEVERITY ) + 1 ) ) - 1 ) -# endif - -/** - * Severity code value for EMERG log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_EMERG_VALUE LOG_EMERG -# else -# define STUMPLESS_SEVERITY_EMERG_VALUE 0 -# endif - -/** - * Severity code value for ALERT log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_ALERT_VALUE LOG_ALERT -# else -# define STUMPLESS_SEVERITY_ALERT_VALUE 1 -# endif - -/** - * Severity code value for CRIT log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_CRIT_VALUE LOG_CRIT -# else -# define STUMPLESS_SEVERITY_CRIT_VALUE 2 -# endif - -/** - * Severity code value for ERR log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_ERR_VALUE LOG_ERR -# else -# define STUMPLESS_SEVERITY_ERR_VALUE 3 -# endif - -/** - * Severity code value for WARNING log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_WARNING_VALUE LOG_WARNING -# else -# define STUMPLESS_SEVERITY_WARNING_VALUE 4 -# endif - -/** - * Severity code value for NOTICE log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_NOTICE_VALUE LOG_NOTICE -# else -# define STUMPLESS_SEVERITY_NOTICE_VALUE 5 -# endif - -/** - * Severity code value for INFO log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_INFO_VALUE LOG_INFO -# else -# define STUMPLESS_SEVERITY_INFO_VALUE 6 -# endif - -/** - * Severity code value for DEBUG log entries. - * - * @since release v2.0.0. - */ -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# define STUMPLESS_SEVERITY_DEBUG_VALUE LOG_DEBUG -# else -# define STUMPLESS_SEVERITY_DEBUG_VALUE 7 -# endif - -/** - * Equivalent to the DEBUG severity code value. Trace level messages include - * extra information, but do not have a distinct severity value in log entries. - * - * @since release v2.1.0 - */ -# define STUMPLESS_SEVERITY_TRACE_VALUE STUMPLESS_SEVERITY_DEBUG_VALUE - -/** - * A macro function that runs the provided action once for each severity, - * providing the symbol and value. The action must take two arguments, the - * first being the symbol name of the severity, and the second the numeric - * value of the severity. - * - * @since release v2.0.0. - */ -# define STUMPLESS_FOREACH_SEVERITY( ACTION ) \ -/** Emergency: system is unusable. */ \ -ACTION( STUMPLESS_SEVERITY_EMERG, STUMPLESS_SEVERITY_EMERG_VALUE ) \ -/** Alert: action must be taken immediately. */ \ -ACTION( STUMPLESS_SEVERITY_ALERT, STUMPLESS_SEVERITY_ALERT_VALUE ) \ -/** Critical: critical conditions. */ \ -ACTION( STUMPLESS_SEVERITY_CRIT, STUMPLESS_SEVERITY_CRIT_VALUE ) \ -/** Error: error conditions. */ \ -ACTION( STUMPLESS_SEVERITY_ERR, STUMPLESS_SEVERITY_ERR_VALUE ) \ -/** Warning: warning conditions. */ \ -ACTION( STUMPLESS_SEVERITY_WARNING, STUMPLESS_SEVERITY_WARNING_VALUE ) \ -/** Notice: normal but significant condition. */ \ -ACTION( STUMPLESS_SEVERITY_NOTICE, STUMPLESS_SEVERITY_NOTICE_VALUE ) \ -/** Informational: informational messages. */ \ -ACTION( STUMPLESS_SEVERITY_INFO, STUMPLESS_SEVERITY_INFO_VALUE ) \ -/** Debug: debug-level messages. */ \ -ACTION( STUMPLESS_SEVERITY_DEBUG, STUMPLESS_SEVERITY_DEBUG_VALUE ) - -# ifdef __cplusplus -extern "C" { -# endif - -/** - * All possible severity codes available to log entries. - * - * In versions prior to 2.0.0, these values were simply #define symbols. They - * have been changed to an enum to clearly convey proper usage. - * - * @since release v2.0.0. - */ -enum stumpless_severity { - STUMPLESS_FOREACH_SEVERITY( STUMPLESS_GENERATE_ENUM ) -}; - -/** - * Equivalent to the DEBUG severity. Trace level messages include extra - * information, but do not have a distinct severity value in log entries. - * - * @since release v2.1.0 - */ -# define STUMPLESS_SEVERITY_TRACE STUMPLESS_SEVERITY_DEBUG - -/** - * Gets the string representation of the given severity. - * - * This is a string literal that should not be modified or freed by the caller. - * - * **Thread Safety: MT-Safe** - * This function is thread safe. - * - * **Async Signal Safety: AS-Safe** - * This function is safe to call from signal handlers. - * - * **Async Cancel Safety: AC-Safe** - * This function is safe to call from threads that may be asynchronously - * cancelled. - * - * @param severity The severity to get the string from. - * - * @return The string representation of the given severity. - */ -STUMPLESS_PUBLIC_FUNCTION -const char * -stumpless_get_severity_string( enum stumpless_severity severity ); - -/** - * Gets the enum value corresponding to the given severity string. - * - * **Thread Safety: MT-Safe** - * This function is thread safe. - * - * **Async Signal Safety: AS-Safe** - * This function is safe to call from signal handlers. - * - * **Async Cancel Safety: AC-Safe** - * This function is safe to call from threads that may be asynchronously - * cancelled. - * - * @since release v2.1.0. - * - * @param severity_string The severity name to get the enum from. - * - * @return The enum integer corresponding to the given severity or -1 if - * the string is not a valid severity name. - */ -STUMPLESS_PUBLIC_FUNCTION -enum stumpless_severity -stumpless_get_severity_enum( const char *severity_string ); - /** * Gets the string corresponding to the given int prival value. * @@ -254,11 +39,11 @@ stumpless_get_severity_enum( const char *severity_string ); * This function is safe to call from threads that may be asynchronously * cancelled. * - * @since release v2.1.0. + * @since release v2.2.0. * * @param prival The prival name to get the string from. * - * @return + * @return The string representation of the severity and facility from the given prival. */ STUMPLESS_PUBLIC_FUNCTION const char * diff --git a/src/prival.c b/src/prival.c index cf4197eee..1e7401175 100644 --- a/src/prival.c +++ b/src/prival.c @@ -21,26 +21,18 @@ #include #include - const char * stumpless_get_prival_string(int prival) { const char *prival_string; int severity = get_severity(prival); int facility = get_facility(prival); - asprintf(&prival_string,"%s | %s", stumpless_get_severity_string((enum)*severity), - stumpless_get_facility_string((enum)*facility)); - return prival_string; + if(severity_is_invalid(severity) == 0 || facility_is_invalid(facility) == 0) { + return "NO_SUCH_PRIVAL"; + } else { + asprintf(&prival_string,"%s | %s", stumpless_get_severity_string((enum)*severity), + stumpless_get_facility_string((enum)*facility)); + return prival_string; + } } - -/* private functions */ - -int -get_severity( int prival ) { - return prival & 0x7; -} - -int -get_facility( int prival ) { - return prival & 0xf8; -} \ No newline at end of file + \ No newline at end of file diff --git a/src/windows/stumpless.def b/src/windows/stumpless.def index 5397d84d8..516ec6159 100644 --- a/src/windows/stumpless.def +++ b/src/windows/stumpless.def @@ -222,3 +222,5 @@ EXPORTS stumpless_unload_entry_only @206 stumpless_unload_param @207 vstumpless_load_entry @208 + stumpless_get_prival_string @209 + \ No newline at end of file diff --git a/test/function/prival.cpp b/test/function/prival.cpp new file mode 100644 index 000000000..82acff265 --- /dev/null +++ b/test/function/prival.cpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright 2019-2021 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace { + + class PrivalTest : public::testing::Test { + }; + + TEST( GetPrivalString, ValidPrival ) { + const char *result; + + #define CHECK_PRIVAL_TRUE( STRING, INT ) \ + result = stumpless_get_prival_string( STRING ); \ + EXPECT_STREQ( result, #STRING ); + } +} diff --git a/tools/check_headers/stumpless.yml b/tools/check_headers/stumpless.yml index 330987e3c..a74850836 100644 --- a/tools/check_headers/stumpless.yml +++ b/tools/check_headers/stumpless.yml @@ -632,6 +632,7 @@ "stumpless_get_severity_enum" : "stumpless/severity.h" "stumpless_get_facility_string" : "stumpless/facility.h" "stumpless_get_facility_enum" : "stumpless/facility.h" +"stumpless_get_prival_string" : "stumpless/prival.h" "stumpless_get_target_type_string" : "stumpless/target.h" "STUMPLESS_FOREACH_TARGET_TYPE" : "stumpless/target.h" "STUMPLESS_FOREACH_SEVERITY" : "stumpless/severity.h" From 5852fec62dbe3d639a293381210ece1f3eb07711 Mon Sep 17 00:00:00 2001 From: mk722 Date: Fri, 6 Jan 2023 23:23:16 +0100 Subject: [PATCH 03/11] edit prival.h, prival.c CMake and test --- CMakeLists.txt | 2 +- include/stumpless/prival.h | 5 +---- src/prival.c | 3 +-- src/windows/stumpless.def | 3 +-- test/function/prival.cpp | 16 ++++++++-------- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c6e2b4fa..94086577e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1220,7 +1220,7 @@ add_function_test(perror SOURCES test/function/startup/perror.cpp ) -add_function_test(facility +add_function_test(prival SOURCES test/function/prival.cpp ) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index d20717fe2..e70d82f7f 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -23,9 +23,6 @@ #ifndef __STUMPLESS_PRIVAL_H # define __STUMPLESS_PRIVAL_H -# include -# include - /** * Gets the string corresponding to the given int prival value. * @@ -53,4 +50,4 @@ stumpless_get_prival_string( int prival ); } /* extern "C" */ # endif -#endif /* __STUMPLESS_PRIVAL_H */ +#endif /* __STUMPLESS_PRIVAL_H */ \ No newline at end of file diff --git a/src/prival.c b/src/prival.c index 1e7401175..3de83a24e 100644 --- a/src/prival.c +++ b/src/prival.c @@ -34,5 +34,4 @@ stumpless_get_prival_string(int prival) { stumpless_get_facility_string((enum)*facility)); return prival_string; } -} - \ No newline at end of file +} \ No newline at end of file diff --git a/src/windows/stumpless.def b/src/windows/stumpless.def index 516ec6159..5d5bb821e 100644 --- a/src/windows/stumpless.def +++ b/src/windows/stumpless.def @@ -222,5 +222,4 @@ EXPORTS stumpless_unload_entry_only @206 stumpless_unload_param @207 vstumpless_load_entry @208 - stumpless_get_prival_string @209 - \ No newline at end of file + stumpless_get_prival_string @209 \ No newline at end of file diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 82acff265..2de073ce6 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -18,17 +18,17 @@ #include #include +#include namespace { - class PrivalTest : public::testing::Test { - }; + class PrivalTest : public::testing::Test { + }; - TEST( GetPrivalString, ValidPrival ) { - const char *result; + TEST(GetPrivalString, ValidPrival) { + const char *result; - #define CHECK_PRIVAL_TRUE( STRING, INT ) \ - result = stumpless_get_prival_string( STRING ); \ - EXPECT_STREQ( result, #STRING ); + result = stumpless_get_prival_string( STRING ); \ + EXPECT_STREQ( result, #STRING ); } -} +} \ No newline at end of file From 5d5dcf6074e2f4d4daaca55d2c8ba352ffd1305b Mon Sep 17 00:00:00 2001 From: mk722 Date: Sun, 8 Jan 2023 20:41:21 +0100 Subject: [PATCH 04/11] allocked memory, edited function and .h file --- include/stumpless/prival.h | 8 +++++++- src/prival.c | 25 ++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index e70d82f7f..ec4defaea 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -23,6 +23,12 @@ #ifndef __STUMPLESS_PRIVAL_H # define __STUMPLESS_PRIVAL_H +# include + +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# include +# endif + /** * Gets the string corresponding to the given int prival value. * @@ -43,7 +49,7 @@ * @return The string representation of the severity and facility from the given prival. */ STUMPLESS_PUBLIC_FUNCTION -const char * +const char * stumpless_get_prival_string( int prival ); # ifdef __cplusplus diff --git a/src/prival.c b/src/prival.c index 3de83a24e..fbff3ef54 100644 --- a/src/prival.c +++ b/src/prival.c @@ -20,18 +20,21 @@ #include #include #include +#include +#include "private/facility.h" +#include "private/severity.h" +#include "private/memory.h" -const char * -stumpless_get_prival_string(int prival) { - const char *prival_string; - int severity = get_severity(prival); - int facility = get_facility(prival); - if(severity_is_invalid(severity) == 0 || facility_is_invalid(facility) == 0) { - return "NO_SUCH_PRIVAL"; - } else { - asprintf(&prival_string,"%s | %s", stumpless_get_severity_string((enum)*severity), - stumpless_get_facility_string((enum)*facility)); - return prival_string; +const char * stumpless_get_prival_string(int prival) { + const char *prival_string; + int severit, facility; + + prival_string = alloc_mem(30); + severity = get_severity(prival); + facility = get_facility(prival); + + asprintf(&prival_string, "%s | %s", stumpless_get_severity_string(severity), stumpless_get_facility_string(facility)); + return prival_string; } } \ No newline at end of file From ef939d92530130b78c0712fb9b1972a4ac1d7c7a Mon Sep 17 00:00:00 2001 From: mk722 Date: Sun, 8 Jan 2023 21:08:22 +0100 Subject: [PATCH 05/11] allocked memory, edited function and .h file --- include/stumpless/prival.h | 2 +- src/prival.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index ec4defaea..8131d681a 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -56,4 +56,4 @@ stumpless_get_prival_string( int prival ); } /* extern "C" */ # endif -#endif /* __STUMPLESS_PRIVAL_H */ \ No newline at end of file +#endif /* __STUMPLESS_PRIVAL_H */ diff --git a/src/prival.c b/src/prival.c index fbff3ef54..2fd29e33a 100644 --- a/src/prival.c +++ b/src/prival.c @@ -28,13 +28,12 @@ const char * stumpless_get_prival_string(int prival) { const char *prival_string; - int severit, facility; + int severity, facility; prival_string = alloc_mem(30); severity = get_severity(prival); facility = get_facility(prival); - asprintf(&prival_string, "%s | %s", stumpless_get_severity_string(severity), stumpless_get_facility_string(facility)); + snprintf(&prival_string, 30, "%s | %s", stumpless_get_severity_string(severity), stumpless_get_facility_string(facility)); return prival_string; - } } \ No newline at end of file From 443c8b7726c70e4f43af279d4e2f397c96e3160a Mon Sep 17 00:00:00 2001 From: mk722 Date: Sun, 8 Jan 2023 22:03:28 +0100 Subject: [PATCH 06/11] allocked memory, edited function and .h file --- src/prival.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index 2fd29e33a..1bf4362e1 100644 --- a/src/prival.c +++ b/src/prival.c @@ -36,4 +36,4 @@ const char * stumpless_get_prival_string(int prival) { snprintf(&prival_string, 30, "%s | %s", stumpless_get_severity_string(severity), stumpless_get_facility_string(facility)); return prival_string; -} \ No newline at end of file +} From 9793f975fa0384b388bbba89f545df1b326f439b Mon Sep 17 00:00:00 2001 From: mk722 Date: Sun, 8 Jan 2023 23:34:18 +0100 Subject: [PATCH 07/11] allocked memory, edited function and .h file --- src/prival.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index 1bf4362e1..e5c5f45ea 100644 --- a/src/prival.c +++ b/src/prival.c @@ -34,6 +34,7 @@ const char * stumpless_get_prival_string(int prival) { severity = get_severity(prival); facility = get_facility(prival); - snprintf(&prival_string, 30, "%s | %s", stumpless_get_severity_string(severity), stumpless_get_facility_string(facility)); + snprintf(&prival_string, 30, "%s | %s", stumpless_get_severity_string(severity), + stumpless_get_facility_string(facility)); return prival_string; } From 29b0f4ed048676dad56a4b8327499d1f2c21e4c2 Mon Sep 17 00:00:00 2001 From: mk722 Date: Sun, 8 Jan 2023 23:40:04 +0100 Subject: [PATCH 08/11] param not null --- src/prival.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/prival.c b/src/prival.c index e5c5f45ea..1161b2843 100644 --- a/src/prival.c +++ b/src/prival.c @@ -24,9 +24,13 @@ #include "private/facility.h" #include "private/severity.h" #include "private/memory.h" +#include "private/validate.h" const char * stumpless_get_prival_string(int prival) { + + VALIDATE_ARG_NOT_NULL(prival); + const char *prival_string; int severity, facility; From c1eb9d88c15fe27f3855c4b389d01498ee008c71 Mon Sep 17 00:00:00 2001 From: mk722 Date: Mon, 9 Jan 2023 00:32:42 +0100 Subject: [PATCH 09/11] edit include and test --- src/prival.c | 4 ++-- test/function/prival.cpp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/prival.c b/src/prival.c index 1161b2843..9c90d4c0c 100644 --- a/src/prival.c +++ b/src/prival.c @@ -34,11 +34,11 @@ const char * stumpless_get_prival_string(int prival) { const char *prival_string; int severity, facility; - prival_string = alloc_mem(30); + prival_string = alloc_mem(8); severity = get_severity(prival); facility = get_facility(prival); - snprintf(&prival_string, 30, "%s | %s", stumpless_get_severity_string(severity), + snprintf(&prival_string, 8, "%s | %s", stumpless_get_severity_string(severity), stumpless_get_facility_string(facility)); return prival_string; } diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 2de073ce6..10e8a108a 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -18,7 +18,6 @@ #include #include -#include namespace { From f919616fae64aba3b79f0b270a61859ddf48e475 Mon Sep 17 00:00:00 2001 From: mk722 Date: Mon, 9 Jan 2023 03:40:27 +0100 Subject: [PATCH 10/11] edit test --- test/function/prival.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 10e8a108a..083e85208 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -27,7 +27,7 @@ namespace { TEST(GetPrivalString, ValidPrival) { const char *result; - result = stumpless_get_prival_string( STRING ); \ - EXPECT_STREQ( result, #STRING ); + result = stumpless_get_prival_string( 11 ); \ + EXPECT_STREQ( result, "3 | 8" ); } } \ No newline at end of file From 105f8b3b2d59de7d2990bacac2df5d2124962b81 Mon Sep 17 00:00:00 2001 From: mk722 Date: Mon, 9 Jan 2023 12:45:49 +0100 Subject: [PATCH 11/11] edit test --- include/stumpless.h | 1 + src/prival.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/stumpless.h b/include/stumpless.h index bb4c75378..21ad5d395 100644 --- a/include/stumpless.h +++ b/include/stumpless.h @@ -52,6 +52,7 @@ # include # include # include +# include # include # include # include diff --git a/src/prival.c b/src/prival.c index 9c90d4c0c..65dac74d3 100644 --- a/src/prival.c +++ b/src/prival.c @@ -32,7 +32,8 @@ const char * stumpless_get_prival_string(int prival) { VALIDATE_ARG_NOT_NULL(prival); const char *prival_string; - int severity, facility; + int severity; + int facility; prival_string = alloc_mem(8); severity = get_severity(prival);