From: Ralph Corderoy Date: Sun, 13 Aug 2017 16:13:34 +0000 (+0100) Subject: pop_retr(): Add a `void *closure' to be passed to action callback. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/d3d8f636ed951b4c02bdeeb146b528fe00dfbb48?ds=inline pop_retr(): Add a `void *closure' to be passed to action callback. Only caller passes in NULL for the moment, and doesn't use it in the callback, but it will allow fewer scopes by name of the variables the action callback uses. --- diff --git a/h/popsbr.h b/h/popsbr.h index 7193f1f5..fab83e14 100644 --- a/h/popsbr.h +++ b/h/popsbr.h @@ -8,7 +8,7 @@ int pop_init (char *, char *, char *, char *, int, int, char *, int, const char *); int pop_fd (char *, int, char *, int); int pop_stat (int *, int *); -int pop_retr (int, int (*)(char *)); +int pop_retr (int, int (*)(void *, char *), void *); int pop_dele (int); int pop_quit (void); int pop_done (void); diff --git a/uip/inc.c b/uip/inc.c index 0df0a4de..26cdbe53 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -157,7 +157,7 @@ static FILE *in; * prototypes */ static void inc_done(int) NORETURN; -static int pop_action(char *); +static int pop_action(void *closure, char *); int maildir_srt(const void *va, const void *vb) @@ -596,7 +596,7 @@ main (int argc, char **argv) chmod (cp, m_gmprot ()); start = stop = 0L; - if (pop_retr (i, pop_action) == NOTOK) + if (pop_retr(i, pop_action, NULL) == NOTOK) adios (NULL, "%s", response); if (fflush (pf)) @@ -915,8 +915,9 @@ inc_done (int status) } static int -pop_action (char *s) +pop_action(void *closure, char *s) { + NMH_UNUSED(closure); fprintf (pf, "%s\n", s); stop += strlen (s) + 1; return 0; /* Is return value used? This was missing before 1999-07-15. */ diff --git a/uip/popsbr.c b/uip/popsbr.c index 8d54e021..fba13992 100644 --- a/uip/popsbr.c +++ b/uip/popsbr.c @@ -27,7 +27,7 @@ static netsec_context *nsc = NULL; static int command(const char *, ...); static int multiline(void); -static int traverse (int (*)(char *), const char *, ...); +static int traverse (int (*)(void *, char *), void *closure, const char *, ...); static int vcommand(const char *, va_list); static int pop_getline (char *, int, netsec_context *); static int pop_sasl_callback(enum sasl_message_type, unsigned const char *, @@ -481,14 +481,14 @@ pop_stat (int *nmsgs, int *nbytes) int -pop_retr (int msgno, int (*action)(char *)) +pop_retr (int msgno, int (*action)(void *, char *), void *closure) { - return traverse (action, "RETR %d", msgno); + return traverse (action, closure, "RETR %d", msgno); } static int -traverse (int (*action)(char *), const char *fmt, ...) +traverse (int (*action)(void *, char *), void *closure, const char *fmt, ...) { int result, snoopstate; va_list ap; @@ -517,7 +517,7 @@ traverse (int (*action)(char *), const char *fmt, ...) return OK; case OK: - (*action) (response); + (*action)(closure, response); break; } }