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 (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 }
62 
63 
71 char *
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 }
97 
98 
105 char *
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 }
116 
117 
125 char *
127  const char *test)
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 }
162 
163 
172 char *
174  int count)
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 }
200 
201 
202 /* 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:66
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.