]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add event_add_int_non_zero()
authorsergey.kitov <sergey.kitov@open-xchange.com>
Tue, 7 Dec 2021 14:58:43 +0000 (16:58 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 26 Jan 2022 09:11:52 +0000 (09:11 +0000)
src/lib/lib-event.c
src/lib/lib-event.h

index 77b07f6bbe65dd4983d43b8e2f68fc9c5e071f75..87db436c84672fdcffb2eb678b7f1194b71b226a 100644 (file)
@@ -1099,6 +1099,14 @@ event_add_int(struct event *event, const char *key, intmax_t num)
        return event;
 }
 
+struct event *
+event_add_int_nonzero(struct event *event, const char *key, intmax_t num)
+{
+       if (num != 0)
+               return event_add_int(event, key, num);
+       return event;
+}
+
 struct event *
 event_inc_int(struct event *event, const char *key, intmax_t num)
 {
@@ -1663,6 +1671,13 @@ event_passthrough_add_int(const char *key, intmax_t num)
        return &event_passthrough_vfuncs;
 }
 
+static struct event_passthrough *
+event_passthrough_add_int_nonzero(const char *key, intmax_t num)
+{
+       event_add_int_nonzero(last_passthrough_event(), key, num);
+       return &event_passthrough_vfuncs;
+}
+
 static struct event_passthrough *
 event_passthrough_add_timeval(const char *key, const struct timeval *tv)
 {
@@ -1702,6 +1717,7 @@ struct event_passthrough event_passthrough_vfuncs = {
        .add_fields = event_passthrough_add_fields,
        .add_str = event_passthrough_add_str,
        .add_int = event_passthrough_add_int,
+       .add_int_nonzero = event_passthrough_add_int_nonzero,
        .add_timeval = event_passthrough_add_timeval,
        .inc_int = event_passthrough_inc_int,
        .strlist_append = event_passthrough_strlist_append,
index 9d92901a31e8a445b11cb6db4c735e8bb194c1c9..74aafd72f9618e119152a52673bbe72bb74fbc28 100644 (file)
@@ -81,6 +81,8 @@ struct event_passthrough {
                (*add_str)(const char *key, const char *value);
        struct event_passthrough *
                (*add_int)(const char *key, intmax_t num);
+       struct event_passthrough *
+               (*add_int_nonzero)(const char *key, intmax_t num);
        struct event_passthrough *
                (*add_timeval)(const char *key, const struct timeval *tv);
 
@@ -329,6 +331,9 @@ struct event *
 event_add_str(struct event *event, const char *key, const char *value);
 struct event *
 event_add_int(struct event *event, const char *key, intmax_t num);
+/* Adds int value to event if it is non-zero */
+struct event *
+event_add_int_nonzero(struct event *event, const char *key, intmax_t num);
 /* Increase the key's value. If it's not set or isn't an integer type,
    initialize the value to num. */
 struct event *