Skip to content

Commit

Permalink
old-stats: Contexts are now required or checked
Browse files Browse the repository at this point in the history
Satisfies static analyzers
  • Loading branch information
cmouse authored and mrannanj committed Feb 20, 2018
1 parent afba4cf commit 4efb529
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/plugins/old-stats/mail-stats-connection.c
Expand Up @@ -14,7 +14,7 @@
int mail_stats_connection_connect(struct stats_connection *conn,
struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
string_t *str = t_str_new(128);

str_append(str, "CONNECT\t");
Expand Down Expand Up @@ -42,7 +42,7 @@ int mail_stats_connection_connect(struct stats_connection *conn,
void mail_stats_connection_disconnect(struct stats_connection *conn,
struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
string_t *str = t_str_new(128);

str_append(str, "DISCONNECT\t");
Expand All @@ -58,7 +58,7 @@ void mail_stats_connection_send_session(struct stats_connection *conn,
struct mail_user *user,
const struct stats *stats)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
string_t *str = t_str_new(256);
buffer_t *buf;

Expand Down
22 changes: 11 additions & 11 deletions src/plugins/old-stats/stats-plugin.c
Expand Up @@ -12,7 +12,7 @@
#include "stats-plugin.h"

#define STATS_CONTEXT(obj) \
MODULE_CONTEXT(obj, stats_storage_module)
MODULE_CONTEXT_REQUIRE(obj, stats_storage_module)

/* If session isn't refreshed every 15 minutes, it's dropped.
Must be smaller than MAIL_SESSION_IDLE_TIMEOUT_MSECS in stats server */
Expand Down Expand Up @@ -47,7 +47,7 @@ static void session_stats_refresh_timeout(struct mail_user *user);

static void stats_io_activate(struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
struct mail_stats *mail_stats;

if (stats_user_count == 1) {
Expand All @@ -67,7 +67,7 @@ static void stats_io_activate(struct mail_user *user)

static void stats_add_session(struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
struct stats *new_stats, *diff_stats;
const char *error;

Expand Down Expand Up @@ -120,7 +120,7 @@ session_stats_need_send(struct stats_user *suser, time_t now,

static void session_stats_refresh(struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
unsigned int to_next_secs;
time_t now = time(NULL);
bool changed;
Expand Down Expand Up @@ -149,7 +149,7 @@ stats_transaction_begin(struct mailbox *box,
enum mailbox_transaction_flags flags,
const char *reason)
{
struct stats_user *suser = STATS_USER_CONTEXT(box->storage->user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(box->storage->user);
struct stats_mailbox *sbox = STATS_CONTEXT(box);
struct mailbox_transaction_context *trans;
struct stats_transaction_context *strans;
Expand Down Expand Up @@ -189,7 +189,7 @@ stats_transaction_commit(struct mailbox_transaction_context *ctx,
{
struct stats_transaction_context *strans = STATS_CONTEXT(ctx);
struct stats_mailbox *sbox = STATS_CONTEXT(ctx->box);
struct stats_user *suser = STATS_USER_CONTEXT(ctx->box->storage->user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(ctx->box->storage->user);

stats_transaction_free(suser, strans);
return sbox->module_ctx.super.transaction_commit(ctx, changes_r);
Expand All @@ -200,7 +200,7 @@ stats_transaction_rollback(struct mailbox_transaction_context *ctx)
{
struct stats_transaction_context *strans = STATS_CONTEXT(ctx);
struct stats_mailbox *sbox = STATS_CONTEXT(ctx->box);
struct stats_user *suser = STATS_USER_CONTEXT(ctx->box->storage->user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(ctx->box->storage->user);

stats_transaction_free(suser, strans);
sbox->module_ctx.super.transaction_rollback(ctx);
Expand All @@ -211,7 +211,7 @@ static bool stats_search_next_nonblock(struct mail_search_context *ctx,
{
struct stats_mailbox *sbox = STATS_CONTEXT(ctx->transaction->box);
struct mail_user *user = ctx->transaction->box->storage->user;
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
bool ret;

ret = sbox->module_ctx.super.
Expand Down Expand Up @@ -289,7 +289,7 @@ static void session_stats_refresh_timeout(struct mail_user *user)

static void stats_io_deactivate(struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
unsigned int last_update_secs;

if (stats_global_user == NULL)
Expand All @@ -309,7 +309,7 @@ static void stats_io_deactivate(struct mail_user *user)

static void stats_user_stats_fill(struct mail_user *user, struct stats *stats)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
struct mail_stats *mail_stats;

mail_stats = stats_fill_ptr(stats, mail_stats_item);
Expand All @@ -320,7 +320,7 @@ static void stats_user_stats_fill(struct mail_user *user, struct stats *stats)

static void stats_user_deinit(struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
struct stats_user *suser = STATS_USER_CONTEXT_REQUIRE(user);
struct stats_connection *stats_conn = suser->stats_conn;

i_assert(stats_user_count > 0);
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/old-stats/stats-plugin.h
Expand Up @@ -8,6 +8,9 @@
#define STATS_USER_CONTEXT(obj) \
MODULE_CONTEXT(obj, stats_user_module)

#define STATS_USER_CONTEXT_REQUIRE(obj) \
MODULE_CONTEXT_REQUIRE(obj, stats_user_module)

struct stats_user {
union mail_user_module_context module_ctx;

Expand Down

0 comments on commit 4efb529

Please sign in to comment.