pidgin/pidgin

741992355ead
GSoC History API including sqlite history adapter

The History API has been created to drive all message handling in purple3. It will be used to update existing messages for edits, reactions, pinning, read/deliver receipts, etc. The API uses an adapter pattern, to abstract out backends, but provides a SQLite3 backend by default.

It also provides search capabilities using a custom query language that can easily be expanded over time. It will be use by both the end user to search messages and the frontends to implement features like a pinned messages button. A command line utility is also provided for searching outside of the program itself.

## Remaining Items

**These all will most likely be done by the Pidgin core team after GSoC when we figure out exactly how to solve them.**

Need to store database in purple config directory
* Gary has spent some time looking at this and it looks like the purple-history cli will need to become a purple-ui to make this work write as in the future other adapters will be plugins.

Other things to consider:
- For simplicity, the SqliteHistoryAdapter is parsing the query itself, but for consistency having `PurpleHistoryAdapter` parse the query and pass tokens to the subclass might be something we want to do.

Testing Done:
## Unit Tests
History Manager
History Adapter

## Integration Tests
purplehistorycore created for integration tests.
PurpleSqliteHistoryAdapter functionality tested:
- Creates proper db schema
- Writes logs
- Reads logs
- Queries using query language
- Deletes using query language

Bugs closed: PIDGIN-17526, PIDGIN-17532, PIDGIN-17533, PIDGIN-17534

Reviewed at https://reviews.imfreedom.org/r/877/
/* pidgin
*
* Pidgin is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
* source distribution.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#ifndef PURPLE_GLIBCOMPAT_H
#define PURPLE_GLIBCOMPAT_H
/*
* SECTION:glibcompat
* @section_id: libpurple-glibcompat
* @short_description: <filename>glibcompat.h</filename>
* @title: GLib version-dependent definitions
*
* This file is internal to libpurple. Do not use!
* Also, any public API should not depend on this file.
*/
#include <glib.h>
/* glib's definition of g_stat+GStatBuf seems to be broken on mingw64-w32 (and
* possibly other 32-bit windows), so instead of relying on it,
* we'll define our own.
*/
#if defined(_WIN32) && !defined(_MSC_VER) && !defined(_WIN64)
# include <glib/gstdio.h>
typedef struct _stat GStatBufW32;
static inline int
purple_g_stat(const gchar *filename, GStatBufW32 *buf)
{
return g_stat(filename, (GStatBuf*)buf);
}
# define GStatBuf GStatBufW32
# define g_stat purple_g_stat
#endif
#if !GLIB_CHECK_VERSION(2, 58, 0)
#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f))
static inline GTimeZone *
g_time_zone_new_offset(gint32 seconds) {
GTimeZone *tz = NULL;
gchar *identifier = NULL;
/* Seemingly, we should be using @seconds directly to set the
* #TransitionInfo.gmt_offset to avoid all this string building and
* parsing. However, we always need to set the #GTimeZone.name to a
* constructed string anyway, so we might as well reuse its code.
*/
identifier = g_strdup_printf("%c%02u:%02u:%02u",
(seconds >= 0) ? '+' : '-',
(ABS (seconds) / 60) / 60,
(ABS (seconds) / 60) % 60,
ABS (seconds) % 60);
tz = g_time_zone_new(identifier);
g_free(identifier);
g_assert(g_time_zone_get_offset(tz, 0) == seconds);
return tz;
}
#endif /* !GLIB_CHECK_VERSION(2, 58, 0) */
#if !GLIB_CHECK_VERSION(2, 62, 0)
static inline gchar *
g_date_time_format_iso8601(GDateTime *datetime) {
GString *outstr = NULL;
gchar *main_date = NULL;
gint64 offset;
/* Main date and time. */
main_date = g_date_time_format(datetime, "%Y-%m-%dT%H:%M:%S");
outstr = g_string_new(main_date);
g_free(main_date);
/* Timezone. Format it as `%:::z` unless the offset is zero, in which case
* we can simply use `Z`. */
offset = g_date_time_get_utc_offset(datetime);
if (offset == 0) {
g_string_append_c(outstr, 'Z');
} else {
gchar *time_zone = g_date_time_format(datetime, "%:::z");
g_string_append(outstr, time_zone);
g_free(time_zone);
}
return g_string_free(outstr, FALSE);
}
#endif /* GLIB_CHECK_VERSION(2, 62, 0) */
/* Backport the static inline version of g_memdup2 if we don't have g_memdup2.
* see https://mail.gnome.org/archives/desktop-devel-list/2021-February/msg00000.html
* for more information.
*/
#if !GLIB_CHECK_VERSION(2, 67, 3)
static inline gpointer
g_memdup2(gconstpointer mem, gsize byte_size) {
gpointer new_mem = NULL;
if(mem && byte_size != 0) {
new_mem = g_malloc (byte_size);
memcpy (new_mem, mem, byte_size);
}
return new_mem;
}
#endif /* !GLIB_CHECK_VERSION(2, 67, 3) */
#endif /* PURPLE_GLIBCOMPAT_H */