From 9a400bf9bf5ccfe0db5644238d7c055d75d7a436 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org.ua>
Date: Fri, 25 Nov 2011 15:02:59 +0200
Subject: [PATCH] Change callback signature in imap client.

The purpose is to avoid using variadic calls in order to let the compiler
do the necessary argument checking.

* include/mailutils/imap.h (mu_imap_callback_t): Take a pair of size_t
and void * arguments instead of the single va_list.
(mu_imap_callback): Likewise.
* libproto/imap/callback.c: Likewise.
* libproto/imap/resproc.c: Update callback calls.
* mu/imap.c: Update callback declarations.
---
 include/mailutils/imap.h |  5 ++---
 libproto/imap/callback.c |  9 ++-------
 libproto/imap/resproc.c  | 13 +++++++------
 mu/imap.c                | 10 ++++------
 4 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/include/mailutils/imap.h b/include/mailutils/imap.h
index 5448ef2..cb679d0 100644
--- a/include/mailutils/imap.h
+++ b/include/mailutils/imap.h
@@ -18,7 +18,6 @@
 #ifndef _MAILUTILS_IMAP_H
 #define _MAILUTILS_IMAP_H
 
-#include <stdarg.h>
 #include <mailutils/iterator.h>
 #include <mailutils/debug.h>
 #include <mailutils/stream.h>
@@ -124,9 +123,9 @@ extern struct mu_kwd _mu_imap_status_name_table[];
 #define MU_IMAP_CB_PREAUTH         10
 #define _MU_IMAP_CB_MAX            11
 
-typedef void (*mu_imap_callback_t) (void *, int code, va_list ap);
+typedef void (*mu_imap_callback_t) (void *, int code, size_t sdat, void *pdat);
   
-void mu_imap_callback (mu_imap_t imap, int code, ...);
+void mu_imap_callback (mu_imap_t imap, int code, size_t sdat, void *pdat);
 
 void mu_imap_register_callback_function (mu_imap_t imap, int code,
 					 mu_imap_callback_t callback,
diff --git a/libproto/imap/callback.c b/libproto/imap/callback.c
index 7fbc998..9800169 100644
--- a/libproto/imap/callback.c
+++ b/libproto/imap/callback.c
@@ -23,16 +23,11 @@
 #include <mailutils/sys/imap.h>
 
 void
-mu_imap_callback (mu_imap_t imap, int code, ...)
+mu_imap_callback (mu_imap_t imap, int code, size_t sdat, void *pdat)
 {
-  va_list ap;
-  
   if (code < 0 || code >= _MU_IMAP_CB_MAX || !imap->callback[code].action)
     return;
-  
-  va_start (ap, code);
-  imap->callback[code].action (imap->callback[code].data, code, ap);
-  va_end (ap);
+  imap->callback[code].action (imap->callback[code].data, code, sdat, pdat);
 }
 
 void
diff --git a/libproto/imap/resproc.c b/libproto/imap/resproc.c
index d40d9b2..d939690 100644
--- a/libproto/imap/resproc.c
+++ b/libproto/imap/resproc.c
@@ -96,7 +96,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
 	  _mu_imap_collect_flags (arg, &imap->mbox_stat.permanent_flags))
 	break;
       imap->mbox_stat.flags |= MU_IMAP_STAT_PERMANENT_FLAGS;
-      mu_imap_callback (imap, MU_IMAP_CB_PERMANENT_FLAGS, &imap->mbox_stat);
+      mu_imap_callback (imap, MU_IMAP_CB_PERMANENT_FLAGS, 0, &imap->mbox_stat);
       return;
 	  
     case MU_IMAP_RESPONSE_UIDNEXT:
@@ -108,7 +108,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
 	{
 	  imap->mbox_stat.uidnext = n;
 	  imap->mbox_stat.flags |= MU_IMAP_STAT_UIDNEXT;
-	  mu_imap_callback (imap, MU_IMAP_CB_UIDNEXT, &imap->mbox_stat);
+	  mu_imap_callback (imap, MU_IMAP_CB_UIDNEXT, 0, &imap->mbox_stat);
 	}
       return;
 			    
@@ -121,7 +121,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
 	{
 	  imap->mbox_stat.uidvalidity = n;
 	  imap->mbox_stat.flags |= MU_IMAP_STAT_UIDVALIDITY;
-	  mu_imap_callback (imap, MU_IMAP_CB_UIDVALIDITY, &imap->mbox_stat);
+	  mu_imap_callback (imap, MU_IMAP_CB_UIDVALIDITY, 0, &imap->mbox_stat);
 	}
       return;
       
@@ -134,7 +134,8 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
 	{
 	  imap->mbox_stat.first_unseen = n;
 	  imap->mbox_stat.flags |= MU_IMAP_STAT_FIRST_UNSEEN;
-	  mu_imap_callback (imap, MU_IMAP_CB_FIRST_UNSEEN, &imap->mbox_stat);
+	  mu_imap_callback (imap, MU_IMAP_CB_FIRST_UNSEEN, 0,
+			    &imap->mbox_stat);
 	}
       return;
     }
@@ -284,7 +285,7 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp)
 	    return 1;
 	  imap->mbox_stat.message_count = n;
 	  imap->mbox_stat.flags |= MU_IMAP_STAT_MESSAGE_COUNT;
-	  mu_imap_callback (imap, MU_IMAP_CB_MESSAGE_COUNT, resp,
+	  mu_imap_callback (imap, MU_IMAP_CB_MESSAGE_COUNT, 0,
 			    &imap->mbox_stat);
 	  return 0;
 	}
@@ -298,7 +299,7 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp)
 	    return 1;
 	  imap->mbox_stat.recent_count = n;
 	  imap->mbox_stat.flags |= MU_IMAP_STAT_RECENT_COUNT;
-	  mu_imap_callback (imap, MU_IMAP_CB_RECENT_COUNT, resp,
+	  mu_imap_callback (imap, MU_IMAP_CB_RECENT_COUNT, 0,
 			    &imap->mbox_stat);
 	  return 0;
 	}
diff --git a/mu/imap.c b/mu/imap.c
index 892fb87..4edce2d 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -163,10 +163,9 @@ imap_prompt_env ()
 
 /* Callbacks */
 static void
-imap_popauth_callback (void *data, int code, va_list ap)
+imap_popauth_callback (void *data, int code, size_t sdat, void *pdat)
 {
-  int rcode = va_arg (ap, int);
-  const char *text = va_arg (ap, const char *);
+  const char *text = pdat;
   if (text)
     mu_diag_output (MU_DIAG_INFO, _("session authenticated: %s"), text);
   else
@@ -174,10 +173,9 @@ imap_popauth_callback (void *data, int code, va_list ap)
 }
 
 static void
-imap_bye_callback (void *data, int code, va_list ap)
+imap_bye_callback (void *data, int code, size_t sdat, void *pdat)
 {
-  int rcode = va_arg (ap, int);
-  const char *text = va_arg (ap, const char *);
+  const char *text = pdat;
   if (text)
     mu_diag_output (MU_DIAG_INFO, _("server is closing connection: %s"), text);
   else
--
libgit2 0.24.0