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 to string function #413

Merged
merged 39 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d7cf2ce
Implement stumpless_get_prival_string
uFarad Apr 4, 2024
cb53656
Updated CMakeLists to include prival
uFarad Apr 4, 2024
2574d14
Fixed header issues
uFarad Apr 4, 2024
d18372a
Fixing compile issues
uFarad Apr 4, 2024
9a7446a
Fix more compiling issues
uFarad Apr 4, 2024
c8b8bb1
More compile errors
uFarad Apr 4, 2024
515023a
Revert "More compile errors"
uFarad Apr 4, 2024
0dd26c7
More compile errors
uFarad Apr 4, 2024
7651ca5
Corrected comment typo
uFarad Apr 4, 2024
037dbcf
Removed hanging }
uFarad Apr 5, 2024
6961429
Fixed over-allocation
uFarad Apr 6, 2024
025a34c
Merge branch 'latest' into prival
uFarad Apr 10, 2024
5de7dca
Fixed ordering so that test function is built
uFarad Apr 15, 2024
e205e01
Corrected source dir
uFarad Apr 15, 2024
3e7bf70
Fixed function name in header
uFarad Apr 15, 2024
767d263
Adding cstdlib
uFarad Apr 15, 2024
f2c8e5f
Trying to include headers in extern C
uFarad Apr 15, 2024
cafd1a3
Revert "Trying to include headers in extern C"
uFarad Apr 15, 2024
2fd1dd6
Revert "Adding cstdlib"
uFarad Apr 15, 2024
3d763ce
Revert "Corrected source dir"
uFarad Apr 15, 2024
9b6513a
Revert "Fixed ordering so that test function is built"
uFarad Apr 15, 2024
f26f711
Fixed cmakelists order
uFarad Apr 15, 2024
4128458
Trying extern C for prival.h
uFarad Apr 15, 2024
4f6962e
Trying another way
uFarad Apr 15, 2024
d903d8a
Fiixing header to use extern C
uFarad Apr 15, 2024
8b2fb8a
Testing resultant string length
uFarad Apr 15, 2024
6f9d868
Fixed test to comply with RFC
uFarad Apr 15, 2024
ded8f47
Readded divider newline
uFarad Apr 17, 2024
41472a9
Remove unused header
uFarad Apr 17, 2024
37458a2
Renamed header guard to meet project requirements
uFarad Apr 17, 2024
e055424
Corrected comments that returned string should be freed
uFarad Apr 17, 2024
97d531c
Used specific language for memory free notice
uFarad Apr 17, 2024
c57d53d
Added since tag
uFarad Apr 17, 2024
72b0d6a
Corrected safety information
uFarad Apr 17, 2024
3381591
Remove unused include
uFarad Apr 17, 2024
24226ce
Removed unused headers
uFarad Apr 18, 2024
5e117cd
Removed more unused includes
uFarad Apr 18, 2024
e904ae3
Revert "Removed more unused includes"
uFarad Apr 18, 2024
c50a81e
Re-added string.h
uFarad Apr 18, 2024
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 @@ -233,6 +233,7 @@ set(STUMPLESS_SOURCES
${PROJECT_SOURCE_DIR}/src/version.c
${PROJECT_SOURCE_DIR}/src/validate.c
${PROJECT_SOURCE_DIR}/src/priority.c
${PROJECT_SOURCE_DIR}/src/prival.c
)


Expand Down Expand Up @@ -698,6 +699,7 @@ install(FILES
${PROJECT_SOURCE_DIR}/include/stumpless/target.h
${PROJECT_SOURCE_DIR}/include/stumpless/version.h
${PROJECT_SOURCE_DIR}/include/stumpless/priority.h
${PROJECT_SOURCE_DIR}/include/stumpless/prival.h
DESTINATION "include/stumpless"
)

Expand Down Expand Up @@ -1016,6 +1018,10 @@ add_function_test(priority
SOURCES ${PROJECT_SOURCE_DIR}/test/function/priority.cpp
)

add_function_test(prival
SOURCES ${PROJECT_SOURCE_DIR}/test/function/prival.cpp
)

add_custom_target(build-test
DEPENDS ${STUMPLESS_FUNCTION_TESTS}
)
Expand Down
1 change: 1 addition & 0 deletions include/stumpless.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#include <stumpless/target/stream.h>
#include <stumpless/version.h>
#include <stumpless/priority.h>
#include <stumpless/prival.h>

#ifdef STUMPLESS_CHAIN_TARGETS_SUPPORTED
/** @example chain_example.c
Expand Down
62 changes: 62 additions & 0 deletions include/stumpless/prival.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* SPDX-License-Identifier: Apache-2.0 */

/*
* Copyright 2018-2023 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
* Function for converting prival from int to string
*/

#ifndef __STUMPLESS_PRIVAL_H
# define __STUMPLESS_PRIVAL_H

# include <stumpless/config.h>

#ifdef __cplusplus
extern "C" {
#endif
/**
* Gets the string representation of the given prival.
*
* The string returned must be freed by the caller when it is no longer
* needed to avoid memory leaks.
*
* **Thread Safety: MT-Safe**
* This function is thread safe.
*
* **Async Signal Safety: AS-Unsafe heap**
* This function is not safe to call from signal handlers due to the use of
* memory management functions.
*
* **Async Cancel Safety: AC-Unsafe heap**
* This function is not safe to call from threads that may be asynchronously
* cancelled due to the use of memory management functions.
*
* @since release v2.2.0
*
goatshriek marked this conversation as resolved.
Show resolved Hide resolved
* @param prival int to get the string from.
*
* @return The string representation of the given prival.
*/
STUMPLESS_PUBLIC_FUNCTION
const char *
stumpless_get_prival_string( int prival );

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

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

const char* stumpless_get_prival_string( int prival ) {
const char *severity = stumpless_get_severity_string( get_severity( prival ) );
const char *facility = stumpless_get_facility_string( get_facility( prival ) );

size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 4); //+3 for formatting, +1 for termination
char *prival_string = alloc_mem( prival_string_length );

snprintf(prival_string, prival_string_length, "%s | %s", severity, facility);

return prival_string;
}
2 changes: 2 additions & 0 deletions src/windows/stumpless.def
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,5 @@ EXPORTS
stumpless_get_chain_length @227
stumpless_new_chain @228
stumpless_set_entry_message_str_w @229

stumpless_get_prival_string @230
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, "STUMPLESS_SEVERITY_ERR | STUMPLESS_FACILITY_USER" );
}
}
1 change: 1 addition & 0 deletions tools/check_headers/stumpless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,4 @@
"STUMPLESS_FOREACH_TARGET_TYPE" : "stumpless/target.h"
"STUMPLESS_FOREACH_SEVERITY" : "stumpless/severity.h"
"stumpless_prival_from_string" : "stumpless/priority.h"
"stumpless_get_prival_string" : "stumpless/prival.h"
Loading