no-DB mode implementation #94
@@ -55,7 +55,7 @@
|
||||
|
||||
static sqlite3* g_chatlog_database;
|
||||
|
||||
static void _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid);
|
||||
static void _add_to_db(ProfMessage* message, const char* type, const Jid* const from_jid, const Jid* const to_jid);
|
||||
static char* _get_db_filename(ProfAccount* account);
|
||||
static prof_msg_type_t _get_message_type_type(const char* const type);
|
||||
static prof_enc_t _get_message_enc_type(const char* const encstr);
|
||||
@@ -147,7 +147,7 @@ _sqlite_init(ProfAccount* account)
|
||||
return TRUE;
|
||||
|
jabber.developer marked this conversation as resolved
|
||||
}
|
||||
|
||||
char* query = "CREATE TABLE IF NOT EXISTS `ChatLogs` ("
|
||||
const char* query = "CREATE TABLE IF NOT EXISTS `ChatLogs` ("
|
||||
|
jabber.developer marked this conversation as resolved
Outdated
jabber.developer
commented
Here and in other places, can we return necessary documentation detailing DB fields, decisions, and other useful points? Here and in other places, can we return necessary documentation detailing DB fields, decisions, and other useful points?
jabber.developer2
commented
Corrected Corrected
|
||||
"`id` INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
"`from_jid` TEXT NOT NULL, "
|
||||
"`to_jid` TEXT NOT NULL, "
|
||||
@@ -251,7 +251,7 @@ _sqlite_add_incoming(ProfMessage* message)
|
||||
}
|
||||
|
||||
static void
|
||||
_log_database_add_outgoing(char* type, const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc)
|
||||
_log_database_add_outgoing(const char* type, const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc)
|
||||
{
|
||||
ProfMessage* msg = message_init();
|
||||
|
||||
@@ -350,8 +350,8 @@ _sqlite_get_previous_chat(const gchar* const contact_barejid, const gchar* start
|
||||
return DB_RESPONSE_ERROR;
|
||||
}
|
||||
|
||||
gchar* sort1 = from_start ? "ASC" : "DESC";
|
||||
gchar* sort2 = !flip ? "ASC" : "DESC";
|
||||
const gchar* sort1 = from_start ? "ASC" : "DESC";
|
||||
const gchar* sort2 = !flip ? "ASC" : "DESC";
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
auto_gchar gchar* end_date_fmt = end_time ? g_strdup(end_time) : g_date_time_format_iso8601(now);
|
||||
auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM ("
|
||||
@@ -571,7 +571,7 @@ _get_message_enc_type(const char* const encstr)
|
||||
// --- Core write logic ---
|
||||
|
||||
static void
|
||||
_add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid)
|
||||
_add_to_db(ProfMessage* message, const char* type, const Jid* const from_jid, const Jid* const to_jid)
|
||||
{
|
||||
auto_gchar gchar* pref_dblog = prefs_get_string(PREF_DBLOG);
|
||||
sqlite_int64 original_message_id = -1;
|
||||
|
||||
@@ -268,7 +268,8 @@ main(int argc, char* argv[])
|
||||
};
|
||||
|
||||
/* Test group registry for easy extension */
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
const char* name;
|
||||
const struct CMUnitTest* tests;
|
||||
size_t count;
|
||||
|
||||
@@ -377,11 +377,6 @@ init_prof_test(void **state)
|
||||
"[notifications]\n"
|
||||
"message=false\n"
|
||||
"room=false\n");
|
||||
const char *flatfile_env = getenv("PROF_FLATFILE");
|
||||
if (flatfile_env && strcmp(flatfile_env, "1") == 0) {
|
||||
fprintf(prc, "[logging]\ndblog=flatfile\n");
|
||||
printf("[PROF_TEST] Wrote profrc with dblog=flatfile: %s\n", profrc_path);
|
||||
}
|
||||
fclose(prc);
|
||||
}
|
||||
|
||||
@@ -441,17 +436,33 @@ prof_stop(void)
|
||||
{
|
||||
if (fd > 0 && child_pid > 0) {
|
||||
prof_input("/quit");
|
||||
sleep(1);
|
||||
waitpid(child_pid, NULL, 0);
|
||||
sleep_ms(QUIT_GRACE_MS);
|
||||
close(fd);
|
||||
fd = 0;
|
||||
int exited = 0;
|
||||
for (int i = 0; i < SHUTDOWN_POLL_MAX; i++) {
|
||||
if (waitpid(child_pid, NULL, WNOHANG) != 0) {
|
||||
exited = 1;
|
||||
break;
|
||||
}
|
||||
sleep_ms(SHUTDOWN_POLL_MS);
|
||||
}
|
||||
if (!exited) {
|
||||
kill(child_pid, SIGTERM);
|
||||
for (int i = 0; i < SIGTERM_POLL_MAX; i++) {
|
||||
if (waitpid(child_pid, NULL, WNOHANG) != 0) { exited = 1; break; }
|
||||
sleep_ms(SHUTDOWN_POLL_MS);
|
||||
}
|
||||
if (!exited) {
|
||||
kill(child_pid, SIGKILL);
|
||||
waitpid(child_pid, NULL, 0);
|
||||
}
|
||||
}
|
||||
child_pid = 0;
|
||||
}
|
||||
/* Reset output buffer for clean restart */
|
||||
output_len = 0;
|
||||
output_buffer[0] = '\0';
|
||||
/* Brief delay to let stabber release old connection state */
|
||||
usleep(200000); /* 200ms */
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -316,7 +316,8 @@ message_db_history_long_message(void **state)
|
||||
"<message id='long1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>%s</body>"
|
||||
"</message>", body);
|
||||
"</message>",
|
||||
body);
|
||||
stbbr_send(xml);
|
||||
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
Reference in New Issue
Block a user
We might want to also check integrity of the tables (whether they exist + maybe even their columns). But it would introduce further complexity and should be a subject of a separate issue.
Postponed