Просмотр исходного кода

tag verbose output when channel links two verbose stores

otherwise it's pure guesswork to assign the output to particular stores.
Oswald Buddenhagen 11 лет назад
Родитель
Сommit
92b892d247
4 измененных файлов с 25 добавлено и 12 удалено
  1. 13 9
      src/drv_imap.c
  2. 1 1
      src/drv_maildir.c
  3. 5 1
      src/isync.h
  4. 6 1
      src/main.c

+ 13 - 9
src/drv_imap.c

@@ -83,6 +83,7 @@ struct imap_cmd;
 
 typedef struct imap_store {
 	store_t gen;
+	const char *label; /* foreign */
 	const char *prefix;
 	int ref_count;
 	/* trash folder's existence is not confirmed yet */
@@ -254,9 +255,9 @@ send_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
 		if (ctx->num_in_progress)
 			printf( "(%d in progress) ", ctx->num_in_progress );
 		if (memcmp( cmd->cmd, "LOGIN", 5 ))
-			printf( ">>> %s", buf );
+			printf( "%s>>> %s", ctx->label, buf );
 		else
-			printf( ">>> %d LOGIN <user> <pass>\n", cmd->tag );
+			printf( "%s>>> %d LOGIN <user> <pass>\n", ctx->label, cmd->tag );
 		fflush( stdout );
 	}
 	if (socket_write( &ctx->conn, buf, bufl, KeepOwn ) < 0)
@@ -692,9 +693,9 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
 				goto postpone;
 
 			if (DFlags & XVERBOSE) {
-				puts( "=========" );
+				printf( "%s=========\n", ctx->label );
 				fwrite( cur->val, cur->len, 1, stdout );
-				puts( "=========" );
+				printf( "%s=========\n", ctx->label );
 				fflush( stdout );
 			}
 
@@ -702,7 +703,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
 			if (!(s = socket_read_line( &ctx->conn )))
 				goto postpone;
 			if (DFlags & VERBOSE) {
-				puts( s );
+				printf( "%s%s\n", ctx->label, s );
 				fflush( stdout );
 			}
 		} else if (*s == '"') {
@@ -1167,7 +1168,7 @@ imap_socket_read( void *aux )
 		if (!(cmd = socket_read_line( &ctx->conn )))
 			return;
 		if (DFlags & VERBOSE) {
-			puts( cmd );
+			printf( "%s%s\n", ctx->label, cmd );
 			fflush( stdout );
 		}
 
@@ -1425,7 +1426,7 @@ do_cram_auth( imap_store_t *ctx, struct imap_cmd *cmdp, const char *prompt )
 	cram( prompt, srvc->user, srvc->pass, &resp, &l );
 
 	if (DFlags & VERBOSE) {
-		printf( ">+> %s\n", resp );
+		printf( "%s>+> %s\n", ctx->label, resp );
 		fflush( stdout );
 	}
 	if (socket_write( &ctx->conn, resp, l, GiveOwn ) < 0)
@@ -1457,7 +1458,7 @@ static void imap_open_store_ssl_bail( imap_store_t * );
 static void imap_open_store_bail( imap_store_t * );
 
 static void
-imap_open_store( store_conf_t *conf,
+imap_open_store( store_conf_t *conf, const char *label,
                  void (*cb)( store_t *srv, void *aux ), void *aux )
 {
 	imap_store_conf_t *cfg = (imap_store_conf_t *)conf;
@@ -1468,12 +1469,14 @@ imap_open_store( store_conf_t *conf,
 	for (ctxp = &unowned; (ctx = (imap_store_t *)*ctxp); ctxp = &ctx->gen.next)
 		if (ctx->gen.conf == conf) {
 			*ctxp = ctx->gen.next;
+			ctx->label = label;
 			cb( &ctx->gen, aux );
 			return;
 		}
 	for (ctxp = &unowned; (ctx = (imap_store_t *)*ctxp); ctxp = &ctx->gen.next)
 		if (((imap_store_conf_t *)ctx->gen.conf)->server == srvc) {
 			*ctxp = ctx->gen.next;
+			ctx->label = label;
 			/* One could ping the server here, but given that the idle timeout
 			 * is at least 30 minutes, this sounds pretty pointless. */
 			free_string_list( ctx->gen.boxes );
@@ -1491,6 +1494,7 @@ imap_open_store( store_conf_t *conf,
 
 	ctx = nfcalloc( sizeof(*ctx) );
 	ctx->gen.conf = conf;
+	ctx->label = label;
 	ctx->ref_count = 1;
 	ctx->callbacks.imap_open = cb;
 	ctx->callback_aux = aux;
@@ -2355,7 +2359,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
 }
 
 struct driver imap_driver = {
-	DRV_CRLF,
+	DRV_CRLF | DRV_VERBOSE,
 	imap_parse_store,
 	imap_cleanup,
 	imap_open_store,

+ 1 - 1
src/drv_maildir.c

@@ -122,7 +122,7 @@ maildir_join_path( const char *prefix, const char *box )
 }
 
 static void
-maildir_open_store( store_conf_t *conf,
+maildir_open_store( store_conf_t *conf, const char *label ATTR_UNUSED,
                     void (*cb)( store_t *ctx, void *aux ), void *aux )
 {
 	maildir_store_t *ctx;

+ 5 - 1
src/isync.h

@@ -268,6 +268,10 @@ typedef struct {
    and as CRLF is the canonical format, we convert.
 */
 #define DRV_CRLF        1
+/*
+   This flag says that the driver will act upon (DFlags & VERBOSE).
+*/
+#define DRV_VERBOSE     2
 
 #define LIST_PATH       1
 #define LIST_INBOX      2
@@ -283,7 +287,7 @@ struct driver {
 
 	/* Open a store with the given configuration. This may recycle existing
 	 * server connections. Upon failure, a null store is passed to the callback. */
-	void (*open_store)( store_conf_t *conf,
+	void (*open_store)( store_conf_t *conf, const char *label,
 	                    void (*cb)( store_t *ctx, void *aux ), void *aux );
 
 	/* Mark the store as available for recycling. Server connection may be kept alive. */

+ 6 - 1
src/main.c

@@ -519,6 +519,7 @@ sync_chans( main_vars_t *mvars, int ent )
 	channel_conf_t *chan;
 	string_list_t *mbox, *sbox, **mboxp, **sboxp;
 	char *channame, *boxp, *nboxp;
+	const char *labels[2];
 	int t;
 
 	if (!mvars->cben)
@@ -585,10 +586,14 @@ sync_chans( main_vars_t *mvars, int ent )
 		mvars->state[M] = mvars->state[S] = ST_FRESH;
 		info( "Channel %s\n", mvars->chan->name );
 		mvars->skip = mvars->cben = 0;
+		if (mvars->chan->stores[M]->driver->flags & mvars->chan->stores[S]->driver->flags & DRV_VERBOSE)
+			labels[M] = "M: ", labels[S] = "S: ";
+		else
+			labels[M] = labels[S] = "";
 		for (t = 0; t < 2; t++) {
 			info( "Opening %s %s...\n", str_ms[t], mvars->chan->stores[t]->name );
 			mvars->drv[t] = mvars->chan->stores[t]->driver;
-			mvars->drv[t]->open_store( mvars->chan->stores[t], store_opened, AUX );
+			mvars->drv[t]->open_store( mvars->chan->stores[t], labels[t], store_opened, AUX );
 			if (mvars->skip)
 				break;
 		}