about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/cmd_defs.c2
-rw-r--r--src/ui/buffer.c5
-rw-r--r--src/ui/buffer.h4
-rw-r--r--src/ui/window.c61
4 files changed, 41 insertions, 31 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 936427b1..9c9340de 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2386,7 +2386,7 @@ static struct cmd_t command_defs[] =
             "/correction <on>|<off>",
             "/correction char <char>")
         CMD_DESC(
-            "Settings regarding Last Message Correction (XEP-0308). Caution: We do not yet check the 'from' field. So it could happen that someone else is overwriting the actual message. "
+            "Settings regarding Last Message Correction (XEP-0308)."
             "Corrections will only work in MUC and regular chat windows. MUC PMs won't be allowed.")
         CMD_ARGS(
             { "on|off", "Enable/Disable support for last message correction."},
diff --git a/src/ui/buffer.c b/src/ui/buffer.c
index c1d5e070..54178632 100644
--- a/src/ui/buffer.c
+++ b/src/ui/buffer.c
@@ -81,8 +81,7 @@ buffer_free(ProfBuff buffer)
 }
 
 void
-buffer_append(ProfBuff buffer, const char *show_char, int pad_indent, GDateTime *time,
-    int flags, theme_item_t theme_item, const char *const display_from, const char *const message, DeliveryReceipt *receipt, const char *const id)
+buffer_append(ProfBuff buffer, const char *show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char *const display_from, const char *const from_jid, const char *const message, DeliveryReceipt *receipt, const char *const id)
 {
     ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
     e->show_char = strdup(show_char);
@@ -91,6 +90,7 @@ buffer_append(ProfBuff buffer, const char *show_char, int pad_indent, GDateTime
     e->theme_item = theme_item;
     e->time = g_date_time_ref(time);
     e->display_from = display_from ? strdup(display_from) : NULL;
+    e->from_jid = from_jid ? strdup(from_jid) : NULL;
     e->message = strdup(message);
     e->receipt = receipt;
     if (id) {
@@ -168,6 +168,7 @@ _free_entry(ProfBuffEntry *entry)
     free(entry->show_char);
     free(entry->message);
     free(entry->display_from);
+    free(entry->from_jid);
     free(entry->id);
     free(entry->receipt);
     g_date_time_unref(entry->time);
diff --git a/src/ui/buffer.h b/src/ui/buffer.h
index 1ed7d4ae..997e2a49 100644
--- a/src/ui/buffer.h
+++ b/src/ui/buffer.h
@@ -56,6 +56,7 @@ typedef struct prof_buff_entry_t {
     // from as it is displayed
     // might be nick, jid..
     char *display_from;
+    char *from_jid;
     char *message;
     DeliveryReceipt *receipt;
     // message id, in case we have it
@@ -66,8 +67,7 @@ typedef struct prof_buff_t *ProfBuff;
 
 ProfBuff buffer_create();
 void buffer_free(ProfBuff buffer);
-void buffer_append(ProfBuff buffer, const char *show_char, int pad_indent, GDateTime *time,
-    int flags, theme_item_t theme_item, const char *const display_from, const char *const message, DeliveryReceipt *receipt, const char *const id);
+void buffer_append(ProfBuff buffer, const char *show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char *const display_from, const char *const barejid, const char *const message, DeliveryReceipt *receipt, const char *const id);
 void buffer_remove_entry_by_id(ProfBuff buffer, const char *const id);
 int buffer_size(ProfBuff buffer);
 ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
diff --git a/src/ui/window.c b/src/ui/window.c
index 552cd5ce..1a7cfc21 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -64,7 +64,8 @@
 
 #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
 
-static void _win_printf(ProfWin *window, const char *show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char *const from, const char *const message_id, const char *const message, ...);
+static void
+_win_printf(ProfWin *window, const char *show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char *const display_from, const char *const from_jid, const char *const message_id, const char *const message, ...);
 static void _win_print_internal(ProfWin *window, const char *show_char, int pad_indent, GDateTime *time,
     int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt);
 static void _win_print_wrapped(WINDOW *win, const char *const message, size_t indent, int pad_indent);
@@ -1062,7 +1063,7 @@ win_show_status_string(ProfWin *window, const char *const from,
 }
 
 static void
-_win_correct(ProfWin *window, const char *const message, const char *const id, const char *const replace_id)
+_win_correct(ProfWin *window, const char *const message, const char *const id, const char *const replace_id, const char *const from_jid)
 {
     ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->buffer, replace_id);
     if (!entry) {
@@ -1070,6 +1071,12 @@ _win_correct(ProfWin *window, const char *const message, const char *const id, c
         return;
     }
 
+    if (g_strcmp0(entry->from_jid, from_jid) != 0) {
+        log_debug("Illicit LMC attempt from %s for message from %s with: %s", from_jid, entry->from_jid, message);
+        cons_show("Illicit LMC attempt from %s for message from %s", from_jid, entry->from_jid);
+        return;
+    }
+
     /*TODO: set date?
     if (entry->date) {
         if (entry->date->timestamp) {
@@ -1126,16 +1133,16 @@ win_print_incoming(ProfWin *window, const char *const display_name_from, ProfMes
             }
 
             if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
-                _win_correct(window, message->plain, message->id, message->replace_id);
+                _win_correct(window, message->plain, message->id, message->replace_id, message->jid->barejid);
             } else {
-                _win_printf(window, enc_char, 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->id, "%s", message->plain);
+                _win_printf(window, enc_char, 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->jid->barejid, message->id, "%s", message->plain);
             }
 
             free(enc_char);
             break;
         }
         case WIN_PRIVATE:
-            _win_printf(window, "-", 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->id, "%s", message->plain);
+            _win_printf(window, "-", 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->jid->barejid, message->id, "%s", message->plain);
             break;
         default:
             assert(FALSE);
@@ -1146,16 +1153,16 @@ win_print_incoming(ProfWin *window, const char *const display_name_from, ProfMes
 void
 win_print_them(ProfWin *window, theme_item_t theme_item, const char *const show_char, int flags, const char *const them)
 {
-    _win_printf(window, show_char, 0, NULL, flags | NO_ME | NO_EOL, theme_item, them, NULL, "");
+    _win_printf(window, show_char, 0, NULL, flags | NO_ME | NO_EOL, theme_item, them, NULL, NULL, "");
 }
 
 void
 win_println_incoming_muc_msg(ProfWin *window, char *show_char, int flags, const ProfMessage *const message)
 {
     if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
-        _win_correct(window, message->plain, message->id, message->replace_id);
+        _win_correct(window, message->plain, message->id, message->replace_id, message->jid->fulljid);
     } else {
-        _win_printf(window, show_char, 0, message->timestamp, flags | NO_ME, THEME_TEXT_THEM, message->jid->resourcepart, message->id, "%s", message->plain);
+        _win_printf(window, show_char, 0, message->timestamp, flags | NO_ME, THEME_TEXT_THEM, message->jid->resourcepart, message->jid->fulljid, message->id, "%s", message->plain);
     }
 
     inp_nonblocking(TRUE);
@@ -1167,9 +1174,9 @@ win_print_outgoing_muc_msg(ProfWin *window, char *show_char, const char *const m
     GDateTime *timestamp = g_date_time_new_now_local();
 
     if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && replace_id) {
-        _win_correct(window, message, id, replace_id);
+        _win_correct(window, message, id, replace_id, me);
     } else {
-        _win_printf(window, show_char, 0, timestamp, 0, THEME_TEXT_ME, me, id, "%s", message);
+        _win_printf(window, show_char, 0, timestamp, 0, THEME_TEXT_ME, me, me, id, "%s", message);
     }
 
     inp_nonblocking(TRUE);
@@ -1181,10 +1188,12 @@ win_print_outgoing(ProfWin *window, const char *show_char, const char *const id,
 {
     GDateTime *timestamp = g_date_time_new_now_local();
 
+    const char *myjid = connection_get_fulljid();
     if (replace_id) {
-        _win_correct(window, message, id, replace_id);
+        _win_correct(window, message, id, replace_id, myjid);
     } else {
-        _win_printf(window, show_char, 0, timestamp, 0, THEME_TEXT_THEM, "me", id, "%s", message);
+        //TODO my jid
+        _win_printf(window, show_char, 0, timestamp, 0, THEME_TEXT_THEM, "me", myjid, id, "%s", message);
     }
 
     inp_nonblocking(TRUE);
@@ -1196,7 +1205,7 @@ win_print_history(ProfWin *window, GDateTime *timestamp, const char *const messa
 {
     g_date_time_ref(timestamp);
 
-    buffer_append(window->layout->buffer, "-", 0, timestamp, 0, THEME_TEXT_HISTORY, "", message, NULL, NULL);
+    buffer_append(window->layout->buffer, "-", 0, timestamp, 0, THEME_TEXT_HISTORY, "", NULL, message, NULL, NULL);
     _win_print_internal(window, "-", 0, timestamp, 0, THEME_TEXT_HISTORY, "", message, NULL);
 
     inp_nonblocking(TRUE);
@@ -1213,7 +1222,7 @@ win_print(ProfWin *window, theme_item_t theme_item, const char *show_char, const
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, show_char, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL, NULL);
+    buffer_append(window->layout->buffer, show_char, 0, timestamp, NO_EOL, theme_item, "", NULL, fmt_msg->str, NULL, NULL);
     _win_print_internal(window, show_char, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1233,7 +1242,7 @@ win_println(ProfWin *window, theme_item_t theme_item, const char *show_char, con
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, show_char, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL, NULL);
+    buffer_append(window->layout->buffer, show_char, 0, timestamp, 0, theme_item, "", NULL, fmt_msg->str, NULL, NULL);
     _win_print_internal(window, show_char, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1253,7 +1262,7 @@ win_println_indent(ProfWin *window, int pad, const char *const message, ...)
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, "-", pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL, NULL);
+    buffer_append(window->layout->buffer, "-", pad, timestamp, 0, THEME_DEFAULT, "", NULL, fmt_msg->str, NULL, NULL);
     _win_print_internal(window, "-", pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1273,7 +1282,7 @@ win_append(ProfWin *window, theme_item_t theme_item, const char *const message,
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL, NULL);
+    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE | NO_EOL, theme_item, "", NULL, fmt_msg->str, NULL, NULL);
     _win_print_internal(window, "-", 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1293,7 +1302,7 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL, NULL);
+    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE, theme_item, "", NULL, fmt_msg->str, NULL, NULL);
     _win_print_internal(window, "-", 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1313,7 +1322,7 @@ win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL, NULL);
+    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", NULL, fmt_msg->str, NULL, NULL);
     _win_print_internal(window, "-", 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1333,7 +1342,7 @@ win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *con
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL, NULL);
+    buffer_append(window->layout->buffer, "-", 0, timestamp, NO_DATE | NO_ME, theme_item, "", NULL, fmt_msg->str, NULL, NULL);
     _win_print_internal(window, "-", 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1357,10 +1366,11 @@ win_print_outgoing_with_receipt(ProfWin *window, const char *show_char, const ch
     DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t));
     receipt->received = FALSE;
 
+    const char *myjid = connection_get_fulljid();
     if (replace_id) {
-        _win_correct(window, message, id, replace_id);
+        _win_correct(window, message, id, replace_id, myjid);
     } else {
-        buffer_append(window->layout->buffer, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt, id);
+        buffer_append(window->layout->buffer, show_char, 0, time, 0, THEME_TEXT_ME, from, myjid, message, receipt, id);
         _win_print_internal(window, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt);
     }
 
@@ -1403,8 +1413,7 @@ win_newline(ProfWin *window)
 }
 
 static void
-_win_printf(ProfWin *window, const char *show_char, int pad_indent, GDateTime *timestamp,
-    int flags, theme_item_t theme_item, const char *const display_from, const char *const message_id, const char *const message, ...)
+_win_printf(ProfWin *window, const char *show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char *const display_from, const char *const from_jid, const char *const message_id, const char *const message, ...)
 {
     if (timestamp == NULL) {
         timestamp = g_date_time_new_now_local();
@@ -1417,7 +1426,7 @@ _win_printf(ProfWin *window, const char *show_char, int pad_indent, GDateTime *t
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, display_from, fmt_msg->str, NULL, message_id);
+    buffer_append(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, display_from, from_jid, fmt_msg->str, NULL, message_id);
 
     _win_print_internal(window, show_char, pad_indent, timestamp, flags, theme_item, display_from, fmt_msg->str, NULL);
 
@@ -1900,7 +1909,7 @@ win_insert_last_read_position_marker(ProfWin *window, char* id)
     // the trackbar/separator will actually be print in win_redraw().
     // this only puts it in the buffer and win_redraw() will interpret it.
     // so that we have the correct length even when resizing.
-    buffer_append(window->layout->buffer, " ", 0, time, 0, THEME_TEXT, NULL, "-", NULL, id);
+    buffer_append(window->layout->buffer, " ", 0, time, 0, THEME_TEXT, NULL, NULL, "-", NULL, id);
     win_redraw(window);
 
     g_date_time_unref(time);