# HG changeset patch # User mikael # Date 1114374258 0 # Node ID 8ac67e951eab8a596e741028de51712d8d4124b5 # Parent edb5591e2e64ffdc6d34fbe1acce853581f1bacc [/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. diff -r edb5591e2e64 -r 8ac67e951eab mcabber/mcabberrc.example --- a/mcabber/mcabberrc.example Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/mcabberrc.example Sun Apr 24 20:24:18 2005 +0000 @@ -12,10 +12,24 @@ resource = yourresource ssl = 0 +# Keepalive +# If you need a ping/keepalive to leave your connection open, you +# can use the pinginterval. Setting this option to 0 disables the ping. +# Default value is 40 seconds. +#pinginterval = 40 +pinginterval = 0 + # Set hide_offline_buddies to 1 to display only connected buddies # in the roster. #hide_offline_buddies = 0 +# History logging +# You can save the messages history: set logging = 1 +# Default logging directory (logging_dir) is $HOME/.mcabber/ +logging = 1 +# logging_dir = /home/mikael/.mcabber/ + + # The colors # NOTE: the following settings may or may not be used currently... :) diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/Makefile.am --- a/mcabber/src/Makefile.am Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/src/Makefile.am Sun Apr 24 20:24:18 2005 +0000 @@ -3,7 +3,7 @@ commands.c commands.h compl.c compl.h \ hbuf.c hbuf.h screen.c screen.h \ parsecfg.c parsecfg.h utf8.c utf8.h \ - histolog.c histolog.h \ + hooks.c hooks.h histolog.c histolog.h \ utils.c utils.h lang.c lang.h list.h harddefines.h LDADD = -lglib-2.0 -lncurses -lpanel -lssl \ diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/TODO --- a/mcabber/src/TODO Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/src/TODO Sun Apr 24 20:24:18 2005 +0000 @@ -3,7 +3,6 @@ * Should not stay on buddy buffer when one moves to a group * Pending message not displayed if buddy outside Contact window -* Check keepalive TODO: diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/commands.c --- a/mcabber/src/commands.c Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/src/commands.c Sun Apr 24 20:24:18 2005 +0000 @@ -26,6 +26,7 @@ #include "roster.h" #include "screen.h" #include "compl.h" +#include "hooks.h" #include "utf8.h" #include "utils.h" @@ -139,8 +140,8 @@ return; } - // UI part - scr_WriteOutgoingMessage(jid, msg); + // local part (UI, logging, etc.) + hk_message_out(jid, 0, msg); // Network part buffer = utf8_encode(msg); diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/histolog.c --- 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 #include #include +#include +#include +#include +#include #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); +} + diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/histolog.h --- a/mcabber/src/histolog.h Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/src/histolog.h Sun Apr 24 20:24:18 2005 +0000 @@ -3,6 +3,13 @@ #include +#include "jabglue.h" + +void hlog_enable(guint enable, char *root_dir); +inline void hlog_write_message(const char *jid, time_t timestamp, int sent, + const char *msg); +inline void hlog_write_status(const char *jid, time_t timestamp, + enum imstatus status); #endif /* __HISTOLOG_H__ */ diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/hooks.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcabber/src/hooks.c Sun Apr 24 20:24:18 2005 +0000 @@ -0,0 +1,49 @@ +/* + * hooks.c -- Hooks layer + * + * Copyright (C) 2005 Mikael Berthe + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ + +#include + +#include "hooks.h" +#include "roster.h" +#include "histolog.h" + + +inline void hk_message_in(const char *jid, time_t timestamp, const char *msg) +{ + scr_WriteIncomingMessage(jid, msg); + hlog_write_message(jid, timestamp, FALSE, msg); +} + +inline void hk_message_out(const char *jid, time_t timestamp, const char *msg) +{ + scr_WriteOutgoingMessage(jid, msg); + hlog_write_message(jid, timestamp, TRUE, msg); +} + +inline void hk_statuschange(const char *jid, time_t timestamp, + enum imstatus status) +{ + scr_LogPrint("Buddy status has changed: [%c>%c] <%s>", + imstatus2char[roster_getstatus(jid)], imstatus2char[status], jid); + roster_setstatus(jid, status); + hlog_write_status(jid, 0, status); +} + diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/hooks.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcabber/src/hooks.h Sun Apr 24 20:24:18 2005 +0000 @@ -0,0 +1,13 @@ +#ifndef __HOOKS_H__ +#define __HOOKS_H__ 1 + +#include +#include "jabglue.h" + + +inline void hk_message_in(const char *jid, time_t timestamp, const char *msg); +inline void hk_message_out(const char *jid, time_t timestamp, const char *msg); +inline void hk_statuschange(const char *jid, time_t timestamp, + enum imstatus status); + +#endif /* __HOOKS_H__ */ diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/src/jabglue.c Sun Apr 24 20:24:18 2005 +0000 @@ -25,6 +25,7 @@ #include "jabglue.h" #include "roster.h" #include "screen.h" +#include "hooks.h" #include "utils.h" #define JABBERPORT 5222 @@ -68,6 +69,7 @@ file_logger(j, io, buf); } +/* static void jidsplit(const char *jid, char **user, char **host, char **res) { @@ -89,6 +91,7 @@ *user = strdup(tmp); free(tmp); } +*/ char *jidtodisp(const char *jid) { @@ -140,11 +143,8 @@ void jb_keepalive() { - if (jc) { - // XXX Only if connected... + if (jc && online) jab_send_raw(jc, " \t "); - scr_LogPrint("Sent keepalive"); - } jb_reset_keepalive(); } @@ -365,17 +365,20 @@ void gotmessage(char *type, const char *from, const char *body, const char *enc) { - char *u, *h, *r; + char *jid; - jidsplit(from, &u, &h, &r); /* + //char *u, *h, *r; + //jidsplit(from, &u, &h, &r); // Maybe we should remember the resource? if (r) scr_LogPrint("There is an extra part in message (resource?): %s", r); + //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type); */ - //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type); - scr_WriteIncomingMessage(jidtodisp(from), body); + jid = jidtodisp(from); + hk_message_in(jid, 0, body); + free(jid); } void statehandler(jconn conn, int state) @@ -654,10 +657,14 @@ } r = jidtodisp(from); + /* if (ust != roster_getstatus(r)) scr_LogPrint("Buddy status has changed: [%c>%c] <%s>", imstatus2char[roster_getstatus(r)], imstatus2char[ust], r); roster_setstatus(r, ust); + */ + if (ust != roster_getstatus(r)) + hk_statuschange(r, 0, ust); free(r); buddylist_build(); scr_DrawRoster(); diff -r edb5591e2e64 -r 8ac67e951eab mcabber/src/main.c --- a/mcabber/src/main.c Sun Apr 24 17:38:48 2005 +0000 +++ b/mcabber/src/main.c Sun Apr 24 20:24:18 2005 +0000 @@ -11,6 +11,7 @@ #include "parsecfg.h" #include "roster.h" #include "commands.h" +#include "histolog.h" #include "lang.h" #include "utils.h" #include "harddefines.h" @@ -149,6 +150,10 @@ ut_WriteLog("Drawing main window...\n"); scr_DrawMainWindow(); + optstring = cfg_read("logging"); + if (optstring && (atoi(optstring) > 0)) + hlog_enable(TRUE, cfg_read("logging_dir")); + ssl = 0; optstring = cfg_read("ssl"); if (optstring && (atoi(optstring) > 0))