Commit 9a400bf9 9a400bf9bf5ccfe0db5644238d7c055d75d7a436 by Sergey Poznyakoff

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.
1 parent 904b2a75
......@@ -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,
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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
......