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