push-notification-driver-ox.c revision 3e13cdffb51ff975f70f347d143c89c19f46091f
/* Copyright (c) 2015 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "hash.h"
#include "http-client.h"
#include "http-url.h"
#include "ioloop.h"
#include "istream.h"
#include "json-parser.h"
#include "mailbox-attribute.h"
#include "mail-storage-private.h"
#include "str.h"
#include "push-notification-drivers.h"
#include "push-notification-event-messagenew.h"
#include "push-notification-events.h"
#include "push-notification-txn-msg.h"
#define OX_LOG_LABEL "OX Push Notification: "
#define OX_METADATA_KEY \
/* Default values. */
/* This is data that is shared by all plugin users. */
struct push_notification_driver_ox_global {
struct http_client *http_client;
int refcount;
};
/* This is data specific to an OX driver. */
struct push_notification_driver_ox_config {
};
/* This is data specific to an OX driver transaction. */
struct push_notification_driver_ox_txn {
const char *user;
};
static void
{
struct http_client_settings http_set;
}
}
static int
{
/* Valid config keys: url */
return -1;
}
return -1;
}
}
return 0;
}
static const char *push_notification_driver_ox_get_metadata
(struct push_notification_driver_txn *dtxn)
{
struct mail_attribute_value attr;
struct mail_namespace *ns;
int ret;
/* Get canonical INBOX, where private server-level metadata is stored.
* See imap/cmd-getmetadata.c */
/* Use the currently open transaction. */
} else {
if (mailbox_open(inbox) < 0) {
} else {
}
}
OX_METADATA_KEY, &attr);
if (ret < 0) {
} else if (ret == 0) {
} else {
}
/* the commit doesn't matter though. */
}
}
if (!use_existing_txn) {
}
}
static bool push_notification_driver_ox_begin_txn
(struct push_notification_driver_txn *dtxn)
{
const char *const *args;
bool mbox_found = FALSE;
struct push_notification_driver_ox_txn *txn;
return FALSE;
}
/* Unused keys: events, expire, folder */
/* TODO: To be implemented later(?) */
const char *const *events = default_events;
const char *const *mboxes = default_mboxes;
if (expire < ioloop_time) {
"Skipped due to expiration (%ld < %ld)",
(long)expire, (long)ioloop_time);
return FALSE;
}
mbox_found = TRUE;
break;
}
}
if (mbox_found == FALSE) {
"Skipped because %s is not a watched mailbox",
return FALSE;
}
/* Valid keys: user */
}
}
}
return FALSE;
}
struct push_notification_event_messagenew_config, 1);
"Handling MessageNew event");
}
}
return TRUE;
}
static void push_notification_driver_ox_http_callback
{
case 2:
// Success.
if (user->mail_debug) {
"Notification sent successfully: %u %s",
}
break;
default:
// Error.
break;
}
}
/* Callback needed for i_stream_add_destroy_callback() in
* push_notification_driver_ox_process_msg. */
{
}
static void push_notification_driver_ox_process_msg
(struct push_notification_driver_txn *dtxn,
struct push_notification_txn_msg *msg)
{
struct push_notification_driver_ox_config *dconfig =
struct http_client_request *http_req;
struct push_notification_driver_ox_txn *txn =
if (messagenew == NULL) {
return;
}
user);
"application/json; charset=utf-8");
}
}
}
}
static void push_notification_driver_ox_deinit
{
}
}
static void push_notification_driver_ox_cleanup(void)
{
}
}
}
/* Driver definition */
extern struct push_notification_driver push_notification_driver_ox;
.name = "ox",
.v = {
}
};