-
-/*
- * Some utility functions
- */
-
-/**
- * Removes all directory separators from absolute filename
- * @param file the absolute file name, e.g. as found in argv[0]
- * @return extracted file name, has to be freed by caller
- */
-static char *
-extract_filename (const char *file)
-{
- char *pch = GNUNET_strdup (file);
- char *backup = pch;
- char *filename = NULL;
- char *res;
-#if WINDOWS
- if ((strlen (pch) >= 3) && pch[1] == ':')
- {
- if (NULL != strstr (pch, "\\"))
- {
- pch = strtok (pch, "\\");
- while (pch != NULL)
- {
- pch = strtok (NULL, "\\");
- if (pch != NULL)
- filename = pch;
- }
- }
- }
- if (filename != NULL)
- pch = filename; /* If we miss the next condition, filename = pch will
- * not harm us.
- */
-#endif
- if (NULL != strstr (pch, "/"))
- {
- pch = strtok (pch, "/");
- while (pch != NULL)
- {
- pch = strtok (NULL, "/");
- if (pch != NULL)
- {
- filename = pch;
- }
- }
- }
- else
- filename = pch;
-
- res = GNUNET_strdup (filename);
- GNUNET_free (backup);
- return res;
-}
-
-
-/**
- * Extracts the test filename from an absolute file name and removes the extension
- * @param file absolute file name
- * @param dest where to store result
- */
-void
-GNUNET_TRANSPORT_TESTING_get_test_name (const char *file,
- char **dest)
-{
- char *filename = extract_filename (file);
- char *backup = filename;
- char *dotexe;
-
- if (filename == NULL)
- goto fail;
-
- /* remove "lt-" */
- filename = strstr (filename, "tes");
- if (filename == NULL)
- goto fail;
-
- /* remove ".exe" */
- if (NULL != (dotexe = strstr (filename, ".exe")))
- dotexe[0] = '\0';
-
- goto suc;
-
-fail:
- (*dest) = NULL;
- return;
-
-suc:
- /* create filename */
- GNUNET_asprintf (dest, "%s", filename);
- GNUNET_free (backup);
-}
-
-
-/**
- * Extracts the filename from an absolute file name and removes the extension
- * @param file absolute file name
- * @param dest where to store result
- */
-void
-GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
- char **dest)
-{
- char *src = extract_filename (file);
- char *split;
-
- split = strstr (src, ".");
- if (split != NULL)
- {
- split[0] = '\0';
- }
- GNUNET_asprintf (dest, "%s", src);
- GNUNET_free (src);
-}
-
-
-/**
- * Extracts the plugin name from an absolute file name and the test name
- *
- * @param file absolute file name
- * @param test test name
- * @param dest where to store result
- */
-void
-GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
- const char *test,
- char **dest)
-{
- char *filename;
- char *dotexe;
- char *e = extract_filename (file);
- char *t = extract_filename (test);
-
- if (NULL == e)
- goto fail;
- /* remove "lt-" */
- filename = strstr (e, "tes");
- if (NULL == filename)
- goto fail;
- /* remove ".exe" */
- if (NULL != (dotexe = strstr (filename, ".exe")))
- dotexe[0] = '\0';
-
- /* find last _ */
- filename = strstr (filename, t);
- if (NULL == filename)
- goto fail;
- /* copy plugin */
- filename += strlen (t);
- if ('\0' != *filename)
- filename++;
- GNUNET_asprintf (dest, "%s", filename);
- goto suc;
-fail:
- (*dest) = NULL;
-suc:
- GNUNET_free (t);
- GNUNET_free (e);
-}
-
-
-/**
- * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
- * if existing ".exe"-prefix and adds the peer-number
- *
- * @param file filename of the test, e.g. argv[0]
- * @param dest where to write the filename
- * @param count peer number
- */
-void
-GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
- char **dest,
- int count)
-{
- char *filename = extract_filename (file);
- char *backup = filename;
- char *dotexe;
-
- if (NULL == filename)
- goto fail;
- /* remove "lt-" */
- filename = strstr (filename, "tes");
- if (NULL == filename)
- goto fail;
- /* remove ".exe" */
- if (NULL != (dotexe = strstr (filename, ".exe")))
- dotexe[0] = '\0';
- GNUNET_asprintf (dest, "%s_peer%u.conf", filename, count);
- GNUNET_free (backup);
- return;
-fail:
- (*dest) = NULL;
- GNUNET_free (backup);
-}
-
-