1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

WIP fix for #516, needs memory cleanup

This commit is contained in:
James Booth 2015-06-29 23:48:41 +01:00
parent fed55b5459
commit dd206ef637
13 changed files with 72 additions and 87 deletions

View File

@ -146,9 +146,9 @@ sv_ev_room_subject(const char * const room, const char * const nick, const char
void
sv_ev_room_history(const char * const room_jid, const char * const nick,
GTimeVal tv_stamp, const char * const message)
GDateTime *timestamp, const char * const message)
{
ui_room_history(room_jid, nick, tv_stamp, message);
ui_room_history(room_jid, nick, timestamp, message);
}
void
@ -293,13 +293,13 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
}
void
sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVal tv_stamp)
sv_ev_delayed_private_message(const char * const fulljid, char *message, GDateTime *timestamp)
{
ui_incoming_private_msg(fulljid, message, &tv_stamp);
ui_incoming_private_msg(fulljid, message, timestamp);
}
void
sv_ev_delayed_message(char *barejid, char *message, GTimeVal tv_stamp)
sv_ev_delayed_message(char *barejid, char *message, GDateTime *timestamp)
{
gboolean new_win = FALSE;
ProfChatWin *chatwin = wins_get_chat(barejid);
@ -309,8 +309,8 @@ sv_ev_delayed_message(char *barejid, char *message, GTimeVal tv_stamp)
new_win = TRUE;
}
ui_incoming_msg(chatwin, NULL, message, &tv_stamp, new_win);
chat_log_msg_in_delayed(barejid, message, &tv_stamp);
ui_incoming_msg(chatwin, NULL, message, timestamp, new_win);
chat_log_msg_in_delayed(barejid, message, timestamp);
}
void

View File

@ -47,13 +47,13 @@ void sv_ev_room_broadcast(const char *const room_jid,
const char * const message);
void sv_ev_room_subject(const char * const room, const char * const nick, const char * const subject);
void sv_ev_room_history(const char * const room_jid, const char * const nick,
GTimeVal tv_stamp, const char * const message);
GDateTime *timestamp, const char * const message);
void sv_ev_room_message(const char * const room_jid, const char * const nick,
const char * const message);
void sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_message);
void sv_ev_incoming_private_message(const char * const fulljid, char *message);
void sv_ev_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp);
void sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVal tv_stamp);
void sv_ev_delayed_message(char *fulljid, char *message, GDateTime *timestamp);
void sv_ev_delayed_private_message(const char * const fulljid, char *message, GDateTime *timestamp);
void sv_ev_typing(char *barejid, char *resource);
void sv_ev_paused(char *barejid, char *resource);
void sv_ev_inactive(char *barejid, char *resource);

View File

@ -91,7 +91,7 @@ static gchar * _get_main_log_file(void);
static void _rotate_log_file(void);
static char* _log_string_from_level(log_level_t level);
static void _chat_log_chat(const char * const login, const char * const other,
const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp);
const gchar * const msg, chat_log_direction_t direction, GDateTime *timestamp);
void
log_debug(const char * const msg, ...)
@ -353,19 +353,19 @@ chat_log_msg_in(const char * const barejid, const char * const msg)
}
void
chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp)
chat_log_msg_in_delayed(const char * const barejid, const char * msg, GDateTime *timestamp)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid);
_chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, tv_stamp);
_chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, timestamp);
jid_destroy(jidp);
}
}
static void
_chat_log_chat(const char * const login, const char * const other,
const char * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp)
const char * const msg, chat_log_direction_t direction, GDateTime *timestamp)
{
struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other);
@ -380,16 +380,9 @@ _chat_log_chat(const char * const login, const char * const other,
g_hash_table_replace(logs, strdup(other), dated_log);
}
gchar *date_fmt = NULL;
GDateTime *dt = NULL;
if (tv_stamp == NULL) {
dt = g_date_time_new_now_local();
} else {
dt = g_date_time_new_from_timeval_utc(tv_stamp);
}
date_fmt = g_date_time_format(dt, "%H:%M:%S");
if (timestamp == NULL) timestamp = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(timestamp, "%H:%M:%S");
FILE *logp = fopen(dated_log->filename, "a");
g_chmod(dated_log->filename, S_IRUSR | S_IWUSR);
if (logp) {
@ -414,7 +407,6 @@ _chat_log_chat(const char * const login, const char * const other,
}
g_free(date_fmt);
g_date_time_unref(dt);
}
void

View File

@ -74,7 +74,7 @@ void chat_log_otr_msg_out(const char * const barejid, const char * const msg);
void chat_log_pgp_msg_out(const char * const barejid, const char * const msg);
void chat_log_msg_in(const char * const barejid, const char * const msg);
void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp);
void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GDateTime *timestamp);
void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted);
void chat_log_pgp_msg_in(const char * const barejid, const char * const msg);

View File

@ -416,7 +416,7 @@ ui_message_receipt(const char * const barejid, const char * const id)
}
void
ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GTimeVal *tv_stamp, gboolean win_created)
ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created)
{
ProfWin *window = (ProfWin*)chatwin;
int num = wins_get_num(window);
@ -425,7 +425,7 @@ ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char *
// currently viewing chat window with sender
if (wins_is_current(window)) {
win_print_incoming_message(window, tv_stamp, display_name, message);
win_print_incoming_message(window, timestamp, display_name, message);
title_bar_set_typing(FALSE);
status_bar_active(num);
@ -444,14 +444,14 @@ ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char *
}
// show users status first, when receiving message via delayed delivery
if (tv_stamp && win_created) {
if (timestamp && win_created) {
PContact pcontact = roster_get_contact(chatwin->barejid);
if (pcontact) {
win_show_contact(window, pcontact);
}
}
win_print_incoming_message(window, tv_stamp, display_name, message);
win_print_incoming_message(window, timestamp, display_name, message);
}
if (prefs_get_boolean(PREF_BEEP)) {
@ -466,7 +466,7 @@ ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char *
}
void
ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp)
ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp)
{
char *display_from = NULL;
display_from = get_nick_from_full_jid(fulljid);
@ -482,7 +482,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
// currently viewing chat window with sender
if (wins_is_current(window)) {
win_print_incoming_message(window, tv_stamp, display_from, message);
win_print_incoming_message(window, timestamp, display_from, message);
title_bar_set_typing(FALSE);
status_bar_active(num);
@ -491,7 +491,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
privatewin->unread++;
status_bar_new(num);
cons_show_incoming_message(display_from, num);
win_print_incoming_message(window, tv_stamp, display_from, message);
win_print_incoming_message(window, timestamp, display_from, message);
if (prefs_get_boolean(PREF_FLASH)) {
flash();
@ -1665,7 +1665,7 @@ ui_room_nick_change(const char * const roomjid, const char * const nick)
void
ui_room_history(const char * const roomjid, const char * const nick,
GTimeVal tv_stamp, const char * const message)
GDateTime *timestamp, const char * const message)
{
ProfWin *window = (ProfWin*)wins_get_muc(roomjid);
if (window == NULL) {
@ -1684,7 +1684,7 @@ ui_room_history(const char * const roomjid, const char * const nick,
g_string_append(line, message);
}
win_print(window, '-', &tv_stamp, NO_COLOUR_DATE, 0, "", line->str);
win_print(window, '-', timestamp, NO_COLOUR_DATE, 0, "", line->str);
g_string_free(line, TRUE);
}
}
@ -2808,11 +2808,9 @@ _win_show_history(ProfChatWin *chatwin, const char * const contact)
char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh);
char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm);
char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss);
GDateTime *time = g_date_time_new_local(2000, 1, 1, ihh, imm, iss);
GTimeVal tv;
g_date_time_to_timeval(time, &tv);
win_print((ProfWin*)chatwin, '-', &tv, NO_COLOUR_DATE, 0, "", curr->data+11);
g_date_time_unref(time);
GDateTime *timestamp = g_date_time_new_local(2000, 1, 1, ihh, imm, iss);
win_print((ProfWin*)chatwin, '-', timestamp, NO_COLOUR_DATE, 0, "", curr->data+11);
g_date_time_unref(timestamp);
// header
} else {
win_print((ProfWin*)chatwin, '-', NULL, 0, 0, "", curr->data);

View File

@ -101,8 +101,8 @@ void ui_handle_stanza(const char * const msg);
// ui events
void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity);
void ui_contact_typing(const char * const barejid, const char * const resource);
void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GTimeVal *tv_stamp, gboolean win_created);
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp);
void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created);
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp);
void ui_message_receipt(const char * const barejid, const char * const id);
void ui_disconnected(void);
@ -129,7 +129,7 @@ void ui_room_occupant_role_and_affiliation_change(const char * const roomjid, co
const char * const affiliation, const char * const actor, const char * const reason);
void ui_room_roster(const char * const roomjid, GList *occupants, const char * const presence);
void ui_room_history(const char * const roomjid, const char * const nick,
GTimeVal tv_stamp, const char * const message);
GDateTime *timestamp, const char * const message);
void ui_room_message(const char * const roomjid, const char * const nick,
const char * const message);
void ui_room_subject(const char * const roomjid, const char * const nick, const char * const subject);
@ -350,8 +350,8 @@ void win_hide_subwin(ProfWin *window);
void win_show_subwin(ProfWin *window);
void win_refresh_without_subwin(ProfWin *window);
void win_refresh_with_subwin(ProfWin *window);
void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message);
void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...);
void win_print(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message);
void win_vprint(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...);
char* win_get_title(ProfWin *window);
void win_show_occupant(ProfWin *window, Occupant *occupant);
void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant);

View File

@ -922,14 +922,14 @@ win_show_status_string(ProfWin *window, const char * const from,
}
void
win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
win_print_incoming_message(ProfWin *window, GDateTime *timestamp,
const char * const from, const char * const message)
{
switch (window->type)
{
case WIN_CHAT:
case WIN_PRIVATE:
win_print(window, '-', tv_stamp, NO_ME, THEME_TEXT_THEM, from, message);
win_print(window, '-', timestamp, NO_ME, THEME_TEXT_THEM, from, message);
break;
default:
assert(FALSE);
@ -938,31 +938,25 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
}
void
win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp,
win_vprint(ProfWin *window, const char show_char, GDateTime *timestamp,
int flags, theme_item_t theme_item, const char * const from, const char * const message, ...)
{
va_list arg;
va_start(arg, message);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, message, arg);
win_print(window, show_char, tstamp, flags, theme_item, from, fmt_msg->str);
win_print(window, show_char, timestamp, flags, theme_item, from, fmt_msg->str);
g_string_free(fmt_msg, TRUE);
}
void
win_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
win_print(ProfWin *window, const char show_char, GDateTime *timestamp,
int flags, theme_item_t theme_item, const char * const from, const char * const message)
{
GDateTime *time;
if (timestamp == NULL) timestamp = g_date_time_new_now_local();
if (tstamp == NULL) {
time = g_date_time_new_now_local();
} else {
time = g_date_time_new_from_timeval_utc(tstamp);
}
buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, NULL);
_win_print(window, show_char, time, flags, theme_item, from, message, NULL);
buffer_push(window->layout->buffer, show_char, timestamp, flags, theme_item, from, message, NULL);
_win_print(window, show_char, timestamp, flags, theme_item, from, message, NULL);
// TODO: cross-reference.. this should be replaced by a real event-based system
ui_input_nonblocking(TRUE);
}

View File

@ -59,7 +59,7 @@ void win_show_status_string(ProfWin *window, const char * const from,
const char * const show, const char * const status,
GDateTime *last_activity, const char * const pre,
const char * const default_show);
void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
void win_print_incoming_message(ProfWin *window, GDateTime *timestamp,
const char * const from, const char * const message);
void win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags,
theme_item_t theme_item, const char * const from, const char * const message, char *id);

View File

@ -559,10 +559,9 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
}
// determine if the notifications happened whilst offline
GTimeVal tv_stamp;
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
if (delayed) {
sv_ev_room_history(jid->barejid, jid->resourcepart, tv_stamp, message);
GDateTime *timestamp = stanza_get_delay(stanza);
if (timestamp) {
sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message);
} else {
sv_ev_room_message(jid->barejid, jid->resourcepart, message);
}
@ -663,10 +662,9 @@ _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid)
return;
}
GTimeVal tv_stamp;
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
if (delayed) {
sv_ev_delayed_private_message(fulljid, message, tv_stamp);
GDateTime *timestamp = stanza_get_delay(stanza);
if (timestamp) {
sv_ev_delayed_private_message(fulljid, message, timestamp);
} else {
sv_ev_incoming_private_message(fulljid, message);
}
@ -761,15 +759,13 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
}
// standard chat message, use jid without resource
GTimeVal tv_stamp;
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
GDateTime *timestamp = stanza_get_delay(stanza);
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
if (body) {
char *message = xmpp_stanza_get_text(body);
if (message) {
if (delayed) {
sv_ev_delayed_message(jid->barejid, message, tv_stamp);
if (timestamp) {
sv_ev_delayed_message(jid->barejid, message, timestamp);
} else {
char *enc_message = NULL;
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED);
@ -787,7 +783,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
}
// handle chat sessions and states
if (!delayed && jid->resourcepart) {
if (!timestamp && jid->resourcepart) {
gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL;

View File

@ -982,17 +982,20 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx, const char * const target)
return iq;
}
gboolean
stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp)
GDateTime*
stanza_get_delay(xmpp_stanza_t * const stanza)
{
GTimeVal utc_stamp;
// first check for XEP-0203 delayed delivery
xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
if (delay) {
char *xmlns = xmpp_stanza_get_attribute(delay, STANZA_ATTR_XMLNS);
if (xmlns && (strcmp(xmlns, "urn:xmpp:delay") == 0)) {
char *stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP);
if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) {
return TRUE;
if (stamp && (g_time_val_from_iso8601(stamp, &utc_stamp))) {
GDateTime *utc_datetime = g_date_time_new_from_timeval_utc(&utc_stamp);
GDateTime *local_datetime = g_date_time_to_local(utc_datetime);
return local_datetime;
}
}
}
@ -1004,13 +1007,15 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp)
char *xmlns = xmpp_stanza_get_attribute(x, STANZA_ATTR_XMLNS);
if (xmlns && (strcmp(xmlns, "jabber:x:delay") == 0)) {
char *stamp = xmpp_stanza_get_attribute(x, STANZA_ATTR_STAMP);
if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) {
return TRUE;
if (stamp && (g_time_val_from_iso8601(stamp, &utc_stamp))) {
GDateTime *utc_datetime = g_date_time_new_from_timeval_utc(&utc_stamp);
GDateTime *local_datetime = g_date_time_to_local(utc_datetime);
return local_datetime;
}
}
}
return FALSE;
return NULL;
}
char *

View File

@ -223,7 +223,7 @@ xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const
gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
gboolean stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp);
GDateTime* stanza_get_delay(xmpp_stanza_t * const stanza);
gboolean stanza_is_muc_presence(xmpp_stanza_t * const stanza);
gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,

View File

@ -60,7 +60,7 @@ void chat_log_otr_msg_out(const char * const barejid, const char * const msg) {}
void chat_log_pgp_msg_out(const char * const barejid, const char * const msg) {}
void chat_log_msg_in(const char * const barejid, const char * const msg) {}
void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp) {}
void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GDateTime *timestamp) {}
void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted) {}
void chat_log_pgp_msg_in(const char * const barejid, const char * const msg) {}

View File

@ -179,10 +179,10 @@ void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activi
}
void ui_contact_typing(const char * const barejid, const char * const resource) {}
void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GTimeVal *tv_stamp, gboolean win_created) {}
void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GDateTime *timestamp, gboolean win_created) {}
void ui_message_receipt(const char * const barejid, const char * const id) {}
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp) {}
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GDateTime *timestamp) {}
void ui_disconnected(void) {}
void ui_recipient_gone(const char * const barejid, const char * const resource) {}
@ -208,7 +208,7 @@ void ui_room_occupant_role_and_affiliation_change(const char * const roomjid, co
const char * const affiliation, const char * const actor, const char * const reason) {}
void ui_room_roster(const char * const roomjid, GList *occupants, const char * const presence) {}
void ui_room_history(const char * const roomjid, const char * const nick,
GTimeVal tv_stamp, const char * const message) {}
GDateTime *timestamp, const char * const message) {}
void ui_room_message(const char * const roomjid, const char * const nick,
const char * const message) {}
void ui_room_subject(const char * const roomjid, const char * const nick, const char * const subject) {}
@ -531,8 +531,8 @@ void win_hide_subwin(ProfWin *window) {}
void win_show_subwin(ProfWin *window) {}
void win_refresh_without_subwin(ProfWin *window) {}
void win_refresh_with_subwin(ProfWin *window) {}
void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message) {}
void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) {}
void win_print(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message) {}
void win_vprint(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) {}
char* win_get_title(ProfWin *window)
{
return NULL;