GNUnet  0.10.x
transport-testing-filenames.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
26 #include "transport-testing.h"
27 
28 
35 static char *
36 extract_filename (const char *file)
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 }
81 
82 
90 char *
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 }
116 
117 
124 char *
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 }
135 
136 
144 char *
146  const char *test)
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 }
181 
182 
191 char *
193  int count)
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 }
219 
220 
221 /* end of transport-testing-filenames.c */
static struct Experiment * e
char * GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
Extracts the test filename from an absolute file name and removes the extension.
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_.
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.
static int res
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.
static struct GNUNET_SCHEDULER_Task * pch
Handle for the parent_control_handler() Task.
Definition: os_priority.c:71
char * GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
Extracts the filename from an absolute file name and removes the extension.
testing lib for transport service
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.