mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-22 23:36:22 +00:00
fix(mam, log): improve datetime handling and memory management in MAM and log fetching
- Introduce static helper `_truncate_datetime_suffix()` to safely trim datetime strings, removing unwanted suffixes like timezone offsets - Replace manual string management with auto_gchar and g_strdup for safer, clearer ownership and to prevent leaks - Add safety checks and logging warnings for unexpected datetime string lengths or null pointers - Refactor _mam_rsm_id_handler to use the helper function and updated string handling - Change log_database_get_previous_chat parameters for consistent ownership semantics, avoiding double frees and mem leaks - Overall improve stability and prevent memory leaks during log database queries
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "glib.h"
|
||||
#include "xmpp/chat_session.h"
|
||||
#include "window_list.h"
|
||||
#include "xmpp/roster_list.h"
|
||||
@@ -585,10 +586,12 @@ _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
|
||||
// first entry's timestamp in the buffer is used. Flip true to prepend to buffer.
|
||||
// Timestamps should be in iso8601
|
||||
db_history_result_t
|
||||
chatwin_db_history(ProfChatWin* chatwin, const char* start_time, char* end_time, gboolean flip)
|
||||
chatwin_db_history(ProfChatWin* chatwin, const gchar* start_time, const gchar* end_time, gboolean flip)
|
||||
{
|
||||
if (!end_time) {
|
||||
end_time = buffer_size(((ProfWin*)chatwin)->layout->buffer) == 0 ? NULL : g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time);
|
||||
auto_gchar gchar* _end_time = NULL;
|
||||
if (!end_time && buffer_size(((ProfWin*)chatwin)->layout->buffer) > 0) {
|
||||
_end_time = g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time);
|
||||
end_time = _end_time;
|
||||
}
|
||||
|
||||
GSList* history = NULL;
|
||||
|
||||
@@ -146,7 +146,7 @@ void chatwin_set_incoming_char(ProfChatWin* chatwin, const char* const ch);
|
||||
void chatwin_unset_incoming_char(ProfChatWin* chatwin);
|
||||
void chatwin_set_outgoing_char(ProfChatWin* chatwin, const char* const ch);
|
||||
void chatwin_unset_outgoing_char(ProfChatWin* chatwin);
|
||||
db_history_result_t chatwin_db_history(ProfChatWin* chatwin, const char* start_time, char* end_time, gboolean flip);
|
||||
db_history_result_t chatwin_db_history(ProfChatWin* chatwin, const gchar* start_time, const gchar* end_time, gboolean flip);
|
||||
|
||||
// MUC window
|
||||
ProfMucWin* mucwin_new(const char* const barejid);
|
||||
|
||||
@@ -711,19 +711,17 @@ win_page_down(ProfWin* window, int scroll_size)
|
||||
if ((*page_start > total_rows - page_space || (*page_start == page_space && *page_start >= total_rows)) && window->type == WIN_CHAT) {
|
||||
int bf_size = buffer_size(window->layout->buffer);
|
||||
if (bf_size > 0) {
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
ProfBuffEntry* last_entry = buffer_get_entry(window->layout->buffer, bf_size - 1);
|
||||
auto_gchar gchar* start = g_date_time_format_iso8601(last_entry->time);
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
gchar* end_date = g_date_time_format_iso8601(now);
|
||||
g_date_time_unref(now);
|
||||
auto_gchar gchar* end_date = g_date_time_format_iso8601(now);
|
||||
if (*scroll_state != WIN_SCROLL_REACHED_BOTTOM && !chatwin_db_history((ProfChatWin*)window, start, end_date, FALSE)) {
|
||||
*scroll_state = WIN_SCROLL_REACHED_BOTTOM;
|
||||
} else if (*scroll_state == WIN_SCROLL_REACHED_BOTTOM) {
|
||||
g_free(end_date);
|
||||
}
|
||||
|
||||
int offset = last_entry->y_end_pos - 1;
|
||||
*page_start = offset - page_space + scroll_size;
|
||||
g_date_time_unref(now);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user