no-DB mode implementation #94
@@ -50,7 +50,8 @@
|
||||
// Dedup key: stanza_id if present, else hash of timestamp+from+body
|
||||
// =========================================================================
|
||||
|
||||
static char*
|
||||
// Returns a g_strdup'd key — callers free with g_free (gchar* convention).
|
||||
static gchar*
|
||||
_make_dedup_key(const char* stanza_id, const char* timestamp, const char* from_jid, const char* body)
|
||||
{
|
||||
if (stanza_id && stanza_id[0] != '\0')
|
||||
@@ -67,7 +68,7 @@ _make_dedup_key(const char* stanza_id, const char* timestamp, const char* from_j
|
||||
g_checksum_update(sum, (const guchar*)(from_jid ? from_jid : ""), -1);
|
||||
g_checksum_update(sum, (const guchar*)"|", 1);
|
||||
g_checksum_update(sum, (const guchar*)(body ? body : ""), -1);
|
||||
char* key = g_strdup(g_checksum_get_string(sum));
|
||||
gchar* key = g_strdup(g_checksum_get_string(sum));
|
||||
g_checksum_free(sum);
|
||||
return key;
|
||||
}
|
||||
@@ -75,14 +76,21 @@ _make_dedup_key(const char* stanza_id, const char* timestamp, const char* from_j
|
||||
// =========================================================================
|
||||
// Helper: reverse ff_jid_to_dir (best-effort)
|
||||
// '_at_' -> '@'
|
||||
// Returns a g_strdup'd jid — callers free with g_free (gchar* convention).
|
||||
// str_replace allocates via libc malloc, so we hand over to g_-allocated.
|
||||
// =========================================================================
|
||||
|
||||
static char*
|
||||
static gchar*
|
||||
_dir_to_jid(const char* dirname)
|
||||
{
|
||||
if (!dirname)
|
||||
return NULL;
|
||||
return str_replace(dirname, "_at_", "@");
|
||||
char* raw = str_replace(dirname, "_at_", "@");
|
||||
if (!raw)
|
||||
return NULL;
|
||||
gchar* gres = g_strdup(raw);
|
||||
free(raw);
|
||||
return gres;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
@@ -118,7 +126,7 @@ _ff_list_contacts(void)
|
||||
while ((entry = g_dir_read_name(dir)) != NULL) {
|
||||
auto_gchar gchar* full_path = g_strdup_printf("%s/%s/history.log", base_dir, entry);
|
||||
if (g_file_test(full_path, G_FILE_TEST_IS_REGULAR)) {
|
||||
char* jid = _dir_to_jid(entry);
|
||||
gchar* jid = _dir_to_jid(entry);
|
||||
if (jid) {
|
||||
contacts = g_slist_prepend(contacts, jid);
|
||||
}
|
||||
@@ -168,20 +176,15 @@ _ff_read_all_lines(const char* contact_barejid)
|
||||
|
||||
while (1) {
|
||||
gboolean truncated = FALSE;
|
||||
char* buf = ff_readline(fp, &truncated);
|
||||
auto_char char* buf = ff_readline(fp, &truncated);
|
||||
if (!buf)
|
||||
break;
|
||||
if (truncated) {
|
||||
free(buf);
|
||||
if (truncated)
|
||||
break;
|
||||
}
|
||||
if (buf[0] == '\0' || buf[0] == '#') {
|
||||
free(buf);
|
||||
if (buf[0] == '\0' || buf[0] == '#')
|
||||
continue;
|
||||
}
|
||||
|
||||
ff_parsed_line_t* pl = ff_parse_line(buf);
|
||||
free(buf);
|
||||
if (pl) {
|
||||
lines = g_slist_prepend(lines, pl);
|
||||
}
|
||||
@@ -234,7 +237,7 @@ _export_one_contact(const char* contact)
|
||||
GSList* existing = _ff_read_all_lines(contact);
|
||||
for (GSList* l = existing; l; l = l->next) {
|
||||
ff_parsed_line_t* pl = l->data;
|
||||
char* key = _make_dedup_key(pl->stanza_id, pl->timestamp_str, pl->from_jid, pl->message);
|
||||
gchar* key = _make_dedup_key(pl->stanza_id, pl->timestamp_str, pl->from_jid, pl->message);
|
||||
g_hash_table_add(seen_keys, key);
|
||||
}
|
||||
int existing_count = g_slist_length(existing);
|
||||
@@ -330,7 +333,7 @@ _export_one_contact(const char* contact)
|
||||
const char* body = msg->plain ? msg->plain : "";
|
||||
const char* sid = msg->id ? msg->id : "";
|
||||
|
||||
char* key = _make_dedup_key(sid, ts, from_jid, body);
|
||||
gchar* key = _make_dedup_key(sid, ts, from_jid, body);
|
||||
if (g_hash_table_contains(seen_keys, key)) {
|
||||
|
jabber.developer marked this conversation as resolved
Outdated
|
||||
g_free(key);
|
||||
contact_skipped++;
|
||||
@@ -509,7 +512,7 @@ log_database_import_from_flatfile(const gchar* const contact_jid)
|
||||
if (!msg)
|
||||
continue;
|
||||
auto_gchar gchar* ts = msg->timestamp ? g_date_time_format_iso8601(msg->timestamp) : g_strdup("");
|
||||
char* key = _make_dedup_key(msg->id, ts, msg->from_jid ? msg->from_jid->barejid : "", msg->plain);
|
||||
gchar* key = _make_dedup_key(msg->id, ts, msg->from_jid ? msg->from_jid->barejid : "", msg->plain);
|
||||
g_hash_table_add(seen_keys, key);
|
||||
}
|
||||
g_slist_free_full(existing_msgs, (GDestroyNotify)message_free);
|
||||
@@ -529,7 +532,7 @@ log_database_import_from_flatfile(const gchar* const contact_jid)
|
||||
continue;
|
||||
|
||||
auto_gchar gchar* ts = g_date_time_format_iso8601(pl->timestamp);
|
||||
|
jabber.developer marked this conversation as resolved
Outdated
jabber.developer
commented
magic number magic number
jabber.developer2
commented
Corrected Corrected
|
||||
char* key = _make_dedup_key(pl->stanza_id, ts, pl->from_jid, pl->message);
|
||||
gchar* key = _make_dedup_key(pl->stanza_id, ts, pl->from_jid, pl->message);
|
||||
|
||||
if (g_hash_table_contains(seen_keys, key)) {
|
||||
g_free(key);
|
||||
|
||||
@@ -145,7 +145,7 @@ _ff_maybe_index_line(ff_contact_state_t* state, const char* buf, off_t pos)
|
||||
char* ts_str = g_strndup(buf, space - buf);
|
||||
GDateTime* dt = g_date_time_new_from_iso8601(ts_str, NULL);
|
||||
if (!dt) {
|
||||
log_warning("flatfile: unparseable timestamp in %s at offset %ld: %s",
|
||||
log_warning("flatfile: unparsable timestamp in %s at offset %ld: %s",
|
||||
state->filepath, (long)pos, ts_str);
|
||||
g_free(ts_str);
|
||||
return;
|
||||
|
||||
@@ -911,15 +911,23 @@ test_stress_mixed_types_and_encodings(void** state)
|
||||
continue;
|
||||
parsed++;
|
||||
|
||||
if (g_strcmp0(pl->type, "chat") == 0) counts[0]++;
|
||||
else if (g_strcmp0(pl->type, "muc") == 0) counts[1]++;
|
||||
else if (g_strcmp0(pl->type, "mucpm") == 0) counts[2]++;
|
||||
if (g_strcmp0(pl->type, "chat") == 0)
|
||||
counts[0]++;
|
||||
else if (g_strcmp0(pl->type, "muc") == 0)
|
||||
counts[1]++;
|
||||
else if (g_strcmp0(pl->type, "mucpm") == 0)
|
||||
counts[2]++;
|
||||
|
||||
if (g_strcmp0(pl->enc, "none") == 0) enc_counts[0]++;
|
||||
else if (g_strcmp0(pl->enc, "omemo") == 0) enc_counts[1]++;
|
||||
else if (g_strcmp0(pl->enc, "otr") == 0) enc_counts[2]++;
|
||||
else if (g_strcmp0(pl->enc, "pgp") == 0) enc_counts[3]++;
|
||||
else if (g_strcmp0(pl->enc, "ox") == 0) enc_counts[4]++;
|
||||
if (g_strcmp0(pl->enc, "none") == 0)
|
||||
enc_counts[0]++;
|
||||
else if (g_strcmp0(pl->enc, "omemo") == 0)
|
||||
enc_counts[1]++;
|
||||
else if (g_strcmp0(pl->enc, "otr") == 0)
|
||||
enc_counts[2]++;
|
||||
else if (g_strcmp0(pl->enc, "pgp") == 0)
|
||||
enc_counts[3]++;
|
||||
else if (g_strcmp0(pl->enc, "ox") == 0)
|
||||
enc_counts[4]++;
|
||||
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user
why
g_freeifkeyischar? Normally, we do this:g_freeforgcharfreeforcharCorrected