changeset 899:a833f3d6119a

Add option 'max_history_age' New option to specify how many days mcabber will load from the history files. (Suggested by "ze" in mcabber chatroom a few weeks ago)
author Mikael Berthe <mikael@lilotux.net>
date Sat, 10 Jun 2006 12:16:09 +0200
parents c65b71dcda94
children b41684465283
files mcabber/mcabberrc.example mcabber/src/histolog.c
diffstat 2 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabberrc.example	Thu Jun 08 21:42:52 2006 +0200
+++ b/mcabber/mcabberrc.example	Sat Jun 10 12:16:09 2006 +0200
@@ -50,6 +50,7 @@
 # History logging
 # You can save the messages history: set logging = 1
 # You can load (read) the messages history: set load_logs = 1
+# If you enable load_logs, you can use the 'max_history_age' setting below.
 # Default logging directory (logging_dir) is $HOME/.mcabber/histo/
 # Defaults for logging, load_logs are 0 (disabled)
 # Note: the logging directory must exist if you enable logging, mcabber
@@ -65,9 +66,15 @@
 # from the server.
 #set load_muc_logs = 0
 
+# When load_logs (or load_muc_logs) is enabled, you can specify a maximum
+# number of history days to load into memory with max_history_age.
+# Default = 0 (disabled -- everything is loaded)
+# Note: this option is only used when reading history files, not later.
+#set max_history_age = 0
+
 # IQ settings
 # Set iq_version_hide_os to 1 if you do not want to allow people to retrieve
-# your OS version
+# your OS version.
 #set iq_version_hide_os = 0
 
 # Beep
--- a/mcabber/src/histolog.c	Thu Jun 08 21:42:52 2006 +0200
+++ b/mcabber/src/histolog.c	Sat Jun 10 12:16:09 2006 +0200
@@ -132,6 +132,7 @@
   struct stat bufstat;
   guint err = 0;
   guint ln = 0; // line number
+  time_t starttime;
 
   if (!FileLoadLogs) return;
 
@@ -158,6 +159,16 @@
       scr_LogPrint(LPRINT_LOGNORM, "Reading <%s> history file...", jid);
   }
 
+  starttime = 0;
+  if (settings_opt_get_int("max_history_age") > 0) {
+    int maxdays = settings_opt_get_int("max_history_age");
+    time(&starttime);
+    if (maxdays >= starttime/86400)
+      starttime = 0;
+    else
+      starttime -= maxdays * 86400;
+  }
+
   /* See write_histo_line() for line format... */
   while (!feof(fp)) {
     guint dataoffset = 25;
@@ -216,6 +227,14 @@
     if ((tail > data+dataoffset+1) && (*(tail-1) == '\n'))
       *(tail-1) = 0;
 
+    // Check if the data is older than max_history_age
+    if (starttime) {
+      if (timestamp > starttime)
+        starttime = 0; // From now on, load everything
+      else
+        continue;
+    }
+
     if (type == 'M') {
       char *converted;
       if (info == 'S')