Skip to content

Commit

Permalink
#93 RadosMetadata, rbox_metadata_key
Browse files Browse the repository at this point in the history
- RadosMetadata moved to separate file rados-metadata.h
- enum rbox_metadata_key moved to separate file rados-types.h
  • Loading branch information
jrse committed Oct 10, 2017
1 parent ef04741 commit 26d5ee6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 110 deletions.
4 changes: 3 additions & 1 deletion src/librmb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
110 changes: 2 additions & 108 deletions src/librmb/rados-mail-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,122 +16,16 @@
#include <iostream>
#include <sstream>
#include <map>

#include "rados-metadata.h"
#include "rados-types.h"
#include <rados/librados.hpp>

#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*(<start offset> <byte count> <options> <ref>) */
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<int>(value)));
}

std::string enum_to_string(enum rbox_metadata_key _key) {
std::string k(1, static_cast<char>(_key));
return k;
}
};

class RadosMailObject {
public:
Expand Down
79 changes: 79 additions & 0 deletions src/librmb/rados-metadata.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include "time.h"
#include <stdlib.h>
#include <rados/librados.hpp>

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<int>(value)));
}

std::string enum_to_string(enum rbox_metadata_key _key) {
std::string k(1, static_cast<char>(_key));
return k;
}
};
} // end namespace
#endif /* SRC_LIBRMB_RADOS_METADATA_H_ */
60 changes: 60 additions & 0 deletions src/librmb/rados-types.h
Original file line number Diff line number Diff line change
@@ -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*(<start offset> <byte count> <options> <ref>) */
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_ */
2 changes: 1 addition & 1 deletion src/librmb/rados-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string>
#include "time.h"
#include <stdlib.h>
#include "rados-mail-object.h"
#include "rados-types.h"

namespace librmb {

Expand Down

0 comments on commit 26d5ee6

Please sign in to comment.