push-notification-driver-ox.c revision 0f58da3fd10d43bf701eba068cb3b84a216f89f1
/* 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. */
#define DEFAULT_CACHE_LIFETIME 60
#define DEFAULT_TIMEOUT_MSECS 2000
#define DEFAULT_RETRY_COUNT 1
/* 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 {
unsigned int cached_ox_metadata_lifetime;
bool use_unsafe_username;
unsigned int http_max_retries;
unsigned int http_timeout_msecs;
char *cached_ox_metadata;
};
/* This is data specific to an OX driver transaction. */
struct push_notification_driver_ox_txn {
const char *unsafe_user;
};
static void
struct push_notification_driver_ox_config *config)
{
struct http_client_settings http_set;
/* this is going to use the first user's settings, but these are
unlikely to change between users so it shouldn't matter much. */
}
}
static int
{
/* Valid config keys: cache_lifetime, url */
return -1;
}
return -1;
}
}
}
}
"Using cache lifetime: %u",
}
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;
return dconfig->cached_ox_metadata;
}
/* 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) {
}
if (!success)
return NULL;
return dconfig->cached_ox_metadata;
}
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 = {
}
};