You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.4 KiB
C++
129 lines
3.4 KiB
C++
2 years ago
|
// This file is under GNU General Public License 3.0
|
||
|
// see LICENSE.txt
|
||
|
|
||
|
#ifndef LIBPEPADAPTER_MESSAGE_CACHE_HH
|
||
|
#define LIBPEPADAPTER_MESSAGE_CACHE_HH
|
||
3 years ago
|
|
||
|
#include <string>
|
||
|
#include <unordered_map>
|
||
|
#include <mutex>
|
||
|
#include <pEp/message_api.h>
|
||
|
#include <pEp/mime.h>
|
||
|
|
||
|
namespace pEp {
|
||
|
class MessageCache {
|
||
|
struct cache_entry {
|
||
2 years ago
|
cache_entry(::message *s, ::message *d) : src(s), dst(d) {}
|
||
3 years ago
|
|
||
|
::message *src;
|
||
|
::message *dst;
|
||
|
};
|
||
|
|
||
|
using cache = std::unordered_map<std::string, cache_entry>;
|
||
|
|
||
|
cache _cache;
|
||
|
std::mutex _mtx;
|
||
3 years ago
|
long long id_range = 42;
|
||
3 years ago
|
long long next_id = 23;
|
||
3 years ago
|
|
||
|
public:
|
||
3 years ago
|
MessageCache();
|
||
|
|
||
2 years ago
|
enum which
|
||
|
{
|
||
|
msg_src = 0,
|
||
|
msg_dst = 1
|
||
|
};
|
||
3 years ago
|
|
||
2 years ago
|
static PEP_STATUS cache_mime_decode_message(
|
||
|
const char *mimetext,
|
||
|
size_t size,
|
||
|
message **msg,
|
||
|
bool *has_possible_pEp_msg);
|
||
3 years ago
|
|
||
3 years ago
|
static PEP_STATUS cache_mime_encode_message(
|
||
2 years ago
|
int one,
|
||
|
const message *msg,
|
||
|
bool omit_fields,
|
||
|
char **mimetext,
|
||
|
bool has_pEp_msg_attachment);
|
||
3 years ago
|
|
||
3 years ago
|
static PEP_STATUS cache_decrypt_message(
|
||
2 years ago
|
PEP_SESSION session,
|
||
|
message *src,
|
||
|
message **dst,
|
||
|
stringlist_t **keylist,
|
||
|
PEP_rating *rating,
|
||
|
PEP_decrypt_flags_t *flags);
|
||
|
|
||
|
static PEP_STATUS cache_encrypt_message(
|
||
|
PEP_SESSION session,
|
||
|
message *src,
|
||
|
stringlist_t *extra,
|
||
|
message **dst,
|
||
|
PEP_enc_format enc_format,
|
||
|
PEP_encrypt_flags_t flags);
|
||
3 years ago
|
|
||
3 years ago
|
static PEP_STATUS cache_encrypt_message_for_self(
|
||
2 years ago
|
PEP_SESSION session,
|
||
|
pEp_identity *target_id,
|
||
|
message *src,
|
||
|
stringlist_t *extra,
|
||
|
message **dst,
|
||
|
PEP_enc_format enc_format,
|
||
|
PEP_encrypt_flags_t flags);
|
||
3 years ago
|
|
||
|
|
||
3 years ago
|
static PEP_STATUS cache_release(std::string id);
|
||
2 years ago
|
static void removeCacheID(::message *msg);
|
||
3 years ago
|
|
||
|
protected:
|
||
3 years ago
|
void release(std::string id);
|
||
|
|
||
2 years ago
|
PEP_STATUS mime_decode_message(
|
||
|
const char *mimetext,
|
||
|
size_t size,
|
||
|
message **msg,
|
||
|
bool *has_possible_pEp_msg);
|
||
3 years ago
|
|
||
|
PEP_STATUS mime_encode_message(
|
||
2 years ago
|
which one,
|
||
|
const message *src,
|
||
|
bool omit_fields,
|
||
|
char **mimetext,
|
||
|
bool has_pEp_msg_attachment);
|
||
3 years ago
|
|
||
3 years ago
|
PEP_STATUS decrypt_message(
|
||
2 years ago
|
PEP_SESSION session,
|
||
|
message *src,
|
||
|
message **dst,
|
||
|
stringlist_t **keylist,
|
||
|
PEP_rating *rating,
|
||
|
PEP_decrypt_flags_t *flags);
|
||
|
|
||
|
PEP_STATUS encrypt_message(
|
||
|
PEP_SESSION session,
|
||
|
message *src,
|
||
|
stringlist_t *extra,
|
||
|
message **dst,
|
||
|
PEP_enc_format enc_format,
|
||
|
PEP_encrypt_flags_t flags);
|
||
3 years ago
|
|
||
3 years ago
|
PEP_STATUS encrypt_message_for_self(
|
||
2 years ago
|
PEP_SESSION session,
|
||
|
pEp_identity *target_id,
|
||
|
message *src,
|
||
|
stringlist_t *extra,
|
||
|
message **dst,
|
||
|
PEP_enc_format enc_format,
|
||
|
PEP_encrypt_flags_t flags);
|
||
|
|
||
|
void generateCacheID(::message *msg);
|
||
|
static std::string cacheID(const ::message *msg);
|
||
3 years ago
|
};
|
||
|
|
||
|
extern MessageCache message_cache;
|
||
2 years ago
|
}; // namespace pEp
|
||
3 years ago
|
|
||
2 years ago
|
#endif // LIBPEPADAPTER_MESSAGE_CACHE_HH
|