Merge 3.0.4.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 24 Nov 2007 19:06:50 +0000 (20:06 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 24 Nov 2007 19:06:50 +0000 (20:06 +0100)
17 files changed:
Makefile
Makefile.settings.in
NEWS
config.default
config.example
configure.ac
src/admin.c
src/auto_away.c [moved from mods/auto_away.c with 59% similarity]
src/ctcp.c
src/ctrlproxy.h
src/internals.h
src/local.h
src/main.c
src/repl.c
src/repl.h
src/settings.c
src/settings.h

index 34f9d73..1a2f21a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,5 @@
 -include Makefile.settings
 
-MODS_SHARED_FILES = $(patsubst %,mods/lib%.$(SHLIBEXT),$(MODS_SHARED))
-
 GCOV = gcov
 
 ifeq ($(WITH_GCOV),1)
@@ -23,11 +21,9 @@ LIBIRC_SHARED = libirc.$(SHLIBEXT).$(PACKAGE_VERSION)
 LIBIRC_SOVERSION = 1.0
 LIBIRC_SONAME = libirc.$(SHLIBEXT).$(LIBIRC_SOVERSION)
 
+.PHONY: all clean distclean install install-bin install-dirs install-doc install-data install-pkgconfig
 
-
-.PHONY: all clean distclean install install-bin install-dirs install-doc install-data install-mods install-pkgconfig
-
-all: $(BINS) $(MODS_SHARED_FILES) 
+all: $(BINS)
 
 doxygen:
        doxygen
@@ -62,6 +58,7 @@ objs = src/posix.o \
           src/listener.o \
           src/log_support.o \
           src/log_custom.o \
+          src/auto_away.o \
           $(SSL_OBJS)
 
 lib_headers = \
@@ -82,7 +79,7 @@ headers = src/admin.h \
                  src/settings.h \
                  src/ssl.h \
                  src/log.h
-dep_files = $(patsubst %.o, %.d, $(objs)) $(patsubst %.o, %.d, $(wildcard mods/*.o))
+dep_files = $(patsubst %.o, %.d, $(objs))
 
 linestack-cmd$(EXEEXT): src/linestack-cmd.o $(objs) $(LIBIRC)
        @echo Linking $@
@@ -96,10 +93,6 @@ ctrlproxy-admin$(EXEEXT): src/admin-cmd.o
        @echo Linking $@
        @$(LD) $(LDFLAGS) -rdynamic -o $@ $^ $(LIBS)
 
-mods/%.o: mods/%.c
-       @echo Compiling for shared library $<
-       @$(CC) -fPIC -I. -Ilib -Isrc $(CFLAGS) $(GCOV_CFLAGS) -c $< -o $@
-
 %.o: %.c
        @echo Compiling $<
        @$(CC) -I. -Ilib -Isrc $(CFLAGS) $(GCOV_CFLAGS) -c $< -o $@
@@ -108,22 +101,23 @@ mods/%.o: mods/%.c
        @$(CC) -I. -Ilib -Isrc -M -MT $(<:.c=.o) $(CFLAGS) $< -o $@
 
 ifeq ($(BZR_CHECKOUT),yes)
-configure: autogen.sh configure.ac acinclude.m4 $(wildcard mods/*/*.m4)
+configure: autogen.sh configure.ac acinclude.m4
        ./$<
 endif
 
 ctrlproxy.pc Makefile.settings: configure Makefile.settings.in ctrlproxy.pc.in
        ./$<
 
-install: all install-dirs install-bin install-header install-mods install-data install-pkgconfig $(EXTRA_INSTALL_TARGETS)
+install: all install-dirs install-bin install-header install-data install-pkgconfig $(EXTRA_INSTALL_TARGETS)
 install-dirs:
        $(INSTALL) -d $(DESTDIR)$(modulesdir)
 
-uninstall: uninstall-bin uninstall-header uninstall-mods uninstall-data uninstall-pkgconfig $(patsubst install-%,uninstall-%,$(EXTRA_INSTALL_TARGETS))
+uninstall: uninstall-bin uninstall-header uninstall-data uninstall-pkgconfig $(patsubst install-%,uninstall-%,$(EXTRA_INSTALL_TARGETS))
 uninstall-bin:
        -rm -f $(DESTDIR)$(bindir)/ctrlproxy$(EXEEXT) \
                   $(DESTDIR)$(bindir)/ctrlproxy-admin$(EXEEXT)
        -rmdir $(DESTDIR)$(bindir)
+       -rmdir $(DESTDIR)$(modulesdir)
 
 install-bin:
        $(INSTALL) -d $(DESTDIR)$(bindir)
@@ -161,14 +155,6 @@ install-data:
        $(INSTALL) -m 0644 config.default $(DESTDIR)$(DEFAULT_CONFIG_DIR)/config
        $(INSTALL) -m 0644 config.admin $(DESTDIR)$(DEFAULT_CONFIG_DIR)/networks/admin
 
-install-mods: all 
-       $(INSTALL) -d $(DESTDIR)$(modulesdir)
-       $(INSTALL) $(MODS_SHARED_FILES) $(DESTDIR)$(modulesdir)
-
-uninstall-mods:
-       -rm -f $(patsubst %,$(DESTDIR)$(modulesdir)/%,$(notdir $(MODS_SHARED_FILES)))
-       -rmdir $(DESTDIR)$(modulesdir)
-
 install-pkgconfig:
        $(INSTALL) -d $(DESTDIR)$(libdir)/pkgconfig
        $(INSTALL) -m 0644 ctrlproxy.pc $(DESTDIR)$(libdir)/pkgconfig
@@ -184,10 +170,6 @@ lcov:
        lcov --base-directory `pwd` --directory . --capture --output-file ctrlproxy.info
        genhtml -o coverage ctrlproxy.info
 
-mods/lib%.$(SHLIBEXT): mods/%.o
-       @echo Linking $@
-       @$(LD) $(LDFLAGS) -fPIC -shared -o $@ $^
-
 $(LIBIRC_STATIC): $(lib_objs)
        @echo Linking $@
        @ar -rcs $@ $^
@@ -196,12 +178,10 @@ $(LIBIRC_SHARED): $(lib_objs)
        $(LD) -shared $(LDFLAGS) -Wl,-soname,$(LIBIRC_SONAME) -o $@ $^
 
 clean::
-       @echo Removing .so files
-       @rm -f $(MODS_SHARED_FILES)
        @echo Removing dependency files
        @rm -f $(dep_files)
        @echo Removing object files and executables
-       @rm -f src/*.o testsuite/check ctrlproxy$(EXEEXT) testsuite/*.o *~ mods/*.o
+       @rm -f src/*.o testsuite/check ctrlproxy$(EXEEXT) testsuite/*.o *~
        @rm -f linestack-cmd$(EXEEXT) ctrlproxy-admin$(EXEEXT)
        @echo Removing gcov output
        @rm -f *.gcov *.gcno *.gcda 
@@ -249,8 +229,6 @@ testsuite/check: $(check_objs) $(objs) $(LIBIRC)
        @echo Linking $@
        @$(CC) $(LIBS) -o $@ $^ $(CHECK_LIBS)
 
-CTRLPROXY_MODULESDIR=$(shell pwd)/mods
-
 check:: testsuite/check
        @echo Running testsuite
        @$(VALGRIND) ./testsuite/check
index 4c7ac97..d272097 100644 (file)
@@ -19,7 +19,6 @@ cdatadir = @datadir@/ctrlproxy
 EXEEXT = @EXEEXT@
 OBJEXT = @OBJEXT@
 CFLAGS = @CFLAGS@ @COMMON_CFLAGS@
-MODS_SHARED = auto_away @MODS_SHARED@
 LDFLAGS = @LDFLAGS@
 BINS = @BINS@
 scriptdir = $(cdatadir)/scripts
diff --git a/NEWS b/NEWS
index bb929cf..7e08cc3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,14 @@
  Otherwise indicated differently, all changes made by 
      Jelmer Vernooij.
 
+Ctrlproxy 3.0.5 UNRELEASED
+
+  IMPROVEMENTS
+  
+    * Integrate auto-away module into the core.
+
+       * New settings ``autosave'', ``replication''
+
 Ctrlproxy 3.0.4 2007-11-24
 
   IMPROVEMENTS
index 12c3844..133874e 100644 (file)
@@ -58,17 +58,17 @@ admin-log = true
 # Whether to update a networks name based on the NETWORK= line sent when 
 # connected to it
 #learn-network-name = true
+#
+# Automatically set AWAY after a certain period of time
+#auto-away-enable = true
+#auto-away-message = I'm currently away, sorry!
+#auto-away-time = 300 # in seconds
+#auto-away-nick = jelmer|away
 
-# Irssi-style logging
-[log-irssi]
+# Logging
+#logging = none|irssi|custom
 #logfile = /home/jelmer/tmp/ctrlproxy
 
 # Work as a socks proxy
 #[socks]
 #allow = jelmer:secret, foo:bar
-
-# Automatically set AWAY after a certain period of time
-#[auto-away]
-#message = I'm currently away, sorry!
-#time = 300 # in seconds
-#nick = jelmer|away
index 21d645a..ddc4fca 100644 (file)
@@ -40,16 +40,17 @@ autosave = true
 # Networks to connect to on startup. Seperate by semicolons
 autoconnect = admin
 # autoconnect = admin;irc.oftc.net;irc.freenode.net;
+#
+# Automatically set AWAY after a certain period of time
+#auto-away-enable = true
+#auto-away-message = I'm currently away, sorry!
+#auto-away-time = 300 # in seconds
 
 # Irssi-style logging
-[log-irssi]
-# logfile = /home/jelmer/tmp/ctrlproxy
+#logging = irssi
+#logfile = /home/jelmer/tmp/ctrlproxy
 
 # Work as a socks proxy
 #[socks]
 #allow = jelmer:secret, foo:bar
 
-# Automatically set AWAY after a certain period of time
-#[auto-away]
-#message = I'm currently away, sorry!
-#time = 300 # in seconds
index 8b8b60f..5c686c6 100644 (file)
@@ -99,7 +99,6 @@ AC_SUBST(EXTRA_INSTALL_TARGETS)
 
 BINS="$BINS ctrlproxy$ac_cv_exeext"
 AC_SUBST(BINS)
-AC_SUBST(MODS_SHARED)
 
 AC_DEFINE(_GNU_SOURCE, 1, [Use GNU extensions])
 
index 3a5b895..d389779 100644 (file)
@@ -1003,6 +1003,42 @@ static gboolean report_time_set(admin_handle h, const char *value)
        return interpret_boolean(h, value, &g->config->report_time);
 }
 
+static gboolean autosave_set(admin_handle h, const char *value)
+{
+       struct global *g = admin_get_global(h);
+
+       return interpret_boolean(h, value, &g->config->autosave);
+}
+
+static char *autosave_get(admin_handle h)
+{
+       struct global *g = admin_get_global(h);
+
+       return g_strdup(g->config->autosave?"true":"false");
+}
+
+static char *replication_get(admin_handle h)
+{
+       struct global *g = admin_get_global(h);
+
+       return g_strdup(g->config->replication);
+}
+
+static gboolean replication_set(admin_handle h, const char *value)
+{
+       struct global *g = admin_get_global(h);
+
+       if (repl_find_backend(value) == NULL) {
+               admin_out(h, "No such replication backend `%s'", value);
+               return FALSE;
+       }
+
+       g_free(g->config->replication);
+       g->config->replication = g_strdup(value);
+
+       return TRUE;
+}
+
 static struct admin_setting {
        const char *name;
        char *(*get) (admin_handle h);
@@ -1011,6 +1047,8 @@ static struct admin_setting {
        { "log_level", log_level_get, log_level_set },
        { "motd-file", motd_file_get, motd_file_set },
        { "report-time", report_time_get, report_time_set },
+       { "autosave", autosave_get, autosave_set },
+       { "replication", replication_get, replication_set },
        { NULL, NULL, NULL }
 };
 
similarity index 59%
rename from mods/auto_away.c
rename to src/auto_away.c
index e7f3ad3..1406e2e 100644 (file)
 #include "ctrlproxy.h"
 #include <string.h>
 
-#define DEFAULT_TIME (10 * 60)
-
 struct auto_away_data {
+       struct auto_away_config *config;
        time_t last_message;
-       time_t max_idle_time;
        guint timeout_id;
-       gint client_limit;
        struct global *global;
-       char *message;
-       char *nick;
 };
 
 static gboolean check_time(gpointer user_data) 
 {
        struct auto_away_data *d = (struct auto_away_data *)user_data;
 
-       if (time(NULL) - d->last_message > d->max_idle_time) {
+       if (time(NULL) - d->last_message > d->config->max_idle_time) {
                GList *sl;
                for (sl = d->global->networks; sl; sl = sl->next) {
                        struct network *s = (struct network *)sl->data;
                        if (s->connection.state == NETWORK_CONNECTION_STATE_MOTD_RECVD &&
                                s->state != NULL && !s->state->is_away && 
-                           (d->client_limit < 0 || g_list_length(s->clients) <= d->client_limit)) {
+                           (d->config->client_limit < 0 || g_list_length(s->clients) <= d->config->client_limit)) {
                                network_send_args(s, "AWAY", 
-                                                                 d->message != NULL?d->message:"Auto Away", 
+                                                                 d->config->message != NULL?d->config->message:"Auto Away", 
                                                                  NULL);
-                               if (d->nick != NULL) {
-                                       network_send_args(s, "NICK", d->nick, NULL);
+                               if (d->config->nick != NULL) {
+                                       network_send_args(s, "NICK", d->config->nick, NULL);
                                }
                        }
                }
@@ -91,58 +86,20 @@ static gboolean new_client(struct client *c, void *userdata)
 {
        struct auto_away_data *d = userdata;
 
-       if (d->client_limit >= 0 && d->client_limit < g_list_length(c->network->clients)+1)
+       if (d->config->client_limit >= 0 && d->config->client_limit < g_list_length(c->network->clients)+1)
                network_send_args(c->network, "AWAY", NULL);
 
        return TRUE;
 }
 
-static void load_config(struct global *global)
+void auto_away_add(struct global *global, struct auto_away_config *config)
 {
-       struct auto_away_data *d;
-       GKeyFile *kf = global->config->keyfile;
-
-       if (!g_key_file_has_group(kf, "auto-away")) {
-               del_server_filter("auto-away");
-               return;
-       }
-
-       d = g_new0(struct auto_away_data, 1);
-       d->global = global;
-       
-       add_server_filter("auto-away", log_data, d, -1);
+       struct auto_away_data *d = g_new0(struct auto_away_data, 1);
 
+       d->config = config;
        d->last_message = time(NULL);
-       d->message = g_key_file_get_string(kf, "auto-away", "message", NULL);
-       d->nick = g_key_file_get_string(kf, "auto-away", "nick", NULL);
-       if (g_key_file_has_key(kf, "auto-away", "client_limit", NULL)) {
-               d->client_limit = g_key_file_get_integer(kf, "auto-away", "client_limit", NULL);
-               if (g_key_file_has_key(kf, "auto-away", "only_noclient", NULL))
-                       log_global(LOG_WARNING, "auto-away: not using only_noclient because client_limit is set");
-       }
-       else if (g_key_file_has_key(kf, "auto-away", "only_noclient", NULL)) {
-               d->client_limit = g_key_file_get_boolean(kf, "auto-away", "only_noclient", NULL) ? 0 : -1;
-               log_global(LOG_WARNING, "auto-away: only_noclient is deprecated, please use client_limit instead");
-       }
-       else
-               d->client_limit = -1;
-       if (g_key_file_has_key(kf, "auto-away", "time", NULL))
-               d->max_idle_time = g_key_file_get_integer(kf, "auto-away", "time", NULL);
-       else
-               d->max_idle_time = DEFAULT_TIME;
-
        d->timeout_id = g_timeout_add(1000, check_time, d);
+       d->global = global;
        add_new_client_hook("auto-away", new_client, d);
+       add_server_filter("auto-away", log_data, d, -1);
 }
-
-static gboolean init_plugin() 
-{
-       register_load_config_notify(load_config);
-       return TRUE;
-}
-
-struct plugin_ops plugin = {
-       .name = "auto_away",
-       .version = CTRLPROXY_PLUGIN_VERSION,
-       .init = init_plugin,
-};
index c711a59..5344571 100644 (file)
@@ -22,6 +22,9 @@
 #include <sys/utsname.h>
 #endif
 
+/**
+ * Represents a CTCP request
+ */
 struct ctcp_handle 
 {
        struct network *network;
index 6dcb7d2..ab6b258 100644 (file)
@@ -27,7 +27,7 @@
 #include <glib.h>
 #include <gmodule.h>
 
-#define CTRLPROXY_PLUGIN_VERSION 2
+#define CTRLPROXY_PLUGIN_VERSION 3
 
 /**
  * @file
index 531e560..e87e109 100644 (file)
@@ -133,7 +133,11 @@ gboolean stop_unix_socket(struct global *);
 /* log_custom.c */
 void log_custom_load(struct log_file_config *config);
 
+/* listener.c */
 void free_listeners(struct global *global);
 
+/* auto_away.c */
+void auto_away_add(struct global *global, struct auto_away_config *config);
+
 #endif /* __INTERNALS_H__ */
 
index 56cd524..af3aaa7 100644 (file)
@@ -32,5 +32,8 @@
 /* Default port that will be used if no port was specified */
 #define DEFAULT_IRC_PORT "6667"
 
+/* Standard auto-away time if auto-away is enabled but 
+ * no time was specified. In seconds. */
+#define AUTO_AWAY_DEFAULT_TIME (10 * 60)
 
 #endif /* _CTRLPROXY_LOCAL_H_ */
index 8609c72..2e704f7 100644 (file)
@@ -309,11 +309,10 @@ int main(int argc, char **argv)
 
        start_unix_socket(my_global);
        start_admin_socket(my_global);
-
        autoconnect_networks(my_global);
-
        init_listeners(my_global);
-
+       if (my_global->config->auto_away != NULL)
+               auto_away_add(my_global, my_global->config->auto_away);
        g_option_context_free(pc);
 
        atexit(clean_exit);
index ff9a440..6ea485d 100644 (file)
@@ -249,6 +249,22 @@ void register_replication_backend(const struct replication_backend *backend)
        backends = g_list_append(backends, g_memdup(backend, sizeof(*backend)));
 }
 
+struct replication_backend *repl_find_backend(const char *name)
+{
+       GList *gl;
+
+       if (name == NULL)
+               name = "none";
+
+       for (gl = backends; gl; gl = gl->next) {
+               struct replication_backend *backend = gl->data;
+               if (!strcmp(backend->name, name))
+                       return backend;
+       }
+
+       return NULL;
+}
+
 /**
  * Replicate the current state and backlog to the client.
  *
@@ -256,22 +272,12 @@ void register_replication_backend(const struct replication_backend *backend)
  */
 void client_replicate(struct client *client)
 {
-       void (*fn) (struct client *);
        const char *bn = client->network->global->config->replication;
-       GList *gl;
+       struct replication_backend *backend;
        
-       if (bn == NULL)
-               bn = "none";
-
-       fn = NULL;
-
-       for (gl = backends; gl; gl = gl->next) {
-               struct replication_backend *backend = gl->data;
-               if (!strcmp(backend->name, bn))
-                       fn = backend->replication_fn;
-       }
+       backend = repl_find_backend(bn);
 
-       if (fn == NULL) {
+       if (backend == NULL) {
                log_client(LOG_WARNING, client, 
                                   "Unable to find replication backend '%s'", bn);
 
@@ -281,5 +287,5 @@ void client_replicate(struct client *client)
                return;
        } 
 
-       fn(client);
+       backend->replication_fn(client);
 }
index 6d9e7cb..417f4b1 100644 (file)
@@ -34,5 +34,6 @@ struct replication_backend {
 };
 
 void register_replication_backend(const struct replication_backend *);
+struct replication_backend *repl_find_backend(const char *name);
 
 #endif /* __CTRLPROXY_REPL_H__ */
index c44bc5e..b54e629 100644 (file)
@@ -664,34 +664,59 @@ static void config_load_networks(struct ctrlproxy_config *cfg)
        g_dir_close(dir);
 }
 
-#define FETCH_SETTING(data, kf, name) (data)->name = g_key_file_get_string((kf), "log-custom", __STRING(name), NULL)
+#define FETCH_SETTING(data, kf, section, prefix, name) (data)->name = g_key_file_get_string((kf), (section), prefix __STRING(name), NULL)
 
 static void config_load_log(struct ctrlproxy_config *config)
 {
        GKeyFile *kf = config->keyfile;
        struct log_file_config *data;
        char *logbasedir;
+       char *logging = NULL;
+
+       if (g_key_file_get_string(kf, "global", "logging", NULL) != NULL) {
+               logging = g_key_file_get_string(kf, "global", "logging", NULL);
+       }
 
        if (g_key_file_has_group(kf, "log-custom")) {
                data = g_new0(struct log_file_config, 1);
 
-               FETCH_SETTING(data, kf, nickchange);
-               FETCH_SETTING(data, kf, logfilename);
-               FETCH_SETTING(data, kf, topic);
-               FETCH_SETTING(data, kf, notopic);
-               FETCH_SETTING(data, kf, part);
-               FETCH_SETTING(data, kf, join);
-               FETCH_SETTING(data, kf, msg);
-               FETCH_SETTING(data, kf, notice);
-               FETCH_SETTING(data, kf, action);
-               FETCH_SETTING(data, kf, kick);
-               FETCH_SETTING(data, kf, quit);
-               FETCH_SETTING(data, kf, mode);
+               FETCH_SETTING(data, kf, "log-custom", "", nickchange);
+               FETCH_SETTING(data, kf, "log-custom", "", logfilename);
+               FETCH_SETTING(data, kf, "log-custom", "", topic);
+               FETCH_SETTING(data, kf, "log-custom", "", notopic);
+               FETCH_SETTING(data, kf, "log-custom", "", part);
+               FETCH_SETTING(data, kf, "log-custom", "", join);
+               FETCH_SETTING(data, kf, "log-custom", "", msg);
+               FETCH_SETTING(data, kf, "log-custom", "", notice);
+               FETCH_SETTING(data, kf, "log-custom", "", action);
+               FETCH_SETTING(data, kf, "log-custom", "", kick);
+               FETCH_SETTING(data, kf, "log-custom", "", quit);
+               FETCH_SETTING(data, kf, "log-custom", "", mode);
 
                log_custom_load(data);
        }
 
-       if (g_key_file_has_group(kf, "log-irssi")) {
+       if (logging != NULL && !strcmp(logging, "custom")) {
+               data = g_new0(struct log_file_config, 1);
+
+               FETCH_SETTING(data, kf, "global", "", logfilename);
+               FETCH_SETTING(data, kf, "global", "log-format-", nickchange);
+               FETCH_SETTING(data, kf, "global", "log-format-", topic);
+               FETCH_SETTING(data, kf, "global", "log-format-", notopic);
+               FETCH_SETTING(data, kf, "global", "log-format-", part);
+               FETCH_SETTING(data, kf, "global", "log-format-", join);
+               FETCH_SETTING(data, kf, "global", "log-format-", msg);
+               FETCH_SETTING(data, kf, "global", "log-format-", notice);
+               FETCH_SETTING(data, kf, "global", "log-format-", action);
+               FETCH_SETTING(data, kf, "global", "log-format-", kick);
+               FETCH_SETTING(data, kf, "global", "log-format-", quit);
+               FETCH_SETTING(data, kf, "global", "log-format-", mode);
+
+               log_custom_load(data);
+       }
+
+       if (g_key_file_has_group(kf, "log-irssi") || 
+               (logging != NULL && !strcmp(logging, "irssi"))) {
                data = g_new0(struct log_file_config, 1);
 
                data->join = "%h:%M -!- %n [%u] has joined %c";
@@ -706,11 +731,13 @@ static void config_load_log(struct ctrlproxy_config *config)
                data->notopic = "%h:%M -!- %n has removed the topic";
                data->nickchange = "%h:%M -!- %n is now known as %r";
 
-               if (!g_key_file_has_key(kf, "log-irssi", "logfile", NULL)) {
+               if (g_key_file_has_key(kf, "log-irssi", "logfile", NULL)) {
+                       logbasedir = g_key_file_get_string(kf, "log-irssi", "logfile", NULL);
+               } else if (g_key_file_has_key(kf, "global", "logfile", NULL)) {
+                       logbasedir = g_key_file_get_string(kf, "global", "logfile", NULL);
+               } else {
                        logbasedir = g_build_filename(config->config_dir, 
                                                                                  "log_irssi", NULL);
-               } else {
-                       logbasedir = g_key_file_get_string(kf, "log-irssi", "logfile", NULL);
                }
 
                data->logfilename = g_strdup_printf("%s/%%N/%%@", logbasedir);
@@ -719,6 +746,62 @@ static void config_load_log(struct ctrlproxy_config *config)
 
                log_custom_load(data);
        }
+
+       if (logging != NULL && 
+                       strcmp(logging, "irssi") != 0 && 
+                       strcmp(logging, "custom") != 0 &&
+                       strcmp(logging, "none") != 0) {
+               log_global(LOG_WARNING, "Unknown log type `%s'", logging);
+       }
+
+       g_free(logging);
+}
+
+static void config_load_auto_away(struct ctrlproxy_config *config)
+{
+       struct auto_away_config *d;
+       GKeyFile *kf = config->keyfile;
+
+       if (g_key_file_has_group(kf, "auto-away")) {
+               d = g_new0(struct auto_away_config, 1);
+               
+               d->message = g_key_file_get_string(kf, "auto-away", "message", NULL);
+               d->nick = g_key_file_get_string(kf, "auto-away", "nick", NULL);
+               if (g_key_file_has_key(kf, "auto-away", "client_limit", NULL)) {
+                       d->client_limit = g_key_file_get_integer(kf, "auto-away", "client_limit", NULL);
+                       if (g_key_file_has_key(kf, "auto-away", "only_noclient", NULL))
+                               log_global(LOG_WARNING, "auto-away: not using only_noclient because client_limit is set");
+               }
+               else if (g_key_file_has_key(kf, "auto-away", "only_noclient", NULL)) {
+                       d->client_limit = g_key_file_get_boolean(kf, "auto-away", "only_noclient", NULL) ? 0 : -1;
+                       log_global(LOG_WARNING, "auto-away: only_noclient is deprecated, please use client_limit instead");
+               }
+               else
+                       d->client_limit = -1;
+               if (g_key_file_has_key(kf, "auto-away", "time", NULL))
+                       d->max_idle_time = g_key_file_get_integer(kf, "auto-away", "time", NULL);
+               else
+                       d->max_idle_time = AUTO_AWAY_DEFAULT_TIME;
+       } else if (g_key_file_has_key(kf, "global", "auto-away-enable", NULL) &&
+                          g_key_file_get_boolean(kf, "global", "auto-away-enable", NULL)) {
+               d = g_new0(struct auto_away_config, 1);
+               
+               d->message = g_key_file_get_string(kf, "global", "auto-away-message", NULL);
+               d->nick = g_key_file_get_string(kf, "global", "auto-away-nick", NULL);
+               if (g_key_file_has_key(kf, "global", "auto-away-client-limit", NULL)) {
+                       d->client_limit = g_key_file_get_integer(kf, "global", "auto-away-client-limit", NULL);
+               }
+               else
+                       d->client_limit = -1;
+               if (g_key_file_has_key(kf, "global", "auto-away-time", NULL))
+                       d->max_idle_time = g_key_file_get_integer(kf, "global", "auto-away-time", NULL);
+               else
+                       d->max_idle_time = AUTO_AWAY_DEFAULT_TIME;
+       } else {
+               return;
+       }
+
+       config->auto_away = d;
 }
 
 struct ctrlproxy_config *init_configuration(void)
@@ -826,6 +909,7 @@ struct ctrlproxy_config *load_configuration(const char *dir)
        config_load_listeners(cfg);
        config_load_listeners_socks(cfg);
        config_load_log(cfg);
+       config_load_auto_away(cfg);
 
        size = 0;
        autoconnect_list = g_key_file_get_string_list(kf, "global", "autoconnect", &size, NULL);
index 0be1302..5050774 100644 (file)
@@ -102,6 +102,9 @@ struct allow_rule {
        char *password;
 };
 
+/**
+ * Configuration for a single listener
+ */
 struct listener_config {
        gboolean ssl;
        gpointer ssl_credentials;
@@ -113,6 +116,13 @@ struct listener_config {
        gboolean is_default; /* Whether this is the "default" listener, stored in ~/.ctrlproxy/config */
 };
 
+struct auto_away_config {
+       time_t max_idle_time;
+       gint client_limit;
+       char *message;
+       char *nick;
+};
+
 /**
  * Configuration
  */
@@ -136,6 +146,7 @@ struct ctrlproxy_config {
        int listener_autoport;
        gboolean learn_nickserv;
        gboolean learn_network_name;
+       struct auto_away_config *auto_away;
 };
 
 /* config.c */