GNUnet  0.10.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 WINDOWS
44  if ((strlen (pch) >= 3) && pch[1] == ':')
45  {
46  if (NULL != strstr (pch, "\\"))
47  {
48  pch = strtok (pch, "\\");
49  while (pch != NULL)
50  {
51  pch = strtok (NULL, "\\");
52  if (pch != NULL)
53  filename = pch;
54  }
55  }
56  }
57  if (filename != NULL)
58  pch = filename; /* If we miss the next condition, filename = pch will
59  * not harm us.
60  */
61 #endif
62  if (NULL != strstr (pch, "/"))
63  {
64  pch = strtok (pch, "/");
65  while (pch != NULL)
66  {
67  pch = strtok (NULL, "/");
68  if (pch != NULL)
69  {
70  filename = pch;
71  }
72  }
73  }
74  else
75  filename = pch;
76 
77  res = GNUNET_strdup (filename);
78  GNUNET_free (backup);
79  return res;
80 }
#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:71
#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 91 of file transport-testing-filenames.c.

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

Referenced by GNUNET_TRANSPORT_TESTING_main_().

92 {
93  char *backup = extract_filename (file);
94  char *filename = backup;
95  char *dotexe;
96  char *ret;
97 
98  if (NULL == filename)
99  return NULL;
100 
101  /* remove "lt-" */
102  filename = strstr (filename, "test");
103  if (NULL == filename)
104  {
105  GNUNET_free (backup);
106  return NULL;
107  }
108 
109  /* remove ".exe" */
110  if (NULL != (dotexe = strstr (filename, ".exe")))
111  dotexe[0] = '\0';
112  ret = GNUNET_strdup (filename);
113  GNUNET_free (backup);
114  return ret;
115 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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 125 of file transport-testing-filenames.c.

References extract_filename().

Referenced by GNUNET_TRANSPORT_TESTING_main_().

126 {
127  char *src = extract_filename (file);
128  char *split;
129 
130  split = strstr (src, ".");
131  if (NULL != split)
132  split[0] = '\0';
133  return src;
134 }
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 145 of file transport-testing-filenames.c.

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

Referenced by GNUNET_TRANSPORT_TESTING_main_().

147 {
148  char *filename;
149  char *dotexe;
150  char *e = extract_filename (file);
151  char *t = extract_filename (test);
152  char *ret;
153 
154  if (NULL == e)
155  goto fail;
156  /* remove "lt-" */
157  filename = strstr (e, "tes");
158  if (NULL == filename)
159  goto fail;
160  /* remove ".exe" */
161  if (NULL != (dotexe = strstr (filename, ".exe")))
162  dotexe[0] = '\0';
163 
164  /* find last _ */
165  filename = strstr (filename, t);
166  if (NULL == filename)
167  goto fail;
168  /* copy plugin */
169  filename += strlen (t);
170  if ('\0' != *filename)
171  filename++;
172  ret = GNUNET_strdup (filename);
173  goto suc;
174 fail:
175  ret = NULL;
176 suc:
177  GNUNET_free (t);
178  GNUNET_free (e);
179  return ret;
180 }
static struct Experiment * e
static struct GNUNET_SCHEDULER_Task * t
Main task.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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 192 of file transport-testing-filenames.c.

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

Referenced by GNUNET_TRANSPORT_TESTING_main_().

194 {
195  char *filename = extract_filename (file);
196  char *backup = filename;
197  char *dotexe;
198  char *ret;
199 
200  if (NULL == filename)
201  return NULL;
202  /* remove "lt-" */
203  filename = strstr (filename, "test");
204  if (NULL == filename)
205  goto fail;
206  /* remove ".exe" */
207  if (NULL != (dotexe = strstr (filename, ".exe")))
208  dotexe[0] = '\0';
209  GNUNET_asprintf (&ret,
210  "%s_peer%u.conf",
211  filename,
212  count);
213  GNUNET_free (backup);
214  return ret;
215 fail:
216  GNUNET_free (backup);
217  return NULL;
218 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
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: