Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added prival function #323

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1218,6 +1220,10 @@ add_function_test(perror
SOURCES test/function/startup/perror.cpp
)

add_function_test(prival
SOURCES test/function/prival.cpp
)

add_function_test(severity
SOURCES test/function/severity.cpp
)
Expand Down
1 change: 1 addition & 0 deletions include/stumpless.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
# include <stumpless/memory.h>
# include <stumpless/option.h>
# include <stumpless/param.h>
# include <stumpless/prival.h>
# include <stumpless/severity.h>
# include <stumpless/target.h>
# include <stumpless/target/buffer.h>
Expand Down
59 changes: 59 additions & 0 deletions include/stumpless/prival.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* 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
goatshriek marked this conversation as resolved.
Show resolved Hide resolved
* Prival codes for function to create severity and facility string from prival int value.
*/

#ifndef __STUMPLESS_PRIVAL_H
# define __STUMPLESS_PRIVAL_H

# include <stumpless/config.h>
goatshriek marked this conversation as resolved.
Show resolved Hide resolved

# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
# include <syslog.h>
# endif

/**
* 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.2.0.
*
* @param prival The prival name to get the string from.
*
* @return The string representation of the severity and facility from the given prival.
*/
STUMPLESS_PUBLIC_FUNCTION
const char *
stumpless_get_prival_string( int prival );

# ifdef __cplusplus
} /* extern "C" */
# endif

#endif /* __STUMPLESS_PRIVAL_H */
45 changes: 45 additions & 0 deletions src/prival.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 <stdio.h>
#include <stumpless/prival.h>
#include <stumpless/severity.h>
#include <stumpless/facility.h>
#include <stumpless/memory.h>
#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;
int facility;

prival_string = alloc_mem(8);
severity = get_severity(prival);
facility = get_facility(prival);

snprintf(&prival_string, 8, "%s | %s", stumpless_get_severity_string(severity),
stumpless_get_facility_string(facility));
return prival_string;
}
1 change: 1 addition & 0 deletions src/windows/stumpless.def
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@ EXPORTS
stumpless_unload_entry_only @206
stumpless_unload_param @207
vstumpless_load_entry @208
stumpless_get_prival_string @209
33 changes: 33 additions & 0 deletions test/function/prival.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 <gtest/gtest.h>
#include <stumpless.h>

namespace {

class PrivalTest : public::testing::Test {
};

TEST(GetPrivalString, ValidPrival) {
const char *result;

result = stumpless_get_prival_string( 11 ); \
EXPECT_STREQ( result, "3 | 8" );
}
}
1 change: 1 addition & 0 deletions tools/check_headers/stumpless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"