210 lines
6.5 KiB
C++
210 lines
6.5 KiB
C++
// Copyright (c) 2013, IOnU Security, Inc.
|
|
// Copyright (c) 2016, Sequence Logic, Inc. All rights reserved.
|
|
|
|
#ifndef PUB_SUB_MESSAGE
|
|
#define PUB_SUB_MESSAGE
|
|
|
|
#include "eyetime.h"
|
|
|
|
#include "../cppcoreobjects/cloudguardurn.h"
|
|
|
|
#include <iosfwd>
|
|
|
|
#ifdef WIN32
|
|
#ifdef SL_CPPCORE_DLLEXPORT
|
|
#define SL_CPPCORE_EXPORT __declspec(dllexport)
|
|
#else
|
|
#define SL_CPPCORE_EXPORT __declspec(dllimport)
|
|
#endif
|
|
#else
|
|
#define SL_CPPCORE_EXPORT
|
|
#endif
|
|
|
|
namespace sequencelogic
|
|
{
|
|
class PubSubMessage;
|
|
typedef std::shared_ptr<PubSubMessage> PubSubMessagePtr;
|
|
|
|
class JSONObject;
|
|
typedef std::shared_ptr<JSONObject> JSONObjectPtr;
|
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4251 4275) // Disable the dumbass XXXX needs to have dll-interface.
|
|
#endif
|
|
class SL_CPPCORE_EXPORT PubSubMessage
|
|
{
|
|
public:
|
|
enum Action
|
|
{
|
|
PING, // Client A says hello to client B and expects a PONG in reply
|
|
PONG, // Reply to PING/CHAT/REMOVE_DEVICE
|
|
REMOVE_DEVICE, //
|
|
LOGOUT_DEVICE, //
|
|
SHARE, // User A shares a Permissions digest (folder) with a destination
|
|
// no response required, but the receiver can dispose of this to
|
|
// remove any trace that A and B are sharing data
|
|
MODIFY_PROFILE, // sent from device to all offices to indicate office updated
|
|
SHARE_RECEIVED, // Sent by client as "delivery receipt"
|
|
MESSAGE_READ, // Sent by client to indicate user has eyeballed a message
|
|
FLUSH, // Message to flush the local TGI key cache.
|
|
|
|
// SL specific
|
|
STATISTICS_REQUEST, // please give me statistics
|
|
STATISTICS_REPLY, // responseData is a JSONObject with stat keys
|
|
WORKFLOW_READY, // actionData has urn (package) and purpose (wstate)
|
|
WORKFLOW_TRANSITION, // @see WorkflowBot.transitionNode for actionData
|
|
|
|
NONE // No action
|
|
};
|
|
|
|
enum ReplyType
|
|
{
|
|
ANY,
|
|
P2P,
|
|
PUBSUB_MESSAGE
|
|
};
|
|
|
|
static const int VERSION_122;
|
|
static const int VERSION_CURRENT;
|
|
static const char VERSION_TAG[];
|
|
|
|
PubSubMessage();
|
|
PubSubMessage(const CloudGuardURN &src, const CloudGuardURN &dest,
|
|
Action act = NONE, const EyeTime &issueDate = EyeTime());
|
|
PubSubMessage(const std::string &msg);
|
|
PubSubMessage(const JSONObject &msg);
|
|
|
|
std::string toDebugString() const;
|
|
|
|
/**
|
|
* Messages are equivalent if they have the same source, destination, action and actionData values.
|
|
* @param other
|
|
* @return
|
|
*/
|
|
bool isEquivalent(const PubSubMessage &other) const;
|
|
|
|
void setSource(const CloudGuardURN &urn);
|
|
CloudGuardURN getSource() const;
|
|
|
|
void setDestination(const CloudGuardURN &urn);
|
|
CloudGuardURN getDestination() const;
|
|
|
|
/**
|
|
* When publishing a new message this is NOT set by calling client, but rather the server. It will
|
|
* be returned (set) when message is published.
|
|
* @param id
|
|
*/
|
|
void setMessageIdentifier(const std::string &id);
|
|
std::string getMessageIdentifier() const;
|
|
|
|
/**
|
|
* For duplicate messages, it is useful to know how many times this message was attempted.
|
|
* Caller typically doesn't set this, the server does, ala messageIdentifier.
|
|
* @param attempts
|
|
*/
|
|
void setAttempts(int attempts);
|
|
int getAttempts() const;
|
|
|
|
/**
|
|
* Do not use! Client can not reliably set issue date, clock is not synchronized
|
|
* to server.
|
|
*/
|
|
EyeTime getIssueDate() const;
|
|
|
|
int getVersion() const;
|
|
|
|
/**
|
|
* As a side effect, this will set the Expires TTL. If you want a specific TTL set AFTER calling this
|
|
* method.
|
|
* @param a
|
|
*/
|
|
void setAction(Action a);
|
|
Action getAction() const;
|
|
|
|
void setActionData(const JSONObject &data);
|
|
JSONObjectPtr getActionData() const;
|
|
|
|
bool isManualUserReplyRequired() const;
|
|
|
|
void setPermittedReplyType(ReplyType rt);
|
|
ReplyType getPermittedReplyType() const;
|
|
|
|
void setActualReplyType(ReplyType rt);
|
|
ReplyType getActualReplyType() const;
|
|
|
|
void setInReplyToMessageIdentifier(const std::string &id);
|
|
std::string getInReplyToMessageIdentifier() const;
|
|
|
|
Action getReplyToAction() const;
|
|
|
|
void setExpires(const EyeTime &date);
|
|
EyeTime getExpires() const;
|
|
|
|
void setResponseData(const JSONObject &data);
|
|
/**
|
|
* This is only valid if NOT replyType P2P and inReplyToMessageIdentifier is set, e.g. this is an inline
|
|
* response. Note the contents can be very large, e.g. a Base64 encoded .eye file, etc.
|
|
* @return
|
|
*/
|
|
JSONObjectPtr getResponseData() const;
|
|
|
|
/**
|
|
* Check if this message is fully configured.
|
|
* Optional parameter returns an error string.
|
|
* @return
|
|
*/
|
|
bool isValid(std::string *pOptError = NULL) const;
|
|
void invalidate();
|
|
|
|
bool isExpired() const;
|
|
|
|
void setProcessed(const EyeTime &date);
|
|
bool isProcessed() const;
|
|
|
|
CloudGuardURN::URN_TYPE getPublishType() const;
|
|
|
|
static Action getActionFromName(const std::string &actName);
|
|
static std::string getActionName(Action act);
|
|
|
|
std::string toString() const;
|
|
const JSONObject &toJSONObj() const;
|
|
|
|
bool isEmpty() const;
|
|
private:
|
|
static const long long MS_MINUTE = 60L * 1000L;
|
|
static const long long MS_HOUR = 60L * MS_MINUTE;
|
|
static const long long MS_DAY = 24L * MS_HOUR;
|
|
|
|
JSONObjectPtr _pData;
|
|
|
|
struct ActionResponseTTLData
|
|
{
|
|
Action _action;
|
|
Action _reply;
|
|
long long _nTTL; // Microsoft defines a long to be 32 bits, not 64.
|
|
bool _bManualReply;
|
|
CloudGuardURN::URN_TYPE _nUrnType;
|
|
};
|
|
static const ActionResponseTTLData ActionResponseTTL[];
|
|
static const int NUM_ActionResponseTTL;
|
|
|
|
static const char* ACTION_NAMES[];
|
|
static const int NUM_ACTION_NAMES;
|
|
|
|
static const char* REPLY_TYPE_NAMES[];
|
|
static const int NUM_REPLY_TYPE_NAMES;
|
|
static std::string getReplyTypeName(ReplyType rt);
|
|
static ReplyType getReplyFromName(const std::string &rtName);
|
|
|
|
bool _bDispose;
|
|
};
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
#pragma warning(pop)
|
|
#endif
|
|
SL_CPPCORE_EXPORT std::ostream& operator<<(std::ostream &out, const PubSubMessage &msg);
|
|
};
|
|
|
|
|
|
#endif
|