diff --git a/include/stumpless/entry.h b/include/stumpless/entry.h index 1ec0302a8..f2c89a76c 100644 --- a/include/stumpless/entry.h +++ b/include/stumpless/entry.h @@ -592,6 +592,10 @@ stumpless_get_entry_hostname( const struct stumpless_entry *entry ); * Note that if this message was originally set using format specifiers, the * result will have them substituted, instead of the original placeholders. * + * It is also important to note that the message may be NULL if the entry + * does not have one. This differs from other fields like the app id or msgid, + * which will be an RFC 5424 NILVALUE '-' if they have not been set. + * * In versions prior to v2.0.0, the returned pointer was to the internal buffer * used to store the name and was not to be modified by the caller. This * behavior changed in v2.0.0 in order to avoid thread safety issues. @@ -614,9 +618,8 @@ stumpless_get_entry_hostname( const struct stumpless_entry *entry ); * * @param entry The entry to get the message of. * - * @return The message of the entry if no error is encountered. If an error - * was encountered, then NULL is returned and an error code is set - * appropriately. + * @return The message of the entry (which may be NULL). If an error was + * encountered, then NULL is returned and an error code is set appropriately. */ STUMPLESS_PUBLIC_FUNCTION const char * diff --git a/src/entry.c b/src/entry.c index 0988fe246..b2d5b76ee 100644 --- a/src/entry.c +++ b/src/entry.c @@ -412,13 +412,8 @@ stumpless_get_entry_message( const struct stumpless_entry *entry ) { VALIDATE_ARG_NOT_NULL( entry ); lock_entry( entry ); - if( entry->message_length == 0 ) { - message_copy = alloc_mem( 2 ); - if( !message_copy ) { - goto cleanup_and_return; - } - message_copy[0] = '-'; - message_copy[1] = '\0'; + if( !entry->message ) { + message_copy = NULL; } else { message_copy = alloc_mem( entry->message_length + 1 ); if( !message_copy ) { diff --git a/src/target/sqlite3.c b/src/target/sqlite3.c index 69a7a4b7b..3392bc079 100644 --- a/src/target/sqlite3.c +++ b/src/target/sqlite3.c @@ -382,10 +382,10 @@ stumpless_sqlite3_prepare( const struct stumpless_entry *entry, } if( message_index != 0 ) { - if( entry->message_length == 1 && entry->message[0] == '-' ) { - sql_result = sqlite3_bind_null( insert_stmt, message_index ); - } else { + if( entry->message ) { sql_result = sqlite3_bind_text( insert_stmt, message_index, entry->message, entry->message_length, SQLITE_STATIC ); + } else { + sql_result = sqlite3_bind_null( insert_stmt, message_index ); } if( sql_result != SQLITE_OK ) { raise_sqlite3_error( "could not bind the message to the statement", sql_result ); // TODO l10n diff --git a/test/function/entry.cpp b/test/function/entry.cpp index f202101bc..9d8ddbd66 100644 --- a/test/function/entry.cpp +++ b/test/function/entry.cpp @@ -554,11 +554,8 @@ namespace { const char *message; message = stumpless_get_entry_message( nil_entry ); - EXPECT_NOT_NULL( message ); + EXPECT_NULL( message ); EXPECT_NO_ERROR; - - EXPECT_STREQ( message, "-" ); - free( ( void * ) message ); } TEST_F( EntryTest, GetParamByIndex ) { diff --git a/test/function/target/sqlite3.cpp b/test/function/target/sqlite3.cpp index d70f39113..fdd816530 100644 --- a/test/function/target/sqlite3.cpp +++ b/test/function/target/sqlite3.cpp @@ -104,18 +104,17 @@ TestEntryInDatabase( sqlite3 *db, std::string const &table_name, const struct st "FROM " << table_name; expected_message = stumpless_get_entry_message( entry ); - EXPECT_NOT_NULL( expected_message ); - if( strcmp( expected_message, "-" ) == 0 ) { - query_stream << " WHERE message IS NULL"; - } else { + if( expected_message ) { query_stream << " WHERE message = ?"; + } else { + query_stream << " WHERE message IS NULL"; } std::string result_query = query_stream.str(); sql_result = sqlite3_prepare_v2( db, result_query.c_str(), -1, &result_stmt, NULL ); EXPECT_EQ( sql_result, SQLITE_OK ); - if( strcmp( expected_message, "-" ) != 0 ) { + if( expected_message ) { sql_result = sqlite3_bind_text( result_stmt, 1, expected_message,