Skip to content

Commit

Permalink
#93 removed todos, warnings,reorderd function names
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Oct 10, 2017
1 parent 122279a commit 0ca1488
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 66 deletions.
47 changes: 23 additions & 24 deletions src/librmb/rados-mail-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ using librmb::RadosMailObject;
const char RadosMailObject::X_ATTR_VERSION_VALUE[] = "0.1";
const char RadosMailObject::DATA_BUFFER_NAME[] = "RADOS_MAIL_BUFFER";

void RadosMailObject::set_guid(const uint8_t *_guid) { std::memcpy(this->guid, _guid, sizeof(this->guid)); }

RadosMailObject::RadosMailObject() {
memset(this->guid, 0, GUID_128_SIZE);
this->object_size = -1;
Expand All @@ -33,46 +31,47 @@ RadosMailObject::RadosMailObject() {
this->save_date_rados = 0;
}

std::string RadosMailObject::to_string(const std::string &padding) {
std::string uid = get_metadata(RBOX_METADATA_MAIL_UID);
std::string recv_time_str = get_metadata(RBOX_METADATA_RECEIVED_TIME);
std::string p_size = get_metadata(RBOX_METADATA_PHYSICAL_SIZE);
std::string v_size = get_metadata(RBOX_METADATA_VIRTUAL_SIZE);
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);

std::string rbox_version = get_metadata(RBOX_METADATA_VERSION);
std::string mailbox_guid = get_metadata(RBOX_METADATA_MAILBOX_GUID);
std::string mail_guid = get_metadata(RBOX_METADATA_GUID);
std::string mb_orig_name = get_metadata(RBOX_METADATA_ORIG_MAILBOX);
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);

time_t ts = -1;

if (!recv_time_str.empty()) {
ts = static_cast<time_t>(std::stol(recv_time_str));
ts = static_cast<time_t>(stol(recv_time_str));
}
std::ostringstream ss;
ostringstream ss;

ss << std::endl;
ss << padding << "MAIL: " << static_cast<char>(RBOX_METADATA_MAIL_UID) << "(uid)=" << uid << std::endl;
ss << endl;
ss << padding << "MAIL: " << static_cast<char>(RBOX_METADATA_MAIL_UID) << "(uid)=" << uid << endl;
ss << padding << " "
<< "oid = " << oid << std::endl;
std::string recv_time;
<< "oid = " << oid << endl;
string recv_time;
RadosUtils::convert_time_t_to_str(ts, &recv_time);
ss << padding << " " << static_cast<char>(RBOX_METADATA_RECEIVED_TIME) << "(receive_time)=" << recv_time
<< "\n";
std::string save_time;
string save_time;
RadosUtils::convert_time_t_to_str(save_date_rados, &save_time);
ss << padding << " "
<< "save_time=" << save_time << "\n";
ss << padding << " " << static_cast<char>(RBOX_METADATA_PHYSICAL_SIZE) << "(phy_size)=" << p_size << " "
<< static_cast<char>(RBOX_METADATA_VIRTUAL_SIZE) << "(v_size) = " << v_size << " stat_size=" << object_size
<< std::endl;
<< endl;
ss << padding << " " << static_cast<char>(RBOX_METADATA_MAILBOX_GUID) << "(mailbox_guid)=" << mailbox_guid
<< std::endl;
<< endl;
ss << padding << " " << static_cast<char>(RBOX_METADATA_ORIG_MAILBOX) << "(mailbox_orig_name)=" << mb_orig_name
<< std::endl;
ss << padding << " " << static_cast<char>(RBOX_METADATA_GUID) << "(mail_guid)=" << mail_guid << std::endl;
ss << padding << " " << static_cast<char>(RBOX_METADATA_VERSION) << "(rbox_version): " << rbox_version
<< std::endl;
<< endl;
ss << padding << " " << static_cast<char>(RBOX_METADATA_GUID) << "(mail_guid)=" << mail_guid << endl;
ss << padding << " " << static_cast<char>(RBOX_METADATA_VERSION) << "(rbox_version): " << rbox_version << endl;

return ss.str();
}
61 changes: 28 additions & 33 deletions src/librmb/rados-mail-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,67 @@
#include "rados-types.h"
#include <rados/librados.hpp>

#define GUID_128_SIZE 16

namespace librmb {

using namespace std;
using namespace librados;

class RadosMailObject {
public:
RadosMailObject();
virtual ~RadosMailObject() {}
void set_oid(const char* _oid) { this->oid = _oid; }
void set_oid(const std::string& _oid) { this->oid = _oid; }
void set_state(const std::string& _state) { this->state = _state; }
void set_version(const std::string& _version) { this->version = _version; }

void set_oid(const char* _oid) { this->oid = _oid; }
void set_oid(const string& _oid) { this->oid = _oid; }
void set_state(const string& _state) { this->state = _state; }
void set_version(const string& _version) { this->version = _version; }
void set_guid(const uint8_t* guid);
void set_object_size(const uint64_t& _size) { object_size = _size; }
void set_mail_buffer(char* _mail_buffer) { this->mail_buffer = _mail_buffer; }
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 std::string get_oid() { return this->oid; }
const std::string get_version() { return this->version; }

uint8_t* get_guid_ref() { return guid; }

const string get_oid() { return this->oid; }
const string get_version() { return this->version; }
const uint64_t& get_object_size() { return this->object_size; }

void set_object_size(const uint64_t& _size) { object_size = _size; }

bool has_active_op() { return active_op; }
void set_active_op(bool _active) { this->active_op = _active; }
std::map<librados::AioCompletion*, librados::ObjectWriteOperation*>* get_completion_op_map() {
return &completion_op;
}
void set_mail_buffer(char* _mail_buffer) { this->mail_buffer = _mail_buffer; }
time_t* get_rados_save_date() { return &this->save_date_rados; }
uint8_t* get_guid_ref() { return guid; }
char* get_mail_buffer() { return this->mail_buffer; }
map<string, ceph::bufferlist>* get_metadata() { return &this->attrset; }

std::map<std::string, ceph::bufferlist>* get_metadata() { return &this->attrset; }

std::string get_metadata(rbox_metadata_key key) {
std::string str_key(1, static_cast<char>(key));
map<AioCompletion*, ObjectWriteOperation*>* get_completion_op_map() { return &completion_op; }
string get_metadata(rbox_metadata_key key) {
string str_key(1, static_cast<char>(key));
return get_metadata(str_key);
}
const std::string get_metadata(std::string& key) {
std::string value;
const string get_metadata(string& key) {
string value;
if (attrset.find(key) != attrset.end()) {
value = attrset[key].to_str();
}
return value;
}

std::string to_string(const std::string& padding);
void set_rados_save_date(const time_t& _save_date) { this->save_date_rados = _save_date; }
time_t* get_rados_save_date() { return &this->save_date_rados; }
bool has_active_op() { return active_op; }
string to_string(const string& padding);

private:
std::string oid;
string oid;

std::string state;
std::string version;
string state;
string version;

uint8_t guid[GUID_128_SIZE];
uint64_t object_size; // byte
std::map<librados::AioCompletion*, librados::ObjectWriteOperation*> completion_op;
map<AioCompletion*, ObjectWriteOperation*> completion_op;

bool active_op;
// used as pointer to a buffer_t (to avoid using dovecot datatypes in library)
char* mail_buffer;
time_t save_date_rados;

std::map<std::string, ceph::bufferlist> attrset;
map<string, ceph::bufferlist> attrset;

public:
static const char X_ATTR_VERSION_VALUE[];
Expand Down
2 changes: 2 additions & 0 deletions src/librmb/rados-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace librmb {

#define GUID_128_SIZE 16

enum rbox_metadata_key {
/*
* mailbox global unique id the mail currently is in.
Expand Down
2 changes: 0 additions & 2 deletions src/librmb/rados-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
namespace librmb {

RadosUtils::RadosUtils() {
// TODO Auto-generated constructor stub
}

RadosUtils::~RadosUtils() {
// TODO Auto-generated destructor stub
}

bool RadosUtils::convert_str_to_time_t(const std::string &date, time_t *val) {
Expand Down
5 changes: 2 additions & 3 deletions src/tests/storage-rbox/it_test_copy_rbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) {
desttrans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL, reason);
#endif

search_ctx = mailbox_search_init(desttrans, search_args, NULL, 0, NULL);
search_ctx = mailbox_search_init(desttrans, search_args, NULL, static_cast<mail_fetch_field>(0), NULL);
mail_search_args_unref(&search_args);

while (mailbox_search_next(search_ctx, &mail)) {
Expand All @@ -192,14 +192,13 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) {
if (mailbox_transaction_commit(&desttrans) < 0) {
FAIL() << "tnx commit failed";
}
if (mailbox_sync(box, 0) < 0) {
if (mailbox_sync(box, static_cast<mailbox_sync_flags>(0)) < 0) {
FAIL() << "sync failed";
}

struct rbox_storage *r_storage = (struct rbox_storage *)box->storage;
librados::NObjectIterator iter(r_storage->s->get_io_ctx().nobjects_begin());
std::vector<librmb::RadosMailObject> objects;
int i = 0;
while (iter != r_storage->s->get_io_ctx().nobjects_end()) {
librmb::RadosMailObject obj;
obj.set_oid((*iter).get_oid());
Expand Down
5 changes: 2 additions & 3 deletions src/tests/storage-rbox/it_test_move_rbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) {
desttrans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL, reason);
#endif

search_ctx = mailbox_search_init(desttrans, search_args, NULL, 0, NULL);
search_ctx = mailbox_search_init(desttrans, search_args, NULL, static_cast<mail_fetch_field>(0), NULL);
mail_search_args_unref(&search_args);

while (mailbox_search_next(search_ctx, &mail)) {
Expand All @@ -191,14 +191,13 @@ TEST_F(StorageTest, mail_copy_mail_in_inbox) {
if (mailbox_transaction_commit(&desttrans) < 0) {
FAIL() << "tnx commit failed";
}
if (mailbox_sync(box, 0) < 0) {
if (mailbox_sync(box, static_cast<mailbox_sync_flags>(0)) < 0) {
FAIL() << "sync failed";
}

struct rbox_storage *r_storage = (struct rbox_storage *)box->storage;
librados::NObjectIterator iter(r_storage->s->get_io_ctx().nobjects_begin());
std::vector<librmb::RadosMailObject> objects;
int i = 0;
while (iter != r_storage->s->get_io_ctx().nobjects_end()) {
librmb::RadosMailObject obj;
obj.set_oid((*iter).get_oid());
Expand Down
3 changes: 2 additions & 1 deletion src/tests/sync-rbox/it_test_sync_rbox_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ TEST_F(SyncTest, force_resync_restore_missing_index_entry) {
copy_object(ns, box);
uint32_t msg_count_org = mail_index_view_get_messages_count(box->view);

if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC | MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) < 0) {
if (mailbox_sync(box, static_cast<mailbox_sync_flags>(MAILBOX_SYNC_FLAG_FORCE_RESYNC |
MAILBOX_SYNC_FLAG_FIX_INCONSISTENT)) < 0) {
i_error("Forcing a resync on mailbox %s failed: %s", mailbox, mailbox_get_last_internal_error(box, NULL));
FAIL() << " Forcing a resync on mailbox INBOX Failed";
}
Expand Down

0 comments on commit 0ca1488

Please sign in to comment.