2022-06-16 10:44:35 +00:00
|
|
|
// SPDX-FileCopyrightText: 2017-2022 Oswald Buddenhagen <ossi@users.sf.net>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-isync-GPL-exception
|
2017-04-02 12:57:17 +00:00
|
|
|
/*
|
|
|
|
* mbsync - mailbox synchronizer
|
|
|
|
*/
|
|
|
|
|
2021-12-21 17:44:39 +00:00
|
|
|
#define DEBUG_FLAG DEBUG_DRV
|
|
|
|
|
2017-04-02 12:57:17 +00:00
|
|
|
#include "driver.h"
|
|
|
|
|
2022-06-05 08:49:21 +00:00
|
|
|
BIT_FORMATTER_FUNCTION(opts, OPEN)
|
|
|
|
|
2020-12-14 22:16:01 +00:00
|
|
|
typedef struct gen_cmd gen_cmd_t;
|
|
|
|
|
2020-12-17 14:53:40 +00:00
|
|
|
typedef union proxy_store {
|
2017-04-02 12:57:17 +00:00
|
|
|
store_t gen;
|
2020-12-17 14:53:40 +00:00
|
|
|
struct {
|
|
|
|
STORE(union proxy_store)
|
|
|
|
const char *label; // foreign
|
|
|
|
uint ref_count;
|
|
|
|
driver_t *real_driver;
|
|
|
|
store_t *real_store;
|
2022-02-07 11:53:58 +00:00
|
|
|
gen_cmd_t *pending_cmds, **pending_cmds_append;
|
2020-12-14 22:16:01 +00:00
|
|
|
gen_cmd_t *check_cmds, **check_cmds_append;
|
|
|
|
wakeup_t wakeup;
|
2022-06-01 11:54:48 +00:00
|
|
|
char force_async;
|
2020-12-17 14:53:40 +00:00
|
|
|
|
2022-01-07 21:58:38 +00:00
|
|
|
void (*expunge_callback)( message_t *msg, void *aux );
|
2020-12-17 14:53:40 +00:00
|
|
|
void (*bad_callback)( void *aux );
|
2022-01-07 21:58:38 +00:00
|
|
|
void *callback_aux;
|
2020-12-17 14:53:40 +00:00
|
|
|
};
|
2017-04-02 12:57:17 +00:00
|
|
|
} proxy_store_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
proxy_store_deref( proxy_store_t *ctx )
|
|
|
|
{
|
2020-12-14 22:16:01 +00:00
|
|
|
if (!--ctx->ref_count) {
|
|
|
|
assert( !pending_wakeup( &ctx->wakeup ) );
|
2017-04-02 12:57:17 +00:00
|
|
|
free( ctx );
|
2020-12-14 22:16:01 +00:00
|
|
|
}
|
2017-04-02 12:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int curr_tag;
|
|
|
|
|
2020-12-17 14:53:40 +00:00
|
|
|
#define GEN_CMD \
|
|
|
|
uint ref_count; \
|
|
|
|
int tag; \
|
2020-12-14 22:16:01 +00:00
|
|
|
proxy_store_t *ctx; \
|
|
|
|
gen_cmd_t *next; \
|
|
|
|
void (*queued_cb)( gen_cmd_t *gcmd );
|
2020-12-17 14:53:40 +00:00
|
|
|
|
2020-12-14 22:16:01 +00:00
|
|
|
struct gen_cmd {
|
2020-12-17 14:53:40 +00:00
|
|
|
GEN_CMD
|
2020-12-14 22:16:01 +00:00
|
|
|
};
|
|
|
|
|
2017-04-02 12:57:17 +00:00
|
|
|
static gen_cmd_t *
|
2020-07-08 15:27:37 +00:00
|
|
|
proxy_cmd_new( proxy_store_t *ctx, uint sz )
|
2017-04-02 12:57:17 +00:00
|
|
|
{
|
|
|
|
gen_cmd_t *cmd = nfmalloc( sz );
|
|
|
|
cmd->ref_count = 2;
|
|
|
|
cmd->tag = ++curr_tag;
|
|
|
|
cmd->ctx = ctx;
|
|
|
|
ctx->ref_count++;
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
proxy_cmd_done( gen_cmd_t *cmd )
|
|
|
|
{
|
|
|
|
if (!--cmd->ref_count) {
|
|
|
|
proxy_store_deref( cmd->ctx );
|
|
|
|
free( cmd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 22:16:01 +00:00
|
|
|
static void
|
|
|
|
proxy_wakeup( void *aux )
|
|
|
|
{
|
|
|
|
proxy_store_t *ctx = (proxy_store_t *)aux;
|
|
|
|
|
2022-02-07 11:53:58 +00:00
|
|
|
gen_cmd_t *cmd = ctx->pending_cmds;
|
2020-12-14 22:16:01 +00:00
|
|
|
assert( cmd );
|
2022-02-07 11:53:58 +00:00
|
|
|
if (!(ctx->pending_cmds = cmd->next))
|
|
|
|
ctx->pending_cmds_append = &ctx->pending_cmds;
|
2020-12-14 22:16:01 +00:00
|
|
|
else
|
|
|
|
conf_wakeup( &ctx->wakeup, 0 );
|
|
|
|
cmd->queued_cb( cmd );
|
|
|
|
proxy_cmd_done( cmd );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_invoke( gen_cmd_t *cmd, int checked, const char *name )
|
2020-12-14 22:16:01 +00:00
|
|
|
{
|
2022-06-01 11:54:48 +00:00
|
|
|
proxy_store_t *ctx = cmd->ctx;
|
|
|
|
if (ctx->force_async) {
|
2022-02-07 11:53:58 +00:00
|
|
|
debug( "%s[% 2d] Queue %s%s\n", ctx->label, cmd->tag, name, checked ? " (checked)" : "" );
|
2020-12-14 22:16:01 +00:00
|
|
|
cmd->next = NULL;
|
|
|
|
if (checked) {
|
2022-02-07 11:53:58 +00:00
|
|
|
*ctx->check_cmds_append = cmd;
|
|
|
|
ctx->check_cmds_append = &cmd->next;
|
2020-12-14 22:16:01 +00:00
|
|
|
} else {
|
2022-02-07 11:53:58 +00:00
|
|
|
*ctx->pending_cmds_append = cmd;
|
|
|
|
ctx->pending_cmds_append = &cmd->next;
|
|
|
|
conf_wakeup( &ctx->wakeup, 0 );
|
2020-12-14 22:16:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-02-07 11:53:58 +00:00
|
|
|
cmd->queued_cb( cmd );
|
2020-12-14 22:16:01 +00:00
|
|
|
proxy_cmd_done( cmd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
proxy_flush_checked_cmds( proxy_store_t *ctx )
|
|
|
|
{
|
|
|
|
if (ctx->check_cmds) {
|
2022-02-07 11:53:58 +00:00
|
|
|
*ctx->pending_cmds_append = ctx->check_cmds;
|
|
|
|
ctx->pending_cmds_append = ctx->check_cmds_append;
|
2020-12-14 22:16:01 +00:00
|
|
|
ctx->check_cmds_append = &ctx->check_cmds;
|
|
|
|
ctx->check_cmds = NULL;
|
|
|
|
conf_wakeup( &ctx->wakeup, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_cancel_queued_cmds( proxy_store_t *ctx )
|
2020-12-14 22:16:01 +00:00
|
|
|
{
|
2022-02-07 11:53:58 +00:00
|
|
|
if (ctx->pending_cmds || ctx->check_cmds) {
|
|
|
|
// This would involve directly invoking the result callbacks with
|
|
|
|
// DRV_CANCEL, for which we'd need another set of dispatch functions.
|
|
|
|
// The autotest doesn't need that, so save the effort.
|
|
|
|
error( "Fatal: Faking asynchronous cancelation is not supported.\n" );
|
|
|
|
abort();
|
2020-12-14 22:16:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-02 12:57:17 +00:00
|
|
|
#if 0
|
|
|
|
//# TEMPLATE GETTER
|
|
|
|
static @type@proxy_@name@( store_t *gctx )
|
|
|
|
{
|
|
|
|
proxy_store_t *ctx = (proxy_store_t *)gctx;
|
|
|
|
|
|
|
|
@type@rv = ctx->real_driver->@name@( ctx->real_store );
|
|
|
|
debug( "%sCalled @name@, ret=@fmt@\n", ctx->label, rv );
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
//# END
|
|
|
|
|
|
|
|
//# TEMPLATE REGULAR
|
|
|
|
static @type@proxy_@name@( store_t *gctx@decl_args@ )
|
|
|
|
{
|
|
|
|
proxy_store_t *ctx = (proxy_store_t *)gctx;
|
|
|
|
|
|
|
|
@pre_print_args@
|
|
|
|
debug( "%sEnter @name@@print_fmt_args@\n", ctx->label@print_pass_args@ );
|
|
|
|
@print_args@
|
|
|
|
@type@rv = ctx->real_driver->@name@( ctx->real_store@pass_args@ );
|
2022-06-05 08:49:21 +00:00
|
|
|
debug( "%sLeave @name@, ret=@print_fmt_ret@\n", ctx->label, @print_pass_ret@ );
|
2017-04-02 12:57:17 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
//# END
|
|
|
|
|
|
|
|
//# TEMPLATE REGULAR_VOID
|
2020-12-17 21:03:06 +00:00
|
|
|
static @type@proxy_@name@( store_t *gctx@decl_args@ )
|
2017-04-02 12:57:17 +00:00
|
|
|
{
|
|
|
|
proxy_store_t *ctx = (proxy_store_t *)gctx;
|
|
|
|
|
|
|
|
@pre_print_args@
|
|
|
|
debug( "%sEnter @name@@print_fmt_args@\n", ctx->label@print_pass_args@ );
|
|
|
|
@print_args@
|
|
|
|
ctx->real_driver->@name@( ctx->real_store@pass_args@ );
|
|
|
|
debug( "%sLeave @name@\n", ctx->label );
|
|
|
|
@action@
|
|
|
|
}
|
|
|
|
//# END
|
|
|
|
|
2021-12-23 22:51:42 +00:00
|
|
|
//# TEMPLATE CALLBACK_VOID
|
|
|
|
debug( "%s[% 2d] Callback enter @name@\n", ctx->label, cmd->tag );
|
|
|
|
@print_cb_args@
|
|
|
|
//# END
|
|
|
|
//# TEMPLATE CALLBACK_STS
|
|
|
|
debug( "%s[% 2d] Callback enter @name@, sts=%d\n", ctx->label, cmd->tag, sts );
|
|
|
|
//# END
|
|
|
|
//# TEMPLATE CALLBACK_STS_PRN
|
|
|
|
debug( "%s[% 2d] Callback enter @name@, sts=%d\n", ctx->label, cmd->tag, sts );
|
|
|
|
if (sts == DRV_OK) {
|
|
|
|
@print_cb_args@
|
|
|
|
}
|
|
|
|
//# END
|
|
|
|
//# TEMPLATE CALLBACK_STS_FMT
|
|
|
|
if (sts == DRV_OK) {
|
|
|
|
debug( "%s[% 2d] Callback enter @name@, sts=" stringify(DRV_OK) "@print_fmt_cb_args@\n", ctx->label, cmd->tag@print_pass_cb_args@ );
|
|
|
|
@print_cb_args@
|
|
|
|
} else {
|
|
|
|
debug( "%s[% 2d] Callback enter @name@, sts=%d\n", ctx->label, cmd->tag, sts );
|
|
|
|
}
|
|
|
|
//# END
|
|
|
|
|
2017-04-02 12:57:17 +00:00
|
|
|
//# TEMPLATE CALLBACK
|
2020-12-17 14:53:40 +00:00
|
|
|
typedef union {
|
2022-02-07 11:53:58 +00:00
|
|
|
gen_cmd_t gen;
|
2020-12-17 14:53:40 +00:00
|
|
|
struct {
|
2022-02-07 11:53:58 +00:00
|
|
|
GEN_CMD
|
2020-12-17 14:53:40 +00:00
|
|
|
void (*callback)( @decl_cb_args@void *aux );
|
|
|
|
void *callback_aux;
|
|
|
|
@decl_state@
|
|
|
|
};
|
2017-04-02 12:57:17 +00:00
|
|
|
} @name@_cmd_t;
|
|
|
|
|
|
|
|
static void
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_@name@_cb( @decl_cb_args@void *aux )
|
2017-04-02 12:57:17 +00:00
|
|
|
{
|
2022-02-07 11:53:58 +00:00
|
|
|
@name@_cmd_t *cmd = (@name@_cmd_t *)aux;
|
|
|
|
proxy_store_t *ctx = cmd->ctx;
|
2017-04-02 12:57:17 +00:00
|
|
|
|
2022-03-01 14:16:07 +00:00
|
|
|
@count_step@
|
2021-12-23 22:51:42 +00:00
|
|
|
@print_cb_args_tpl@
|
2017-04-02 12:57:17 +00:00
|
|
|
cmd->callback( @pass_cb_args@cmd->callback_aux );
|
2022-02-07 11:53:58 +00:00
|
|
|
debug( "%s[% 2d] Callback leave @name@\n", ctx->label, cmd->tag );
|
|
|
|
proxy_cmd_done( &cmd->gen );
|
2020-12-14 22:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_do_@name@( gen_cmd_t *gcmd )
|
2020-12-14 22:16:01 +00:00
|
|
|
{
|
2022-02-07 11:53:58 +00:00
|
|
|
@name@_cmd_t *cmd = (@name@_cmd_t *)gcmd;
|
|
|
|
proxy_store_t *ctx = cmd->ctx;
|
2020-12-14 22:16:01 +00:00
|
|
|
|
2022-02-07 11:53:58 +00:00
|
|
|
@pre_print_args@
|
|
|
|
debug( "%s[% 2d] Enter @name@@print_fmt_args@\n", ctx->label, cmd->tag@print_pass_args@ );
|
|
|
|
@print_args@
|
|
|
|
ctx->real_driver->@name@( ctx->real_store@pass_args@, proxy_@name@_cb, cmd );
|
|
|
|
debug( "%s[% 2d] Leave @name@\n", ctx->label, cmd->tag );
|
2017-04-02 12:57:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 21:03:06 +00:00
|
|
|
static @type@proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), void *aux )
|
2017-04-02 12:57:17 +00:00
|
|
|
{
|
|
|
|
proxy_store_t *ctx = (proxy_store_t *)gctx;
|
|
|
|
|
|
|
|
@name@_cmd_t *cmd = (@name@_cmd_t *)proxy_cmd_new( ctx, sizeof(@name@_cmd_t) );
|
2022-02-07 11:53:58 +00:00
|
|
|
cmd->queued_cb = proxy_do_@name@;
|
2017-04-02 12:57:17 +00:00
|
|
|
cmd->callback = cb;
|
|
|
|
cmd->callback_aux = aux;
|
|
|
|
@assign_state@
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_invoke( &cmd->gen, @checked@, "@name@" );
|
2017-04-02 12:57:17 +00:00
|
|
|
}
|
|
|
|
//# END
|
|
|
|
|
|
|
|
//# UNDEFINE list_store_print_fmt_cb_args
|
|
|
|
//# UNDEFINE list_store_print_pass_cb_args
|
|
|
|
//# DEFINE list_store_print_cb_args
|
2021-12-23 22:51:42 +00:00
|
|
|
for (string_list_t *box = boxes; box; box = box->next)
|
|
|
|
debug( " %s\n", box->string );
|
2017-04-02 12:57:17 +00:00
|
|
|
//# END
|
|
|
|
|
2022-03-01 14:16:07 +00:00
|
|
|
//# DEFINE create_box_counted 1
|
|
|
|
|
|
|
|
//# DEFINE delete_box_counted 1
|
|
|
|
|
2022-06-05 08:49:21 +00:00
|
|
|
//# DEFINE prepare_load_box_print_fmt_args , opts=%s
|
|
|
|
//# DEFINE prepare_load_box_print_pass_args , fmt_opts( opts ).str
|
|
|
|
//# DEFINE prepare_load_box_print_fmt_ret %s
|
|
|
|
//# DEFINE prepare_load_box_print_pass_ret fmt_opts( rv ).str
|
|
|
|
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE load_box_pre_print_args
|
2021-12-23 22:12:11 +00:00
|
|
|
char ubuf[12];
|
2017-04-02 12:57:17 +00:00
|
|
|
//# END
|
2019-12-29 10:52:26 +00:00
|
|
|
//# DEFINE load_box_print_fmt_args , [%u,%s] (find >= %u, paired <= %u, new > %u)
|
2022-02-07 11:53:58 +00:00
|
|
|
//# DEFINE load_box_print_pass_args , cmd->minuid, (cmd->maxuid == UINT_MAX) ? "inf" : (nfsnprintf( ubuf, sizeof(ubuf), "%u", cmd->maxuid ), ubuf), cmd->finduid, cmd->pairuid, cmd->newuid
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE load_box_print_args
|
2022-02-07 11:53:58 +00:00
|
|
|
if (cmd->excs.size) {
|
2017-04-02 12:57:17 +00:00
|
|
|
debugn( " excs:" );
|
2022-02-07 11:53:58 +00:00
|
|
|
for (uint t = 0; t < cmd->excs.size; t++)
|
|
|
|
debugn( " %u", cmd->excs.data[t] );
|
2017-04-02 12:57:17 +00:00
|
|
|
debug( "\n" );
|
|
|
|
}
|
|
|
|
//# END
|
2021-12-23 22:51:42 +00:00
|
|
|
//# DEFINE load_box_print_fmt_cb_args , total=%d, recent=%d
|
|
|
|
//# DEFINE load_box_print_pass_cb_args , total_msgs, recent_msgs
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE load_box_print_cb_args
|
2022-01-03 15:53:43 +00:00
|
|
|
for (message_t *msg = msgs; msg; msg = msg->next) {
|
|
|
|
if (msg->status & M_DEAD)
|
|
|
|
continue;
|
2021-12-23 22:51:42 +00:00
|
|
|
debug( " uid=%-5u flags=%-4s size=%-6u tuid=%." stringify(TUIDL) "s\n",
|
|
|
|
msg->uid, (msg->status & M_FLAGS) ? fmt_flags( msg->flags ).str : "?", msg->size, *msg->tuid ? msg->tuid : "?" );
|
2022-01-03 15:53:43 +00:00
|
|
|
}
|
2017-04-02 12:57:17 +00:00
|
|
|
//# END
|
|
|
|
|
2021-12-23 22:51:42 +00:00
|
|
|
//# UNDEFINE find_new_msgs_print_fmt_cb_args
|
|
|
|
//# UNDEFINE find_new_msgs_print_pass_cb_args
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE find_new_msgs_print_cb_args
|
2022-01-03 15:53:43 +00:00
|
|
|
for (message_t *msg = msgs; msg; msg = msg->next) {
|
|
|
|
if (msg->status & M_DEAD)
|
|
|
|
continue;
|
2021-12-23 22:51:42 +00:00
|
|
|
debug( " uid=%-5u tuid=%." stringify(TUIDL) "s\n", msg->uid, msg->tuid );
|
2022-01-03 15:53:43 +00:00
|
|
|
}
|
2017-04-02 12:57:17 +00:00
|
|
|
//# END
|
|
|
|
|
2017-03-21 19:05:29 +00:00
|
|
|
//# DEFINE fetch_msg_print_fmt_args , uid=%u, want_flags=%s, want_date=%s
|
2022-02-07 11:53:58 +00:00
|
|
|
//# DEFINE fetch_msg_print_pass_args , cmd->msg->uid, !(cmd->msg->status & M_FLAGS) ? "yes" : "no", cmd->data->date ? "yes" : "no"
|
2020-07-08 15:27:37 +00:00
|
|
|
//# DEFINE fetch_msg_print_fmt_cb_args , flags=%s, date=%lld, size=%u
|
2022-06-15 15:17:23 +00:00
|
|
|
//# DEFINE fetch_msg_print_pass_cb_args , fmt_flags( cmd->data->flags ).str, (long long)cmd->data->date, cmd->data->len
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE fetch_msg_print_cb_args
|
2021-12-23 22:51:42 +00:00
|
|
|
if (DFlags & DEBUG_DRV_ALL) {
|
2020-12-17 14:53:40 +00:00
|
|
|
printf( "%s=========\n", cmd->ctx->label );
|
2017-04-02 12:57:17 +00:00
|
|
|
fwrite( cmd->data->data, cmd->data->len, 1, stdout );
|
2020-12-17 14:53:40 +00:00
|
|
|
printf( "%s=========\n", cmd->ctx->label );
|
2017-04-02 12:57:17 +00:00
|
|
|
fflush( stdout );
|
|
|
|
}
|
|
|
|
//# END
|
|
|
|
|
2020-07-08 15:27:37 +00:00
|
|
|
//# DEFINE store_msg_print_fmt_args , flags=%s, date=%lld, size=%u, to_trash=%s
|
2022-02-07 11:53:58 +00:00
|
|
|
//# DEFINE store_msg_print_pass_args , fmt_flags( cmd->data->flags ).str, (long long)cmd->data->date, cmd->data->len, cmd->to_trash ? "yes" : "no"
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE store_msg_print_args
|
|
|
|
if (DFlags & DEBUG_DRV_ALL) {
|
|
|
|
printf( "%s>>>>>>>>>\n", ctx->label );
|
2022-02-07 11:53:58 +00:00
|
|
|
fwrite( cmd->data->data, cmd->data->len, 1, stdout );
|
2017-04-02 12:57:17 +00:00
|
|
|
printf( "%s>>>>>>>>>\n", ctx->label );
|
|
|
|
fflush( stdout );
|
|
|
|
}
|
|
|
|
//# END
|
2022-03-01 14:16:07 +00:00
|
|
|
//# DEFINE store_msg_counted 1
|
2017-04-02 12:57:17 +00:00
|
|
|
|
2022-02-07 11:53:58 +00:00
|
|
|
//# DEFINE set_msg_flags_checked 1
|
2017-03-21 19:05:29 +00:00
|
|
|
//# DEFINE set_msg_flags_print_fmt_args , uid=%u, add=%s, del=%s
|
2022-02-07 11:53:58 +00:00
|
|
|
//# DEFINE set_msg_flags_print_pass_args , cmd->uid, fmt_flags( cmd->add ).str, fmt_flags( cmd->del ).str
|
2022-03-01 14:16:07 +00:00
|
|
|
//# DEFINE set_msg_flags_counted 1
|
2017-04-02 12:57:17 +00:00
|
|
|
|
2017-03-21 19:05:29 +00:00
|
|
|
//# DEFINE trash_msg_print_fmt_args , uid=%u
|
2022-02-07 11:53:58 +00:00
|
|
|
//# DEFINE trash_msg_print_pass_args , cmd->msg->uid
|
2022-03-01 14:16:07 +00:00
|
|
|
//# DEFINE trash_msg_counted 1
|
|
|
|
|
|
|
|
//# DEFINE close_box_counted 1
|
2017-04-02 12:57:17 +00:00
|
|
|
|
2020-12-14 22:16:01 +00:00
|
|
|
//# DEFINE commit_cmds_print_args
|
|
|
|
proxy_flush_checked_cmds( ctx );
|
|
|
|
//# END
|
|
|
|
|
|
|
|
//# DEFINE cancel_cmds_print_cb_args
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_cancel_queued_cmds( ctx );
|
2020-12-14 22:16:01 +00:00
|
|
|
//# END
|
|
|
|
|
|
|
|
//# DEFINE free_store_print_args
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_cancel_queued_cmds( ctx );
|
2020-12-14 22:16:01 +00:00
|
|
|
//# END
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE free_store_action
|
|
|
|
proxy_store_deref( ctx );
|
|
|
|
//# END
|
|
|
|
|
2020-12-14 22:16:01 +00:00
|
|
|
//# DEFINE cancel_store_print_args
|
2022-02-07 11:53:58 +00:00
|
|
|
proxy_cancel_queued_cmds( ctx );
|
2020-12-14 22:16:01 +00:00
|
|
|
//# END
|
2017-04-02 12:57:17 +00:00
|
|
|
//# DEFINE cancel_store_action
|
|
|
|
proxy_store_deref( ctx );
|
|
|
|
//# END
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 21:58:38 +00:00
|
|
|
//# SPECIAL set_callbacks
|
2017-04-02 12:57:17 +00:00
|
|
|
static void
|
2022-01-07 21:58:38 +00:00
|
|
|
proxy_set_callbacks( store_t *gctx, void (*exp_cb)( message_t *, void * ),
|
|
|
|
void (*bad_cb)( void * ), void *aux )
|
2017-04-02 12:57:17 +00:00
|
|
|
{
|
|
|
|
proxy_store_t *ctx = (proxy_store_t *)gctx;
|
|
|
|
|
2022-01-07 21:58:38 +00:00
|
|
|
ctx->expunge_callback = exp_cb;
|
|
|
|
ctx->bad_callback = bad_cb;
|
|
|
|
ctx->callback_aux = aux;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
proxy_invoke_expunge_callback( message_t *msg, proxy_store_t *ctx )
|
|
|
|
{
|
|
|
|
ctx->ref_count++;
|
|
|
|
debug( "%sCallback enter expunged message %u\n", ctx->label, msg->uid );
|
|
|
|
ctx->expunge_callback( msg, ctx->callback_aux );
|
|
|
|
debug( "%sCallback leave expunged message %u\n", ctx->label, msg->uid );
|
|
|
|
proxy_store_deref( ctx );
|
2017-04-02 12:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
proxy_invoke_bad_callback( proxy_store_t *ctx )
|
|
|
|
{
|
2020-08-03 10:39:33 +00:00
|
|
|
ctx->ref_count++;
|
2017-04-02 12:57:17 +00:00
|
|
|
debug( "%sCallback enter bad store\n", ctx->label );
|
2022-01-07 21:58:38 +00:00
|
|
|
ctx->bad_callback( ctx->callback_aux );
|
2020-08-03 10:39:33 +00:00
|
|
|
debug( "%sCallback leave bad store\n", ctx->label );
|
|
|
|
proxy_store_deref( ctx );
|
2017-04-02 12:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//# EXCLUDE alloc_store
|
|
|
|
store_t *
|
2022-06-01 11:54:48 +00:00
|
|
|
proxy_alloc_store( store_t *real_ctx, const char *label, int force_async )
|
2017-04-02 12:57:17 +00:00
|
|
|
{
|
|
|
|
proxy_store_t *ctx;
|
|
|
|
|
2022-04-12 11:00:54 +00:00
|
|
|
ctx = nfzalloc( sizeof(*ctx) );
|
2020-12-17 14:53:40 +00:00
|
|
|
ctx->driver = &proxy_driver;
|
2017-04-02 12:57:17 +00:00
|
|
|
ctx->gen.conf = real_ctx->conf;
|
|
|
|
ctx->ref_count = 1;
|
|
|
|
ctx->label = label;
|
2022-06-01 11:54:48 +00:00
|
|
|
ctx->force_async = force_async;
|
2022-02-07 11:53:58 +00:00
|
|
|
ctx->pending_cmds_append = &ctx->pending_cmds;
|
2020-12-14 22:16:01 +00:00
|
|
|
ctx->check_cmds_append = &ctx->check_cmds;
|
2017-04-02 12:57:17 +00:00
|
|
|
ctx->real_driver = real_ctx->driver;
|
|
|
|
ctx->real_store = real_ctx;
|
2022-01-07 21:58:38 +00:00
|
|
|
ctx->real_driver->set_callbacks( ctx->real_store,
|
|
|
|
(void (*)( message_t *, void * ))proxy_invoke_expunge_callback,
|
|
|
|
(void (*)( void * ))proxy_invoke_bad_callback, ctx );
|
2020-12-14 22:16:01 +00:00
|
|
|
init_wakeup( &ctx->wakeup, proxy_wakeup, ctx );
|
2017-04-02 12:57:17 +00:00
|
|
|
return &ctx->gen;
|
|
|
|
}
|
|
|
|
|
|
|
|
//# EXCLUDE parse_store
|
|
|
|
//# EXCLUDE cleanup
|
|
|
|
//# EXCLUDE get_fail_state
|
|
|
|
|
|
|
|
#include "drv_proxy.inc"
|