Skip to content

Commit 5f96f5a

Browse files
committed
start removing target name parameters
1 parent 28dbf54 commit 5f96f5a

File tree

8 files changed

+53
-81
lines changed

8 files changed

+53
-81
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fixes, check out the
2323
thread safety tests (default is ON).
2424
- `BUILD_BENCHMARKING` CMake option controls the building of the performance
2525
tests (default is OFF).
26+
- Targets may have a mapping function to modify entries before they are logged.
2627

2728
### Changed
2829
- Refactor:
@@ -34,6 +35,12 @@ fixes, check out the
3435
build options for shared libraries and testing.
3536
- C++ is no longer required to build the project if testing and benchmarking
3637
are disabled.
38+
- Filter functions have a third parameter of a void pointer, to allow custom
39+
data to be used during decision making.
40+
- Targets no longer have a name associated with them directly. Instead, a
41+
name can be optionally assigned, and later used for retrieval. This removes
42+
the `name` parameter from the following functions:
43+
* `stumpless_open_buffer_target_`
3744

3845
### Fixed
3946
- Strings that are a case-insensitive prefix of a valid severity string are

include/stumpless/target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* SPDX-License-Identifier: Apache-2.0 */
22

33
/*
4-
* Copyright 2018-2024 Joel E. Anderson
4+
* Copyright 2018-2025 Joel E. Anderson
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.

include/stumpless/target/buffer.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* SPDX-License-Identifier: Apache-2.0 */
22

33
/*
4-
* Copyright 2018-2022 Joel E. Anderson
4+
* Copyright 2018-2025 Joel E. Anderson
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -91,9 +91,11 @@ stumpless_close_buffer_target( const struct stumpless_target *target );
9191
* Messages are overwritten as new messages come in. If the user of the buffer
9292
* target is not reading these, they will be lost.
9393
*
94-
* **Thread Safety: MT-Safe race:name**
95-
* This function is thread safe, of course assuming that name is not modified by
96-
* any other threads during execution.
94+
* In versions prior to 3.0.0, this function also had a name parameter that
95+
* was used for the target.
96+
*
97+
* **Thread Safety: MT-Safe**
98+
* This function is thread safe.
9799
*
98100
* **Async Signal Safety: AS-Unsafe heap**
99101
* This function is not safe to call from signal handlers due to the use of
@@ -103,9 +105,6 @@ stumpless_close_buffer_target( const struct stumpless_target *target );
103105
* This function is not safe to call from threads that may be asynchronously
104106
* cancelled, as the memory allocation function may not be AC-Safe itself.
105107
*
106-
* @param name The name of the target to open. This is only used for
107-
* identification of the target.
108-
*
109108
* @param buffer The buffer to write messages to.
110109
*
111110
* @param size The number of characters the provided buffer can hold.
@@ -115,8 +114,7 @@ stumpless_close_buffer_target( const struct stumpless_target *target );
115114
*/
116115
STUMPLESS_PUBLIC_FUNCTION
117116
struct stumpless_target *
118-
stumpless_open_buffer_target( const char *name,
119-
char *buffer,
117+
stumpless_open_buffer_target( char *buffer,
120118
size_t size );
121119

122120
/**

src/target.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,13 @@ new_target( enum stumpless_target_type type, const char *name ) {
11531153
goto fail;
11541154
}
11551155

1156-
target->name = copy_cstring_with_length( name, &target->name_length );
1157-
if( !target->name ) {
1158-
goto fail_name;
1156+
if( name ){
1157+
target->name = copy_cstring_with_length( name, &target->name_length );
1158+
if( !target->name ) {
1159+
goto fail_name;
1160+
}
1161+
} else {
1162+
target->name = NULL;
11591163
}
11601164

11611165
config_assign_cached_mutex( target->mutex );
@@ -1165,7 +1169,7 @@ new_target( enum stumpless_target_type type, const char *name ) {
11651169

11661170
target->id = NULL;
11671171
target->type = type;
1168-
target->options = stumpless_get_default_options( );
1172+
target->options = stumpless_get_default_options();
11691173
target->default_prival = get_prival( STUMPLESS_DEFAULT_FACILITY,
11701174
STUMPLESS_DEFAULT_SEVERITY );
11711175
target->default_app_name[0] = '-';
@@ -1182,6 +1186,7 @@ new_target( enum stumpless_target_type type, const char *name ) {
11821186

11831187
fail_mutex:
11841188
free_mem( target->name );
1189+
target->name = NULL;
11851190
fail_name:
11861191
free_mem( target );
11871192
fail:

src/target/buffer.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ stumpless_close_buffer_target( const struct stumpless_target *target ) {
4848
}
4949

5050
struct stumpless_target *
51-
stumpless_open_buffer_target( const char *name,
52-
char *buffer,
51+
stumpless_open_buffer_target( char *buffer,
5352
size_t size ) {
5453
struct stumpless_target *target;
5554

56-
VALIDATE_ARG_NOT_NULL( name );
5755
VALIDATE_ARG_NOT_NULL( buffer );
5856

59-
target = new_target( STUMPLESS_BUFFER_TARGET, name );
57+
target = new_target( STUMPLESS_BUFFER_TARGET, NULL );
6058

6159
if( !target ) {
6260
goto fail;

test/function/leak/buffer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
/*
4-
* Copyright 2018-2024 Joel E. Anderson
4+
* Copyright 2018-2025 Joel E. Anderson
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -38,12 +38,11 @@ namespace {
3838

3939
INIT_MEMORY_COUNTER( buffer_leak );
4040

41-
target = stumpless_open_buffer_target( "buffer-leak-testing",
42-
buffer,
41+
target = stumpless_open_buffer_target( buffer,
4342
TEST_BUFFER_LENGTH );
4443
ASSERT_NOT_NULL( target );
4544

46-
entry = create_entry( );
45+
entry = create_entry();
4746
ASSERT_NOT_NULL( entry );
4847

4948
for( i = 0; i < 1000; i++ ) {
@@ -54,7 +53,7 @@ namespace {
5453
stumpless_destroy_entry_and_contents( entry );
5554
stumpless_close_buffer_target( target );
5655

57-
stumpless_free_all( );
56+
stumpless_free_all();
5857

5958
ASSERT_NO_LEAK( buffer_leak );
6059
}

test/function/target/buffer.cpp

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
/*
4-
* Copyright 2018-2024 Joel E. Anderson
4+
* Copyright 2018-2025 Joel E. Anderson
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -49,24 +49,13 @@ namespace {
4949
struct stumpless_param *param;
5050

5151
buffer[0] = '\0';
52-
target = stumpless_open_buffer_target( "buffer target testing",
53-
buffer,
52+
target = stumpless_open_buffer_target( buffer,
5453
TEST_BUFFER_LENGTH );
5554

5655
stumpless_set_target_default_app_name( target, "buffer-target-test" );
5756
stumpless_set_target_default_msgid( target, "default-message" );
5857

59-
basic_entry = stumpless_new_entry( STUMPLESS_FACILITY_USER,
60-
STUMPLESS_SEVERITY_INFO,
61-
"stumpless-unit-test",
62-
"basic-entry",
63-
"basic test message" );
64-
65-
element = stumpless_new_element( "basic-element" );
66-
stumpless_add_element( basic_entry, element );
67-
68-
param = stumpless_new_param( "basic-param-name", "basic-param-value" );
69-
stumpless_add_param( element, param );
58+
basic_entry = create_entry();
7059
}
7160

7261
virtual void
@@ -94,9 +83,11 @@ namespace {
9483

9584
EXPECT_THAT( read_buffer,
9685
HasSubstr( std::to_string( basic_entry->prival ) ) );
97-
EXPECT_THAT( read_buffer, HasSubstr( "basic-element" ) );
98-
EXPECT_THAT( read_buffer, HasSubstr( "basic-param-name" ) );
99-
EXPECT_THAT( read_buffer, HasSubstr( "basic-param-value" ) );
86+
EXPECT_THAT( read_buffer, HasSubstr( "fixture-element" ) );
87+
EXPECT_THAT( read_buffer, HasSubstr( "fixture-param-1" ) );
88+
EXPECT_THAT( read_buffer, HasSubstr( "fixture-value-1" ) );
89+
EXPECT_THAT( read_buffer, HasSubstr( "fixture-param-2" ) );
90+
EXPECT_THAT( read_buffer, HasSubstr( "fixture-value-2" ) );
10091

10192
TestRFC5424Compliance(buffer);
10293
}
@@ -243,12 +234,10 @@ namespace {
243234
/* non-fixture tests */
244235

245236
TEST( BufferTargetCloseTest, Generic ) {
246-
const char *target_name = "normal target";
247237
struct stumpless_target *target;
248238
char buffer[100];
249239

250-
target = stumpless_open_buffer_target( target_name,
251-
buffer,
240+
target = stumpless_open_buffer_target( buffer,
252241
sizeof( buffer ) );
253242
EXPECT_NO_ERROR;
254243
EXPECT_NOT_NULL( target );
@@ -259,8 +248,6 @@ namespace {
259248

260249
EXPECT_EQ( stumpless_get_current_target( ),
261250
stumpless_get_default_target( ) );
262-
EXPECT_STRNE( stumpless_get_current_target( )->name,
263-
target_name );
264251

265252
stumpless_free_all( );
266253
}
@@ -285,12 +272,11 @@ namespace {
285272
struct stumpless_target *target;
286273
char buffer[100];
287274

288-
target = stumpless_open_buffer_target( "normal target",
289-
buffer,
275+
target = stumpless_open_buffer_target( buffer,
290276
sizeof( buffer ) );
291277
ASSERT_NOT_NULL( target );
292278

293-
EXPECT_EQ( target, stumpless_get_current_target( ) );
279+
EXPECT_EQ( target, stumpless_get_current_target() );
294280

295281
stumpless_close_buffer_target( target );
296282
}
@@ -303,8 +289,7 @@ namespace {
303289
set_malloc_result = stumpless_set_malloc( MALLOC_FAIL );
304290
ASSERT_NOT_NULL( set_malloc_result );
305291

306-
target = stumpless_open_buffer_target( "malloc-fail-buffer",
307-
buffer,
292+
target = stumpless_open_buffer_target( buffer,
308293
sizeof( buffer ) );
309294
EXPECT_NULL( target );
310295
EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE );
@@ -316,20 +301,8 @@ namespace {
316301
TEST( BufferTargetOpenTest, NullBuffer ) {
317302
const struct stumpless_target *target;
318303

319-
target = stumpless_open_buffer_target( "null-buffer",
320-
NULL,
321-
100 );
322-
ASSERT_NULL( target );
323-
EXPECT_ERROR_ID_EQ( STUMPLESS_ARGUMENT_EMPTY );
324-
}
325-
326-
TEST( BufferTargetOpenTest, NullName ) {
327-
struct stumpless_target *target;
328-
char buffer[100];
329-
330304
target = stumpless_open_buffer_target( NULL,
331-
buffer,
332-
sizeof( buffer ) );
305+
100 );
333306
ASSERT_NULL( target );
334307
EXPECT_ERROR_ID_EQ( STUMPLESS_ARGUMENT_EMPTY );
335308
}
@@ -340,8 +313,7 @@ namespace {
340313
size_t i;
341314

342315
for( i=0; i < 100; i++ ) {
343-
targets[i] = stumpless_open_buffer_target( "many target test",
344-
buffer,
316+
targets[i] = stumpless_open_buffer_target( buffer,
345317
sizeof( buffer ) );
346318
EXPECT_NO_ERROR;
347319
ASSERT_NOT_NULL( targets[i] );
@@ -369,13 +341,12 @@ namespace {
369341
char read_buffer[READ_BUFFER_LENGTH];
370342
size_t read_result;
371343

372-
target = stumpless_open_buffer_target( "wrap-around-test",
373-
buffer,
344+
target = stumpless_open_buffer_target( buffer,
374345
sizeof( buffer ) );
375346
EXPECT_NO_ERROR;
376347
ASSERT_NOT_NULL( target );
377348

378-
entry = create_entry( );
349+
entry = create_entry();
379350
EXPECT_NO_ERROR;
380351
EXPECT_NOT_NULL( entry );
381352

@@ -385,8 +356,7 @@ namespace {
385356

386357
stumpless_close_buffer_target( target );
387358

388-
target = stumpless_open_buffer_target( "wrap-around-test",
389-
buffer,
359+
target = stumpless_open_buffer_target( buffer,
390360
write_result + 2 );
391361
EXPECT_NO_ERROR;
392362
EXPECT_NOT_NULL( target );

test/function/target/chain.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
/*
4-
* Copyright 2024 Joel E. Anderson
4+
* Copyright 2024-2025 Joel E. Anderson
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -41,8 +41,7 @@ namespace {
4141
SetUp( void ) override {
4242
size_t i;
4343
chain = stumpless_new_chain( "test-fixture" );
44-
target_1 = stumpless_open_buffer_target( "chain-element-1",
45-
buffer,
44+
target_1 = stumpless_open_buffer_target( buffer,
4645
sizeof( buffer ) );
4746
stumpless_add_target_to_chain( chain, target_1 );
4847

@@ -75,8 +74,7 @@ namespace {
7574
starting_length = stumpless_get_chain_length( chain );
7675
EXPECT_NO_ERROR;
7776

78-
target = stumpless_open_buffer_target( "chain-add-new",
79-
target_buffer,
77+
target = stumpless_open_buffer_target( target_buffer,
8078
sizeof( target_buffer ) );
8179
ASSERT_NOT_NULL( target );
8280

@@ -118,8 +116,7 @@ namespace {
118116
starting_length = stumpless_get_chain_length( full_chain );
119117
EXPECT_NO_ERROR;
120118

121-
target = stumpless_open_buffer_target( "chain-add-new",
122-
target_buffer,
119+
target = stumpless_open_buffer_target( target_buffer,
123120
sizeof( target_buffer ) );
124121
ASSERT_NOT_NULL( target );
125122

@@ -157,8 +154,7 @@ namespace {
157154
starting_length = stumpless_get_chain_length( full_chain );
158155
EXPECT_NO_ERROR;
159156

160-
target = stumpless_open_buffer_target( "chain-add-new",
161-
target_buffer,
157+
target = stumpless_open_buffer_target( target_buffer,
162158
sizeof( target_buffer ) );
163159
ASSERT_NOT_NULL( target );
164160

@@ -312,8 +308,7 @@ namespace {
312308
ASSERT_NOT_NULL( chain );
313309

314310
for( i = 0; i < STUMPLESS_CHAIN_TARGET_ARRAY_LENGTH + 1; i++ ){
315-
sub_target = stumpless_open_buffer_target( "sub-target",
316-
buffer,
311+
sub_target = stumpless_open_buffer_target( buffer,
317312
sizeof( buffer ) );
318313
EXPECT_NO_ERROR;
319314

0 commit comments

Comments
 (0)