From 643d2fdb93342cce841f1cc4736189d48dab0e3f Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 23 Dec 2009 17:49:26 -0500 Subject: [PATCH] Make Perl-side of the incoming_chatstate callback optional. --- thperl.c | 24 ++++++++++++++++++------ thperl.h | 5 ++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/thperl.c b/thperl.c index 61ec24b..4f297d2 100644 --- a/thperl.c +++ b/thperl.c @@ -532,6 +532,7 @@ void validate_callback (SV *cb) * @param subref (SV *) to call on subscription requests from legacy users * @param subref (SV *) to call on connection errors * @param subref (SV *) to call when connections have succeeded + * @param subref (SV *) to call on incoming chatstate (optional) */ void thrasher_wrapper_init (SV *timeout_add_cb, SV *input_add_cb, @@ -542,8 +543,11 @@ void thrasher_wrapper_init (SV *timeout_add_cb, SV *legacy_user_add_user_cb, SV *connection_error_cb, SV *connection_cb, - SV *incoming_chatstate_cb) + ...) { + va_list argp; + va_start(argp, connection_cb); + SV* incoming_chatstate_cb = va_arg(argp, SV*); g_return_if_fail(timeout_add_cb); g_return_if_fail(input_add_cb); @@ -554,7 +558,6 @@ void thrasher_wrapper_init (SV *timeout_add_cb, g_return_if_fail(legacy_user_add_user_cb); g_return_if_fail(connection_error_cb); g_return_if_fail(connection_cb); - g_return_if_fail(incoming_chatstate_cb); /* Set the bindings for our function table */ callback_funcs = g_hash_table_new_full(g_direct_hash, @@ -577,7 +580,9 @@ void thrasher_wrapper_init (SV *timeout_add_cb, validate_callback(legacy_user_add_user_cb); validate_callback(connection_error_cb); validate_callback(connection_cb); - validate_callback(incoming_chatstate_cb); + if (incoming_chatstate_cb) { + validate_callback(incoming_chatstate_cb); + } dSP; @@ -596,7 +601,12 @@ void thrasher_wrapper_init (SV *timeout_add_cb, callback.legacy_user_add_user = newSVsv(legacy_user_add_user_cb); callback.connection_error = newSVsv(connection_error_cb); callback.connection = newSVsv(connection_cb); - callback.incoming_chatstate = newSVsv(incoming_chatstate_cb); + if (incoming_chatstate_cb) { + callback.incoming_chatstate = newSVsv(incoming_chatstate_cb); + } + else { + callback.incoming_chatstate = 0; + } SPAGAIN; PUTBACK; @@ -1287,8 +1297,10 @@ void thrasher_wrapper_incoming_chatstate(PurpleAccount* pa, g_return_if_fail(pa != NULL); g_return_if_fail(who != NULL); - /* @exception bail if our callback doesn't exist */ - g_return_if_fail(callback.incoming_chatstate != NULL); + /* bail if Perl-side doesn't implement this */ + if (! callback.incoming_chatstate) { + return; + } gchar* jid = thrasher_account_get_jid(pa); /* @exception bail if account has no JID */ diff --git a/thperl.h b/thperl.h index 5ba0fb4..9930a49 100644 --- a/thperl.h +++ b/thperl.h @@ -180,6 +180,9 @@ void thrasher_action_ft_recv_request_respond(size_t id, unsigned int accept); void thrasher_action_ft_cancel_local(size_t id); /* Perl-end Wrappers */ +#ifdef SWIG +%varargs(1, SV *cb_arg = NULL) thrasher_wrapper_init; +#endif /* SWIG */ void thrasher_wrapper_init (SV *timeout_add_cb, SV *input_add_cb, SV *source_remove_cb, @@ -189,7 +192,7 @@ void thrasher_wrapper_init (SV *timeout_add_cb, SV *legacy_user_add_user_cb, SV *connection_error_cb, SV *connection_cb, - SV *incoming_chatstate_cb); + ...); void thrasher_wrapper_ft_init(SV *ft_recv_request_cb, SV *ft_recv_accept_cb, -- 2.11.4.GIT