Mercurial > ~mikael > mcabber > hg
diff mcabber/src/histolog.c @ 113:8ac67e951eab
[/trunk] Changeset 127 by mikael
* Add a "hooks" layer.
Hooks are used when multiples operations should be done when an event
araises. For example message in/out, status change...
2 more files; Makefile updated.
* Logging is ready.
* Add 2 options:
- "logging" (bool): enable/disable history logging
- "logging_dir" (char): root dir for logging files
* Document pinginterval (keepalive) in the sample config file.
* Send keepalive only when online.
author | mikael |
---|---|
date | Sun, 24 Apr 2005 20:24:18 +0000 |
parents | d896962c16fa |
children | 1e8f646e2c5b |
line wrap: on
line diff
--- a/mcabber/src/histolog.c Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/src/histolog.c Sun Apr 24 20:24:18 2005 +0000 @@ -22,8 +22,13 @@ #include <string.h> #include <stdlib.h> #include <time.h> +#include <ctype.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include "histolog.h" +#include "jabglue.h" #include "screen.h" static guint UseFileLogging; @@ -47,12 +52,13 @@ // write() // Adds a history (multi-)line to the jid's history logfile -static void write(const char *jid, - time_t timestamp, guchar type, guchar info, char *data) +static void write_histo_line(const char *jid, + time_t timestamp, guchar type, guchar info, const char *data) { guint len = 0; + FILE *fp; time_t ts; - char *p; + const char *p; char *filename = user_histo_file(jid); if (!filename) @@ -80,8 +86,11 @@ * We don't check them, we'll trust the caller. */ - scr_LogPrint("Log to [%s]:", filename); - scr_LogPrint("%c %c %10d %03d %s", type, info, ts, len, data); + fp = fopen(filename, "a"); + if (!fp) + return; + fprintf(fp, "%c %c %10u %03d %s\n", type, info, (unsigned int)ts, len, data); + fclose(fp); } // hlog_enable() @@ -121,3 +130,18 @@ } } +inline void hlog_write_message(const char *jid, time_t timestamp, int sent, + const char *msg) +{ + write_histo_line(jid, timestamp, 'M', ((sent) ? 'S' : 'R'), msg); +} + +inline void hlog_write_status(const char *jid, time_t timestamp, + enum imstatus status) +{ + // #1 XXX Check status value? + // #2 We could add a user-readable comment + write_histo_line(jid, timestamp, 'S', toupper(imstatus2char[status]), + NULL); +} +