aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/conversation_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-06 08:43:16 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-06 08:43:16 +0000
commitaece72e29b041e2dfbc5b49d2fd0d49f8ab2124e (patch)
treecce216b507c99bf6723e15da5158e68a57a55f41 /src/conversation/conversation_api.c
parent310f312557954662ffc32f74bbacdb63d76ede3d (diff)
downloadgnunet-aece72e29b041e2dfbc5b49d2fd0d49f8ab2124e.tar.gz
gnunet-aece72e29b041e2dfbc5b49d2fd0d49f8ab2124e.zip
addressing #3431
Diffstat (limited to 'src/conversation/conversation_api.c')
-rw-r--r--src/conversation/conversation_api.c91
1 files changed, 11 insertions, 80 deletions
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c
index 4e9901c81..bc6d0f460 100644
--- a/src/conversation/conversation_api.c
+++ b/src/conversation/conversation_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2013 Christian Grothoff (and other contributing authors) 3 (C) 2013, 2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -38,11 +38,6 @@
38enum CallerState 38enum CallerState
39{ 39{
40 /** 40 /**
41 * We still need to reverse lookup the caller ID.
42 */
43 CS_RESOLVE,
44
45 /**
46 * The phone is ringing (user knows about incoming call). 41 * The phone is ringing (user knows about incoming call).
47 */ 42 */
48 CS_RINGING, 43 CS_RINGING,
@@ -112,21 +107,11 @@ struct GNUNET_CONVERSATION_Caller
112 struct GNUNET_MICROPHONE_Handle *mic; 107 struct GNUNET_MICROPHONE_Handle *mic;
113 108
114 /** 109 /**
115 * Active NAMESTORE lookup (or NULL).
116 */
117 struct GNUNET_NAMESTORE_QueueEntry *qe;
118
119 /**
120 * Identity of the person calling us. 110 * Identity of the person calling us.
121 */ 111 */
122 struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; 112 struct GNUNET_CRYPTO_EcdsaPublicKey caller_id;
123 113
124 /** 114 /**
125 * Caller ID of the person calling us as a string.
126 */
127 char *caller_id_str;
128
129 /**
130 * Internal handle to identify the caller with the service. 115 * Internal handle to identify the caller with the service.
131 */ 116 */
132 uint32_t cid; 117 uint32_t cid;
@@ -238,40 +223,6 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone);
238 223
239 224
240/** 225/**
241 * We have resolved the caller ID using our name service.
242 *
243 * @param cls the `struct GNUNET_CONVERSATION_Caller`
244 * @param zone our zone used for resolution
245 * @param label name of the caller
246 * @param rd_count number of records we have in @a rd
247 * @param rd records we have for the caller's label
248 */
249static void
250handle_caller_name (void *cls,
251 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
252 const char *label,
253 unsigned int rd_count,
254 const struct GNUNET_GNSRECORD_Data *rd)
255{
256 struct GNUNET_CONVERSATION_Caller *caller = cls;
257 struct GNUNET_CONVERSATION_Phone *phone = caller->phone;
258 char *name;
259
260 caller->qe = NULL;
261 if (NULL == label)
262 name = GNUNET_strdup (GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id));
263 else
264 GNUNET_asprintf (&name, "%s.gnu", label);
265 caller->caller_id_str = name;
266 caller->state = CS_RINGING;
267 phone->event_handler (phone->event_handler_cls,
268 GNUNET_CONVERSATION_EC_PHONE_RING,
269 caller,
270 name);
271}
272
273
274/**
275 * Process recorded audio data. 226 * Process recorded audio data.
276 * 227 *
277 * @param cls closure with the `struct GNUNET_CONVERSATION_Caller` 228 * @param cls closure with the `struct GNUNET_CONVERSATION_Caller`
@@ -323,14 +274,13 @@ handle_phone_ring (void *cls,
323 GNUNET_CONTAINER_DLL_insert (phone->caller_head, 274 GNUNET_CONTAINER_DLL_insert (phone->caller_head,
324 phone->caller_tail, 275 phone->caller_tail,
325 caller); 276 caller);
326 caller->state = CS_RESOLVE;
327 caller->caller_id = ring->caller_id; 277 caller->caller_id = ring->caller_id;
328 caller->cid = ring->cid; 278 caller->cid = ring->cid;
329 caller->qe = GNUNET_NAMESTORE_zone_to_name (phone->ns, 279 caller->state = CS_RINGING;
330 &phone->my_zone, 280 phone->event_handler (phone->event_handler_cls,
331 &ring->caller_id, 281 GNUNET_CONVERSATION_EC_PHONE_RING,
332 &handle_caller_name, 282 caller,
333 caller); 283 &caller->caller_id);
334 break; 284 break;
335 } 285 }
336} 286}
@@ -364,19 +314,14 @@ handle_phone_hangup (void *cls,
364 314
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "Received HANG_UP message, terminating call with `%s'\n", 316 "Received HANG_UP message, terminating call with `%s'\n",
367 caller->caller_id_str); 317 GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id));
368 switch (caller->state) 318 switch (caller->state)
369 { 319 {
370 case CS_RESOLVE:
371 /* application doesn't even know about call yet */
372 GNUNET_NAMESTORE_cancel (caller->qe);
373 caller->qe = NULL;
374 break;
375 case CS_RINGING: 320 case CS_RINGING:
376 phone->event_handler (phone->event_handler_cls, 321 phone->event_handler (phone->event_handler_cls,
377 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, 322 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP,
378 caller, 323 caller,
379 caller->caller_id_str); 324 &caller->caller_id);
380 break; 325 break;
381 case CS_ACTIVE: 326 case CS_ACTIVE:
382 caller->speaker->disable_speaker (caller->speaker->cls); 327 caller->speaker->disable_speaker (caller->speaker->cls);
@@ -384,7 +329,7 @@ handle_phone_hangup (void *cls,
384 phone->event_handler (phone->event_handler_cls, 329 phone->event_handler (phone->event_handler_cls,
385 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, 330 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP,
386 caller, 331 caller,
387 caller->caller_id_str); 332 &caller->caller_id);
388 break; 333 break;
389 case CS_CALLEE_SUSPENDED: 334 case CS_CALLEE_SUSPENDED:
390 case CS_CALLER_SUSPENDED: 335 case CS_CALLER_SUSPENDED:
@@ -392,7 +337,7 @@ handle_phone_hangup (void *cls,
392 phone->event_handler (phone->event_handler_cls, 337 phone->event_handler (phone->event_handler_cls,
393 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, 338 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP,
394 caller, 339 caller,
395 caller->caller_id_str); 340 &caller->caller_id);
396 break; 341 break;
397 } 342 }
398 GNUNET_CONTAINER_DLL_remove (phone->caller_head, 343 GNUNET_CONTAINER_DLL_remove (phone->caller_head,
@@ -424,9 +369,6 @@ handle_phone_suspend (void *cls,
424 return; 369 return;
425 switch (caller->state) 370 switch (caller->state)
426 { 371 {
427 case CS_RESOLVE:
428 GNUNET_break_op (0);
429 break;
430 case CS_RINGING: 372 case CS_RINGING:
431 GNUNET_break_op (0); 373 GNUNET_break_op (0);
432 break; 374 break;
@@ -472,9 +414,6 @@ handle_phone_resume (void *cls,
472 return; 414 return;
473 switch (caller->state) 415 switch (caller->state)
474 { 416 {
475 case CS_RESOLVE:
476 GNUNET_break_op (0);
477 break;
478 case CS_RINGING: 417 case CS_RINGING:
479 GNUNET_break_op (0); 418 GNUNET_break_op (0);
480 break; 419 break;
@@ -522,9 +461,6 @@ handle_phone_audio_message (void *cls,
522 return; 461 return;
523 switch (caller->state) 462 switch (caller->state)
524 { 463 {
525 case CS_RESOLVE:
526 GNUNET_break_op (0);
527 break;
528 case CS_RINGING: 464 case CS_RINGING:
529 GNUNET_break_op (0); 465 GNUNET_break_op (0);
530 break; 466 break;
@@ -581,7 +517,7 @@ clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone)
581 phone->event_handler (phone->event_handler_cls, 517 phone->event_handler (phone->event_handler_cls,
582 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, 518 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP,
583 caller, 519 caller,
584 caller->caller_id_str); 520 &caller->caller_id);
585 GNUNET_CONVERSATION_caller_hang_up (caller); 521 GNUNET_CONVERSATION_caller_hang_up (caller);
586 } 522 }
587} 523}
@@ -781,10 +717,6 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller)
781 717
782 switch (caller->state) 718 switch (caller->state)
783 { 719 {
784 case CS_RESOLVE:
785 GNUNET_NAMESTORE_cancel (caller->qe);
786 caller->qe = NULL;
787 break;
788 case CS_ACTIVE: 720 case CS_ACTIVE:
789 caller->speaker->disable_speaker (caller->speaker->cls); 721 caller->speaker->disable_speaker (caller->speaker->cls);
790 caller->mic->disable_microphone (caller->mic->cls); 722 caller->mic->disable_microphone (caller->mic->cls);
@@ -799,7 +731,6 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller)
799 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); 731 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
800 hang->cid = caller->cid; 732 hang->cid = caller->cid;
801 GNUNET_MQ_send (phone->mq, e); 733 GNUNET_MQ_send (phone->mq, e);
802 GNUNET_free_non_null (caller->caller_id_str);
803 GNUNET_free (caller); 734 GNUNET_free (caller);
804} 735}
805 736