GNUnet  0.20.0
transport-testing-filenames2.c File Reference
#include "platform.h"
#include "transport-testing2.h"
Include dependency graph for transport-testing-filenames2.c:

Go to the source code of this file.

Functions

static char * extract_filename (const char *file)
 Removes all directory separators from absolute filename. More...
 
char * GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
 Extracts the test filename from an absolute file name and removes the extension. More...
 
char * GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file)
 Extracts the filename from an absolute file name and removes the extension. More...
 
char * GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, const char *test)
 Extracts the plugin name from an absolute file name and the test name. More...
 
char * GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count)
 This function takes the filename (e.g. More...
 

Function Documentation

◆ extract_filename()

static char* extract_filename ( const char *  file)
static

Removes all directory separators from absolute filename.

Parameters
filethe absolute file name, e.g. as found in argv[0]
Returns
extracted file name, has to be freed by caller

Definition at line 37 of file transport-testing-filenames2.c.

38 {
39  char *pch = GNUNET_strdup (file);
40  char *backup = pch;
41  char *filename = NULL;
42  char *res;
43 
44  if (NULL != strstr (pch, "/"))
45  {
46  pch = strtok (pch, "/");
47  while (pch != NULL)
48  {
49  pch = strtok (NULL, "/");
50  if (pch != NULL)
51  {
52  filename = pch;
53  }
54  }
55  }
56  else
57  filename = pch;
58 
60  GNUNET_free (backup);
61  return res;
62 }
static int res
static char * filename
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_free(ptr)
Wrapper around free.
static struct GNUNET_SCHEDULER_Task * pch
Handle for the parent_control_handler() Task.
Definition: os_priority.c:67

References filename, GNUNET_free, GNUNET_strdup, pch, and res.

Referenced by GNUNET_TRANSPORT_TESTING_get_config_name(), GNUNET_TRANSPORT_TESTING_get_test_name(), GNUNET_TRANSPORT_TESTING_get_test_plugin_name(), and GNUNET_TRANSPORT_TESTING_get_test_source_name().

Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_test_name()

char* GNUNET_TRANSPORT_TESTING_get_test_name ( const char *  file)

Extracts the test filename from an absolute file name and removes the extension.

Parameters
fileabsolute file name
Returns
the result

Definition at line 73 of file transport-testing-filenames2.c.

74 {
75  char *backup = extract_filename (file);
76  char *filename = backup;
77  char *dotexe;
78  char *ret;
79 
80  if (NULL == filename)
81  return NULL;
82 
83  /* remove "lt-" */
84  filename = strstr (filename, "test");
85  if (NULL == filename)
86  {
87  GNUNET_free (backup);
88  return NULL;
89  }
90 
91  /* remove ".exe" */
92  if (NULL != (dotexe = strstr (filename, ".exe")))
93  dotexe[0] = '\0';
95  GNUNET_free (backup);
96  return ret;
97 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * extract_filename(const char *file)
Removes all directory separators from absolute filename.

References extract_filename(), filename, GNUNET_free, GNUNET_strdup, and ret.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_test_source_name()

char* GNUNET_TRANSPORT_TESTING_get_test_source_name ( const char *  file)

Extracts the filename from an absolute file name and removes the extension.

Parameters
fileabsolute file name
Returns
the result

Definition at line 107 of file transport-testing-filenames2.c.

108 {
109  char *src = extract_filename (file);
110  char *split;
111 
112  split = strstr (src, ".");
113  if (NULL != split)
114  split[0] = '\0';
115  return src;
116 }

References extract_filename().

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_test_plugin_name()

char* GNUNET_TRANSPORT_TESTING_get_test_plugin_name ( const char *  file,
const char *  test 
)

Extracts the plugin name from an absolute file name and the test name.

Extracts the plugin anme from an absolute file name and the test name.

Parameters
fileabsolute file name
testtest name
Returns
the result

Definition at line 127 of file transport-testing-filenames2.c.

129 {
130  char *filename;
131  char *dotexe;
132  char *e = extract_filename (file);
133  char *t = extract_filename (test);
134  char *ret;
135 
136  if (NULL == e)
137  goto fail;
138  /* remove "lt-" */
139  filename = strstr (e, "tes");
140  if (NULL == filename)
141  goto fail;
142  /* remove ".exe" */
143  if (NULL != (dotexe = strstr (filename, ".exe")))
144  dotexe[0] = '\0';
145 
146  /* find last _ */
147  filename = strstr (filename, t);
148  if (NULL == filename)
149  goto fail;
150  /* copy plugin */
151  filename += strlen (t);
152  if ('\0' != *filename)
153  filename++;
155  goto suc;
156 fail:
157  ret = NULL;
158 suc:
159  GNUNET_free (t);
160  GNUNET_free (e);
161  return ret;
162 }
static struct Experiment * e
static struct GNUNET_SCHEDULER_Task * t
Main task.

References e, extract_filename(), filename, GNUNET_free, GNUNET_strdup, ret, and t.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_config_name()

char* GNUNET_TRANSPORT_TESTING_get_config_name ( const char *  file,
int  count 
)

This function takes the filename (e.g.

argv[0), removes a "lt-"-prefix and if existing ".exe"-prefix and adds the peer-number

Parameters
filefilename of the test, e.g. argv[0]
countpeer number
Returns
the result

Definition at line 174 of file transport-testing-filenames2.c.

176 {
177  char *filename = extract_filename (file);
178  char *backup = filename;
179  char *dotexe;
180  char *ret;
181 
182  if (NULL == filename)
183  return NULL;
184  /* remove "lt-" */
185  filename = strstr (filename, "test");
186  if (NULL == filename)
187  goto fail;
188  /* remove ".exe" */
189  if (NULL != (dotexe = strstr (filename, ".exe")))
190  dotexe[0] = '\0';
192  "%s_peer%u.conf",
193  filename,
194  count);
195  GNUNET_free (backup);
196  return ret;
197 fail:
198  GNUNET_free (backup);
199  return NULL;
200 }
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.

References extract_filename(), filename, GNUNET_asprintf(), GNUNET_free, and ret.

Here is the call graph for this function: