Skip to content

Commit

Permalink
lib-storage: convert dbox-single to use container_of
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef 'Jeff' Sipek authored and cmouse committed Sep 7, 2017
1 parent 804fa3f commit df39630
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/lib-storage/index/dbox-single/sdbox-copy.c
Expand Up @@ -93,15 +93,14 @@ static int
sdbox_copy_hardlink(struct mail_save_context *_ctx, struct mail *mail)
{
struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
struct sdbox_mailbox *dest_mbox =
(struct sdbox_mailbox *)_ctx->transaction->box;
struct sdbox_mailbox *dest_mbox = SDBOX_MAILBOX(_ctx->transaction->box);
struct sdbox_mailbox *src_mbox;
struct dbox_file *src_file, *dest_file;
const char *src_path, *dest_path;
int ret;

if (strcmp(mail->box->storage->name, SDBOX_STORAGE_NAME) == 0)
src_mbox = (struct sdbox_mailbox *)mail->box;
src_mbox = SDBOX_MAILBOX(mail->box);
else {
/* Source storage isn't sdbox, can't hard link */
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/lib-storage/index/dbox-single/sdbox-mail.c
Expand Up @@ -30,7 +30,7 @@ static void sdbox_mail_set_expunged(struct dbox_mail *mail)
static int sdbox_mail_file_set(struct dbox_mail *mail)
{
struct mail *_mail = &mail->imail.mail.mail;
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)_mail->box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(_mail->box);
bool deleted;
int ret;

Expand Down Expand Up @@ -64,7 +64,7 @@ static int
sdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
const char **value_r)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)_mail->box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(_mail->box);
struct dbox_mail *mail = DBOX_MAIL(_mail);
struct stat st;

Expand Down
20 changes: 10 additions & 10 deletions src/lib-storage/index/dbox-single/sdbox-save.c
Expand Up @@ -33,11 +33,12 @@ struct sdbox_save_context {
ARRAY(struct dbox_file *) files;
};

#define SDBOX_SAVECTX(s) container_of(DBOX_SAVECTX(s), struct sdbox_save_context, ctx)

struct dbox_file *
sdbox_save_file_get_file(struct mailbox_transaction_context *t, uint32_t seq)
{
struct sdbox_save_context *ctx =
(struct sdbox_save_context *)t->save_ctx;
struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);
struct dbox_file *const *files, *file;
unsigned int count;

Expand All @@ -55,9 +56,8 @@ sdbox_save_file_get_file(struct mailbox_transaction_context *t, uint32_t seq)
struct mail_save_context *
sdbox_save_alloc(struct mailbox_transaction_context *t)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)t->box;
struct sdbox_save_context *ctx =
(struct sdbox_save_context *)t->save_ctx;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(t->box);
struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);

i_assert((t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);

Expand All @@ -81,7 +81,7 @@ sdbox_save_alloc(struct mailbox_transaction_context *t)

void sdbox_save_add_file(struct mail_save_context *_ctx, struct dbox_file *file)
{
struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct dbox_file *const *files;
unsigned int count;

Expand All @@ -99,7 +99,7 @@ void sdbox_save_add_file(struct mail_save_context *_ctx, struct dbox_file *file)

int sdbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
{
struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct dbox_file *file;
int ret;

Expand Down Expand Up @@ -298,7 +298,7 @@ static void dbox_save_unref_files(struct sdbox_save_context *ctx)

int sdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
{
struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct mailbox_transaction_context *_t = _ctx->transaction;
const struct mail_index_header *hdr;

Expand Down Expand Up @@ -344,7 +344,7 @@ int sdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
void sdbox_transaction_save_commit_post(struct mail_save_context *_ctx,
struct mail_index_transaction_commit_result *result)
{
struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct mail_storage *storage = _ctx->transaction->box->storage;

_ctx->transaction = NULL; /* transaction is already freed */
Expand Down Expand Up @@ -373,7 +373,7 @@ void sdbox_transaction_save_commit_post(struct mail_save_context *_ctx,

void sdbox_transaction_save_rollback(struct mail_save_context *_ctx)
{
struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);

if (!ctx->ctx.finished)
sdbox_save_cancel(_ctx);
Expand Down
14 changes: 7 additions & 7 deletions src/lib-storage/index/dbox-single/sdbox-storage.c
Expand Up @@ -134,7 +134,7 @@ sdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS |
MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY;

mbox->storage = (struct sdbox_storage *)storage;
mbox->storage = SDBOX_STORAGE(storage);
return &mbox->box;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ int sdbox_mailbox_create_indexes(struct mailbox *box,
const struct mailbox_update *update,
struct mail_index_transaction *trans)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct mail_index_transaction *new_trans = NULL;
const struct mail_index_header *hdr;
uint32_t uid_validity, uid_next;
Expand Down Expand Up @@ -291,7 +291,7 @@ sdbox_get_attachment_path_suffix(struct dbox_file *_file)

void sdbox_set_mailbox_corrupted(struct mailbox *box)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct sdbox_index_header hdr;
bool need_resize;

Expand Down Expand Up @@ -329,7 +329,7 @@ static int sdbox_mailbox_alloc_index(struct sdbox_mailbox *mbox)

static int sdbox_mailbox_open(struct mailbox *box)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct sdbox_index_header hdr;
bool need_resize;
time_t path_ctime;
Expand Down Expand Up @@ -369,7 +369,7 @@ static int sdbox_mailbox_open(struct mailbox *box)

static void sdbox_mailbox_close(struct mailbox *box)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);

if (mbox->corrupted_rebuild_count != 0)
(void)sdbox_sync(mbox, 0);
Expand All @@ -380,7 +380,7 @@ static int
sdbox_mailbox_create(struct mailbox *box,
const struct mailbox_update *update, bool directory)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct sdbox_index_header hdr;
bool need_resize;

Expand All @@ -407,7 +407,7 @@ sdbox_mailbox_get_metadata(struct mailbox *box,
enum mailbox_metadata_items items,
struct mailbox_metadata *metadata_r)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);

if (index_mailbox_get_metadata(box, items, metadata_r) < 0)
return -1;
Expand Down
3 changes: 3 additions & 0 deletions src/lib-storage/index/dbox-single/sdbox-storage.h
Expand Up @@ -33,6 +33,9 @@ struct sdbox_mailbox {
guid_128_t mailbox_guid;
};

#define SDBOX_STORAGE(s) container_of(DBOX_STORAGE(s), struct sdbox_storage, storage)
#define SDBOX_MAILBOX(s) container_of(s, struct sdbox_mailbox, box)

extern struct mail_vfuncs sdbox_mail_vfuncs;

int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
Expand Down
4 changes: 2 additions & 2 deletions src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c
Expand Up @@ -68,7 +68,7 @@ static int
sdbox_sync_add_file(struct index_rebuild_context *ctx,
const char *fname, bool primary)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(ctx->box);
struct dbox_file *file;
uint32_t uid;
int ret;
Expand Down Expand Up @@ -136,7 +136,7 @@ static int sdbox_sync_index_rebuild_dir(struct index_rebuild_context *ctx,

static void sdbox_sync_update_header(struct index_rebuild_context *ctx)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(ctx->box);
struct sdbox_index_header hdr;
bool need_resize;

Expand Down
2 changes: 1 addition & 1 deletion src/lib-storage/index/dbox-single/sdbox-sync.c
Expand Up @@ -309,7 +309,7 @@ int sdbox_sync(struct sdbox_mailbox *mbox, enum sdbox_sync_flags flags)
struct mailbox_sync_context *
sdbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
enum sdbox_sync_flags sdbox_sync_flags = 0;
int ret = 0;

Expand Down

0 comments on commit df39630

Please sign in to comment.