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.
Showing
4 changed files
with
15 additions
and
22 deletions
... | @@ -18,7 +18,6 @@ | ... | @@ -18,7 +18,6 @@ |
18 | #ifndef _MAILUTILS_IMAP_H | 18 | #ifndef _MAILUTILS_IMAP_H |
19 | #define _MAILUTILS_IMAP_H | 19 | #define _MAILUTILS_IMAP_H |
20 | 20 | ||
21 | #include <stdarg.h> | ||
22 | #include <mailutils/iterator.h> | 21 | #include <mailutils/iterator.h> |
23 | #include <mailutils/debug.h> | 22 | #include <mailutils/debug.h> |
24 | #include <mailutils/stream.h> | 23 | #include <mailutils/stream.h> |
... | @@ -124,9 +123,9 @@ extern struct mu_kwd _mu_imap_status_name_table[]; | ... | @@ -124,9 +123,9 @@ extern struct mu_kwd _mu_imap_status_name_table[]; |
124 | #define MU_IMAP_CB_PREAUTH 10 | 123 | #define MU_IMAP_CB_PREAUTH 10 |
125 | #define _MU_IMAP_CB_MAX 11 | 124 | #define _MU_IMAP_CB_MAX 11 |
126 | 125 | ||
127 | typedef void (*mu_imap_callback_t) (void *, int code, va_list ap); | 126 | typedef void (*mu_imap_callback_t) (void *, int code, size_t sdat, void *pdat); |
128 | 127 | ||
129 | void mu_imap_callback (mu_imap_t imap, int code, ...); | 128 | void mu_imap_callback (mu_imap_t imap, int code, size_t sdat, void *pdat); |
130 | 129 | ||
131 | void mu_imap_register_callback_function (mu_imap_t imap, int code, | 130 | void mu_imap_register_callback_function (mu_imap_t imap, int code, |
132 | mu_imap_callback_t callback, | 131 | mu_imap_callback_t callback, | ... | ... |
... | @@ -23,16 +23,11 @@ | ... | @@ -23,16 +23,11 @@ |
23 | #include <mailutils/sys/imap.h> | 23 | #include <mailutils/sys/imap.h> |
24 | 24 | ||
25 | void | 25 | void |
26 | mu_imap_callback (mu_imap_t imap, int code, ...) | 26 | mu_imap_callback (mu_imap_t imap, int code, size_t sdat, void *pdat) |
27 | { | 27 | { |
28 | va_list ap; | ||
29 | |||
30 | if (code < 0 || code >= _MU_IMAP_CB_MAX || !imap->callback[code].action) | 28 | if (code < 0 || code >= _MU_IMAP_CB_MAX || !imap->callback[code].action) |
31 | return; | 29 | return; |
32 | 30 | imap->callback[code].action (imap->callback[code].data, code, sdat, pdat); | |
33 | va_start (ap, code); | ||
34 | imap->callback[code].action (imap->callback[code].data, code, ap); | ||
35 | va_end (ap); | ||
36 | } | 31 | } |
37 | 32 | ||
38 | void | 33 | void | ... | ... |
... | @@ -96,7 +96,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) | ... | @@ -96,7 +96,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) |
96 | _mu_imap_collect_flags (arg, &imap->mbox_stat.permanent_flags)) | 96 | _mu_imap_collect_flags (arg, &imap->mbox_stat.permanent_flags)) |
97 | break; | 97 | break; |
98 | imap->mbox_stat.flags |= MU_IMAP_STAT_PERMANENT_FLAGS; | 98 | imap->mbox_stat.flags |= MU_IMAP_STAT_PERMANENT_FLAGS; |
99 | mu_imap_callback (imap, MU_IMAP_CB_PERMANENT_FLAGS, &imap->mbox_stat); | 99 | mu_imap_callback (imap, MU_IMAP_CB_PERMANENT_FLAGS, 0, &imap->mbox_stat); |
100 | return; | 100 | return; |
101 | 101 | ||
102 | case MU_IMAP_RESPONSE_UIDNEXT: | 102 | case MU_IMAP_RESPONSE_UIDNEXT: |
... | @@ -108,7 +108,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) | ... | @@ -108,7 +108,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) |
108 | { | 108 | { |
109 | imap->mbox_stat.uidnext = n; | 109 | imap->mbox_stat.uidnext = n; |
110 | imap->mbox_stat.flags |= MU_IMAP_STAT_UIDNEXT; | 110 | imap->mbox_stat.flags |= MU_IMAP_STAT_UIDNEXT; |
111 | mu_imap_callback (imap, MU_IMAP_CB_UIDNEXT, &imap->mbox_stat); | 111 | mu_imap_callback (imap, MU_IMAP_CB_UIDNEXT, 0, &imap->mbox_stat); |
112 | } | 112 | } |
113 | return; | 113 | return; |
114 | 114 | ||
... | @@ -121,7 +121,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) | ... | @@ -121,7 +121,7 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) |
121 | { | 121 | { |
122 | imap->mbox_stat.uidvalidity = n; | 122 | imap->mbox_stat.uidvalidity = n; |
123 | imap->mbox_stat.flags |= MU_IMAP_STAT_UIDVALIDITY; | 123 | imap->mbox_stat.flags |= MU_IMAP_STAT_UIDVALIDITY; |
124 | mu_imap_callback (imap, MU_IMAP_CB_UIDVALIDITY, &imap->mbox_stat); | 124 | mu_imap_callback (imap, MU_IMAP_CB_UIDVALIDITY, 0, &imap->mbox_stat); |
125 | } | 125 | } |
126 | return; | 126 | return; |
127 | 127 | ||
... | @@ -134,7 +134,8 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) | ... | @@ -134,7 +134,8 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data) |
134 | { | 134 | { |
135 | imap->mbox_stat.first_unseen = n; | 135 | imap->mbox_stat.first_unseen = n; |
136 | imap->mbox_stat.flags |= MU_IMAP_STAT_FIRST_UNSEEN; | 136 | imap->mbox_stat.flags |= MU_IMAP_STAT_FIRST_UNSEEN; |
137 | mu_imap_callback (imap, MU_IMAP_CB_FIRST_UNSEEN, &imap->mbox_stat); | 137 | mu_imap_callback (imap, MU_IMAP_CB_FIRST_UNSEEN, 0, |
138 | &imap->mbox_stat); | ||
138 | } | 139 | } |
139 | return; | 140 | return; |
140 | } | 141 | } |
... | @@ -284,7 +285,7 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp) | ... | @@ -284,7 +285,7 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp) |
284 | return 1; | 285 | return 1; |
285 | imap->mbox_stat.message_count = n; | 286 | imap->mbox_stat.message_count = n; |
286 | imap->mbox_stat.flags |= MU_IMAP_STAT_MESSAGE_COUNT; | 287 | imap->mbox_stat.flags |= MU_IMAP_STAT_MESSAGE_COUNT; |
287 | mu_imap_callback (imap, MU_IMAP_CB_MESSAGE_COUNT, resp, | 288 | mu_imap_callback (imap, MU_IMAP_CB_MESSAGE_COUNT, 0, |
288 | &imap->mbox_stat); | 289 | &imap->mbox_stat); |
289 | return 0; | 290 | return 0; |
290 | } | 291 | } |
... | @@ -298,7 +299,7 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp) | ... | @@ -298,7 +299,7 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp) |
298 | return 1; | 299 | return 1; |
299 | imap->mbox_stat.recent_count = n; | 300 | imap->mbox_stat.recent_count = n; |
300 | imap->mbox_stat.flags |= MU_IMAP_STAT_RECENT_COUNT; | 301 | imap->mbox_stat.flags |= MU_IMAP_STAT_RECENT_COUNT; |
301 | mu_imap_callback (imap, MU_IMAP_CB_RECENT_COUNT, resp, | 302 | mu_imap_callback (imap, MU_IMAP_CB_RECENT_COUNT, 0, |
302 | &imap->mbox_stat); | 303 | &imap->mbox_stat); |
303 | return 0; | 304 | return 0; |
304 | } | 305 | } | ... | ... |
... | @@ -163,10 +163,9 @@ imap_prompt_env () | ... | @@ -163,10 +163,9 @@ imap_prompt_env () |
163 | 163 | ||
164 | /* Callbacks */ | 164 | /* Callbacks */ |
165 | static void | 165 | static void |
166 | imap_popauth_callback (void *data, int code, va_list ap) | 166 | imap_popauth_callback (void *data, int code, size_t sdat, void *pdat) |
167 | { | 167 | { |
168 | int rcode = va_arg (ap, int); | 168 | const char *text = pdat; |
169 | const char *text = va_arg (ap, const char *); | ||
170 | if (text) | 169 | if (text) |
171 | mu_diag_output (MU_DIAG_INFO, _("session authenticated: %s"), text); | 170 | mu_diag_output (MU_DIAG_INFO, _("session authenticated: %s"), text); |
172 | else | 171 | else |
... | @@ -174,10 +173,9 @@ imap_popauth_callback (void *data, int code, va_list ap) | ... | @@ -174,10 +173,9 @@ imap_popauth_callback (void *data, int code, va_list ap) |
174 | } | 173 | } |
175 | 174 | ||
176 | static void | 175 | static void |
177 | imap_bye_callback (void *data, int code, va_list ap) | 176 | imap_bye_callback (void *data, int code, size_t sdat, void *pdat) |
178 | { | 177 | { |
179 | int rcode = va_arg (ap, int); | 178 | const char *text = pdat; |
180 | const char *text = va_arg (ap, const char *); | ||
181 | if (text) | 179 | if (text) |
182 | mu_diag_output (MU_DIAG_INFO, _("server is closing connection: %s"), text); | 180 | mu_diag_output (MU_DIAG_INFO, _("server is closing connection: %s"), text); |
183 | else | 181 | else | ... | ... |
-
Please register or sign in to post a comment