bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz#include "push-notification-event-flagsset.h"
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic struct push_notification_event_flagsset_config default_config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void *push_notification_event_flagsset_default_config(void)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsset_debug_msg
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz(struct push_notification_txn_event *event)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsset_data *data = event->data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Answered flag set", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Flagged flag set", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Deleted flag set", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Draft flag set", EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_foreach(&data->keywords_set, keyword) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz i_debug("%s: Keyword set [%s]", EVENT_NAME, *keyword);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic struct push_notification_event_flagsset_data *
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_event_flagsset_get_data(struct push_notification_txn *ptxn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *ec)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsset_data *data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = push_notification_txn_msg_get_eventdata(msg, EVENT_NAME);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsset_data, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz p_array_init(&data->keywords_set, ptxn->pool, 4);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz push_notification_txn_msg_set_eventdata(ptxn, msg, ec, data);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsset_flags_event(
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *ec,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsset_config *config =
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz (struct push_notification_event_flagsset_config *)ec->config;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsset_data *data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz unsigned int i;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz for (i = 0; i < N_ELEMENTS(flag_check_always); i++) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Only create data element if at least one flag was set. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = push_notification_event_flagsset_get_data(ptxn, msg, ec);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsset_keywords_event(
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *ec,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *const *old_keywords)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsset_data *data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz const char *k, *const *keywords, *const *op;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz data = push_notification_event_flagsset_get_data(ptxn, msg, ec);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz for (op = old_keywords; *op != NULL; op++) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstatic void push_notification_event_flagsset_free_msg(
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_event *event)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_flagsset_data *data = event->data;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if (array_is_created(&data->keywords_set)) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz/* Event definition */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzextern struct push_notification_event push_notification_event_flagsset;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzstruct push_notification_event push_notification_event_flagsset = {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .default_config = push_notification_event_flagsset_default_config
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .debug_msg = push_notification_event_flagsset_debug_msg,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .free_msg = push_notification_event_flagsset_free_msg
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz .flagchange = push_notification_event_flagsset_flags_event,