[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r16666 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r16666 - gnunet/src/transport |
Date: |
Thu, 1 Sep 2011 11:23:52 +0200 |
Author: wachs
Date: 2011-09-01 11:23:52 +0200 (Thu, 01 Sep 2011)
New Revision: 16666
Modified:
gnunet/src/transport/transport-testing.c
gnunet/src/transport/transport-testing.h
Log:
latest changes
Modified: gnunet/src/transport/transport-testing.c
===================================================================
--- gnunet/src/transport/transport-testing.c 2011-09-01 03:29:46 UTC (rev
16665)
+++ gnunet/src/transport/transport-testing.c 2011-09-01 09:23:52 UTC (rev
16666)
@@ -205,6 +205,12 @@
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 @@
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 @@
{
pch = strtok (NULL, "/");
if (pch != NULL)
- {
+ {
filename = pch;
- }
+ }
}
}
else
filename = pch;
- res = strdup(filename);
+
+ 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 @@
/* 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);
}
Modified: gnunet/src/transport/transport-testing.h
===================================================================
--- gnunet/src/transport/transport-testing.h 2011-09-01 03:29:46 UTC (rev
16665)
+++ gnunet/src/transport/transport-testing.h 2011-09-01 09:23:52 UTC (rev
16666)
@@ -123,7 +123,15 @@
*/
/**
- * 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 @@
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 */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r16666 - gnunet/src/transport,
gnunet <=