diff --git a/src/dict-rados/dict-rados.cpp b/src/dict-rados/dict-rados.cpp index ede9828f..5c785472 100644 --- a/src/dict-rados/dict-rados.cpp +++ b/src/dict-rados/dict-rados.cpp @@ -10,7 +10,7 @@ */ #ifdef HAVE_CONFIG_H - #include "dovecot-ceph-plugin-config.h" +#include "dovecot-ceph-plugin-config.h" #endif #include @@ -346,9 +346,6 @@ int rados_dict_lookup(struct dict *_dict, pool_t pool, const char *key, const ch return RADOS_COMMIT_RET_NOTFOUND; } -static void rados_dict_transaction_private_complete_callback(completion_t comp, void *arg); -static void rados_dict_transaction_shared_complete_callback(completion_t comp, void *arg); - #define ENORESULT 1000 class rados_dict_transaction_context { @@ -361,7 +358,6 @@ class rados_dict_transaction_context { void *context = nullptr; dict_transaction_commit_callback_t *callback; - map set_map; set unset_set; map atomic_inc_map; @@ -403,7 +399,7 @@ class rados_dict_transaction_context { return true; } else if (!key.compare(0, strlen(DICT_PATH_SHARED), DICT_PATH_SHARED)) { dirty_shared = true; - return false; + return false; } i_unreached(); } @@ -531,8 +527,6 @@ void rados_dict_set_timestamp(struct dict_transaction_context *_ctx, const struc } #endif - - void (*transaction_commit)(struct dict_transaction_context *ctx, bool async, dict_transaction_commit_callback_t *callback, void *context); @@ -563,15 +557,15 @@ int rados_dict_transaction_commit(struct dict_transaction_context *_ctx, bool as ctx->atomic_inc_not_found ? RADOS_COMMIT_RET_NOTFOUND : (failed ? RADOS_COMMIT_RET_FAILED : RADOS_COMMIT_RET_OK); if (callback != nullptr) { #if DOVECOT_PREREQ(2, 3) - struct dict_commit_result result = {static_cast(ret), nullptr}; // TODO(p.mauritius): text? - callback(&result, ctx->context); + struct dict_commit_result result = {static_cast(ret), nullptr}; // TODO(p.mauritius): text? + callback(&result, ctx->context); #else - callback(ret, ctx->context); + callback(ret, ctx->context); #endif - } + } - delete ctx; - ctx = NULL; + delete ctx; + ctx = NULL; #if DOVECOT_PREREQ(2, 3) return; diff --git a/src/librmb/rados-mail-object.cpp b/src/librmb/rados-mail-object.cpp index 2054652c..05473a3f 100644 --- a/src/librmb/rados-mail-object.cpp +++ b/src/librmb/rados-mail-object.cpp @@ -34,20 +34,31 @@ RadosMailObject::~RadosMailObject() {} void RadosMailObject::set_guid(const uint8_t *_guid) { memcpy(this->guid, _guid, sizeof(this->guid)); } std::string RadosMailObject::to_string(const string &padding) { - string uid = get_metadata(RBOX_METADATA_MAIL_UID); - string recv_time_str = get_metadata(RBOX_METADATA_RECEIVED_TIME); - string p_size = get_metadata(RBOX_METADATA_PHYSICAL_SIZE); - string v_size = get_metadata(RBOX_METADATA_VIRTUAL_SIZE); - - string rbox_version = get_metadata(RBOX_METADATA_VERSION); - string mailbox_guid = get_metadata(RBOX_METADATA_MAILBOX_GUID); - string mail_guid = get_metadata(RBOX_METADATA_GUID); - string mb_orig_name = get_metadata(RBOX_METADATA_ORIG_MAILBOX); + string uid; + get_metadata(RBOX_METADATA_MAIL_UID, &uid); + string recv_time_str; + get_metadata(RBOX_METADATA_RECEIVED_TIME, &recv_time_str); + string p_size; + get_metadata(RBOX_METADATA_PHYSICAL_SIZE, &p_size); + string v_size; + get_metadata(RBOX_METADATA_VIRTUAL_SIZE, &v_size); + + string rbox_version; + get_metadata(RBOX_METADATA_VERSION, &rbox_version); + string mailbox_guid; + get_metadata(RBOX_METADATA_MAILBOX_GUID, &mailbox_guid); + string mail_guid; + get_metadata(RBOX_METADATA_GUID, &mail_guid); + string mb_orig_name; + get_metadata(RBOX_METADATA_ORIG_MAILBOX, &mb_orig_name); // string keywords = get_metadata(RBOX_METADATA_OLDV1_KEYWORDS); - string flags = get_metadata(RBOX_METADATA_OLDV1_FLAGS); - string pvt_flags = get_metadata(RBOX_METADATA_PVT_FLAGS); - string from_envelope = get_metadata(RBOX_METADATA_FROM_ENVELOPE); + string flags; + get_metadata(RBOX_METADATA_OLDV1_FLAGS, &flags); + string pvt_flags; + get_metadata(RBOX_METADATA_PVT_FLAGS, &pvt_flags); + string from_envelope; + get_metadata(RBOX_METADATA_FROM_ENVELOPE, &from_envelope); time_t ts = -1; if (!recv_time_str.empty()) { diff --git a/src/librmb/rados-mail-object.h b/src/librmb/rados-mail-object.h index 632977b1..88aa92c6 100644 --- a/src/librmb/rados-mail-object.h +++ b/src/librmb/rados-mail-object.h @@ -33,54 +33,50 @@ class RadosMailObject { RadosMailObject(); virtual ~RadosMailObject(); - void set_oid(const char* _oid) { - this->oid = _oid; -} -void set_oid(const string& _oid) { this->oid = _oid; } -void set_guid(const uint8_t* guid); -void set_mail_size(const uint64_t& _size) { object_size = _size; } -void set_active_op(bool _active) { this->active_op = _active; } -void set_rados_save_date(const time_t& _save_date) { this->save_date_rados = _save_date; } - -const string& get_oid() { return this->oid; } -const uint64_t& get_mail_size() { return this->object_size; } - -time_t* get_rados_save_date() { return &this->save_date_rados; } -uint8_t* get_guid_ref() { return this->guid; } -librados::bufferlist* get_mail_buffer() { return &this->mail_buffer; } -map* get_metadata() { return &this->attrset; } - -map* get_completion_op_map() { return &completion_op; } - -string get_metadata(rbox_metadata_key key) { - string str_key(1, static_cast(key)); - return get_metadata(str_key); -} - -string get_metadata(const string& key) { - string value; - if (attrset.find(key) != attrset.end()) { - value = attrset[key].to_str(); + void set_oid(const char* _oid) { this->oid = _oid; } + void set_oid(const string& _oid) { this->oid = _oid; } + void set_guid(const uint8_t* guid); + void set_mail_size(const uint64_t& _size) { object_size = _size; } + void set_active_op(bool _active) { this->active_op = _active; } + void set_rados_save_date(const time_t& _save_date) { this->save_date_rados = _save_date; } + + const string& get_oid() { return this->oid; } + const uint64_t& get_mail_size() { return this->object_size; } + + time_t* get_rados_save_date() { return &this->save_date_rados; } + uint8_t* get_guid_ref() { return this->guid; } + librados::bufferlist* get_mail_buffer() { return &this->mail_buffer; } + map* get_metadata() { return &this->attrset; } + + map* get_completion_op_map() { return &completion_op; } + + void get_metadata(rbox_metadata_key key, std::string* value) { + string str_key(1, static_cast(key)); + get_metadata(str_key, value); } - return value; -} - -bool is_index_ref() { return index_ref; } -void set_index_ref(bool ref) { this->index_ref = ref; } -bool is_valid() { return valid; } -void set_valid(bool valid_) { valid = valid_; } -bool has_active_op() { return active_op; } -string to_string(const string& padding); -void add_metadata(const RadosMetadata& metadata) { attrset[metadata.key] = metadata.bl; } - -map* get_extended_metadata() { return &this->extended_attrset; } -void add_extended_metadata(RadosMetadata& metadata) { extended_attrset[metadata.key] = metadata.bl; } -const string get_extended_metadata(string& key) { - string value; - if (extended_attrset.find(key) != extended_attrset.end()) { - value = extended_attrset[key].to_str(); + + void get_metadata(const string& key, std::string* value) { + if (attrset.find(key) != attrset.end()) { + *value = attrset[key].to_str(); + } } - return value; + + bool is_index_ref() { return index_ref; } + void set_index_ref(bool ref) { this->index_ref = ref; } + bool is_valid() { return valid; } + void set_valid(bool valid_) { valid = valid_; } + bool has_active_op() { return active_op; } + string to_string(const string& padding); + void add_metadata(const RadosMetadata& metadata) { attrset[metadata.key] = metadata.bl; } + + map* get_extended_metadata() { return &this->extended_attrset; } + void add_extended_metadata(RadosMetadata& metadata) { extended_attrset[metadata.key] = metadata.bl; } + const string get_extended_metadata(string& key) { + string value; + if (extended_attrset.find(key) != extended_attrset.end()) { + value = extended_attrset[key].to_str(); + } + return value; } private: @@ -98,10 +94,10 @@ const string get_extended_metadata(string& key) { map extended_attrset; bool valid; bool index_ref; + public: static const char X_ATTR_VERSION_VALUE[]; static const char DATA_BUFFER_NAME[]; - }; } // namespace librmb diff --git a/src/librmb/tools/rmb/mailbox_tools.cpp b/src/librmb/tools/rmb/mailbox_tools.cpp index 71a6fd22..fbbb4522 100644 --- a/src/librmb/tools/rmb/mailbox_tools.cpp +++ b/src/librmb/tools/rmb/mailbox_tools.cpp @@ -97,7 +97,9 @@ int MailboxTools::build_filename(librmb::RadosMailObject* mail_obj, std::string* } std::stringstream ss; - ss << mail_obj->get_metadata(librmb::RBOX_METADATA_MAIL_UID) << "."; + std::string m_mail_uid; + mail_obj->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &m_mail_uid); + ss << m_mail_uid << "."; ss << mail_obj->get_oid(); *filename = ss.str(); return filename->empty() ? -1 : 0; diff --git a/src/librmb/tools/rmb/rados-mail-box.h b/src/librmb/tools/rmb/rados-mail-box.h index 932f4048..5e401f44 100644 --- a/src/librmb/tools/rmb/rados-mail-box.h +++ b/src/librmb/tools/rmb/rados-mail-box.h @@ -22,10 +22,8 @@ namespace librmb { class RadosMailBox { public: - - RadosMailBox(const std::string& _mailbox_guid, int _mail_count, const std::string &_mbox_orig_name) : mailbox_guid(_mailbox_guid), - mail_count(_mail_count), - mbox_orig_name(_mbox_orig_name) { + RadosMailBox(const std::string &_mailbox_guid, int _mail_count, const std::string &_mbox_orig_name) + : mailbox_guid(_mailbox_guid), mail_count(_mail_count), mbox_orig_name(_mbox_orig_name) { this->mailbox_size = 0; this->total_mails = 0; this->parser = nullptr; @@ -50,7 +48,9 @@ class RadosMailBox { it != parser->get_predicates().end(); ++it) { if (mail->get_metadata()->find(it->first) != mail->get_metadata()->end()) { std::string key = it->first; - if (it->second->eval(mail->get_metadata(key))) { + std::string value; + mail->get_metadata(key, &value); + if (it->second->eval(value)) { mails.push_back(mail); } return; diff --git a/src/librmb/tools/rmb/rmb-commands.cpp b/src/librmb/tools/rmb/rmb-commands.cpp index 6363a307..ac6237c8 100644 --- a/src/librmb/tools/rmb/rmb-commands.cpp +++ b/src/librmb/tools/rmb/rmb-commands.cpp @@ -10,9 +10,9 @@ */ #include "rmb-commands.h" +#include #include // std::sort #include -#include #include "../../rados-cluster-impl.h" #include "../../rados-storage-impl.h" @@ -35,8 +35,7 @@ RmbCommands::RmbCommands(librmb::RadosStorage *storage_, librmb::RadosCluster *c is_debug = ((*opts).find("debug") != (*opts).end()) ? true : false; } } -RmbCommands::~RmbCommands() { -} +RmbCommands::~RmbCommands() {} void RmbCommands::print_debug(const std::string &msg) { if (this->is_debug) { @@ -111,7 +110,7 @@ int RmbCommands::delete_with_save_log(const std::string &save_log, const std::st cluster.deinit(); return count; } -// TODO:: currently untestable with mocks. + int RmbCommands::lspools() { librmb::RadosClusterImpl cluster; @@ -135,7 +134,7 @@ int RmbCommands::delete_namespace(librmb::RadosStorageMetadataModule *ms, std::vector &mail_objects, librmb::RadosCephConfig *cfg, bool confirmed) { librmb::CmdLineParser parser("-"); - if(parser.parse_ls_string()){ + if (parser.parse_ls_string()) { std::string sort_type = "uid"; int ret = load_objects(ms, mail_objects, sort_type); if (ret < 0 || mail_objects.size() == 0) { @@ -163,7 +162,7 @@ int RmbCommands::delete_mail(bool confirmed) { print_debug("entry: delete_mail"); if (!confirmed) { std::cout << "WARNING: Deleting a mail object will remove the " - "object from ceph, but not from dovecot index, this " + "object from ceph, but not from dovecot index, this " "may lead to corrupt mailbox\n" << " add --yes-i-really-really-mean-it to confirm the delete " << std::endl; } else { @@ -228,9 +227,9 @@ int RmbCommands::rename_user(librmb::RadosCephConfig *cfg, bool confirmed, const } } else { std::cout << "Error renaming copy failed: return code: " << ret << " oid: " << src_ << std::endl; - } - print_debug("end: rename_user"); - return ret; + } + print_debug("end: rename_user"); + return ret; } int RmbCommands::configuration(bool confirmed, librmb::RadosCephConfig &ceph_cfg) { @@ -294,45 +293,57 @@ int RmbCommands::configuration(bool confirmed, librmb::RadosCephConfig &ceph_cfg } bool RmbCommands::sort_uid(librmb::RadosMailObject *i, librmb::RadosMailObject *j) { - std::string::size_type sz; // alias of size_t - std::string t = i->get_metadata(librmb::RBOX_METADATA_MAIL_UID); + std::string t; + i->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &t); try { - long i_uid = std::stol(t, &sz); - long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_MAIL_UID), &sz); + uint64_t i_uid = std::stol(t, &sz); + std::string m_mail_uid; + j->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &m_mail_uid); + uint64_t j_uid = std::stol(m_mail_uid, &sz); + return i_uid < j_uid; } catch (std::exception &e) { - std::cerr << " sort_uid: " << t << "(" << i->get_oid() << ") or " << j->get_metadata(librmb::RBOX_METADATA_MAIL_UID) - << " (" << j->get_oid() << ") is not a number" << std::endl; + std::string uid; + j->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &uid); + std::cerr << " sort_uid: " << t << "(" << i->get_oid() << ") or " << uid << " (" << j->get_oid() + << ") is not a number" << std::endl; return false; } } bool RmbCommands::sort_recv_date(librmb::RadosMailObject *i, librmb::RadosMailObject *j) { std::string::size_type sz; // alias of size_t - std::string t = i->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME); + std::string t; + i->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &t); try { - long i_uid = std::stol(t, &sz); - long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), &sz); + int64_t i_uid = std::stol(t, &sz); + std::string m_time; + j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &m_time); + int64_t j_uid = std::stol(m_time, &sz); return i_uid < j_uid; } catch (std::exception &e) { - std::cerr << " sort_recv_date: " << t << " or " << j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME) - << " is not a number" << std::endl; + std::string m_recv_time; + j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &m_recv_time); + std::cerr << " sort_recv_date: " << t << " or " << m_recv_time << " is not a number" << std::endl; return false; } } bool RmbCommands::sort_phy_size(librmb::RadosMailObject *i, librmb::RadosMailObject *j) { - std::string::size_type sz; // alias of size_t - std::string t = i->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE); + std::string t; + i->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &t); try { - long i_uid = std::stol(t, &sz); - long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), &sz); + uint64_t i_uid = std::stol(t, &sz); + std::string m_phy_size; + j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &m_phy_size); + uint64_t j_uid = std::stol(m_phy_size, &sz); return i_uid < j_uid; } catch (std::exception &e) { - std::cerr << " sort_physical_size: " << t << " or " << j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE) - << " is not a number" << std::endl; + std::string m_phy_size; + j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &m_phy_size); + std::cerr << " sort_physical_size: " << t << " or " << m_phy_size << " is not a number" << std::endl; return false; } } @@ -472,9 +483,11 @@ int RmbCommands::query_mail_storage(std::vector *mail std::map mailbox; for (std::vector::iterator it = mail_objects->begin(); it != mail_objects->end(); ++it) { std::string mailbox_key = std::string(1, static_cast(librmb::RBOX_METADATA_MAILBOX_GUID)); - std::string mailbox_guid = (*it)->get_metadata(mailbox_key); + std::string mailbox_guid; + (*it)->get_metadata(mailbox_key, &mailbox_guid); std::string mailbox_orig_name_key = std::string(1, static_cast(librmb::RBOX_METADATA_ORIG_MAILBOX)); - std::string mailbox_orig_name = (*it)->get_metadata(mailbox_orig_name_key); + std::string mailbox_orig_name; + (*it)->get_metadata(mailbox_orig_name_key, &mailbox_orig_name); if (parser->contains_key(mailbox_key)) { librmb::Predicate *p = parser->get_predicate(mailbox_key); diff --git a/src/storage-rbox/rbox-copy.cpp b/src/storage-rbox/rbox-copy.cpp index 0dbc9a17..1ca03ae1 100644 --- a/src/storage-rbox/rbox-copy.cpp +++ b/src/storage-rbox/rbox-copy.cpp @@ -254,6 +254,7 @@ static int rbox_mail_storage_try_copy(struct mail_save_context **_ctx, struct ma // set src as expunged struct expunged_item *item = p_new(default_pool, struct expunged_item, 1); + i_zero(item); guid_128_from_string(src_oid.c_str(), item->oid); array_append(&rmailbox->moved_items, &item, 1); diff --git a/src/storage-rbox/rbox-mail.cpp b/src/storage-rbox/rbox-mail.cpp index 5f9830c6..2247ae93 100644 --- a/src/storage-rbox/rbox-mail.cpp +++ b/src/storage-rbox/rbox-mail.cpp @@ -43,6 +43,7 @@ using librmb::RadosMailObject; using librmb::rbox_metadata_key; void rbox_mail_set_expunged(struct rbox_mail *mail) { + FUNC_START(); struct mail *_mail = &mail->imail.mail.mail; mail_index_refresh(_mail->box->index); @@ -55,6 +56,7 @@ void rbox_mail_set_expunged(struct rbox_mail *mail) { mail_storage_set_error(_mail->box->storage, MAIL_ERROR_EXPUNGED, "requested messages no longer exist."); rbox_set_mailbox_corrupted(_mail->box); } + FUNC_END(); } int rbox_get_index_record(struct mail *_mail) { @@ -63,10 +65,9 @@ int rbox_get_index_record(struct mail *_mail) { struct rbox_mailbox *rbox = (struct rbox_mailbox *)_mail->transaction->box; if (rmail->last_seq != _mail->seq) { - const struct obox_mail_index_record *obox_rec; const void *rec_data; mail_index_lookup_ext(_mail->transaction->view, _mail->seq, rbox->ext_id, &rec_data, NULL); - obox_rec = static_cast(rec_data); + const struct obox_mail_index_record *obox_rec = static_cast(rec_data); if (obox_rec == nullptr) { i_error("no index entry for %d, ext_id=%d ,mail_object->oid='%s'", _mail->seq, rbox->ext_id, @@ -81,7 +82,6 @@ int rbox_get_index_record(struct mail *_mail) { rmail->mail_object->set_oid(guid_128_to_string(rmail->index_oid)); rmail->last_seq = _mail->seq; - } FUNC_END(); return 0; @@ -104,13 +104,15 @@ struct mail *rbox_mail_alloc(struct mailbox_transaction_context *t, enum mail_fe } static int rbox_mail_metadata_get(struct rbox_mail *rmail, enum rbox_metadata_key key, char **value_r) { + FUNC_START(); struct mail *mail = (struct mail *)rmail; struct rbox_storage *r_storage = (struct rbox_storage *)mail->box->storage; - int ret = -1; + enum mail_flags flags = index_mail_get_flags(mail); bool alt_storage = is_alternate_storage_set(flags) && is_alternate_pool_valid(mail->box); if (rbox_open_rados_connection(mail->box, alt_storage) < 0) { i_error("ERROR, cannot open rados connection (rbox_mail_metadata_get)"); + FUNC_END(); return -1; } @@ -120,23 +122,25 @@ static int rbox_mail_metadata_get(struct rbox_mail *rmail, enum rbox_metadata_ke } else { r_storage->ms->get_storage()->set_io_ctx(&r_storage->s->get_io_ctx()); } - ret = r_storage->ms->get_storage()->load_metadata(rmail->mail_object); - if (ret < 0) { - if (ret == -ENOENT) { - i_warning("Errorcode: %d cannot get x_attr from object %s, process %d", ret, + int ret_load_metadata = r_storage->ms->get_storage()->load_metadata(rmail->mail_object); + if (ret_load_metadata < 0) { + if (ret_load_metadata == -ENOENT) { + i_warning("Errorcode: %d cannot get x_attr from object %s, process %d", ret_load_metadata, rmail->mail_object->get_oid().c_str(), getpid()); rbox_mail_set_expunged(rmail); } else { - i_error("Errorcode: %d cannot get x_attr from object %s, process %d", ret, rmail->mail_object->get_oid().c_str(), - getpid()); + i_error("Errorcode: %d cannot get x_attr from object %s, process %d", ret_load_metadata, + rmail->mail_object->get_oid().c_str(), getpid()); } + FUNC_END(); return -1; } - std::string value = rmail->mail_object->get_metadata(key); + std::string value; + rmail->mail_object->get_metadata(key, &value); if (!value.empty()) { *value_r = i_strdup(value.c_str()); } - + FUNC_END(); return 0; } @@ -363,7 +367,8 @@ static int rbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED, s FUNC_END_RET("ret == -1; connection to rados failed"); return -1; } - librmb::RadosStorage *rados_storage = alt_storage ? ((struct rbox_storage *)_mail->box->storage)->alt : ((struct rbox_storage *)_mail->box->storage)->s; + librmb::RadosStorage *rados_storage = alt_storage ? ((struct rbox_storage *)_mail->box->storage)->alt + : ((struct rbox_storage *)_mail->box->storage)->s; if (alt_storage) { rados_storage->set_namespace(rados_storage->get_namespace()); } @@ -420,7 +425,8 @@ static int rbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED, s static int rbox_get_cached_metadata(struct rbox_mail *mail, enum rbox_metadata_key key, enum index_cache_field cache_field, const char **value_r) { struct index_mail *imail = &mail->imail; - struct index_mailbox_context *ibox = reinterpret_cast(RBOX_INDEX_STORAGE_CONTEXT(imail->mail.mail.box)); + struct index_mailbox_context *ibox = + reinterpret_cast(RBOX_INDEX_STORAGE_CONTEXT(imail->mail.mail.box)); char *value = NULL; string_t *str; @@ -545,7 +551,6 @@ static void rbox_mail_close(struct mail *_mail) { if (rmail_->mail_object != nullptr) { r_storage->s->free_mail_object(rmail_->mail_object); rmail_->mail_object = nullptr; - } index_mail_close(_mail); @@ -566,23 +571,46 @@ static void rbox_index_mail_set_seq(struct mail *_mail, uint32_t seq, bool savin /*ebd if old version */ // rbox_mail_free, -struct mail_vfuncs rbox_mail_vfuncs = { - rbox_mail_close, index_mail_free, rbox_index_mail_set_seq, index_mail_set_uid, index_mail_set_uid_cache_updates, - index_mail_prefetch, index_mail_precache, index_mail_add_temp_wanted_fields, - - index_mail_get_flags, index_mail_get_keywords, index_mail_get_keyword_indexes, index_mail_get_modseq, - index_mail_get_pvt_modseq, index_mail_get_parts, index_mail_get_date, rbox_mail_get_received_date, - rbox_mail_get_save_date, rbox_mail_get_virtual_size, rbox_mail_get_physical_size, index_mail_get_first_header, - index_mail_get_headers, index_mail_get_header_stream, rbox_mail_get_stream, index_mail_get_binary_stream, - rbox_mail_get_special, +struct mail_vfuncs rbox_mail_vfuncs = {rbox_mail_close, + index_mail_free, + rbox_index_mail_set_seq, + index_mail_set_uid, + index_mail_set_uid_cache_updates, + index_mail_prefetch, + index_mail_precache, + index_mail_add_temp_wanted_fields, + + index_mail_get_flags, + index_mail_get_keywords, + index_mail_get_keyword_indexes, + index_mail_get_modseq, + index_mail_get_pvt_modseq, + index_mail_get_parts, + index_mail_get_date, + rbox_mail_get_received_date, + rbox_mail_get_save_date, + rbox_mail_get_virtual_size, + rbox_mail_get_physical_size, + index_mail_get_first_header, + index_mail_get_headers, + index_mail_get_header_stream, + rbox_mail_get_stream, + index_mail_get_binary_stream, + rbox_mail_get_special, #if DOVECOT_PREREQ(2, 3) - index_mail_get_backend_mail, + index_mail_get_backend_mail, #else index_mail_get_real_mail, #endif - index_mail_update_flags, index_mail_update_keywords, index_mail_update_modseq, index_mail_update_pvt_modseq, NULL, - index_mail_expunge, index_mail_set_cache_corrupted, index_mail_opened, + index_mail_update_flags, + index_mail_update_keywords, + index_mail_update_modseq, + index_mail_update_pvt_modseq, + NULL, + index_mail_expunge, + index_mail_set_cache_corrupted, + index_mail_opened, #ifdef DOVECOT_CEPH_PLUGINS_HAVE_INDEX_MAIL_SET_CACHE_CORRUPTED_REASON - index_mail_set_cache_corrupted_reason + index_mail_set_cache_corrupted_reason #endif }; diff --git a/src/storage-rbox/rbox-save.cpp b/src/storage-rbox/rbox-save.cpp index 4b0062af..43fff3d1 100644 --- a/src/storage-rbox/rbox-save.cpp +++ b/src/storage-rbox/rbox-save.cpp @@ -62,14 +62,13 @@ struct mail_save_context *rbox_save_alloc(struct mailbox_transaction_context *t) r_ctx->ctx.transaction = t; r_ctx->mbox = rbox; r_ctx->trans = t->itrans; - r_ctx->current_object = nullptr; - }else { - r_ctx->current_object = nullptr; + } else { r_ctx->failed = FALSE; r_ctx->finished = FALSE; r_ctx->output_stream = NULL; r_ctx->input = NULL; } + r_ctx->current_object = nullptr; t->save_ctx = &r_ctx->ctx; @@ -78,17 +77,14 @@ struct mail_save_context *rbox_save_alloc(struct mailbox_transaction_context *t) } int setup_mail_object(struct mail_save_context *_ctx) { - rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; - struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; - struct mail_save_data *mdata = &_ctx->data; + struct rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; guid_128_generate(r_ctx->mail_oid); - - r_ctx->current_object = r_storage->s->alloc_mail_object(); + r_ctx->current_object = ((struct rbox_storage *)&r_ctx->mbox->storage->storage)->s->alloc_mail_object(); r_ctx->current_object->set_oid(guid_128_to_string(r_ctx->mail_oid)); - if (mdata->guid != NULL) { - string str(mdata->guid); + if (_ctx->data.guid != NULL) { + string str(_ctx->data.guid); librmb::RadosUtils::find_and_replace(&str, "-", ""); // remove hyphens if they exist mail_generate_guid_128_hash(str.c_str(), r_ctx->mail_guid); } else { @@ -99,9 +95,8 @@ int setup_mail_object(struct mail_save_context *_ctx) { void rbox_add_to_index(struct mail_save_context *_ctx) { FUNC_START(); - struct mail_save_data *mdata = &_ctx->data; - rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; - uint8_t save_flags = 0x0; + struct rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; + uint8_t save_flags = _ctx->data.flags & ~MAIL_RECENT; /* add to index */ #if DOVECOT_PREREQ(2, 3) @@ -111,10 +106,9 @@ void rbox_add_to_index(struct mail_save_context *_ctx) { r_ctx->seq = mdata->stub_seq; } #else - mail_index_append(r_ctx->trans, mdata->uid, &r_ctx->seq); + mail_index_append(r_ctx->trans, _ctx->data.uid, &r_ctx->seq); #endif - save_flags = mdata->flags & ~MAIL_RECENT; mail_index_update_flags(r_ctx->trans, r_ctx->seq, MODIFY_REPLACE, static_cast(save_flags)); if (_ctx->data.keywords != NULL) { @@ -137,14 +131,13 @@ void rbox_add_to_index(struct mail_save_context *_ctx) { } void rbox_move_index(struct mail_save_context *_ctx, struct mail *src_mail) { - struct mail_save_data *mdata = &_ctx->data; + FUNC_START(); rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; - uint8_t save_flags = 0x0; + uint8_t save_flags = _ctx->data.flags & ~MAIL_RECENT; /* add to index */ - save_flags = mdata->flags & ~MAIL_RECENT; - mail_index_append(r_ctx->trans, mdata->uid, &r_ctx->seq); + mail_index_append(r_ctx->trans, _ctx->data.uid, &r_ctx->seq); mail_index_update_flags(r_ctx->trans, r_ctx->seq, MODIFY_REPLACE, static_cast(save_flags)); @@ -167,8 +160,8 @@ void rbox_move_index(struct mail_save_context *_ctx, struct mail *src_mail) { r_ctx->current_object->set_oid(guid_128_to_string(r_ctx->mail_oid)); r_ctx->objects.push_back(r_ctx->current_object); - if (mdata->guid != NULL) { - string str(mdata->guid); + if (_ctx->data.guid != NULL) { + string str(_ctx->data.guid); librmb::RadosUtils::find_and_replace(&str, "-", ""); // remove hyphens if they exist mail_generate_guid_128_hash(str.c_str(), r_ctx->mail_guid); } else { @@ -185,6 +178,7 @@ void rbox_move_index(struct mail_save_context *_ctx, struct mail *src_mail) { if (_ctx->dest_mail != NULL) { mail_set_seq_saving(_ctx->dest_mail, r_ctx->seq); } + FUNC_END(); } void init_output_stream(mail_save_context *_ctx) { FUNC_START(); @@ -343,7 +337,7 @@ static int rbox_save_mail_set_metadata(struct rbox_save_context *ctx, librmb::Ra unsigned int count_keywords; const char *const *keywords = array_get(&rmail->imail.data.keywords, &count_keywords); - for (unsigned int i = 0; i < count_keyword_indexes; i++) { + for (unsigned int i = 0; i < count_keyword_indexes; ++i) { // set keyword_idx : keyword_value std::string key_idx = std::to_string(keyword_indexes[i]); std::string keyword_value = keywords[i]; @@ -359,9 +353,13 @@ static int rbox_save_mail_set_metadata(struct rbox_save_context *ctx, librmb::Ra } static void clean_up_failed(struct rbox_save_context *r_ctx) { + FUNC_START(); struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; - r_storage->s->wait_for_rados_operations(r_ctx->objects); + if (r_storage->s->wait_for_rados_operations(r_ctx->objects)) { + i_error("Librados waiting for rados operations failed"); + // try to clean up! + } for (std::vector::iterator it_cur_obj = r_ctx->objects.begin(); it_cur_obj != r_ctx->objects.end(); ++it_cur_obj) { @@ -382,9 +380,11 @@ static void clean_up_failed(struct rbox_save_context *r_ctx) { clean_up_mail_object_list(r_ctx, r_storage); r_ctx->mail_count--; + FUNC_END(); } static void clean_up_write_finish(struct mail_save_context *_ctx) { + FUNC_START(); struct rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; r_ctx->finished = TRUE; @@ -398,7 +398,7 @@ static void clean_up_write_finish(struct mail_save_context *_ctx) { } index_save_context_free(_ctx); - + FUNC_END(); } int rbox_save_finish(struct mail_save_context *_ctx) { @@ -406,34 +406,32 @@ int rbox_save_finish(struct mail_save_context *_ctx) { struct rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; - if (!r_ctx->failed) { if (_ctx->data.save_date != (time_t)-1) { - uint32_t save_date = _ctx->data.save_date; - index_mail_cache_add((struct index_mail *)_ctx->dest_mail, MAIL_CACHE_SAVE_DATE, &save_date, sizeof(save_date)); + index_mail_cache_add((struct index_mail *)_ctx->dest_mail, MAIL_CACHE_SAVE_DATE, &_ctx->data.save_date, + sizeof(_ctx->data.save_date)); } - struct mail_save_data *mdata = &r_ctx->ctx.data; - if (mdata->output != r_ctx->output_stream) { + if (r_ctx->ctx.data.output != r_ctx->output_stream) { #if DOVECOT_PREREQ(2, 3) /* e.g. zlib plugin had changed this. make sure we successfully write the trailer. */ - o_stream_finish(mdata->output); + o_stream_finish(r_ctx->ctx.data.output); #else - if (o_stream_nfinish(mdata->output) < 0) { + if (o_stream_nfinish(r_ctx->ctx.data.output) < 0) { mail_storage_set_critical(r_ctx->ctx.transaction->box->storage, "write(%s) failed: %m", - o_stream_get_name(mdata->output)); + o_stream_get_name(r_ctx->ctx.data.output)); r_ctx->failed = TRUE; } #endif /* e.g. zlib plugin had changed this */ o_stream_ref(r_ctx->output_stream); - o_stream_destroy(&mdata->output); - mdata->output = r_ctx->output_stream; + o_stream_destroy(&r_ctx->ctx.data.output); + r_ctx->ctx.data.output = r_ctx->output_stream; } // reset virtual size index_mail_cache_parse_deinit(_ctx->dest_mail, r_ctx->ctx.data.received_date, !r_ctx->failed); - // always save to primary storage + // always save to primary storage if (rbox_open_rados_connection(_ctx->transaction->box, false) < 0) { i_error("ERROR, cannot open rados connection (rbox_save_finish)"); r_ctx->failed = true; @@ -474,10 +472,11 @@ void rbox_save_cancel(struct mail_save_context *_ctx) { } static int rbox_save_assign_uids(struct rbox_save_context *r_ctx, const ARRAY_TYPE(seq_range) * uids) { + FUNC_START(); struct seq_range_iter iter; unsigned int n = 0; uint32_t uid = -1; - + if (r_ctx->objects.size() > 0) { seq_range_array_iter_init(&iter, uids); struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; @@ -495,22 +494,19 @@ static int rbox_save_assign_uids(struct rbox_save_context *r_ctx, const ARRAY_TY } } i_assert(!seq_range_array_iter_nth(&iter, n, &uid)); - } - + } + FUNC_END(); return 0; } int rbox_transaction_save_commit_pre(struct mail_save_context *_ctx) { FUNC_START(); struct rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; - struct mailbox_transaction_context *_t = _ctx->transaction; - struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; - const struct mail_index_header *hdr; - struct seq_range_iter iter; + librmb::RadosStorage *storage = ((struct rbox_storage *)&r_ctx->mbox->storage->storage)->s; i_assert(r_ctx->finished); - r_ctx->failed = r_storage->s->wait_for_rados_operations(r_ctx->objects); + r_ctx->failed = storage->wait_for_rados_operations(r_ctx->objects); // if one write fails! all writes will be reverted and r_ctx->failed is true! if (r_ctx->failed) { @@ -530,12 +526,13 @@ int rbox_transaction_save_commit_pre(struct mail_save_context *_ctx) { return -1; } - hdr = mail_index_get_header(r_ctx->sync_ctx->sync_view); - mail_index_append_finish_uids(r_ctx->trans, hdr->next_uid, &_t->changes->saved_uids); - _t->changes->uid_validity = r_ctx->sync_ctx->uid_validity; + const struct mail_index_header *hdr = mail_index_get_header(r_ctx->sync_ctx->sync_view); + mail_index_append_finish_uids(r_ctx->trans, hdr->next_uid, &_ctx->transaction->changes->saved_uids); + _ctx->transaction->changes->uid_validity = r_ctx->sync_ctx->uid_validity; - seq_range_array_iter_init(&iter, &_t->changes->saved_uids); - if (rbox_save_assign_uids(r_ctx, &_t->changes->saved_uids) < 0) { + struct seq_range_iter iter; + seq_range_array_iter_init(&iter, &_ctx->transaction->changes->saved_uids); + if (rbox_save_assign_uids(r_ctx, &_ctx->transaction->changes->saved_uids) < 0) { rbox_transaction_save_rollback(_ctx); return -1; } @@ -548,7 +545,7 @@ int rbox_transaction_save_commit_pre(struct mail_save_context *_ctx) { _ctx->dest_mail = NULL; } } - _t->changes->uid_validity = hdr->uid_validity; + _ctx->transaction->changes->uid_validity = hdr->uid_validity; FUNC_END(); return 0; @@ -570,18 +567,19 @@ void rbox_transaction_save_commit_post(struct mail_save_context *_ctx, } void clean_up_mail_object_list(struct rbox_save_context *r_ctx, struct rbox_storage *r_storage) { + FUNC_START(); for (std::vector::iterator it = r_ctx->objects.begin(); it != r_ctx->objects.end(); ++it) { r_storage->s->free_mail_object(*it); *it = nullptr; } r_ctx->objects.clear(); + FUNC_END(); } void rbox_transaction_save_rollback(struct mail_save_context *_ctx) { FUNC_START(); struct rbox_save_context *r_ctx = (struct rbox_save_context *)_ctx; - struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; if (!r_ctx->finished) { rbox_save_cancel(&r_ctx->ctx); @@ -598,7 +596,7 @@ void rbox_transaction_save_rollback(struct mail_save_context *_ctx) { } } - clean_up_mail_object_list(r_ctx, r_storage); + clean_up_mail_object_list(r_ctx, (struct rbox_storage *)&r_ctx->mbox->storage->storage); guid_128_empty(r_ctx->mail_guid); guid_128_empty(r_ctx->mail_oid); diff --git a/src/storage-rbox/rbox-storage.cpp b/src/storage-rbox/rbox-storage.cpp index d2397e15..2b954a6e 100644 --- a/src/storage-rbox/rbox-storage.cpp +++ b/src/storage-rbox/rbox-storage.cpp @@ -60,6 +60,7 @@ struct mail_storage *rbox_storage_alloc(void) { pool_t pool; pool = pool_alloconly_create("rbox storage", 256); storage = p_new(pool, struct rbox_storage, 1); + i_zero(storage); storage->storage = rbox_storage; storage->storage.pool = pool; storage->cluster = new librmb::RadosClusterImpl(); @@ -76,7 +77,6 @@ struct mail_storage *rbox_storage_alloc(void) { return &storage->storage; } - void rbox_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED, struct mailbox_list_settings *set) { FUNC_START(); @@ -101,7 +101,7 @@ static const char *rbox_storage_find_root_dir(const struct mail_namespace *ns) { const char *path = t_strconcat(home, "/rbox", NULL); if (access(path, R_OK | W_OK | X_OK) == 0) { #ifdef DEBUG - i_debug("rbox: root exists (%s)", path); + i_debug("rbox: root exists (%s)", path); #endif return path; } @@ -219,6 +219,7 @@ struct mailbox *rbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_ pool = pool_alloconly_create("rbox mailbox", 1024); rbox = p_new(pool, struct rbox_mailbox, 1); + i_zero(rbox); rbox_mailbox.v = rbox_mailbox_vfuncs; rbox->box = rbox_mailbox; rbox->box.pool = pool; @@ -433,8 +434,6 @@ int rbox_open_rados_connection(struct mailbox *box, bool alt_storage) { return ret; } - - static void rbox_update_header(struct rbox_mailbox *mbox, struct mail_index_transaction *trans, const struct mailbox_update *update) { FUNC_START(); diff --git a/src/storage-rbox/rbox-sync-rebuild.cpp b/src/storage-rbox/rbox-sync-rebuild.cpp index 81082c56..c9a35760 100644 --- a/src/storage-rbox/rbox-sync-rebuild.cpp +++ b/src/storage-rbox/rbox-sync-rebuild.cpp @@ -31,8 +31,10 @@ int rbox_sync_add_object(struct index_rebuild_context *ctx, const std::string &o bool alt_storage, uint32_t next_uid) { FUNC_START(); struct rbox_mailbox *rbox_mailbox = (struct rbox_mailbox *)ctx->box; - std::string xattr_mail_uid = mail_obj->get_metadata(rbox_metadata_key::RBOX_METADATA_MAIL_UID); - std::string xattr_guid = mail_obj->get_metadata(rbox_metadata_key::RBOX_METADATA_GUID); + std::string xattr_mail_uid; + mail_obj->get_metadata(rbox_metadata_key::RBOX_METADATA_MAIL_UID, &xattr_mail_uid); + std::string xattr_guid; + mail_obj->get_metadata(rbox_metadata_key::RBOX_METADATA_GUID, &xattr_guid); struct mail_storage *storage = ctx->box->storage; struct rbox_storage *r_storage = (struct rbox_storage *)storage; uint32_t seq; @@ -219,6 +221,7 @@ int rbox_sync_index_rebuild_objects(struct index_rebuild_context *ctx) { pool = pool_alloconly_create("rbox rebuild pool", 256); rebuild_ctx = p_new(pool, struct rbox_sync_rebuild_ctx, 1); + i_zero(rebuild_ctx); rebuild_ctx->alt_storage = false; rebuild_ctx->next_uid = INT_MAX; diff --git a/src/storage-rbox/rbox-sync.cpp b/src/storage-rbox/rbox-sync.cpp index 6377180e..f3ad02e9 100644 --- a/src/storage-rbox/rbox-sync.cpp +++ b/src/storage-rbox/rbox-sync.cpp @@ -9,7 +9,7 @@ * License version 2.1, as published by the Free Software * Foundation. See file COPYING. */ - +#include #include extern "C" { @@ -61,6 +61,7 @@ static void rbox_sync_expunge(struct rbox_sync_context *ctx, uint32_t seq1, uint mail_index_expunge(ctx->trans, seq1); struct expunged_item *item = p_new(default_pool, struct expunged_item, 1); + i_zero(item); item->uid = uid; if (rbox_get_oid_from_index(ctx->sync_view, seq1, ((struct rbox_mailbox *)box)->ext_id, &item->oid) < 0) { // continue anyway @@ -103,7 +104,6 @@ static int update_extended_metadata(struct rbox_sync_context *ctx, uint32_t seq1 if (rbox_get_oid_from_index(ctx->sync_view, seq1, ((struct rbox_mailbox *)box)->ext_id, &index_oid) >= 0) { const char *oid = guid_128_to_string(index_oid); - std::string key_oid(oid); std::string ext_key = std::to_string(keyword_idx); if (remove) { @@ -186,7 +186,8 @@ static int update_flags(struct rbox_sync_context *ctx, uint32_t seq1, uint32_t s librmb::RadosMailObject mail_object; mail_object.set_oid(oid); r_storage->ms->get_storage()->load_metadata(&mail_object); - std::string flags_metadata = mail_object.get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS); + std::string flags_metadata; + mail_object.get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &flags_metadata); uint8_t flags; if (librmb::RadosUtils::string_to_flags(flags_metadata, &flags)) { if (add_flags != 0) { @@ -371,7 +372,7 @@ int rbox_sync_begin(struct rbox_mailbox *mbox, struct rbox_sync_context **ctx_r, if (ret >= 0) { // sync_ctx->flags werden gesetzt. ret = index_storage_expunged_sync_begin(&mbox->box, &ctx->index_sync_ctx, &ctx->sync_view, &ctx->trans, - static_cast(sync_flags)); + static_cast(sync_flags)); if (mail_index_reset_fscked(mbox->box.index)) rbox_set_mailbox_corrupted(&mbox->box); } @@ -382,24 +383,24 @@ int rbox_sync_begin(struct rbox_mailbox *mbox, struct rbox_sync_context **ctx_r, *ctx_r = NULL; FUNC_END_RET("ret <= 0"); return ret; -} -if (!rebuild) { - ret = rbox_sync_index(ctx); -} -if (ret <= 0) { - mail_index_sync_rollback(&ctx->index_sync_ctx); - if (ret < 0) { - index_storage_expunging_deinit(&ctx->mbox->box); - array_delete(&ctx->expunged_items, array_count(&ctx->expunged_items) - 1, 1); - array_free(&ctx->expunged_items); - i_free(ctx); - return -1; } -} + if (!rebuild) { + ret = rbox_sync_index(ctx); + } + if (ret <= 0) { + mail_index_sync_rollback(&ctx->index_sync_ctx); + if (ret < 0) { + index_storage_expunging_deinit(&ctx->mbox->box); + array_delete(&ctx->expunged_items, array_count(&ctx->expunged_items) - 1, 1); + array_free(&ctx->expunged_items); + i_free(ctx); + return -1; + } + } -*ctx_r = ctx; -FUNC_END(); -return 0; + *ctx_r = ctx; + FUNC_END(); + return 0; } struct AioRemove { @@ -431,8 +432,7 @@ static int rbox_sync_object_expunge(AioRemove *stat) { return ret_remove; } - -static void aio_cb(rados_completion_t cb, void *arg) { +static void expunge_cb(rados_completion_t cb, void *arg) { AioRemove *stat = static_cast(arg); if (stat->completion->get_return_value() == 0) { struct mailbox *box = &stat->ctx->mbox->box; @@ -479,7 +479,7 @@ static void rbox_sync_expunge_rbox_objects(struct rbox_sync_context *ctx) { AioRemove *stat = new AioRemove(); stat->ctx = ctx; stat->item = item; - stat->completion = librados::Rados::aio_create_completion(static_cast(stat), aio_cb, NULL); + stat->completion = librados::Rados::aio_create_completion(static_cast(stat), expunge_cb, NULL); completions.push_back(stat->completion); // make it async! rbox_sync_object_expunge(stat); @@ -506,7 +506,7 @@ int rbox_sync_finish(struct rbox_sync_context **_ctx, bool success) { struct rbox_sync_context *ctx = *_ctx; int ret = success ? 0 : -1; struct expunged_item *const *exp_items, *exp_item; - unsigned int count =0 ; + unsigned int count = 0; *_ctx = NULL; if (success) { diff --git a/src/tests/storage-rbox/it_test_copy_rbox.cpp b/src/tests/storage-rbox/it_test_copy_rbox.cpp index 808ab2c1..48be3373 100644 --- a/src/tests/storage-rbox/it_test_copy_rbox.cpp +++ b/src/tests/storage-rbox/it_test_copy_rbox.cpp @@ -137,32 +137,67 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) { librmb::RadosMailObject *mail1 = objects[0]; librmb::RadosMailObject *mail2 = objects[1]; - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF), mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE), - mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_GUID), mail2->get_metadata(librmb::RBOX_METADATA_GUID)); - - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID), - mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX), - mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER), - mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL), mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS), mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VERSION), mail2->get_metadata(librmb::RBOX_METADATA_VERSION)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME)); - - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID), mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID)); + std::string val; + std::string val2; + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val); + mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val); + mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VERSION, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VERSION, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val2); + ASSERT_NE(val, val2); ASSERT_EQ(2, (int)box->index->map->hdr.messages_count); delete mail1; diff --git a/src/tests/storage-rbox/it_test_copy_rbox_alt.cpp b/src/tests/storage-rbox/it_test_copy_rbox_alt.cpp index 0348762f..e416a1f6 100644 --- a/src/tests/storage-rbox/it_test_copy_rbox_alt.cpp +++ b/src/tests/storage-rbox/it_test_copy_rbox_alt.cpp @@ -161,32 +161,67 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) { librmb::RadosMailObject *mail1 = objects_alt[0]; librmb::RadosMailObject *mail2 = objects_alt[1]; - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF), mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE), - mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_GUID), mail2->get_metadata(librmb::RBOX_METADATA_GUID)); - - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID), - mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX), - mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER), - mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL), mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS), mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VERSION), mail2->get_metadata(librmb::RBOX_METADATA_VERSION)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME)); - - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID), mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID)); + std::string val; + std::string val2; + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val); + mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val); + mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VERSION, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VERSION, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val2); + ASSERT_NE(val, val2); ASSERT_EQ(2, (int)box->index->map->hdr.messages_count); r_storage->alt->delete_mail(mail1); diff --git a/src/tests/storage-rbox/it_test_doveadm_backup_rbox.cpp b/src/tests/storage-rbox/it_test_doveadm_backup_rbox.cpp index d4fa090d..ad096fee 100644 --- a/src/tests/storage-rbox/it_test_doveadm_backup_rbox.cpp +++ b/src/tests/storage-rbox/it_test_doveadm_backup_rbox.cpp @@ -144,33 +144,67 @@ TEST_F(StorageTest, mail_doveadm_backup_copy_mail_in_inbox) { librmb::RadosMailObject *mail1 = objects[0]; librmb::RadosMailObject *mail2 = objects[1]; - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF), mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE), - mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_GUID), mail2->get_metadata(librmb::RBOX_METADATA_GUID)); - - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID), - mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX), - mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER), - mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL), mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS), mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VERSION), mail2->get_metadata(librmb::RBOX_METADATA_VERSION)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME)); - - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID), mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID)); - + std::string val; + std::string val2; + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val); + mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val); + mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VERSION, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VERSION, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val2); + ASSERT_NE(val, val2); ASSERT_EQ(2, (int)box->index->map->hdr.messages_count); delete mail1; delete mail2; diff --git a/src/tests/storage-rbox/it_test_lda_rbox.cpp b/src/tests/storage-rbox/it_test_lda_rbox.cpp index 7f2c5461..d419065e 100644 --- a/src/tests/storage-rbox/it_test_lda_rbox.cpp +++ b/src/tests/storage-rbox/it_test_lda_rbox.cpp @@ -151,32 +151,67 @@ TEST_F(StorageTest, mail_lda_copy_mail_in_inbox) { librmb::RadosMailObject *mail1 = objects[0]; librmb::RadosMailObject *mail2 = objects[1]; - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF), mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE), - mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_GUID), mail2->get_metadata(librmb::RBOX_METADATA_GUID)); - - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID), - mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX), - mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER), - mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL), mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS), mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VERSION), mail2->get_metadata(librmb::RBOX_METADATA_VERSION)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE), - mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE)); - ASSERT_EQ(mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME), - mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME)); - - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID), mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID)); + std::string val; + std::string val2; + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val); + mail2->get_metadata(librmb::RBOX_METADATA_EXT_REF, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_FROM_ENVELOPE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val); + mail2->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_ORDER, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val); + mail2->get_metadata(librmb::RBOX_METADATA_POP3_UIDL, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val); + mail2->get_metadata(librmb::RBOX_METADATA_PVT_FLAGS, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VERSION, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VERSION, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val); + mail2->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val); + mail2->get_metadata(librmb::RBOX_METADATA_OLDV1_SAVE_TIME, &val2); + ASSERT_EQ(val, val2); + + mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val); + mail2->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val2); + ASSERT_NE(val, val2); ASSERT_EQ(2, (int)box->index->map->hdr.messages_count); delete mail1; diff --git a/src/tests/storage-rbox/it_test_move_rbox.cpp b/src/tests/storage-rbox/it_test_move_rbox.cpp index 79a277c3..1bbec5bd 100644 --- a/src/tests/storage-rbox/it_test_move_rbox.cpp +++ b/src/tests/storage-rbox/it_test_move_rbox.cpp @@ -133,13 +133,23 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) { ASSERT_EQ(1, (int)objects.size()); librmb::RadosMailObject *mail1 = objects[0]; - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_GUID), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX), ""); + std::string val; + std::string val2; + + mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_GUID, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val); + ASSERT_NE(val, val2); ASSERT_EQ(1, (int)box->index->map->hdr.messages_count); delete mail1; diff --git a/src/tests/storage-rbox/it_test_move_rbox_alt.cpp b/src/tests/storage-rbox/it_test_move_rbox_alt.cpp index c7fa9def..45626403 100644 --- a/src/tests/storage-rbox/it_test_move_rbox_alt.cpp +++ b/src/tests/storage-rbox/it_test_move_rbox_alt.cpp @@ -159,13 +159,23 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) { ASSERT_EQ(1, (int)objects.size()); librmb::RadosMailObject *mail1 = objects[0]; - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_GUID), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), ""); - ASSERT_NE(mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX), ""); + std::string val; + std::string val2; + + mail1->get_metadata(librmb::RBOX_METADATA_MAIL_UID, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_GUID, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_MAILBOX_GUID, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_VIRTUAL_SIZE, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME, &val); + ASSERT_NE(val, val2); + mail1->get_metadata(librmb::RBOX_METADATA_ORIG_MAILBOX, &val); + ASSERT_NE(val, val2); ASSERT_EQ(1, (int)box->index->map->hdr.messages_count); r_storage->alt->delete_mail(mail1); diff --git a/src/tests/storage-rbox/it_test_storage_rbox.cpp b/src/tests/storage-rbox/it_test_storage_rbox.cpp index 5d84dace..b2f6d195 100644 --- a/src/tests/storage-rbox/it_test_storage_rbox.cpp +++ b/src/tests/storage-rbox/it_test_storage_rbox.cpp @@ -218,7 +218,8 @@ TEST_F(StorageTest, mail_save_to_inbox_with_flags) { librmb::RadosMailObject obj; obj.set_oid((*iter).get_oid()); r_storage->ms->get_storage()->load_metadata(&obj); - std::string str = obj.get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS); + std::string str; + obj.get_metadata(librmb::RBOX_METADATA_OLDV1_FLAGS, &str); uint8_t flags; librmb::RadosUtils::string_to_flags(str, &flags); EXPECT_EQ(0x01, flags); diff --git a/src/tests/test-utils/it_utils.cpp b/src/tests/test-utils/it_utils.cpp index 90bed146..186aef36 100644 --- a/src/tests/test-utils/it_utils.cpp +++ b/src/tests/test-utils/it_utils.cpp @@ -7,12 +7,15 @@ * Foundation. See file COPYING. */ -#include "../test-utils/it_utils.h" +#include "it_utils.h" + +#include #include "gtest/gtest.h" #include "gmock/gmock.h" #include "../mocks/mock_test.h" #include "istream-bufferlist.h" + using ::testing::AtLeast; using ::testing::Return; using ::testing::_;