Skip to content

Commit e38995b

Browse files
committed
email_lib: add disk I/O wrapper for MJSON
1 parent 78e1bc6 commit e38995b

File tree

5 files changed

+149
-183
lines changed

5 files changed

+149
-183
lines changed

include/gromox/mjson.hpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22
#include <memory>
33
#include <optional>
44
#include <string>
5+
#include <unordered_map>
56
#include <vector>
67
#include <json/value.h>
78
#include <gromox/util.hpp>
89

910
struct MJSON_MIME;
1011
using MJSON_MIME_ENUM = void (*)(MJSON_MIME *, void *);
1112

13+
struct GX_EXPORT mjson_io {
14+
std::unordered_map<std::string, std::string> m_cache;
15+
using c_iter = decltype(m_cache)::const_iterator;
16+
17+
bool exists(const std::string &path) const;
18+
c_iter find(const std::string &path);
19+
void place(const std::string &path, std::string &&ctnt);
20+
void clear() { m_cache.clear(); }
21+
bool valid(c_iter it) const { return it != m_cache.cend(); }
22+
bool invalid(c_iter it) const { return it == m_cache.cend(); }
23+
static std::string substr(c_iter it, size_t of, size_t ln);
24+
};
25+
1226
struct GX_EXPORT MJSON_MIME {
1327
std::vector<MJSON_MIME> children;
1428
enum mime_type mime_type = mime_type::none;
@@ -50,12 +64,12 @@ struct GX_EXPORT MJSON {
5064

5165
void clear();
5266
BOOL load_from_json(const Json::Value &);
53-
int fetch_structure(const char *cset, BOOL ext, std::string &out) const;
67+
int fetch_structure(mjson_io &, const char *cset, BOOL ext, std::string &out) const;
5468
int fetch_envelope(const char *cset, std::string &out) const;
5569
bool has_rfc822_part() const;
56-
BOOL rfc822_build(const char *storage_path) const;
57-
BOOL rfc822_get(MJSON *other_pjson, const char *storage_path, const char *id, char *mjson_id, char *mime_id) const;
58-
int rfc822_fetch(const char *storage_path, const char *cset, BOOL ext, std::string &out) const;
70+
BOOL rfc822_build(mjson_io &, const char *storage_path) const;
71+
BOOL rfc822_get(mjson_io &, MJSON *other_pjson, const char *storage_path, const char *id, char *mjson_id, char *mime_id) const;
72+
int rfc822_fetch(mjson_io &, const char *storage_path, const char *cset, BOOL ext, std::string &out) const;
5973
const char *get_mail_filename() const { return filename.c_str(); }
6074
const char *get_mail_received() const { return received.c_str(); }
6175
const char *get_mail_messageid() const { return msgid.c_str(); }

0 commit comments

Comments
 (0)