GNUnet  0.11.x
Functions
transport-testing-filenames.c File Reference

convenience string manipulation functions for tests More...

#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 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...
 

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 36 of file transport-testing-filenames.c.

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().

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

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

Referenced by GNUNET_TRANSPORT_TESTING_main_().

73 {
74  char *backup = extract_filename (file);
75  char *filename = backup;
76  char *dotexe;
77  char *ret;
78 
79  if (NULL == filename)
80  return NULL;
81 
82  /* remove "lt-" */
83  filename = strstr (filename, "test");
84  if (NULL == filename)
85  {
86  GNUNET_free (backup);
87  return NULL;
88  }
89 
90  /* remove ".exe" */
91  if (NULL != (dotexe = strstr (filename, ".exe")))
92  dotexe[0] = '\0';
93  ret = GNUNET_strdup (filename);
94  GNUNET_free (backup);
95  return ret;
96 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * filename
static char * extract_filename(const char *file)
Removes all directory separators from absolute filename.
#define GNUNET_free(ptr)
Wrapper around free.
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.

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

Parameters
fileabsolute file name
Returns
the result

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

References extract_filename().

Referenced by GNUNET_TRANSPORT_TESTING_main_().

107 {
108  char *src = extract_filename (file);
109  char *split;
110 
111  split = strstr (src, ".");
112  if (NULL != split)
113  split[0] = '\0';
114  return src;
115 }
static char * extract_filename(const char *file)
Removes all directory separators from absolute filename.
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 *  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 126 of file transport-testing-filenames.c.

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

Referenced by GNUNET_TRANSPORT_TESTING_main_().

128 {
129  char *filename;
130  char *dotexe;
131  char *e = extract_filename (file);
132  char *t = extract_filename (test);
133  char *ret;
134 
135  if (NULL == e)
136  goto fail;
137  /* remove "lt-" */
138  filename = strstr (e, "tes");
139  if (NULL == filename)
140  goto fail;
141  /* remove ".exe" */
142  if (NULL != (dotexe = strstr (filename, ".exe")))
143  dotexe[0] = '\0';
144 
145  /* find last _ */
146  filename = strstr (filename, t);
147  if (NULL == filename)
148  goto fail;
149  /* copy plugin */
150  filename += strlen (t);
151  if ('\0' != *filename)
152  filename++;
153  ret = GNUNET_strdup (filename);
154  goto suc;
155 fail:
156  ret = NULL;
157 suc:
158  GNUNET_free (t);
159  GNUNET_free (e);
160  return ret;
161 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct Experiment * e
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * filename
static char * extract_filename(const char *file)
Removes all directory separators from absolute filename.
#define GNUNET_free(ptr)
Wrapper around free.
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
the result

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

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

Referenced by GNUNET_TRANSPORT_TESTING_main_().

175 {
176  char *filename = extract_filename (file);
177  char *backup = filename;
178  char *dotexe;
179  char *ret;
180 
181  if (NULL == filename)
182  return NULL;
183  /* remove "lt-" */
184  filename = strstr (filename, "test");
185  if (NULL == filename)
186  goto fail;
187  /* remove ".exe" */
188  if (NULL != (dotexe = strstr (filename, ".exe")))
189  dotexe[0] = '\0';
190  GNUNET_asprintf (&ret,
191  "%s_peer%u.conf",
192  filename,
193  count);
194  GNUNET_free (backup);
195  return ret;
196 fail:
197  GNUNET_free (backup);
198  return NULL;
199 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * filename
static char * extract_filename(const char *file)
Removes all directory separators from absolute filename.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: