GNUnet  0.20.0
transport-testing-filenames.c File Reference

convenience string manipulation functions for tests More...

#include "platform.h"
#include "transport-testing.h"
Include dependency graph for transport-testing-filenames.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 anme 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...
 

Detailed Description

convenience string manipulation functions for tests

Author
Matthias Wachs
Christian Grothoff

Definition in file transport-testing-filenames.c.

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-filenames.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
resulting test name

Definition at line 66 of file transport-testing-filenames.c.

67 {
68  char *backup = extract_filename (file);
69  char *filename = backup;
70  char *dotexe;
71  char *ret;
72 
73  if (NULL == filename)
74  return NULL;
75 
76  /* remove "lt-" */
77  filename = strstr (filename, "test");
78  if (NULL == filename)
79  {
80  GNUNET_free (backup);
81  return NULL;
82  }
83 
84  /* remove ".exe" */
85  if (NULL != (dotexe = strstr (filename, ".exe")))
86  dotexe[0] = '\0';
88  GNUNET_free (backup);
89  return ret;
90 }
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.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller 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 source name

Definition at line 94 of file transport-testing-filenames.c.

95 {
96  char *src = extract_filename (file);
97  char *split;
98 
99  split = strstr (src, ".");
100  if (NULL != split)
101  split[0] = '\0';
102  return src;
103 }

References extract_filename().

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_test_plugin_name()

char* GNUNET_TRANSPORT_TESTING_get_test_plugin_name ( const char *  executable,
const char *  testname 
)

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

Parameters
fileabsolute file name
testtest name
Returns
the plugin name

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

109 {
110  char *filename;
111  char *dotexe;
112  char *e = extract_filename (file);
113  char *t = extract_filename (test);
114  char *ret;
115 
116  if (NULL == e)
117  goto fail;
118  /* remove "lt-" */
119  filename = strstr (e, "tes");
120  if (NULL == filename)
121  goto fail;
122  /* remove ".exe" */
123  if (NULL != (dotexe = strstr (filename, ".exe")))
124  dotexe[0] = '\0';
125 
126  /* find last _ */
127  filename = strstr (filename, t);
128  if (NULL == filename)
129  goto fail;
130  /* copy plugin */
131  filename += strlen (t);
132  if ('\0' != *filename)
133  filename++;
135  goto suc;
136 fail:
137  ret = NULL;
138 suc:
139  GNUNET_free (t);
140  GNUNET_free (e);
141  return ret;
142 }
static struct Experiment * e
static struct GNUNET_SCHEDULER_Task * t
Main task.

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

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller 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
configuration name to use

Definition at line 146 of file transport-testing-filenames.c.

148 {
149  char *filename = extract_filename (file);
150  char *backup = filename;
151  char *dotexe;
152  char *ret;
153 
154  if (NULL == filename)
155  return NULL;
156  /* remove "lt-" */
157  filename = strstr (filename, "test");
158  if (NULL == filename)
159  goto fail;
160  /* remove ".exe" */
161  if (NULL != (dotexe = strstr (filename, ".exe")))
162  dotexe[0] = '\0';
164  "%s_peer%u.conf",
165  filename,
166  count);
167  GNUNET_free (backup);
168  return ret;
169 fail:
170  GNUNET_free (backup);
171  return NULL;
172 }
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.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function: