|
2 | 2 | #include <memory> |
3 | 3 | #include <optional> |
4 | 4 | #include <string> |
| 5 | +#include <unordered_map> |
5 | 6 | #include <vector> |
6 | 7 | #include <json/value.h> |
7 | 8 | #include <gromox/util.hpp> |
8 | 9 |
|
9 | 10 | struct MJSON_MIME; |
10 | 11 | using MJSON_MIME_ENUM = void (*)(MJSON_MIME *, void *); |
11 | 12 |
|
| 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 | + |
12 | 26 | struct GX_EXPORT MJSON_MIME { |
13 | 27 | std::vector<MJSON_MIME> children; |
14 | 28 | enum mime_type mime_type = mime_type::none; |
@@ -50,12 +64,12 @@ struct GX_EXPORT MJSON { |
50 | 64 |
|
51 | 65 | void clear(); |
52 | 66 | 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; |
54 | 68 | int fetch_envelope(const char *cset, std::string &out) const; |
55 | 69 | 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; |
59 | 73 | const char *get_mail_filename() const { return filename.c_str(); } |
60 | 74 | const char *get_mail_received() const { return received.c_str(); } |
61 | 75 | const char *get_mail_messageid() const { return msgid.c_str(); } |
|
0 commit comments