commit 8162ad4872e2fd9927e71a12c6018b57cd3028eb
Author: Oswald Buddenhagen <[email protected]>
Date: Sun Apr 10 00:52:21 2011 +0200
add synchronous return values to more functions
everything which *may* require the cancellation of a main loop needs a
return value.
this excludes cancel(), because it is known to *always* cancel the loop.
open_store() needs no return code because it creates the object which
may be invalided in the first place, so there is nothing which would
reference it until successful completion. its callback otoh may be
already called from the loop.
src/drv_imap.c | 8 ++++----
src/drv_maildir.c | 10 +++++-----
src/isync.h | 6 +++---
src/main.c | 32 ++++++++++++++++----------------
src/sync.c | 13 ++++++-------
5 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/src/drv_imap.c b/src/drv_imap.c
index 5e22763..76d268a 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -1290,7 +1290,7 @@ do_cram_auth( imap_store_t *ctx, struct imap_cmd *cmdp,
const char *prompt )
static void
imap_open_store( store_conf_t *conf,
- void (*cb)( store_t *srv, void *aux ), void *aux )
+ int (*cb)( store_t *srv, void *aux ), void *aux )
{
imap_store_conf_t *cfg = (imap_store_conf_t *)conf;
imap_server_conf_t *srvc = cfg->server;
@@ -1716,16 +1716,16 @@ imap_find_msg( store_t *gctx, const char *tuid,
return cb( uid <= 0 ? DRV_MSG_BAD : DRV_OK, uid, aux );
}
-static void
+static int
imap_list( store_t *gctx,
- void (*cb)( int sts, void *aux ), void *aux )
+ int (*cb)( int sts, void *aux ), void *aux )
{
imap_store_t *ctx = (imap_store_t *)gctx;
int ret;
if ((ret = imap_exec_b( ctx, 0, "LIST \"\" \"%s%%\"", ctx->prefix )) ==
DRV_OK)
gctx->listed = 1;
- cb( ret, aux );
+ return cb( ret, aux );
}
static void
diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index 4d54803..ba9c960 100644
--- a/src/drv_maildir.c
+++ b/src/drv_maildir.c
@@ -95,7 +95,7 @@ maildir_parse_flags( const char *base )
static void
maildir_open_store( store_conf_t *conf,
- void (*cb)( store_t *ctx, void *aux ), void *aux )
+ int (*cb)( store_t *ctx, void *aux ), void *aux )
{
maildir_store_t *ctx;
struct stat st;
@@ -159,9 +159,9 @@ maildir_cleanup_drv( void )
{
}
-static void
+static int
maildir_list( store_t *gctx,
- void (*cb)( int sts, void *aux ), void *aux )
+ int (*cb)( int sts, void *aux ), void *aux )
{
DIR *dir;
struct dirent *de;
@@ -169,7 +169,7 @@ maildir_list( store_t *gctx,
if (!(dir = opendir( gctx->conf->path ))) {
error( "%s: %s\n", gctx->conf->path, strerror(errno) );
cb( DRV_STORE_BAD, aux );
- return;
+ return -1;
}
while ((de = readdir( dir ))) {
const char *inbox = ((maildir_store_conf_t *)gctx->conf)->inbox;
@@ -188,7 +188,7 @@ maildir_list( store_t *gctx,
closedir (dir);
gctx->listed = 1;
- cb( DRV_OK, aux );
+ return cb( DRV_OK, aux );
}
static const char *subdirs[] = { "cur", "new", "tmp" };
diff --git a/src/isync.h b/src/isync.h
index c831b77..c825279 100644
--- a/src/isync.h
+++ b/src/isync.h
@@ -187,12 +187,12 @@ struct driver {
int (*parse_store)( conffile_t *cfg, store_conf_t **storep, int *err );
void (*cleanup)( void );
void (*open_store)( store_conf_t *conf,
- void (*cb)( store_t *ctx, void *aux ), void *aux );
+ int (*cb)( store_t *ctx, void *aux ), void *aux );
void (*disown_store)( store_t *ctx );
store_t *(*own_store)( store_conf_t *conf );
void (*cancel_store)( store_t *ctx );
- void (*list)( store_t *ctx,
- void (*cb)( int sts, void *aux ), void *aux );
+ int (*list)( store_t *ctx,
+ int (*cb)( int sts, void *aux ), void *aux );
void (*prepare_paths)( store_t *ctx );
void (*prepare_opts)( store_t *ctx, int opts );
int (*select)( store_t *ctx, int minuid, int maxuid, int *excs, int
nexcs,
diff --git a/src/main.c b/src/main.c
index 7899a0e..de9eb8c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -210,7 +210,7 @@ typedef struct {
#define E_OPEN 1
#define E_SYNC 2
-static void sync_chans( main_vars_t *mvars, int ent );
+static int sync_chans( main_vars_t *mvars, int ent );
int
main( int argc, char **argv )
@@ -492,14 +492,14 @@ main( int argc, char **argv )
#define ST_OPEN 1
#define ST_CLOSED 2
-static void store_opened( store_t *ctx, void *aux );
-static void store_listed( int sts, void *aux );
+static int store_opened( store_t *ctx, void *aux );
+static int store_listed( int sts, void *aux );
static void done_sync_dyn( int sts, void *aux );
static void done_sync( int sts, void *aux );
#define nz(a,b) ((a)?(a):(b))
-static void
+static int
sync_chans( main_vars_t *mvars, int ent )
{
group_conf_t *group;
@@ -510,7 +510,7 @@ sync_chans( main_vars_t *mvars, int ent )
int t;
if (!mvars->cben)
- return;
+ return 0;
switch (ent) {
case E_OPEN: goto opened;
case E_SYNC: goto syncone;
@@ -564,7 +564,7 @@ sync_chans( main_vars_t *mvars, int ent )
if (mvars->skip)
goto next;
if (mvars->state[M] != ST_OPEN || mvars->state[S] != ST_OPEN)
- return;
+ return 0;
if (mvars->boxlist)
mvars->boxp = mvars->boxlist;
@@ -636,7 +636,7 @@ sync_chans( main_vars_t *mvars, int ent )
syncw:
mvars->cben = 1;
if (!mvars->done)
- return;
+ return 0;
syncone:
if (!mvars->skip)
goto syncml;
@@ -652,7 +652,7 @@ sync_chans( main_vars_t *mvars, int ent )
}
if (mvars->state[M] != ST_CLOSED || mvars->state[S] !=
ST_CLOSED) {
mvars->skip = mvars->cben = 1;
- return;
+ return 0;
}
free_string_list( mvars->cboxes );
free_string_list( mvars->boxes[M] );
@@ -670,9 +670,10 @@ sync_chans( main_vars_t *mvars, int ent )
}
for (t = 0; t < N_DRIVERS; t++)
drivers[t]->cleanup();
+ return -1;
}
-static void
+static int
store_opened( store_t *ctx, void *aux )
{
MVARS(aux)
@@ -681,23 +682,22 @@ store_opened( store_t *ctx, void *aux )
mvars->ret = mvars->skip = 1;
mvars->state[t] = ST_CLOSED;
sync_chans( mvars, E_OPEN );
- return;
+ return -1;
}
mvars->ctx[t] = ctx;
if (mvars->skip) {
mvars->state[t] = ST_OPEN;
- sync_chans( mvars, E_OPEN );
- return;
+ return sync_chans( mvars, E_OPEN );
}
if (!mvars->boxlist && mvars->chan->patterns && !ctx->listed)
- mvars->drv[t]->list( ctx, store_listed, AUX );
+ return mvars->drv[t]->list( ctx, store_listed, AUX );
else {
mvars->state[t] = ST_OPEN;
- sync_chans( mvars, E_OPEN );
+ return sync_chans( mvars, E_OPEN );
}
}
-static void
+static int
store_listed( int sts, void *aux )
{
MVARS(aux)
@@ -715,7 +715,7 @@ store_listed( int sts, void *aux )
mvars->ret = mvars->skip = 1;
break;
}
- sync_chans( mvars, E_OPEN );
+ return sync_chans( mvars, E_OPEN );
}
static void
diff --git a/src/sync.c b/src/sync.c
index e09dec9..6276fe1 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -1528,7 +1528,7 @@ msg_rtrashed( int sts, int uid, copy_vars_t *vars )
}
static int box_closed( int sts, void *aux );
-static void box_closed_p2( sync_vars_t *svars, int t );
+static int box_closed_p2( sync_vars_t *svars, int t );
static int
sync_close( sync_vars_t *svars, int t )
@@ -1542,8 +1542,7 @@ sync_close( sync_vars_t *svars, int t )
debug( "expunging %s\n", str_ms[t] );
return svars->drv[t]->close( svars->ctx[t], box_closed, AUX );
}
- box_closed_p2( svars, t );
- return 0;
+ return box_closed_p2( svars, t );
}
static int
@@ -1554,11 +1553,10 @@ box_closed( int sts, void *aux )
if (check_ret( sts, svars, t ))
return -1;
svars->state[t] |= ST_DID_EXPUNGE;
- box_closed_p2( svars, t );
- return 0;
+ return box_closed_p2( svars, t );
}
-static void
+static int
box_closed_p2( sync_vars_t *svars, int t )
{
sync_rec_t *srec;
@@ -1567,7 +1565,7 @@ box_closed_p2( sync_vars_t *svars, int t )
svars->state[t] |= ST_CLOSED;
if (!(svars->state[1-t] & ST_CLOSED))
- return;
+ return 0;
if ((svars->state[M] | svars->state[S]) & ST_DID_EXPUNGE) {
/* This cleanup is not strictly necessary, as the next full sync
@@ -1627,6 +1625,7 @@ box_closed_p2( sync_vars_t *svars, int t )
}
sync_bail( svars );
+ return -1;
}
static void
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel