aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/test_conversation_api_twocalls.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/conversation/test_conversation_api_twocalls.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/conversation/test_conversation_api_twocalls.c')
-rw-r--r--src/conversation/test_conversation_api_twocalls.c654
1 files changed, 331 insertions, 323 deletions
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c
index f3bb87fd2..797563d7a 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file conversation/test_conversation_api_twocalls.c 21 * @file conversation/test_conversation_api_twocalls.c
22 * @brief testcase for conversation_api.c 22 * @brief testcase for conversation_api.c
@@ -35,13 +35,13 @@
35#include "gnunet_identity_service.h" 35#include "gnunet_identity_service.h"
36#include "gnunet_namestore_service.h" 36#include "gnunet_namestore_service.h"
37 37
38#define FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) 38#define FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250)
39 39
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) 40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 25)
41 41
42#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 42#define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__)
43 43
44#define LOG_DEBUG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 44#define LOG_DEBUG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
45 45
46static const struct GNUNET_CONFIGURATION_Handle *cfg; 46static const struct GNUNET_CONFIGURATION_Handle *cfg;
47 47
@@ -95,7 +95,7 @@ static const char *phone0 = "phone";
95#define CALLER2 &caller2 95#define CALLER2 &caller2
96#define PHONE0 &phone0 96#define PHONE0 &phone0
97 97
98#define CLS_STR(caller) (*((char **) caller)) 98#define CLS_STR(caller) (*((char **)caller))
99 99
100 100
101/** 101/**
@@ -108,8 +108,7 @@ static int call1_finished;
108 */ 108 */
109static int call2_finished; 109static int call2_finished;
110 110
111struct MicContext 111struct MicContext {
112{
113 GNUNET_MICROPHONE_RecordedDataCallback rdc; 112 GNUNET_MICROPHONE_RecordedDataCallback rdc;
114 113
115 void *rdc_cls; 114 void *rdc_cls;
@@ -123,198 +122,198 @@ static struct MicContext call2_mic_ctx;
123 122
124 123
125static void 124static void
126phone_send (void *cls) 125phone_send(void *cls)
127{ 126{
128 char buf[32]; 127 char buf[32];
129 128
130 (void) cls; 129 (void)cls;
131 GNUNET_assert (NULL != phone_rdc); 130 GNUNET_assert(NULL != phone_rdc);
132 GNUNET_snprintf (buf, sizeof (buf), "phone"); 131 GNUNET_snprintf(buf, sizeof(buf), "phone");
133 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); 132 phone_rdc(phone_rdc_cls, strlen(buf) + 1, buf);
134 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, &phone_send, NULL); 133 phone_task = GNUNET_SCHEDULER_add_delayed(FREQ, &phone_send, NULL);
135} 134}
136 135
137 136
138static void 137static void
139call_send (void *cls) 138call_send(void *cls)
140{ 139{
141 struct MicContext *mc = cls; 140 struct MicContext *mc = cls;
142 char buf[32]; 141 char buf[32];
143 142
144 (void) cls; 143 (void)cls;
145 GNUNET_assert (NULL != mc->rdc); 144 GNUNET_assert(NULL != mc->rdc);
146 GNUNET_snprintf (buf, sizeof (buf), "call"); 145 GNUNET_snprintf(buf, sizeof(buf), "call");
147 mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf); 146 mc->rdc(mc->rdc_cls, strlen(buf) + 1, buf);
148 mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ, &call_send, mc); 147 mc->call_task = GNUNET_SCHEDULER_add_delayed(FREQ, &call_send, mc);
149} 148}
150 149
151 150
152static int 151static int
153enable_speaker (void *cls) 152enable_speaker(void *cls)
154{ 153{
155 const char *origin = CLS_STR (cls); 154 const char *origin = CLS_STR(cls);
156 155
157 (void) cls; 156 (void)cls;
158 LOG_DEBUG ("Speaker %s enabled\n", origin); 157 LOG_DEBUG("Speaker %s enabled\n", origin);
159 return GNUNET_OK; 158 return GNUNET_OK;
160} 159}
161 160
162 161
163static void 162static void
164disable_speaker (void *cls) 163disable_speaker(void *cls)
165{ 164{
166 const char *origin = CLS_STR (cls); 165 const char *origin = CLS_STR(cls);
167 166
168 (void) cls; 167 (void)cls;
169 LOG_DEBUG ("Speaker %s disabled\n", origin); 168 LOG_DEBUG("Speaker %s disabled\n", origin);
170} 169}
171 170
172 171
173static void 172static void
174play (void *cls, size_t data_size, const void *data) 173play(void *cls, size_t data_size, const void *data)
175{ 174{
176 static unsigned int phone_i; 175 static unsigned int phone_i;
177 static unsigned int call_i; 176 static unsigned int call_i;
178 177
179 (void) cls; 178 (void)cls;
180 if (0 == strncmp ("call", data, data_size)) 179 if (0 == strncmp("call", data, data_size))
181 call_i++; 180 call_i++;
182 else if (0 == strncmp ("phone", data, data_size)) 181 else if (0 == strncmp("phone", data, data_size))
183 phone_i++; 182 phone_i++;
184 else 183 else
185 { 184 {
186 LOG_DEBUG ("Received %u bytes of unexpected data `%.*s'\n", 185 LOG_DEBUG("Received %u bytes of unexpected data `%.*s'\n",
187 (unsigned int) data_size, 186 (unsigned int)data_size,
188 (int) data_size, 187 (int)data_size,
189 (const char *) data); 188 (const char *)data);
190 } 189 }
191 190
192 if ((20 < call_i) && (20 < phone_i) && (CALLER2 == cls)) 191 if ((20 < call_i) && (20 < phone_i) && (CALLER2 == cls))
193 { 192 {
194 /* time to hang up ... */ 193 /* time to hang up ... */
195 GNUNET_CONVERSATION_call_stop (call2); 194 GNUNET_CONVERSATION_call_stop(call2);
196 call2 = NULL; 195 call2 = NULL;
197 /* reset counters */ 196 /* reset counters */
198 call_i = 0; 197 call_i = 0;
199 phone_i = 0; 198 phone_i = 0;
200 call2_finished = GNUNET_YES; 199 call2_finished = GNUNET_YES;
201 } 200 }
202 if ((20 < call_i) && (20 < phone_i) && (CALLER1 == cls)) 201 if ((20 < call_i) && (20 < phone_i) && (CALLER1 == cls))
203 { 202 {
204 /* time to hang up ... */ 203 /* time to hang up ... */
205 GNUNET_CONVERSATION_call_stop (call1); 204 GNUNET_CONVERSATION_call_stop(call1);
206 call1 = NULL; 205 call1 = NULL;
207 call_i = 0; 206 call_i = 0;
208 phone_i = 0; 207 phone_i = 0;
209 call1_finished = GNUNET_YES; 208 call1_finished = GNUNET_YES;
210 } 209 }
211} 210}
212 211
213 212
214static void 213static void
215destroy_speaker (void *cls) 214destroy_speaker(void *cls)
216{ 215{
217 const char *origin = CLS_STR (cls); 216 const char *origin = CLS_STR(cls);
218 217
219 LOG_DEBUG ("Speaker %s destroyed\n", origin); 218 LOG_DEBUG("Speaker %s destroyed\n", origin);
220} 219}
221 220
222 221
223static struct GNUNET_SPEAKER_Handle call1_speaker = {&enable_speaker, 222static struct GNUNET_SPEAKER_Handle call1_speaker = { &enable_speaker,
224 &play, 223 &play,
225 &disable_speaker, 224 &disable_speaker,
226 &destroy_speaker, 225 &destroy_speaker,
227 CALLER1}; 226 CALLER1 };
228 227
229 228
230static struct GNUNET_SPEAKER_Handle call2_speaker = {&enable_speaker, 229static struct GNUNET_SPEAKER_Handle call2_speaker = { &enable_speaker,
231 &play, 230 &play,
232 &disable_speaker, 231 &disable_speaker,
233 &destroy_speaker, 232 &destroy_speaker,
234 CALLER2}; 233 CALLER2 };
235 234
236 235
237static struct GNUNET_SPEAKER_Handle phone_speaker = {&enable_speaker, 236static struct GNUNET_SPEAKER_Handle phone_speaker = { &enable_speaker,
238 &play, 237 &play,
239 &disable_speaker, 238 &disable_speaker,
240 &destroy_speaker, 239 &destroy_speaker,
241 PHONE0}; 240 PHONE0 };
242 241
243 242
244static int 243static int
245enable_mic (void *cls, 244enable_mic(void *cls,
246 GNUNET_MICROPHONE_RecordedDataCallback rdc, 245 GNUNET_MICROPHONE_RecordedDataCallback rdc,
247 void *rdc_cls) 246 void *rdc_cls)
248{ 247{
249 const char *origin = CLS_STR (cls); 248 const char *origin = CLS_STR(cls);
250 struct MicContext *mc; 249 struct MicContext *mc;
251 250
252 LOG_DEBUG ("Mic %s enabled\n", origin); 251 LOG_DEBUG("Mic %s enabled\n", origin);
253 if (PHONE0 == cls) 252 if (PHONE0 == cls)
254 { 253 {
255 phone_rdc = rdc; 254 phone_rdc = rdc;
256 phone_rdc_cls = rdc_cls; 255 phone_rdc_cls = rdc_cls;
257 GNUNET_break (NULL == phone_task); 256 GNUNET_break(NULL == phone_task);
258 phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL); 257 phone_task = GNUNET_SCHEDULER_add_now(&phone_send, NULL);
259 return GNUNET_OK; 258 return GNUNET_OK;
260 } 259 }
261 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; 260 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx;
262 mc->rdc = rdc; 261 mc->rdc = rdc;
263 mc->rdc_cls = rdc_cls; 262 mc->rdc_cls = rdc_cls;
264 GNUNET_break (NULL == mc->call_task); 263 GNUNET_break(NULL == mc->call_task);
265 mc->call_task = GNUNET_SCHEDULER_add_now (&call_send, mc); 264 mc->call_task = GNUNET_SCHEDULER_add_now(&call_send, mc);
266 return GNUNET_OK; 265 return GNUNET_OK;
267} 266}
268 267
269 268
270static void 269static void
271disable_mic (void *cls) 270disable_mic(void *cls)
272{ 271{
273 const char *origin = CLS_STR (cls); 272 const char *origin = CLS_STR(cls);
274 struct MicContext *mc; 273 struct MicContext *mc;
275 274
276 LOG_DEBUG ("Mic %s disabled\n", origin); 275 LOG_DEBUG("Mic %s disabled\n", origin);
277 if (PHONE0 == cls) 276 if (PHONE0 == cls)
278 { 277 {
279 phone_rdc = NULL; 278 phone_rdc = NULL;
280 phone_rdc_cls = NULL; 279 phone_rdc_cls = NULL;
281 GNUNET_SCHEDULER_cancel (phone_task); 280 GNUNET_SCHEDULER_cancel(phone_task);
282 phone_task = NULL; 281 phone_task = NULL;
283 return; 282 return;
284 } 283 }
285 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; 284 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx;
286 mc->rdc = NULL; 285 mc->rdc = NULL;
287 mc->rdc_cls = NULL; 286 mc->rdc_cls = NULL;
288 GNUNET_SCHEDULER_cancel (mc->call_task); 287 GNUNET_SCHEDULER_cancel(mc->call_task);
289 mc->call_task = NULL; 288 mc->call_task = NULL;
290} 289}
291 290
292 291
293static void 292static void
294destroy_mic (void *cls) 293destroy_mic(void *cls)
295{ 294{
296 const char *origin = CLS_STR (cls); 295 const char *origin = CLS_STR(cls);
297 296
298 LOG_DEBUG ("Mic %s destroyed\n", origin); 297 LOG_DEBUG("Mic %s destroyed\n", origin);
299} 298}
300 299
301 300
302static struct GNUNET_MICROPHONE_Handle call1_mic = {&enable_mic, 301static struct GNUNET_MICROPHONE_Handle call1_mic = { &enable_mic,
303 &disable_mic, 302 &disable_mic,
304 &destroy_mic, 303 &destroy_mic,
305 CALLER1}; 304 CALLER1 };
306 305
307 306
308static struct GNUNET_MICROPHONE_Handle call2_mic = {&enable_mic, 307static struct GNUNET_MICROPHONE_Handle call2_mic = { &enable_mic,
309 &disable_mic, 308 &disable_mic,
310 &destroy_mic, 309 &destroy_mic,
311 CALLER2}; 310 CALLER2 };
312 311
313 312
314static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic, 313static struct GNUNET_MICROPHONE_Handle phone_mic = { &enable_mic,
315 &disable_mic, 314 &disable_mic,
316 &destroy_mic, 315 &destroy_mic,
317 PHONE0}; 316 PHONE0 };
318 317
319 318
320/** 319/**
@@ -323,12 +322,12 @@ static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic,
323 * @param cls closure 322 * @param cls closure
324 */ 323 */
325static void 324static void
326end_test (void *cls) 325end_test(void *cls)
327{ 326{
328 (void) cls; 327 (void)cls;
329 timeout_task = NULL; 328 timeout_task = NULL;
330 fprintf (stderr, "Timeout!\n"); 329 fprintf(stderr, "Timeout!\n");
331 GNUNET_SCHEDULER_shutdown (); 330 GNUNET_SCHEDULER_shutdown();
332} 331}
333 332
334 333
@@ -338,286 +337,295 @@ end_test (void *cls)
338 * @param cls closure 337 * @param cls closure
339 */ 338 */
340static void 339static void
341do_shutdown (void *cls) 340do_shutdown(void *cls)
342{ 341{
343 (void) cls; 342 (void)cls;
344 if (NULL != timeout_task) 343 if (NULL != timeout_task)
345 { 344 {
346 GNUNET_SCHEDULER_cancel (timeout_task); 345 GNUNET_SCHEDULER_cancel(timeout_task);
347 timeout_task = NULL; 346 timeout_task = NULL;
348 } 347 }
349 if (NULL != op) 348 if (NULL != op)
350 { 349 {
351 GNUNET_IDENTITY_cancel (op); 350 GNUNET_IDENTITY_cancel(op);
352 op = NULL; 351 op = NULL;
353 } 352 }
354 if (NULL != call1) 353 if (NULL != call1)
355 { 354 {
356 GNUNET_CONVERSATION_call_stop (call1); 355 GNUNET_CONVERSATION_call_stop(call1);
357 call1 = NULL; 356 call1 = NULL;
358 } 357 }
359 if (NULL != call2) 358 if (NULL != call2)
360 { 359 {
361 GNUNET_CONVERSATION_call_stop (call2); 360 GNUNET_CONVERSATION_call_stop(call2);
362 call2 = NULL; 361 call2 = NULL;
363 } 362 }
364 if (NULL != phone) 363 if (NULL != phone)
365 { 364 {
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); 365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n");
367 GNUNET_CONVERSATION_phone_destroy (phone); 366 GNUNET_CONVERSATION_phone_destroy(phone);
368 phone = NULL; 367 phone = NULL;
369 } 368 }
370 if (NULL != id) 369 if (NULL != id)
371 { 370 {
372 GNUNET_IDENTITY_disconnect (id); 371 GNUNET_IDENTITY_disconnect(id);
373 id = NULL; 372 id = NULL;
374 } 373 }
375 if (NULL != qe) 374 if (NULL != qe)
376 { 375 {
377 GNUNET_NAMESTORE_cancel (qe); 376 GNUNET_NAMESTORE_cancel(qe);
378 qe = NULL; 377 qe = NULL;
379 } 378 }
380 if (NULL != ns) 379 if (NULL != ns)
381 { 380 {
382 GNUNET_NAMESTORE_disconnect (ns); 381 GNUNET_NAMESTORE_disconnect(ns);
383 ns = NULL; 382 ns = NULL;
384 } 383 }
385} 384}
386 385
387 386
388static void 387static void
389caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) 388caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
390{ 389{
391 (void) cls; 390 (void)cls;
392 switch (code) 391 switch (code)
393 { 392 {
394 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 393 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
395 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 394 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
396 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code); 395 LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code);
397 break; 396 break;
398 } 397 }
399} 398}
400 399
401 400
402static void 401static void
403phone_event_handler (void *cls, 402phone_event_handler(void *cls,
404 enum GNUNET_CONVERSATION_PhoneEventCode code, 403 enum GNUNET_CONVERSATION_PhoneEventCode code,
405 struct GNUNET_CONVERSATION_Caller *caller, 404 struct GNUNET_CONVERSATION_Caller *caller,
406 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) 405 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
407{ 406{
408 const char *cid; 407 const char *cid;
409 (void) cls; 408
410 (void) caller_id; 409 (void)cls;
410 (void)caller_id;
411 411
412 switch (code) 412 switch (code)
413 {
414 case GNUNET_CONVERSATION_EC_PHONE_RING:
415 if (NULL == active_caller1)
416 { 413 {
417 active_caller1 = caller; 414 case GNUNET_CONVERSATION_EC_PHONE_RING:
418 cid = "caller1"; 415 if (NULL == active_caller1)
419 GNUNET_CONVERSATION_caller_pick_up (caller, 416 {
420 &caller_event_handler, 417 active_caller1 = caller;
421 (void *) cid, 418 cid = "caller1";
422 &phone_speaker, 419 GNUNET_CONVERSATION_caller_pick_up(caller,
423 &phone_mic); 420 &caller_event_handler,
421 (void *)cid,
422 &phone_speaker,
423 &phone_mic);
424 }
425 else
426 {
427 GNUNET_CONVERSATION_caller_suspend(active_caller1);
428 active_caller2 = caller;
429 cid = "caller2";
430 GNUNET_CONVERSATION_caller_pick_up(caller,
431 &caller_event_handler,
432 (void *)cid,
433 &phone_speaker,
434 &phone_mic);
435 }
436 break;
437
438 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
439 if (caller == active_caller2)
440 {
441 active_caller2 = NULL;
442 GNUNET_CONVERSATION_caller_resume(active_caller1,
443 &phone_speaker,
444 &phone_mic);
445 }
446 else if (caller == active_caller1)
447 {
448 active_caller1 = NULL;
449 GNUNET_break(NULL == active_caller2);
450 GNUNET_SCHEDULER_shutdown();
451 }
452 break;
453
454 default:
455 LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected phone code: %d\n", code);
456 break;
424 } 457 }
425 else
426 {
427 GNUNET_CONVERSATION_caller_suspend (active_caller1);
428 active_caller2 = caller;
429 cid = "caller2";
430 GNUNET_CONVERSATION_caller_pick_up (caller,
431 &caller_event_handler,
432 (void *) cid,
433 &phone_speaker,
434 &phone_mic);
435 }
436 break;
437 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
438 if (caller == active_caller2)
439 {
440 active_caller2 = NULL;
441 GNUNET_CONVERSATION_caller_resume (active_caller1,
442 &phone_speaker,
443 &phone_mic);
444 }
445 else if (caller == active_caller1)
446 {
447 active_caller1 = NULL;
448 GNUNET_break (NULL == active_caller2);
449 GNUNET_SCHEDULER_shutdown ();
450 }
451 break;
452 default:
453 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected phone code: %d\n", code);
454 break;
455 }
456} 458}
457 459
458 460
459static void 461static void
460call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) 462call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
461{ 463{
462 const char *cid = cls; 464 const char *cid = cls;
463 465
464 switch (code) 466 switch (code)
465 { 467 {
466 case GNUNET_CONVERSATION_EC_CALL_RINGING: 468 case GNUNET_CONVERSATION_EC_CALL_RINGING:
467 break; 469 break;
468 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: 470
469 LOG_DEBUG ("Call %s picked\n", cid); 471 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
470 break; 472 LOG_DEBUG("Call %s picked\n", cid);
471 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: 473 break;
472 LOG_DEBUG ("Call %s GNS lookup failed \n", cid); 474
473 break; 475 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
474 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: 476 LOG_DEBUG("Call %s GNS lookup failed \n", cid);
475 LOG_DEBUG ("Call %s hungup\n", cid); 477 break;
476 if (0 == strcmp (cid, "call1")) 478
477 call1 = NULL; 479 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
478 else 480 LOG_DEBUG("Call %s hungup\n", cid);
479 call2 = NULL; 481 if (0 == strcmp(cid, "call1"))
480 break; 482 call1 = NULL;
481 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: 483 else
482 LOG_DEBUG ("Call %s suspended\n", cid); 484 call2 = NULL;
483 break; 485 break;
484 case GNUNET_CONVERSATION_EC_CALL_RESUMED: 486
485 LOG_DEBUG ("Call %s resumed\n", cid); 487 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
486 break; 488 LOG_DEBUG("Call %s suspended\n", cid);
487 case GNUNET_CONVERSATION_EC_CALL_ERROR: 489 break;
488 GNUNET_break (0); 490
489 if (0 == strcmp (cid, "call1")) 491 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
490 call1 = NULL; 492 LOG_DEBUG("Call %s resumed\n", cid);
491 else 493 break;
492 call2 = NULL; 494
493 GNUNET_SCHEDULER_shutdown (); 495 case GNUNET_CONVERSATION_EC_CALL_ERROR:
494 break; 496 GNUNET_break(0);
495 } 497 if (0 == strcmp(cid, "call1"))
498 call1 = NULL;
499 else
500 call2 = NULL;
501 GNUNET_SCHEDULER_shutdown();
502 break;
503 }
496} 504}
497 505
498 506
499static void 507static void
500caller_ego_create_cont (void *cls, 508caller_ego_create_cont(void *cls,
501 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 509 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
502 const char *emsg) 510 const char *emsg)
503{ 511{
504 (void) cls; 512 (void)cls;
505 op = NULL; 513 op = NULL;
506 GNUNET_assert (NULL == emsg); 514 GNUNET_assert(NULL == emsg);
507} 515}
508 516
509 517
510static void 518static void
511namestore_put_cont (void *cls, int32_t success, const char *emsg) 519namestore_put_cont(void *cls, int32_t success, const char *emsg)
512{ 520{
513 (void) cls; 521 (void)cls;
514 qe = NULL; 522 qe = NULL;
515 GNUNET_assert (GNUNET_YES == success); 523 GNUNET_assert(GNUNET_YES == success);
516 GNUNET_assert (NULL == emsg); 524 GNUNET_assert(NULL == emsg);
517 GNUNET_assert (NULL == op); 525 GNUNET_assert(NULL == op);
518 op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); 526 op = GNUNET_IDENTITY_create(id, "caller-ego", &caller_ego_create_cont, NULL);
519} 527}
520 528
521 529
522static void 530static void
523identity_cb (void *cls, 531identity_cb(void *cls,
524 struct GNUNET_IDENTITY_Ego *ego, 532 struct GNUNET_IDENTITY_Ego *ego,
525 void **ctx, 533 void **ctx,
526 const char *name) 534 const char *name)
527{ 535{
528 struct GNUNET_GNSRECORD_Data rd; 536 struct GNUNET_GNSRECORD_Data rd;
529 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 537 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
530 538
531 (void) cls; 539 (void)cls;
532 (void) ctx; 540 (void)ctx;
533 if (NULL == name) 541 if (NULL == name)
534 return; 542 return;
535 if (NULL == ego) 543 if (NULL == ego)
536 return; 544 return;
537 if (0 == strcmp (name, "phone-ego")) 545 if (0 == strcmp(name, "phone-ego"))
538 { 546 {
539 GNUNET_IDENTITY_ego_get_public_key (ego, &pub); 547 GNUNET_IDENTITY_ego_get_public_key(ego, &pub);
540 GNUNET_asprintf (&gns_name, 548 GNUNET_asprintf(&gns_name,
541 "phone.%s", 549 "phone.%s",
542 GNUNET_GNSRECORD_pkey_to_zkey (&pub)); 550 GNUNET_GNSRECORD_pkey_to_zkey(&pub));
543 phone = 551 phone =
544 GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); 552 GNUNET_CONVERSATION_phone_create(cfg, ego, &phone_event_handler, NULL);
545 GNUNET_assert (NULL != phone); 553 GNUNET_assert(NULL != phone);
546 memset (&rd, 0, sizeof (rd)); 554 memset(&rd, 0, sizeof(rd));
547 GNUNET_CONVERSATION_phone_get_record (phone, &rd); 555 GNUNET_CONVERSATION_phone_get_record(phone, &rd);
548 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); 556 GNUNET_assert(rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
549 rd.expiration_time = UINT64_MAX; 557 rd.expiration_time = UINT64_MAX;
550 qe = 558 qe =
551 GNUNET_NAMESTORE_records_store (ns, 559 GNUNET_NAMESTORE_records_store(ns,
552 GNUNET_IDENTITY_ego_get_private_key (ego), 560 GNUNET_IDENTITY_ego_get_private_key(ego),
553 "phone" /* GNS label */, 561 "phone" /* GNS label */,
554 1, 562 1,
555 &rd, 563 &rd,
556 &namestore_put_cont, 564 &namestore_put_cont,
557 NULL); 565 NULL);
558 return; 566 return;
559 } 567 }
560 if (0 == strcmp (name, "caller-ego")) 568 if (0 == strcmp(name, "caller-ego"))
561 { 569 {
562 GNUNET_IDENTITY_ego_get_public_key (ego, &pub); 570 GNUNET_IDENTITY_ego_get_public_key(ego, &pub);
563 GNUNET_asprintf (&gns_caller_id, 571 GNUNET_asprintf(&gns_caller_id,
564 "%s", 572 "%s",
565 GNUNET_GNSRECORD_pkey_to_zkey (&pub)); 573 GNUNET_GNSRECORD_pkey_to_zkey(&pub));
566 call1 = GNUNET_CONVERSATION_call_start (cfg, 574 call1 = GNUNET_CONVERSATION_call_start(cfg,
567 ego, 575 ego,
568 gns_name, 576 gns_name,
569 &call1_speaker, 577 &call1_speaker,
570 &call1_mic, 578 &call1_mic,
571 &call_event_handler, 579 &call_event_handler,
572 (void *) "call1"); 580 (void *)"call1");
573 call2 = GNUNET_CONVERSATION_call_start (cfg, 581 call2 = GNUNET_CONVERSATION_call_start(cfg,
574 ego, 582 ego,
575 gns_name, 583 gns_name,
576 &call2_speaker, 584 &call2_speaker,
577 &call2_mic, 585 &call2_mic,
578 &call_event_handler, 586 &call_event_handler,
579 (void *) "call2"); 587 (void *)"call2");
580 return; 588 return;
581 } 589 }
582} 590}
583 591
584 592
585static void 593static void
586phone_ego_create_cont (void *cls, 594phone_ego_create_cont(void *cls,
587 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 595 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
588 const char *emsg) 596 const char *emsg)
589{ 597{
590 (void) cls; 598 (void)cls;
591 op = NULL; 599 op = NULL;
592 GNUNET_assert (NULL == emsg); 600 GNUNET_assert(NULL == emsg);
593} 601}
594 602
595 603
596static void 604static void
597run (void *cls, 605run(void *cls,
598 const struct GNUNET_CONFIGURATION_Handle *c, 606 const struct GNUNET_CONFIGURATION_Handle *c,
599 struct GNUNET_TESTING_Peer *peer) 607 struct GNUNET_TESTING_Peer *peer)
600{ 608{
601 (void) cls; 609 (void)cls;
602 (void) peer; 610 (void)peer;
603 cfg = c; 611 cfg = c;
604 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); 612 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_test, NULL);
605 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 613 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
606 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); 614 id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL);
607 op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); 615 op = GNUNET_IDENTITY_create(id, "phone-ego", &phone_ego_create_cont, NULL);
608 ns = GNUNET_NAMESTORE_connect (cfg); 616 ns = GNUNET_NAMESTORE_connect(cfg);
609} 617}
610 618
611 619
612int 620int
613main (int argc, char *argv[]) 621main(int argc, char *argv[])
614{ 622{
615 (void) argc; 623 (void)argc;
616 (void) argv; 624 (void)argv;
617 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api_twocalls", 625 if (0 != GNUNET_TESTING_peer_run("test_conversation_api_twocalls",
618 "test_conversation.conf", 626 "test_conversation.conf",
619 &run, 627 &run,
620 NULL)) 628 NULL))
621 return 1; 629 return 1;
622 if (call1_finished && call2_finished) 630 if (call1_finished && call2_finished)
623 return 0; 631 return 0;