From: Timo Sirainen Date: Wed, 15 Aug 2018 13:33:49 +0000 (+0300) Subject: lib: Add event_inc_int() X-Git-Tag: 2.3.9~1556 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12927b843387b2a93fcf1d2e05df7c79af06e567;p=thirdparty%2Fdovecot%2Fcore.git lib: Add event_inc_int() This can be useful when updating counter fields. --- diff --git a/src/lib/lib-event.c b/src/lib/lib-event.c index 416e6b56dd..dd331e9040 100644 --- a/src/lib/lib-event.c +++ b/src/lib/lib-event.c @@ -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) diff --git a/src/lib/lib-event.h b/src/lib/lib-event.h index cd4a84abdb..aeb56ac686 100644 --- a/src/lib/lib-event.h +++ b/src/lib/lib-event.h @@ -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);