]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add event_inc_int()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 15 Aug 2018 13:33:49 +0000 (16:33 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Aug 2018 06:15:09 +0000 (06:15 +0000)
This can be useful when updating counter fields.

src/lib/lib-event.c
src/lib/lib-event.h

index 416e6b56dd962d15106521218691261844a28925..dd331e9040378da91156d64facd63528a239d506 100644 (file)
@@ -419,6 +419,19 @@ event_add_int(struct event *event, const char *key, intmax_t num)
        return event;
 }
 
+struct event *
+event_inc_int(struct event *event, const char *key, intmax_t num)
+{
+       struct event_field *field;
+
+       field = event_find_field_int(event, key);
+       if (field == NULL || field->value_type != EVENT_FIELD_VALUE_TYPE_INTMAX)
+               return event_add_int(event, key, num);
+
+       field->value.intmax += num;
+       return event;
+}
+
 struct event *
 event_add_timeval(struct event *event, const char *key,
                  const struct timeval *tv)
index cd4a84abdb2f831e364a9ccd9df7434462b30b92..aeb56ac686d78e43a1f5f681bc597b7a5b662d05 100644 (file)
@@ -167,6 +167,10 @@ 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);
+/* Increase the key's value. If it's not set or isn't an integer type,
+   initialize the value to num. */
+struct event *
+event_inc_int(struct event *event, const char *key, intmax_t num);
 struct event *
 event_add_timeval(struct event *event, const char *key,
                  const struct timeval *tv);