make set_bad_callback() a proper driver_t entry
... and make the pointers private to the drivers.
This commit is contained in:
parent
f46cf8c887
commit
d624c9af5d
16
src/driver.h
16
src/driver.h
|
@ -89,9 +89,6 @@ typedef struct store {
|
||||||
string_list_t *boxes; /* _list results - own */
|
string_list_t *boxes; /* _list results - own */
|
||||||
char listed; /* was _list already run? */
|
char listed; /* was _list already run? */
|
||||||
|
|
||||||
void (*bad_callback)( void *aux );
|
|
||||||
void *bad_callback_aux;
|
|
||||||
|
|
||||||
/* currently open mailbox */
|
/* currently open mailbox */
|
||||||
char *path; /* own */
|
char *path; /* own */
|
||||||
message_t *msgs; /* own */
|
message_t *msgs; /* own */
|
||||||
|
@ -103,15 +100,6 @@ typedef struct store {
|
||||||
int recent; /* # of recent messages - don't trust this beyond the initial read */
|
int recent; /* # of recent messages - don't trust this beyond the initial read */
|
||||||
} store_t;
|
} store_t;
|
||||||
|
|
||||||
/* When the callback is invoked (at most once per store), the store is fubar;
|
|
||||||
* call the driver's cancel_store() to dispose of it. */
|
|
||||||
static INLINE void
|
|
||||||
set_bad_callback( store_t *ctx, void (*cb)( void *aux ), void *aux )
|
|
||||||
{
|
|
||||||
ctx->bad_callback = cb;
|
|
||||||
ctx->bad_callback_aux = aux;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *data;
|
char *data;
|
||||||
int len;
|
int len;
|
||||||
|
@ -160,6 +148,10 @@ struct driver {
|
||||||
* return quickly, and must not fail. */
|
* return quickly, and must not fail. */
|
||||||
store_t *(*alloc_store)( store_conf_t *conf, const char *label );
|
store_t *(*alloc_store)( store_conf_t *conf, const char *label );
|
||||||
|
|
||||||
|
/* When this callback is invoked (at most once per store), the store is fubar;
|
||||||
|
* call cancel_store() to dispose of it. */
|
||||||
|
void (*set_bad_callback)( store_t *ctx, void (*cb)( void *aux ), void *aux );
|
||||||
|
|
||||||
/* Open/connect the store. This may recycle existing server connections. */
|
/* Open/connect the store. This may recycle existing server connections. */
|
||||||
void (*connect_store)( store_t *ctx,
|
void (*connect_store)( store_t *ctx,
|
||||||
void (*cb)( int sts, void *aux ), void *aux );
|
void (*cb)( int sts, void *aux ), void *aux );
|
||||||
|
|
|
@ -131,6 +131,9 @@ struct imap_store {
|
||||||
int sasl_cont;
|
int sasl_cont;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void (*bad_callback)( void *aux );
|
||||||
|
void *bad_callback_aux;
|
||||||
|
|
||||||
conn_t conn; /* this is BIG, so put it last */
|
conn_t conn; /* this is BIG, so put it last */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -404,7 +407,7 @@ static void
|
||||||
submit_imap_cmd( imap_store_t *ctx, imap_cmd_t *cmd )
|
submit_imap_cmd( imap_store_t *ctx, imap_cmd_t *cmd )
|
||||||
{
|
{
|
||||||
assert( ctx );
|
assert( ctx );
|
||||||
assert( ctx->gen.bad_callback );
|
assert( ctx->bad_callback );
|
||||||
assert( cmd );
|
assert( cmd );
|
||||||
assert( cmd->param.done );
|
assert( cmd->param.done );
|
||||||
|
|
||||||
|
@ -1540,10 +1543,19 @@ imap_deref( imap_store_t *ctx )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
imap_set_bad_callback( store_t *gctx, void (*cb)( void *aux ), void *aux )
|
||||||
|
{
|
||||||
|
imap_store_t *ctx = (imap_store_t *)gctx;
|
||||||
|
|
||||||
|
ctx->bad_callback = cb;
|
||||||
|
ctx->bad_callback_aux = aux;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
imap_invoke_bad_callback( imap_store_t *ctx )
|
imap_invoke_bad_callback( imap_store_t *ctx )
|
||||||
{
|
{
|
||||||
ctx->gen.bad_callback( ctx->gen.bad_callback_aux );
|
ctx->bad_callback( ctx->bad_callback_aux );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************* imap_free_store *******************/
|
/******************* imap_free_store *******************/
|
||||||
|
@ -1568,7 +1580,7 @@ imap_free_store( store_t *gctx )
|
||||||
{
|
{
|
||||||
free_generic_messages( gctx->msgs );
|
free_generic_messages( gctx->msgs );
|
||||||
gctx->msgs = 0;
|
gctx->msgs = 0;
|
||||||
set_bad_callback( gctx, imap_cancel_unowned, gctx );
|
imap_set_bad_callback( gctx, imap_cancel_unowned, gctx );
|
||||||
gctx->next = unowned;
|
gctx->next = unowned;
|
||||||
unowned = gctx;
|
unowned = gctx;
|
||||||
}
|
}
|
||||||
|
@ -1584,7 +1596,7 @@ imap_cleanup( void )
|
||||||
|
|
||||||
for (ctx = unowned; ctx; ctx = nctx) {
|
for (ctx = unowned; ctx; ctx = nctx) {
|
||||||
nctx = ctx->next;
|
nctx = ctx->next;
|
||||||
set_bad_callback( ctx, (void (*)(void *))imap_cancel_store, ctx );
|
imap_set_bad_callback( ctx, (void (*)(void *))imap_cancel_store, ctx );
|
||||||
if (((imap_store_t *)ctx)->state != SST_BAD) {
|
if (((imap_store_t *)ctx)->state != SST_BAD) {
|
||||||
((imap_store_t *)ctx)->expectBYE = 1;
|
((imap_store_t *)ctx)->expectBYE = 1;
|
||||||
imap_exec( (imap_store_t *)ctx, 0, imap_cleanup_p2, "LOGOUT" );
|
imap_exec( (imap_store_t *)ctx, 0, imap_cleanup_p2, "LOGOUT" );
|
||||||
|
@ -3194,6 +3206,7 @@ struct driver imap_driver = {
|
||||||
imap_parse_store,
|
imap_parse_store,
|
||||||
imap_cleanup,
|
imap_cleanup,
|
||||||
imap_alloc_store,
|
imap_alloc_store,
|
||||||
|
imap_set_bad_callback,
|
||||||
imap_connect_store,
|
imap_connect_store,
|
||||||
imap_free_store,
|
imap_free_store,
|
||||||
imap_cancel_store,
|
imap_cancel_store,
|
||||||
|
|
|
@ -78,6 +78,9 @@ typedef struct {
|
||||||
char *usedb;
|
char *usedb;
|
||||||
#endif /* USE_DB */
|
#endif /* USE_DB */
|
||||||
wakeup_t lcktmr;
|
wakeup_t lcktmr;
|
||||||
|
|
||||||
|
void (*bad_callback)( void *aux );
|
||||||
|
void *bad_callback_aux;
|
||||||
} maildir_store_t;
|
} maildir_store_t;
|
||||||
|
|
||||||
#ifdef USE_DB
|
#ifdef USE_DB
|
||||||
|
@ -287,7 +290,16 @@ maildir_cleanup_drv( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
maildir_invoke_bad_callback( store_t *ctx )
|
maildir_set_bad_callback( store_t *gctx, void (*cb)( void *aux ), void *aux )
|
||||||
|
{
|
||||||
|
maildir_store_t *ctx = (maildir_store_t *)gctx;
|
||||||
|
|
||||||
|
ctx->bad_callback = cb;
|
||||||
|
ctx->bad_callback_aux = aux;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
maildir_invoke_bad_callback( maildir_store_t *ctx )
|
||||||
{
|
{
|
||||||
ctx->bad_callback( ctx->bad_callback_aux );
|
ctx->bad_callback( ctx->bad_callback_aux );
|
||||||
}
|
}
|
||||||
|
@ -475,6 +487,7 @@ static void
|
||||||
maildir_list_store( store_t *gctx, int flags,
|
maildir_list_store( store_t *gctx, int flags,
|
||||||
void (*cb)( int sts, void *aux ), void *aux )
|
void (*cb)( int sts, void *aux ), void *aux )
|
||||||
{
|
{
|
||||||
|
maildir_store_t *ctx = (maildir_store_t *)gctx;
|
||||||
maildir_store_conf_t *conf = (maildir_store_conf_t *)gctx->conf;
|
maildir_store_conf_t *conf = (maildir_store_conf_t *)gctx->conf;
|
||||||
|
|
||||||
if (conf->sub_style == SUB_MAILDIRPP
|
if (conf->sub_style == SUB_MAILDIRPP
|
||||||
|
@ -483,7 +496,7 @@ maildir_list_store( store_t *gctx, int flags,
|
||||||
&& maildir_list_path( gctx, flags, conf->inbox ) < 0) ||
|
&& maildir_list_path( gctx, flags, conf->inbox ) < 0) ||
|
||||||
((flags & LIST_INBOX)
|
((flags & LIST_INBOX)
|
||||||
&& maildir_list_inbox( gctx, flags, gctx->conf->path ) < 0))) {
|
&& maildir_list_inbox( gctx, flags, gctx->conf->path ) < 0))) {
|
||||||
maildir_invoke_bad_callback( gctx );
|
maildir_invoke_bad_callback( ctx );
|
||||||
cb( DRV_CANCELED, aux );
|
cb( DRV_CANCELED, aux );
|
||||||
} else {
|
} else {
|
||||||
cb( DRV_OK, aux );
|
cb( DRV_OK, aux );
|
||||||
|
@ -582,7 +595,7 @@ maildir_validate( const char *box, int create, maildir_store_t *ctx )
|
||||||
if (make_box_dir( buf, bl )) {
|
if (make_box_dir( buf, bl )) {
|
||||||
sys_error( "Maildir error: cannot create mailbox '%s'", box );
|
sys_error( "Maildir error: cannot create mailbox '%s'", box );
|
||||||
((maildir_store_conf_t *)ctx->gen.conf)->failed = FAIL_FINAL;
|
((maildir_store_conf_t *)ctx->gen.conf)->failed = FAIL_FINAL;
|
||||||
maildir_invoke_bad_callback( &ctx->gen );
|
maildir_invoke_bad_callback( ctx );
|
||||||
return DRV_CANCELED;
|
return DRV_CANCELED;
|
||||||
}
|
}
|
||||||
} else if (!S_ISDIR(st.st_mode)) {
|
} else if (!S_ISDIR(st.st_mode)) {
|
||||||
|
@ -1876,6 +1889,7 @@ struct driver maildir_driver = {
|
||||||
maildir_parse_store,
|
maildir_parse_store,
|
||||||
maildir_cleanup_drv,
|
maildir_cleanup_drv,
|
||||||
maildir_alloc_store,
|
maildir_alloc_store,
|
||||||
|
maildir_set_bad_callback,
|
||||||
maildir_connect_store,
|
maildir_connect_store,
|
||||||
maildir_free_store,
|
maildir_free_store,
|
||||||
maildir_free_store, /* _cancel_, but it's the same */
|
maildir_free_store, /* _cancel_, but it's the same */
|
||||||
|
|
|
@ -817,7 +817,7 @@ sync_chans( main_vars_t *mvars, int ent )
|
||||||
for (t = 0; t < 2; t++) {
|
for (t = 0; t < 2; t++) {
|
||||||
mvars->drv[t] = mvars->chan->stores[t]->driver;
|
mvars->drv[t] = mvars->chan->stores[t]->driver;
|
||||||
mvars->ctx[t] = mvars->drv[t]->alloc_store( mvars->chan->stores[t], labels[t] );
|
mvars->ctx[t] = mvars->drv[t]->alloc_store( mvars->chan->stores[t], labels[t] );
|
||||||
set_bad_callback( mvars->ctx[t], store_bad, AUX );
|
mvars->drv[t]->set_bad_callback( mvars->ctx[t], store_bad, AUX );
|
||||||
}
|
}
|
||||||
for (t = 0; ; t++) {
|
for (t = 0; ; t++) {
|
||||||
info( "Opening %s store %s...\n", str_ms[t], mvars->chan->stores[t]->name );
|
info( "Opening %s store %s...\n", str_ms[t], mvars->chan->stores[t]->name );
|
||||||
|
|
|
@ -1002,8 +1002,8 @@ sync_boxes( store_t *ctx[], const char *names[], int present[], channel_conf_t *
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx[t]->uidvalidity = -1;
|
ctx[t]->uidvalidity = -1;
|
||||||
set_bad_callback( ctx[t], store_bad, AUX );
|
|
||||||
svars->drv[t] = ctx[t]->conf->driver;
|
svars->drv[t] = ctx[t]->conf->driver;
|
||||||
|
svars->drv[t]->set_bad_callback( ctx[t], store_bad, AUX );
|
||||||
}
|
}
|
||||||
/* Both boxes must be fully set up at this point, so that error exit paths
|
/* Both boxes must be fully set up at this point, so that error exit paths
|
||||||
* don't run into uninitialized variables. */
|
* don't run into uninitialized variables. */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user