71 lines
2.2 KiB
C
71 lines
2.2 KiB
C
|
|
/*
|
||
|
|
Copyright (c) 2013, 2014 IOnU Security Inc. All rights reserved. Copyright (c) 2015, 2016 Sequence Logic, Inc.
|
||
|
|
Created August 2013 by Kendrick Webster
|
||
|
|
|
||
|
|
K2Daemon/MongoNotifyQueue.h - database interface for ionu
|
||
|
|
push notification queue in MongoDB.
|
||
|
|
*/
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
#include "MongoDB.h"
|
||
|
|
|
||
|
|
namespace MongoDB
|
||
|
|
{
|
||
|
|
namespace nqueue
|
||
|
|
{
|
||
|
|
/*
|
||
|
|
Database and collection names
|
||
|
|
|
||
|
|
A collection is a group of documents (BSON objects).
|
||
|
|
A database contains zero or more named collections.
|
||
|
|
|
||
|
|
These hard-coded values are agreed upon between CloudGuard and
|
||
|
|
this application.
|
||
|
|
*/
|
||
|
|
constexpr const char* DATABASE_NAME = "sequencelogic";
|
||
|
|
constexpr const char* COLLECTION_NAME = "nqueue";
|
||
|
|
//constexpr const char* NAMESPACE = "sequencelogic.nqueue";
|
||
|
|
|
||
|
|
// Values for the "type" field of notification queue documents
|
||
|
|
constexpr const char* TYPE_K2 = "K2"; // From cloudguard, try sending via K2
|
||
|
|
constexpr const char* TYPE_PUSH = "PUSH"; // Requeued due to client not connected, use slow push notifications
|
||
|
|
constexpr const char* TYPE_K2ACK = "K2ACK"; // K2 notification sent, awaiting client ACK
|
||
|
|
constexpr const char* TYPE_K2DFR = "K2DFR"; // Deferred due to K2 transaction already in progress for this client
|
||
|
|
|
||
|
|
// A document within the notification queue
|
||
|
|
typedef struct doc_
|
||
|
|
{
|
||
|
|
std::string id;
|
||
|
|
std::string device;
|
||
|
|
std::string type;
|
||
|
|
std::string info;
|
||
|
|
std::string expires;
|
||
|
|
std::string time;
|
||
|
|
struct doc_* next;
|
||
|
|
}
|
||
|
|
doc_t;
|
||
|
|
|
||
|
|
// Returns a list of documents of <type> (TYPE_K2, TYPE_K2DFR, et. al.)
|
||
|
|
// Sets <try_again> to <true> if a transient connection problem prevented the DB from being queried
|
||
|
|
doc_t* GetByType(const char* type, bool& try_again);
|
||
|
|
|
||
|
|
// Updates <doc->type> for the document matching <doc->id>
|
||
|
|
void Update(doc_t& doc);
|
||
|
|
|
||
|
|
// Updates the <type> field of all DB documents matching <device>
|
||
|
|
void UpdateAllDeviceRecords(const char* device, const char* type);
|
||
|
|
|
||
|
|
// Deletes the document specified by <id>
|
||
|
|
void Delete(const char* id);
|
||
|
|
|
||
|
|
// Call periodically to do background stuff (i.e. flush updates that may have been deferred due to transient connectivity issues)
|
||
|
|
void Timer(void);
|
||
|
|
|
||
|
|
#ifdef TEST_MONGODB
|
||
|
|
// Inserts test data into the collection
|
||
|
|
void AddTestData(void);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
}
|