]> 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)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Nov 2018 13:02:12 +0000 (15:02 +0200)
This can be useful when updating counter fields.

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

index 4c66fdf515ca69663425c5916cf686264db54303..2a9fbbeb128342c1978bb0ae844fc9f121c826a1 100644 (file)
@@ -488,6 +488,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 5c3306eab4fde6a84a417daf000bc50103cd1d09..7e055d7b1e376da0761cf268cb357837c2c0bc83 100644 (file)
@@ -182,6 +182,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);