bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_txn_msg_create(struct push_notification_txn *txn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_msg *msg = NULL;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if (hash_table_is_created(txn->messages)) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz hash_table_create_direct(&txn->messages, txn->pool, 4);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz msg = p_new(txn->pool, struct push_notification_txn_msg, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz msg->mailbox = mailbox_get_vname(mail->box);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz /* Save sequence number - used to determine UID later. */
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz hash_table_insert(txn->messages, POINTER_CAST(txn->t->save_count + 1),
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_txn_msg_end(struct push_notification_txn *ptxn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct mail_transaction_commit_changes *changes)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_driver_txn **dtxn;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if (!hash_table_is_created(ptxn->messages)) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz hiter = hash_table_iterate_init(ptxn->messages);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz seq_range_array_iter_init(&siter, &changes->saved_uids);
2d7ad82a356217c7d763c7075aa3526129373bd8Timo Sirainen /* uid_validity is only set in changes if message is new. */
2d7ad82a356217c7d763c7075aa3526129373bd8Timo Sirainen mailbox_get_open_status(ptxn->mbox, STATUS_UIDVALIDITY, &status);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz while (hash_table_iterate(hiter, ptxn->messages, &key, &value)) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if (seq_range_array_iter_nth(&siter, value->seq, &uid)) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_foreach_modifiable(&ptxn->drivers, dtxn) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if ((*dtxn)->duser->driver->v.process_msg != NULL) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz (*dtxn)->duser->driver->v.process_msg(*dtxn, value);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz push_notification_txn_msg_deinit_eventdata(value);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_txn_msg_get_eventdata(struct push_notification_txn_msg *msg,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_event **mevent;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_foreach_modifiable(&msg->eventdata, mevent) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz if (strcmp((*mevent)->event->event->name, event_name) == 0) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_txn_msg_set_eventdata(struct push_notification_txn *txn,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_event_config *event,
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_event *mevent;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz p_array_init(&msg->eventdata, txn->pool, 4);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz mevent = p_new(txn->pool, struct push_notification_txn_event, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_append(&msg->eventdata, &mevent, 1);
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarzpush_notification_txn_msg_deinit_eventdata(struct push_notification_txn_msg *msg)
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz struct push_notification_txn_event **mevent;
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz array_foreach_modifiable(&msg->eventdata, mevent) {
51ed197520dd9ea534fbc3bc1790ebe3cb5421e2Michael M Slusarz ((*mevent)->event->event->msg.free_msg != NULL)) {