aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/transport-testing.c124
-rw-r--r--src/transport/transport-testing.h30
2 files changed, 118 insertions, 36 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index f71d7b78b..02bab07f4 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -205,6 +205,12 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
205 GNUNET_TRANSPORT_NotifyDisconnect nd, 205 GNUNET_TRANSPORT_NotifyDisconnect nd,
206 void *cb_cls) 206 void *cb_cls)
207{ 207{
208 if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO)
209 {
210 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "File not found: `%s' \n", cfgname);
211 return NULL;
212 }
213
208 struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext)); 214 struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext));
209 215
210 p->cfg = GNUNET_CONFIGURATION_create (); 216 p->cfg = GNUNET_CONFIGURATION_create ();
@@ -341,20 +347,24 @@ void GNUNET_TRANSPORT_TESTING_connect_peers_cancel
341 GNUNET_free (cc); 347 GNUNET_free (cc);
342} 348}
343 349
350
344/* 351/*
345 * Some utility functions 352 * Some utility functions
346 */ 353 */
347 354
355/**
356 * Removes all directory separators from absolute filename
357 * @param file the absolute file name, e.g. as found in argv[0]
358 * @return extracted file name, has to be freed by caller
359 */
348char * 360char *
349extract_filename (const char * file) 361extract_filename (const char *file)
350{ 362{
351 char *pch = strdup (file); 363 char *pch = strdup (file);
352 char *backup = pch; 364 char *backup = pch;
353 char *filename = NULL; 365 char *filename = NULL;
354 char *res; 366 char *res;
355 367
356
357 /* get executable filename */
358 if (NULL != strstr (pch, "/")) 368 if (NULL != strstr (pch, "/"))
359 { 369 {
360 pch = strtok (pch, "/"); 370 pch = strtok (pch, "/");
@@ -362,91 +372,141 @@ extract_filename (const char * file)
362 { 372 {
363 pch = strtok (NULL, "/"); 373 pch = strtok (NULL, "/");
364 if (pch != NULL) 374 if (pch != NULL)
365 { 375 {
366 filename = pch; 376 filename = pch;
367 } 377 }
368 } 378 }
369 } 379 }
370 else 380 else
371 filename = pch; 381 filename = pch;
372 res = strdup(filename);
373 GNUNET_free (backup);
374 382
383 res = strdup (filename);
384 GNUNET_free (backup);
375 return res; 385 return res;
376} 386}
377 387
388/**
389 * Extracts the test filename from an absolute file name and removes the extension
390 * @param file absolute file name
391 * @param dest where to store result
392 */
378void 393void
379GNUNET_TRANSPORT_TESTING_get_test_sourcename (const char * file, char **testname) 394GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest)
380{ 395{
381 char * src = extract_filename (file); 396 char *filename = extract_filename (file);
382 char * split; 397 char *backup = filename;
398 char *dotexe;
399
400 if (filename == NULL)
401 goto fail;
402
403 /* remove "lt-" */
404 filename = strstr (filename, "tes");
405 if (filename == NULL)
406 goto fail;
407
408 /* remove ".exe" */
409 if (NULL != (dotexe = strstr (filename, ".exe")))
410 dotexe[0] = '\0';
411
412 if (filename == NULL)
413 goto fail;
414 goto suc;
415
416fail:
417 (*dest) = NULL;
418 return;
419
420suc:
421 /* create filename */
422 GNUNET_asprintf (dest, "%s", filename);
423 GNUNET_free (backup);
424}
425
426
427/**
428 * Extracts the filename from an absolute file name and removes the extension
429 * @param file absolute file name
430 * @param dest where to store result
431 */
432void
433GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file, char **dest)
434{
435 char *src = extract_filename (file);
436 char *split;
383 437
384 split = strstr (src, "."); 438 split = strstr (src, ".");
385 if (split != NULL) 439 if (split != NULL)
386 { 440 {
387 split[0] = '\0'; 441 split[0] = '\0';
388 } 442 }
389 GNUNET_asprintf(testname, "%s", src); 443 GNUNET_asprintf (dest, "%s", src);
390 GNUNET_free (src); 444 GNUNET_free (src);
391} 445}
392 446
447
448/**
449 * Extracts the plugin anme from an absolute file name and the test name
450 * @param file absolute file name
451 * @param test test name
452 * @param dest where to store result
453 */
393void 454void
394GNUNET_TRANSPORT_TESTING_get_test_plugin (const char * executable, const char * testname, char **pluginname) 455GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
456 const char *test, char **dest)
395{ 457{
396 char *exec = extract_filename (executable); 458 char *e = extract_filename (file);
397 char *test = extract_filename (testname); 459 char *t = extract_filename (test);
398 460
399 char *backup_t = test;
400 char *filename = NULL; 461 char *filename = NULL;
401 char *dotexe; 462 char *dotexe;
402 463
403 if (exec == NULL) 464 if (e == NULL)
404 goto fail; 465 goto fail;
405 466
406 /* remove "lt-" */ 467 /* remove "lt-" */
407 filename = strstr (exec, "tes"); 468 filename = strstr (e, "tes");
408 if (filename == NULL) 469 if (filename == NULL)
409 goto fail; 470 goto fail;
410 471
411 /* remove ".exe" */ 472 /* remove ".exe" */
412 if (NULL != (dotexe = strstr (filename, ".exe"))) 473 if (NULL != (dotexe = strstr (filename, ".exe")))
413 dotexe[0] = '\0'; 474 dotexe[0] = '\0';
414 475
415 /* find last _ */ 476 /* find last _ */
416 filename = strstr (filename, test); 477 filename = strstr (filename, t);
417 if (filename == NULL) 478 if (filename == NULL)
418 goto fail; 479 goto fail;
419 480
420 /* copy plugin */ 481 /* copy plugin */
421 filename += strlen (test); 482 filename += strlen (t);
422 filename++; 483 filename++;
423 GNUNET_asprintf (pluginname, "%s", filename); 484 GNUNET_asprintf (dest, "%s", filename);
424 goto suc; 485 goto suc;
425 486
426fail: 487fail:
427 (*pluginname) = NULL; 488 (*dest) = NULL;
428suc: 489suc:
429 GNUNET_free (backup_t); 490 GNUNET_free (t);
430 GNUNET_free (exec); 491 GNUNET_free (e);
431 492
432} 493}
433 494
434/** 495/**
435 * this function takes the filename (e.g. argv[0), removes a "lt-"-prefix and 496 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
436 * if existing ".exe"-prefix and adds the peer-number 497 * if existing ".exe"-prefix and adds the peer-number
437 * @param file filename of the test, e.g. argv[0] 498 * @param file filename of the test, e.g. argv[0]
438 * @param cfgname where to write the result 499 * @param cfgname where to write the result
439 * @param count peer number 500 * @param count peer number
440 */ 501 */
441void 502void
442GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname, 503GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest,
443 int count) 504 int count)
444{ 505{
445 char *filename = extract_filename (file); 506 char *filename = extract_filename (file);
446 char *backup = filename; 507 char *backup = filename;
447 char *dotexe; 508 char *dotexe;
448 509
449
450 if (filename == NULL) 510 if (filename == NULL)
451 goto fail; 511 goto fail;
452 512
@@ -457,21 +517,19 @@ GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
457 517
458 /* remove ".exe" */ 518 /* remove ".exe" */
459 if (NULL != (dotexe = strstr (filename, ".exe"))) 519 if (NULL != (dotexe = strstr (filename, ".exe")))
460 dotexe[0] = '\0'; 520 dotexe[0] = '\0';
461 521
462 if (filename == NULL) 522 if (filename == NULL)
463 goto fail; 523 goto fail;
464
465 /* copy plugin */
466 goto suc; 524 goto suc;
467 525
468fail: 526fail:
469 (*cfgname) = NULL; 527 (*dest) = NULL;
470 return; 528 return;
471 529
472suc: 530suc:
473 /* create cfg filename */ 531 /* create cfg filename */
474 GNUNET_asprintf (cfgname, "%s_peer%u.conf", filename, count); 532 GNUNET_asprintf (dest, "%s_peer%u.conf", filename, count);
475 GNUNET_free (backup); 533 GNUNET_free (backup);
476} 534}
477 535
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 96fe216e9..852f060e4 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -123,7 +123,15 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (void *cc);
123 */ 123 */
124 124
125/** 125/**
126 * this function takes the filename (e.g. argv[0), removes a "lt-"-prefix and 126 * Extracts the test filename from an absolute file name and removes the extension
127 * @param file absolute file name
128 * @param dest where to store result
129 */
130void
131GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest);
132
133/**
134 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
127 * if existing ".exe"-prefix and adds the peer-number 135 * if existing ".exe"-prefix and adds the peer-number
128 * @param file filename of the test, e.g. argv[0] 136 * @param file filename of the test, e.g. argv[0]
129 * @param cfgname where to write the result 137 * @param cfgname where to write the result
@@ -133,10 +141,26 @@ void
133GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname, 141GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
134 int count); 142 int count);
135 143
144
145/**
146 * Extracts the plugin anme from an absolute file name and the test name
147 * @param file absolute file name
148 * @param test test name
149 * @param dest where to store result
150 */
136void 151void
137GNUNET_TRANSPORT_TESTING_get_test_plugin (const char * executable, const char * testname, char **pluginname); 152GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
153 const char *testname,
154 char **pluginname);
155
138 156
157/**
158 * Extracts the filename from an absolute file name and removes the extenstion
159 * @param file absolute file name
160 * @param dest where to store result
161 */
139void 162void
140GNUNET_TRANSPORT_TESTING_get_test_sourcename (const char * file, char **testname); 163GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
164 char **testname);
141 165
142/* end of transport_testing.h */ 166/* end of transport_testing.h */