summaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-09-01 09:23:52 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-09-01 09:23:52 +0000
commit06e2ee2b2be79cee6acc2628f9b91a3591b014df (patch)
tree32745eb33c7c0ec4c65b10f3487eba51e422fa9d /src/transport
parent734360920c83580d3d1ce2b3c4668da3816e28b2 (diff)
latest changes
Diffstat (limited to 'src/transport')
-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,
GNUNET_TRANSPORT_NotifyDisconnect nd,
void *cb_cls)
{
+ if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "File not found: `%s' \n", cfgname);
+ return NULL;
+ }
+
struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext));
p->cfg = GNUNET_CONFIGURATION_create ();
@@ -341,20 +347,24 @@ void GNUNET_TRANSPORT_TESTING_connect_peers_cancel
GNUNET_free (cc);
}
+
/*
* 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
+ */
char *
-extract_filename (const char * file)
+extract_filename (const char *file)
{
char *pch = strdup (file);
char *backup = pch;
char *filename = NULL;
char *res;
-
- /* get executable filename */
if (NULL != strstr (pch, "/"))
{
pch = strtok (pch, "/");
@@ -362,91 +372,141 @@ extract_filename (const char * file)
{
pch = strtok (NULL, "/");
if (pch != NULL)
- {
+ {
filename = pch;
- }
+ }
}
}
else
filename = pch;
- res = strdup(filename);
- GNUNET_free (backup);
+ res = 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_sourcename (const char * file, char **testname)
+GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest)
{
- char * src = extract_filename (file);
- char * split;
+ 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';
+
+ if (filename == NULL)
+ goto fail;
+ 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(testname, "%s", src);
+ GNUNET_asprintf (dest, "%s", src);
GNUNET_free (src);
}
+
+/**
+ * Extracts the plugin anme 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 (const char * executable, const char * testname, char **pluginname)
+GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
+ const char *test, char **dest)
{
- char *exec = extract_filename (executable);
- char *test = extract_filename (testname);
+ char *e = extract_filename (file);
+ char *t = extract_filename (test);
- char *backup_t = test;
char *filename = NULL;
char *dotexe;
- if (exec == NULL)
+ if (e == NULL)
goto fail;
/* remove "lt-" */
- filename = strstr (exec, "tes");
+ filename = strstr (e, "tes");
if (filename == NULL)
goto fail;
/* remove ".exe" */
if (NULL != (dotexe = strstr (filename, ".exe")))
- dotexe[0] = '\0';
+ dotexe[0] = '\0';
/* find last _ */
- filename = strstr (filename, test);
+ filename = strstr (filename, t);
if (filename == NULL)
goto fail;
/* copy plugin */
- filename += strlen (test);
+ filename += strlen (t);
filename++;
- GNUNET_asprintf (pluginname, "%s", filename);
+ GNUNET_asprintf (dest, "%s", filename);
goto suc;
fail:
- (*pluginname) = NULL;
+ (*dest) = NULL;
suc:
- GNUNET_free (backup_t);
- GNUNET_free (exec);
+ GNUNET_free (t);
+ GNUNET_free (e);
}
/**
- * this function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
+ * 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 cfgname where to write the result
* @param count peer number
*/
void
-GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
+GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest,
int count)
{
char *filename = extract_filename (file);
char *backup = filename;
char *dotexe;
-
if (filename == NULL)
goto fail;
@@ -457,21 +517,19 @@ GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
/* remove ".exe" */
if (NULL != (dotexe = strstr (filename, ".exe")))
- dotexe[0] = '\0';
+ dotexe[0] = '\0';
if (filename == NULL)
goto fail;
-
- /* copy plugin */
goto suc;
fail:
- (*cfgname) = NULL;
- return;
+ (*dest) = NULL;
+ return;
suc:
/* create cfg filename */
- GNUNET_asprintf (cfgname, "%s_peer%u.conf", filename, count);
+ GNUNET_asprintf (dest, "%s_peer%u.conf", filename, count);
GNUNET_free (backup);
}
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);
*/
/**
- * this function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
+ * 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);
+
+/**
+ * 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 cfgname where to write the result
@@ -133,10 +141,26 @@ void
GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **cfgname,
int count);
+
+/**
+ * Extracts the plugin anme 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 (const char * executable, const char * testname, char **pluginname);
+GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
+ const char *testname,
+ char **pluginname);
+
+/**
+ * Extracts the filename from an absolute file name and removes the extenstion
+ * @param file absolute file name
+ * @param dest where to store result
+ */
void
-GNUNET_TRANSPORT_TESTING_get_test_sourcename (const char * file, char **testname);
+GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file,
+ char **testname);
/* end of transport_testing.h */