GNUnet  0.19.5
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 "platform.h"
27 #include "transport-testing.h"
28 
29 
36 static char *
37 extract_filename (const char *file)
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 }
63 
64 
65 char *
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 }
91 
92 
93 char *
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 }
104 
105 
106 char *
108  const char *test)
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 }
143 
144 
145 char *
147  int count)
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 }
173 
174 
175 /* end of transport-testing-filenames.c */
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct Experiment * e
static int res
static char * filename
static struct GNUNET_SCHEDULER_Task * t
Main task.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#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
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.
char * GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
Extracts the filename from an absolute file name and removes the extension.
static char * extract_filename(const char *file)
Removes all directory separators from absolute filename.
char * GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
Extracts the test filename from an absolute file name and removes the extension.
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.
testing lib for transport service