From e35e4dbeb9c349981d0092542aa1e3813bf844c9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 18 Jun 2016 20:07:17 +0000 Subject: convert conversation_api_call.c --- src/conversation/conversation_api_call.c | 84 +++++++++++++++++++------------- 1 file changed, 51 insertions(+), 33 deletions(-) (limited to 'src/conversation') diff --git a/src/conversation/conversation_api_call.c b/src/conversation/conversation_api_call.c index 0984290d3..51b07b7c8 100644 --- a/src/conversation/conversation_api_call.c +++ b/src/conversation/conversation_api_call.c @@ -188,14 +188,14 @@ transmit_call_audio (void *cls, /** - * We received a `struct ClientPhoneSuspendMessage` + * We received a #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND. * * @param cls the `struct GNUNET_CONVERSATION_Call` * @param msg the message */ static void handle_call_suspend (void *cls, - const struct GNUNET_MessageHeader *msg) + const struct ClientPhoneSuspendMessage *msg) { struct GNUNET_CONVERSATION_Call *call = cls; @@ -233,14 +233,14 @@ handle_call_suspend (void *cls, /** - * We received a `struct ClientPhoneResumeMessage` + * We received a #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME. * * @param cls the `struct GNUNET_CONVERSATION_Call` * @param msg the message */ static void handle_call_resume (void *cls, - const struct GNUNET_MessageHeader *msg) + const struct ClientPhoneResumeMessage *msg) { struct GNUNET_CONVERSATION_Call *call = cls; @@ -282,14 +282,14 @@ handle_call_resume (void *cls, /** - * We received a `struct ClientPhonePickedupMessage` + * We received a #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP. * * @param cls the `struct GNUNET_CONVERSATION_Call` * @param msg the message */ static void handle_call_picked_up (void *cls, - const struct GNUNET_MessageHeader *msg) + const struct ClientPhonePickedupMessage *msg) { struct GNUNET_CONVERSATION_Call *call = cls; @@ -323,14 +323,14 @@ handle_call_picked_up (void *cls, /** - * We received a `struct ClientPhoneHangupMessage` + * We received a #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_HANG_UP. * * @param cls the `struct GNUNET_CONVERSATION_Call` * @param msg the message */ static void handle_call_hangup (void *cls, - const struct GNUNET_MessageHeader *msg) + const struct ClientPhoneHangupMessage *msg) { struct GNUNET_CONVERSATION_Call *call = cls; GNUNET_CONVERSATION_CallEventHandler eh; @@ -359,6 +359,22 @@ handle_call_hangup (void *cls, } +/** + * We received a `struct ClientAudioMessage`, check it is well-formed. + * + * @param cls the `struct GNUNET_CONVERSATION_Call` + * @param msg the message + * @return #GNUNET_OK (always well-formed) + */ +static int +check_call_audio (void *cls, + const struct ClientAudioMessage *am) +{ + /* any payload is OK */ + return GNUNET_OK; +} + + /** * We received a `struct ClientAudioMessage` * @@ -366,13 +382,11 @@ handle_call_hangup (void *cls, * @param msg the message */ static void -handle_call_audio_message (void *cls, - const struct GNUNET_MessageHeader *msg) +handle_call_audio (void *cls, + const struct ClientAudioMessage *am) { struct GNUNET_CONVERSATION_Call *call = cls; - const struct ClientAudioMessage *am; - am = (const struct ClientAudioMessage *) msg; switch (call->state) { case CS_LOOKUP: @@ -394,7 +408,7 @@ handle_call_audio_message (void *cls, break; case CS_ACTIVE: call->speaker->play (call->speaker->cls, - ntohs (msg->size) - sizeof (struct ClientAudioMessage), + ntohs (am->header.size) - sizeof (struct ClientAudioMessage), &am[1]); break; case CS_SHUTDOWN: @@ -533,29 +547,33 @@ GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONVERSATION_CallEventHandler event_handler, void *event_handler_cls) { - static struct GNUNET_MQ_MessageHandler handlers[] = - { - { &handle_call_suspend, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, - sizeof (struct ClientPhoneSuspendMessage) }, - { &handle_call_resume, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, - sizeof (struct ClientPhoneResumeMessage) }, - { &handle_call_picked_up, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP, - sizeof (struct ClientPhonePickedupMessage) }, - { &handle_call_hangup, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, - sizeof (struct ClientPhoneHangupMessage) }, - { &handle_call_audio_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, - 0 }, - { NULL, 0, 0 } + struct GNUNET_CONVERSATION_Call *call + = GNUNET_new (struct GNUNET_CONVERSATION_Call); + GNUNET_MQ_hd_fixed_size (call_suspend, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, + struct ClientPhoneSuspendMessage); + GNUNET_MQ_hd_fixed_size (call_resume, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, + struct ClientPhoneResumeMessage); + GNUNET_MQ_hd_fixed_size (call_picked_up, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP, + struct ClientPhonePickedupMessage); + GNUNET_MQ_hd_fixed_size (call_hangup, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, + struct ClientPhoneHangupMessage); + GNUNET_MQ_hd_var_size (call_audio, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, + struct ClientAudioMessage); + struct GNUNET_MQ_MessageHandler handlers[] = { + make_call_suspend_handler (call), + make_call_resume_handler (call), + make_call_picked_up_handler (call), + make_call_hangup_handler (call), + make_call_audio_handler (call), + GNUNET_MQ_handler_end () }; struct GNUNET_CRYPTO_EcdsaPublicKey my_zone; - struct GNUNET_CONVERSATION_Call *call; - call = GNUNET_new (struct GNUNET_CONVERSATION_Call); call->client = GNUNET_CLIENT_connect ("conversation", cfg); if (NULL == call->client) { -- cgit v1.2.3