style(export): gchar*/g_free consistency + auto_char in read loop
All checks were successful
CI Code / Check spelling (pull_request) Successful in 2m12s
CI Code / Check coding style (pull_request) Successful in 2m23s
CI Code / Linux (arch) (pull_request) Successful in 5m35s
CI Code / Linux (debian) (pull_request) Successful in 6m59s
CI Code / Linux (ubuntu) (pull_request) Successful in 7m41s
CI Code / Code Coverage (pull_request) Successful in 6m59s
All checks were successful
CI Code / Check spelling (pull_request) Successful in 2m12s
CI Code / Check coding style (pull_request) Successful in 2m23s
CI Code / Linux (arch) (pull_request) Successful in 5m35s
CI Code / Linux (debian) (pull_request) Successful in 6m59s
CI Code / Linux (ubuntu) (pull_request) Successful in 7m41s
CI Code / Code Coverage (pull_request) Successful in 6m59s
This commit is contained in:
@@ -50,7 +50,8 @@
|
|||||||
// Dedup key: stanza_id if present, else hash of timestamp+from+body
|
// 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)
|
_make_dedup_key(const char* stanza_id, const char* timestamp, const char* from_jid, const char* body)
|
||||||
{
|
{
|
||||||
if (stanza_id && stanza_id[0] != '\0')
|
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*)(from_jid ? from_jid : ""), -1);
|
||||||
g_checksum_update(sum, (const guchar*)"|", 1);
|
g_checksum_update(sum, (const guchar*)"|", 1);
|
||||||
g_checksum_update(sum, (const guchar*)(body ? body : ""), -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);
|
g_checksum_free(sum);
|
||||||
return key;
|
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)
|
// Helper: reverse ff_jid_to_dir (best-effort)
|
||||||
// '_at_' -> '@'
|
// '_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)
|
_dir_to_jid(const char* dirname)
|
||||||
{
|
{
|
||||||
if (!dirname)
|
if (!dirname)
|
||||||
return NULL;
|
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) {
|
while ((entry = g_dir_read_name(dir)) != NULL) {
|
||||||
auto_gchar gchar* full_path = g_strdup_printf("%s/%s/history.log", base_dir, entry);
|
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)) {
|
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) {
|
if (jid) {
|
||||||
contacts = g_slist_prepend(contacts, jid);
|
contacts = g_slist_prepend(contacts, jid);
|
||||||
}
|
}
|
||||||
@@ -168,20 +176,15 @@ _ff_read_all_lines(const char* contact_barejid)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
gboolean truncated = FALSE;
|
gboolean truncated = FALSE;
|
||||||
char* buf = ff_readline(fp, &truncated);
|
auto_char char* buf = ff_readline(fp, &truncated);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
break;
|
break;
|
||||||
if (truncated) {
|
if (truncated)
|
||||||
free(buf);
|
|
||||||
break;
|
break;
|
||||||
}
|
if (buf[0] == '\0' || buf[0] == '#')
|
||||||
if (buf[0] == '\0' || buf[0] == '#') {
|
|
||||||
free(buf);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
ff_parsed_line_t* pl = ff_parse_line(buf);
|
ff_parsed_line_t* pl = ff_parse_line(buf);
|
||||||
free(buf);
|
|
||||||
if (pl) {
|
if (pl) {
|
||||||
lines = g_slist_prepend(lines, pl);
|
lines = g_slist_prepend(lines, pl);
|
||||||
}
|
}
|
||||||
@@ -234,7 +237,7 @@ _export_one_contact(const char* contact)
|
|||||||
GSList* existing = _ff_read_all_lines(contact);
|
GSList* existing = _ff_read_all_lines(contact);
|
||||||
for (GSList* l = existing; l; l = l->next) {
|
for (GSList* l = existing; l; l = l->next) {
|
||||||
ff_parsed_line_t* pl = l->data;
|
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);
|
g_hash_table_add(seen_keys, key);
|
||||||
}
|
}
|
||||||
int existing_count = g_slist_length(existing);
|
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* body = msg->plain ? msg->plain : "";
|
||||||
const char* sid = msg->id ? msg->id : "";
|
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)) {
|
if (g_hash_table_contains(seen_keys, key)) {
|
||||||
g_free(key);
|
g_free(key);
|
||||||
contact_skipped++;
|
contact_skipped++;
|
||||||
@@ -509,7 +512,7 @@ log_database_import_from_flatfile(const gchar* const contact_jid)
|
|||||||
if (!msg)
|
if (!msg)
|
||||||
continue;
|
continue;
|
||||||
auto_gchar gchar* ts = msg->timestamp ? g_date_time_format_iso8601(msg->timestamp) : g_strdup("");
|
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_hash_table_add(seen_keys, key);
|
||||||
}
|
}
|
||||||
g_slist_free_full(existing_msgs, (GDestroyNotify)message_free);
|
g_slist_free_full(existing_msgs, (GDestroyNotify)message_free);
|
||||||
@@ -529,7 +532,7 @@ log_database_import_from_flatfile(const gchar* const contact_jid)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto_gchar gchar* ts = g_date_time_format_iso8601(pl->timestamp);
|
auto_gchar gchar* ts = g_date_time_format_iso8601(pl->timestamp);
|
||||||
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)) {
|
if (g_hash_table_contains(seen_keys, key)) {
|
||||||
g_free(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);
|
char* ts_str = g_strndup(buf, space - buf);
|
||||||
GDateTime* dt = g_date_time_new_from_iso8601(ts_str, NULL);
|
GDateTime* dt = g_date_time_new_from_iso8601(ts_str, NULL);
|
||||||
if (!dt) {
|
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);
|
state->filepath, (long)pos, ts_str);
|
||||||
g_free(ts_str);
|
g_free(ts_str);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -911,15 +911,23 @@ test_stress_mixed_types_and_encodings(void** state)
|
|||||||
continue;
|
continue;
|
||||||
parsed++;
|
parsed++;
|
||||||
|
|
||||||
if (g_strcmp0(pl->type, "chat") == 0) counts[0]++;
|
if (g_strcmp0(pl->type, "chat") == 0)
|
||||||
else if (g_strcmp0(pl->type, "muc") == 0) counts[1]++;
|
counts[0]++;
|
||||||
else if (g_strcmp0(pl->type, "mucpm") == 0) counts[2]++;
|
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]++;
|
if (g_strcmp0(pl->enc, "none") == 0)
|
||||||
else if (g_strcmp0(pl->enc, "omemo") == 0) enc_counts[1]++;
|
enc_counts[0]++;
|
||||||
else if (g_strcmp0(pl->enc, "otr") == 0) enc_counts[2]++;
|
else if (g_strcmp0(pl->enc, "omemo") == 0)
|
||||||
else if (g_strcmp0(pl->enc, "pgp") == 0) enc_counts[3]++;
|
enc_counts[1]++;
|
||||||
else if (g_strcmp0(pl->enc, "ox") == 0) enc_counts[4]++;
|
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);
|
ff_parsed_line_free(pl);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user