GNUnet 0.22.2
transport-testing-filenames2.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-testing2.h"
28
29
36static char *
37extract_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
72char *
74{
75 char *backup = extract_filename (file);
76 char *filename = backup;
77 char *dotexe;
78 char *ret;
79
80 if (NULL == filename)
81 return NULL;
82
83 /* remove "lt-" */
84 filename = strstr (filename, "test");
85 if (NULL == filename)
86 {
87 GNUNET_free (backup);
88 return NULL;
89 }
90
91 /* remove ".exe" */
92 if (NULL != (dotexe = strstr (filename, ".exe")))
93 dotexe[0] = '\0';
95 GNUNET_free (backup);
96 return ret;
97}
98
99
106char *
108{
109 char *src = extract_filename (file);
110 char *split;
111
112 split = strstr (src, ".");
113 if (NULL != split)
114 split[0] = '\0';
115 return src;
116}
117
118
126char *
128 const char *test)
129{
130 char *filename;
131 char *dotexe;
132 char *e = extract_filename (file);
133 char *t = extract_filename (test);
134 char *ret;
135
136 if (NULL == e)
137 goto fail;
138 /* remove "lt-" */
139 filename = strstr (e, "tes");
140 if (NULL == filename)
141 goto fail;
142 /* remove ".exe" */
143 if (NULL != (dotexe = strstr (filename, ".exe")))
144 dotexe[0] = '\0';
145
146 /* find last _ */
147 filename = strstr (filename, t);
148 if (NULL == filename)
149 goto fail;
150 /* copy plugin */
151 filename += strlen (t);
152 if ('\0' != *filename)
153 filename++;
155 goto suc;
156fail:
157 ret = NULL;
158suc:
159 GNUNET_free (t);
160 GNUNET_free (e);
161 return ret;
162}
163
164
173char *
175 int count)
176{
177 char *filename = extract_filename (file);
178 char *backup = filename;
179 char *dotexe;
180 char *ret;
181
182 if (NULL == filename)
183 return NULL;
184 /* remove "lt-" */
185 filename = strstr (filename, "test");
186 if (NULL == filename)
187 goto fail;
188 /* remove ".exe" */
189 if (NULL != (dotexe = strstr (filename, ".exe")))
190 dotexe[0] = '\0';
192 "%s_peer%u.conf",
193 filename,
194 count);
195 GNUNET_free (backup);
196 return ret;
197fail:
198 GNUNET_free (backup);
199 return NULL;
200}
201
202
203/* end of transport-testing-filenames.c */
static int ret
Final status code.
Definition: gnunet-arm.c:93
static char * filename
static char * res
Currently read line or NULL on EOF.
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 name 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.
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.
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.