]> diplodocus.org Git - nmh/commitdiff
pop_retr(): Add a `void *closure' to be passed to action callback.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 13 Aug 2017 16:13:34 +0000 (17:13 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 13 Aug 2017 16:13:34 +0000 (17:13 +0100)
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.

h/popsbr.h
uip/inc.c
uip/popsbr.c

index 7193f1f..fab83e1 100644 (file)
@@ -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);
index 0df0a4d..26cdbe5 100644 (file)
--- 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. */
index 8d54e02..fba1399 100644 (file)
@@ -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;
        }
 }