Add report-time-offset setting.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 8 Dec 2007 19:38:10 +0000 (20:38 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 8 Dec 2007 19:38:10 +0000 (20:38 +0100)
NEWS
lib/network.c
src/admin.c
src/linestack.c
src/linestack.h
src/repl_backends.c
src/settings.c
src/settings.h

diff --git a/NEWS b/NEWS
index 6dfe383486fce7be64d6ac7aa00bbf909e92b9dc..4795623d66120e589f9cbae163c6d843de064d7c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,14 @@
 
 Ctrlproxy 3.0.6 UNRELEASED
 
+  IMPROVEMENTS
+
+    * Add report-time-offset setting.
+
+  BUG FIXES
+
+    * Don't "forget" listener password.
+
 Ctrlproxy 3.0.5 2007-12-07
 
   IMPROVEMENTS
index 84d8de8bb8c95373e63460e5780d035fb0283a69..f8fa41f2f2a41040dc8e2a1c1512bc490cd8b065 100644 (file)
@@ -272,7 +272,7 @@ static gboolean process_from_server(struct network *n, struct line *l)
                        } else if (run_server_filter(n, l, FROM_SERVER)) {
                                if (!strcmp(l->args[0], "PRIVMSG") && 
                                        n->global->config->report_time == REPORT_TIME_ALWAYS)
-                                       l = line_prefix_time(l, time(NULL));
+                                       l = line_prefix_time(l, time(NULL)+n->global->config->report_time_offset);
 
                                clients_send(n->clients, l, NULL);
                        }
@@ -525,7 +525,7 @@ gboolean network_send_line(struct network *s, struct client *c,
                !g_strcasecmp(l.args[0], "NOTICE"))) {
                g_assert(l.origin);
                if (s->global->config->report_time == REPORT_TIME_ALWAYS)
-                       line_prefix_time(&l, time(NULL));
+                       line_prefix_time(&l, time(NULL)+s->global->config->report_time_offset);
 
                clients_send(s->clients, &l, c);
        }
index 4c8524524ab16a09f6c550ee210a11d6adccafb8..4664e1577ec0f90720eec7b3c60e30a32cd91281 100644 (file)
@@ -496,7 +496,8 @@ static void cmd_backlog(admin_handle h, char **args, void *userdata)
                admin_out(h, "Sending backlog for network '%s'", n->info.name);
 
                linestack_send(n->linestack, lm, NULL, admin_get_client(h),
-                                          TRUE, n->global->config->report_time != REPORT_TIME_NEVER);
+                                          TRUE, n->global->config->report_time != REPORT_TIME_NEVER,
+                                          n->global->config->report_time_offset);
 
                g_hash_table_replace(markers, n, linestack_get_marker(n->linestack));
 
@@ -508,7 +509,8 @@ static void cmd_backlog(admin_handle h, char **args, void *userdata)
 
        linestack_send_object(n->linestack, args[1], lm, NULL, 
                                                  admin_get_client(h), TRUE, 
-                                                 n->global->config->report_time != REPORT_TIME_NEVER);
+                                                 n->global->config->report_time != REPORT_TIME_NEVER,
+                                                 n->global->config->report_time_offset);
 
        g_hash_table_replace(markers, n, linestack_get_marker(n->linestack));
 }
@@ -1102,6 +1104,22 @@ static gboolean max_who_age_set(admin_handle h, const char *value)
        return TRUE;
 }
 
+static char *report_time_offset_get(admin_handle h)
+{
+       struct global *g = admin_get_global(h);
+       
+       return g_strdup_printf("%d", g->config->report_time_offset);
+}
+
+static gboolean report_time_offset_set(admin_handle h, const char *value)
+{
+       struct global *g = admin_get_global(h);
+
+       g->config->report_time_offset = atoi(value);
+
+       return TRUE;
+}
+
 /**
  * Table of administration settings that can be
  * viewed and changed using the SET command.
@@ -1120,6 +1138,7 @@ static struct admin_setting {
        { "max_who_age", max_who_age_get, max_who_age_set },
        { "motd-file", motd_file_get, motd_file_set },
        { "report-time", report_time_get, report_time_set },
+       { "report-time-offset", report_time_offset_get, report_time_offset_set },
        { "replication", replication_get, replication_set },
        { NULL, NULL, NULL }
 };
index 18ea8715f6f48ca717d4a417b4bf2790b0946806..83ae4fdc31304a5b07f39925008f27b95d1990c7 100644 (file)
@@ -235,32 +235,37 @@ gboolean linestack_insert_line(struct linestack_context *ctx,
        return ctx->ops->insert_line(ctx, l, state);
 }
 
-static gboolean send_line(struct line *l, time_t t, void *_client)
+struct send_line_privdata {
+       int time_offset;
+       struct client *client;
+};
+
+static gboolean send_line(struct line *l, time_t t, void *_privdata)
 {
-       struct client *c = _client;
-       return client_send_line(c, l);
+       struct send_line_privdata *privdata = _privdata;
+       return client_send_line(privdata->client, l);
 }
 
-static gboolean send_line_timed(struct line *l, time_t t, void *_client)
+static gboolean send_line_timed(struct line *l, time_t t, void *_privdata)
 {
-       struct client *c = _client;
+       struct send_line_privdata *privdata = _privdata;
 
        if ((!g_strcasecmp(l->args[0], "PRIVMSG") ||
                !g_strcasecmp(l->args[0], "NOTICE")) &&
                l->argc > 2) {
-               struct line *nl = line_prefix_time(l, t);
+               struct line *nl = line_prefix_time(l, t+privdata->time_offset);
                gboolean ret;
-               ret = client_send_line(c, nl);
+               ret = client_send_line(privdata->client, nl);
                free_line(nl);
                return ret;
        } else {
-               return client_send_line(c, l);
+               return client_send_line(privdata->client, l);
        }
 }
 
-static gboolean send_line_timed_dataonly(struct line *l, time_t t, void *_client)
+static gboolean send_line_timed_dataonly(struct line *l, time_t t, void *_privdata)
 {
-       struct client *c = _client;
+       struct send_line_privdata *privdata = _privdata;
        gboolean ret;
        struct line *nl;
 
@@ -271,15 +276,15 @@ static gboolean send_line_timed_dataonly(struct line *l, time_t t, void *_client
        if (l->argc <= 2)
                return TRUE;
 
-       nl = line_prefix_time(l, t);
-       ret = client_send_line(c, nl);
+       nl = line_prefix_time(l, t+privdata->time_offset);
+       ret = client_send_line(privdata->client, nl);
        free_line(nl);
        return ret;
 }
 
-static gboolean send_line_dataonly(struct line *l, time_t t, void *_client)
+static gboolean send_line_dataonly(struct line *l, time_t t, void *_privdata)
 {
-       struct client *c = _client;
+       struct send_line_privdata *privdata = _privdata;
 
        if (g_strcasecmp(l->args[0], "PRIVMSG") != 0 && 
                g_strcasecmp(l->args[0], "NOTICE") != 0)
@@ -288,13 +293,17 @@ static gboolean send_line_dataonly(struct line *l, time_t t, void *_client)
        if (l->argc <= 2)
                return TRUE;
 
-       return client_send_line(c, l);
+       return client_send_line(privdata->client, l);
 }
 
-gboolean linestack_send(struct linestack_context *ctx, struct linestack_marker *mf, struct linestack_marker *mt, struct client *c, gboolean dataonly, gboolean timed)
+gboolean linestack_send(struct linestack_context *ctx, struct linestack_marker *mf, struct linestack_marker *mt, struct client *c, gboolean dataonly, gboolean timed, int time_offset)
 {
+       struct send_line_privdata privdata;
        linestack_traverse_fn trav_fn;
 
+       privdata.client = c;
+       privdata.time_offset = time_offset;
+
        if (dataonly) {
                if (timed) 
                        trav_fn = send_line_timed_dataonly;
@@ -307,12 +316,17 @@ gboolean linestack_send(struct linestack_context *ctx, struct linestack_marker *
                        trav_fn = send_line;
        }
 
-       return linestack_traverse(ctx, mf, mt, trav_fn, c);
+       return linestack_traverse(ctx, mf, mt, trav_fn, &privdata);
 }
 
-gboolean linestack_send_object(struct linestack_context *ctx, const char *obj, struct linestack_marker *mf, struct linestack_marker *mt, struct client *c, gboolean dataonly, gboolean timed)
+gboolean linestack_send_object(struct linestack_context *ctx, const char *obj, struct linestack_marker *mf, struct linestack_marker *mt, struct client *c, gboolean dataonly, gboolean timed, int time_offset)
 {
+       struct send_line_privdata privdata;
        linestack_traverse_fn trav_fn;
+
+       privdata.client = c;
+       privdata.time_offset = time_offset;
+
        if (dataonly) {
                if (timed) 
                        trav_fn = send_line_timed_dataonly;
@@ -325,7 +339,7 @@ gboolean linestack_send_object(struct linestack_context *ctx, const char *obj, s
                        trav_fn = send_line;
        }
 
-       return linestack_traverse_object(ctx, obj, mf, mt, trav_fn, c);
+       return linestack_traverse_object(ctx, obj, mf, mt, trav_fn, &privdata);
 }
 
 static gboolean replay_line(struct line *l, time_t t, void *state)
index 72867640bdf09d79cec46526248904cd806dd0ed..07346b45690f4e3487836e80f78c472d324baf30 100644 (file)
@@ -131,7 +131,8 @@ G_MODULE_EXPORT gboolean linestack_send (
                struct linestack_marker *to, /* Can be NULL for 'now' */
                struct client *, 
                gboolean dataonly, 
-               gboolean timed);
+               gboolean timed,
+               int time_offset);
 
 G_MODULE_EXPORT gboolean linestack_send_object (
                struct linestack_context *,
@@ -140,7 +141,8 @@ G_MODULE_EXPORT gboolean linestack_send_object (
                struct linestack_marker *to, /* Can be NULL for 'now' */
                struct client *,
                gboolean dataonly,
-               gboolean timed);
+               gboolean timed,
+               int time_offset);
 
 G_MODULE_EXPORT gboolean linestack_replay (
                struct linestack_context *,
index 32571137bae0190ff718cce3f1c6394ffbbb87f6..508dd29d19751e92d045b605255900e31f272d39 100644 (file)
@@ -89,7 +89,8 @@ static void lastdisconnect_replicate(struct client *c)
        free_network_state(ns);
 
        linestack_send(c->network->linestack, lm, NULL, c, FALSE, 
-                                  c->network->global->config->report_time != REPORT_TIME_NEVER);
+                                  c->network->global->config->report_time != REPORT_TIME_NEVER,
+                                  c->network->global->config->report_time_offset);
 }
 
 static gboolean log_data(struct network *n, const struct line *l, enum data_direction dir, void *userdata) 
@@ -122,7 +123,8 @@ static void simple_replicate(struct client *c)
        free_network_state(ns);
 
        linestack_send(c->network->linestack, m, NULL, c, FALSE, 
-                                  c->network->global->config->report_time != REPORT_TIME_NEVER);
+                                  c->network->global->config->report_time != REPORT_TIME_NEVER,
+                                  c->network->global->config->report_time_offset);
 }
 
 static const struct replication_backend backends[] = {
index fcbec05d7c2528cf9651ced05c2f61491fbadbcb..7c0f389424f2cdf0fc83c49083c28b791318f3c5 100644 (file)
@@ -51,6 +51,7 @@ static const char *builtin_known_keys[] = {
        "replication",
        "linestack",
        "report-time",
+       "report-time-offset",
        "motd-file",
        "default-client-charset",
        "learn-nickserv",
@@ -369,6 +370,10 @@ void save_configuration(struct ctrlproxy_config *cfg, const char *configuration_
                break;
        }
 
+       if (cfg->report_time_offset != 0 ||
+               g_key_file_has_key(cfg->keyfile, "global", "report-time-offset", NULL))
+               g_key_file_set_integer(cfg->keyfile, "global", "report-time-offset", cfg->report_time_offset);
+
        config_save_networks(configuration_dir, cfg->networks);
 
        config_save_listeners(cfg, configuration_dir);
@@ -1037,6 +1042,11 @@ struct ctrlproxy_config *load_configuration(const char *dir)
                g_free(setting);
        }
 
+       cfg->report_time_offset = 0;
+       if (g_key_file_has_key(kf, "global", "report-time-offset", NULL)) {
+               cfg->report_time_offset = g_key_file_get_integer(kf, "global", "report-time-offset", NULL);
+       }
+
     if (g_key_file_has_key(kf, "global", "motd-file", NULL))
                cfg->motd_file = g_key_file_get_string(kf, "global", "motd-file", NULL);
     else 
index 61a7608ff20989952678bae54e2a8f1fee24d5bd..9364a1c27636da10c0611a9d2a84e4469243b590 100644 (file)
@@ -156,6 +156,7 @@ struct ctrlproxy_config {
                REPORT_TIME_NEVER,
                REPORT_TIME_REPLICATION
        } report_time;
+       int report_time_offset;
        int max_who_age;
        GKeyFile *keyfile;
        GList *listeners;