diff --git a/src/librmb/Makefile.am b/src/librmb/Makefile.am index 73736325..4a1d93fa 100644 --- a/src/librmb/Makefile.am +++ b/src/librmb/Makefile.am @@ -20,7 +20,9 @@ headers = \ rados-storage-impl.h \ rados-dictionary-impl.h \ rados-mail-object.h \ - rados-util.h + rados-util.h \ + rados-metadata.h \ + rados-types.h librmb_la_SOURCES = \ $(headers) \ diff --git a/src/librmb/rados-mail-object.h b/src/librmb/rados-mail-object.h index ff1f83e2..3b70cb78 100644 --- a/src/librmb/rados-mail-object.h +++ b/src/librmb/rados-mail-object.h @@ -16,122 +16,16 @@ #include #include #include - +#include "rados-metadata.h" +#include "rados-types.h" #include #define GUID_128_SIZE 16 namespace librmb { -enum rbox_metadata_key { - /* - * mailbox global unique id the mail currently is in. - */ - RBOX_METADATA_MAILBOX_GUID = 'M', - /* Globally unique identifier for the message. Preserved when - copying. */ - RBOX_METADATA_GUID = 'G', - /* POP3 UIDL overriding the default format */ - RBOX_METADATA_POP3_UIDL = 'P', - /* POP3 message ordering (for migrated mails) */ - RBOX_METADATA_POP3_ORDER = 'O', - /* Received UNIX timestamp in hex */ - RBOX_METADATA_RECEIVED_TIME = 'R', - /* Physical message size in hex. Necessary only if it differs from - the dbox_message_header.message_size_hex, for example because the - message is compressed. */ - RBOX_METADATA_PHYSICAL_SIZE = 'Z', - /* Virtual message size in hex (line feeds counted as CRLF) */ - RBOX_METADATA_VIRTUAL_SIZE = 'V', - /* Pointer to external message data. Format is: - 1*( ) */ - RBOX_METADATA_EXT_REF = 'X', - /* Mailbox name where this message was originally saved to. - When rebuild finds a message whose mailbox is unknown, it's - placed to this mailbox. */ - RBOX_METADATA_ORIG_MAILBOX = 'B', - - RBOX_METADATA_MAIL_UID = 'U', - RBOX_METADATA_VERSION = 'I', - /* - * Mails from envelope - */ - RBOX_METADATA_FROM_ENVELOPE = 'A', - RBOX_METADATA_PVT_FLAGS = 'C', - /* metadata used by old Dovecot versions */ - RBOX_METADATA_OLDV1_EXPUNGED = 'E', - RBOX_METADATA_OLDV1_FLAGS = 'F', - RBOX_METADATA_OLDV1_KEYWORDS = 'K', - RBOX_METADATA_OLDV1_SAVE_TIME = 'S', - RBOX_METADATA_OLDV1_SPACE = ' ' -}; - -class RadosMetadata { - public: - - RadosMetadata(enum rbox_metadata_key _key, const std::string& val) { - convert(_key, val); - } - - RadosMetadata(enum rbox_metadata_key _key, const time_t& val) { - convert(_key, val); - } - - RadosMetadata(enum rbox_metadata_key _key, const char* val) { - convert(_key, val); - } - - RadosMetadata(enum rbox_metadata_key _key, const uint& val) { - convert(_key, val); - } - RadosMetadata(enum rbox_metadata_key _key, const size_t& val) { - convert(_key, val); - } - public: - ceph::bufferlist &get_bl(); - std::string &get_key(); - void convert(const char* value, time_t* t) { - std::istringstream stream(value); - stream >> *t; - } - public: - ceph::bufferlist bl; - std::string key; - - private: - - void convert(enum rbox_metadata_key _key, const std::string& val) { - key = enum_to_string(_key); - bl.append(val); - } - - void convert(enum rbox_metadata_key _key, const time_t& time) { - key = enum_to_string(_key); - bl.append(std::to_string(time)); - } - - void convert(enum rbox_metadata_key _key, char* value) { - key = enum_to_string(_key); - bl.append(value); - } - - void convert(enum rbox_metadata_key _key, const uint& value) { - key = enum_to_string(_key); - bl.append(std::to_string(value)); - } - - void convert(enum rbox_metadata_key _key, const size_t& value) { - key = enum_to_string(_key); - bl.append(std::to_string(static_cast(value))); - } - - std::string enum_to_string(enum rbox_metadata_key _key) { - std::string k(1, static_cast(_key)); - return k; - } -}; class RadosMailObject { public: diff --git a/src/librmb/rados-metadata.h b/src/librmb/rados-metadata.h new file mode 100644 index 00000000..0e25023b --- /dev/null +++ b/src/librmb/rados-metadata.h @@ -0,0 +1,79 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Copyright (c) 2017 Tallence AG and the authors + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#ifndef SRC_LIBRMB_RADOS_METADATA_H_ +#define SRC_LIBRMB_RADOS_METADATA_H_ + +#include "rados-types.h" +#include +#include "time.h" +#include +#include + +namespace librmb { + +class RadosMetadata { + public: RadosMetadata(enum rbox_metadata_key _key, const std::string& val) { convert(_key, val); } + + RadosMetadata(enum rbox_metadata_key _key, const time_t& val) { convert(_key, val); } + + RadosMetadata(enum rbox_metadata_key _key, const char* val) { convert(_key, val); } + + RadosMetadata(enum rbox_metadata_key _key, const uint& val) { convert(_key, val); } + + RadosMetadata(enum rbox_metadata_key _key, const size_t& val) { convert(_key, val); } + + public: + ceph::bufferlist& get_bl(); + std::string& get_key(); + + void convert(const char* value, time_t* t) { + std::istringstream stream(value); + stream >> *t; + } + + public: + ceph::bufferlist bl; + std::string key; + + private: + void convert(enum rbox_metadata_key _key, const std::string& val) { + key = enum_to_string(_key); + bl.append(val); + } + + void convert(enum rbox_metadata_key _key, const time_t& time) { + key = enum_to_string(_key); + bl.append(std::to_string(time)); + } + + void convert(enum rbox_metadata_key _key, char* value) { + key = enum_to_string(_key); + bl.append(value); + } + + void convert(enum rbox_metadata_key _key, const uint& value) { + key = enum_to_string(_key); + bl.append(std::to_string(value)); + } + + void convert(enum rbox_metadata_key _key, const size_t& value) { + key = enum_to_string(_key); + bl.append(std::to_string(static_cast(value))); + } + + std::string enum_to_string(enum rbox_metadata_key _key) { + std::string k(1, static_cast(_key)); + return k; + } +}; +} // end namespace +#endif /* SRC_LIBRMB_RADOS_METADATA_H_ */ diff --git a/src/librmb/rados-types.h b/src/librmb/rados-types.h new file mode 100644 index 00000000..3dce2785 --- /dev/null +++ b/src/librmb/rados-types.h @@ -0,0 +1,60 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Copyright (c) 2017 Tallence AG and the authors + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#ifndef SRC_LIBRMB_RADOS_TYPES_H_ +#define SRC_LIBRMB_RADOS_TYPES_H_ + +namespace librmb { + +enum rbox_metadata_key { + /* + * mailbox global unique id the mail currently is in. + */ + RBOX_METADATA_MAILBOX_GUID = 'M', + /* Globally unique identifier for the message. Preserved when + copying. */ + RBOX_METADATA_GUID = 'G', + /* POP3 UIDL overriding the default format */ + RBOX_METADATA_POP3_UIDL = 'P', + /* POP3 message ordering (for migrated mails) */ + RBOX_METADATA_POP3_ORDER = 'O', + /* Received UNIX timestamp in hex */ + RBOX_METADATA_RECEIVED_TIME = 'R', + /* Physical message size in hex. Necessary only if it differs from + the dbox_message_header.message_size_hex, for example because the + message is compressed. */ + RBOX_METADATA_PHYSICAL_SIZE = 'Z', + /* Virtual message size in hex (line feeds counted as CRLF) */ + RBOX_METADATA_VIRTUAL_SIZE = 'V', + /* Pointer to external message data. Format is: + 1*( ) */ + RBOX_METADATA_EXT_REF = 'X', + /* Mailbox name where this message was originally saved to. + When rebuild finds a message whose mailbox is unknown, it's + placed to this mailbox. */ + RBOX_METADATA_ORIG_MAILBOX = 'B', + + RBOX_METADATA_MAIL_UID = 'U', + RBOX_METADATA_VERSION = 'I', + /* + * Mails from envelope + */ + RBOX_METADATA_FROM_ENVELOPE = 'A', + RBOX_METADATA_PVT_FLAGS = 'C', + /* metadata used by old Dovecot versions */ + RBOX_METADATA_OLDV1_EXPUNGED = 'E', + RBOX_METADATA_OLDV1_FLAGS = 'F', + RBOX_METADATA_OLDV1_KEYWORDS = 'K', + RBOX_METADATA_OLDV1_SAVE_TIME = 'S', + RBOX_METADATA_OLDV1_SPACE = ' ' +}; +} // namespace +#endif /* SRC_LIBRMB_RADOS_TYPES_H_ */ diff --git a/src/librmb/rados-util.h b/src/librmb/rados-util.h index 67657e6c..f76a9955 100644 --- a/src/librmb/rados-util.h +++ b/src/librmb/rados-util.h @@ -16,7 +16,7 @@ #include #include "time.h" #include -#include "rados-mail-object.h" +#include "rados-types.h" namespace librmb {