diff options
Diffstat (limited to 'src/transport/transport-testing-filenames2.c')
-rw-r--r-- | src/transport/transport-testing-filenames2.c | 203 |
1 files changed, 0 insertions, 203 deletions
diff --git a/src/transport/transport-testing-filenames2.c b/src/transport/transport-testing-filenames2.c deleted file mode 100644 index 59fa1ebd5..000000000 --- a/src/transport/transport-testing-filenames2.c +++ /dev/null | |||
@@ -1,203 +0,0 @@ | |||
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 | */ | ||
20 | /** | ||
21 | * @file transport-testing-filenames.c | ||
22 | * @brief convenience string manipulation functions for tests | ||
23 | * @author Matthias Wachs | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "transport-testing2.h" | ||
28 | |||
29 | |||
30 | /** | ||
31 | * Removes all directory separators from absolute filename | ||
32 | * | ||
33 | * @param file the absolute file name, e.g. as found in argv[0] | ||
34 | * @return extracted file name, has to be freed by caller | ||
35 | */ | ||
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 | |||
59 | res = GNUNET_strdup (filename); | ||
60 | GNUNET_free (backup); | ||
61 | return res; | ||
62 | } | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Extracts the test filename from an absolute file name and removes | ||
67 | * the extension | ||
68 | * | ||
69 | * @param file absolute file name | ||
70 | * @return the result | ||
71 | */ | ||
72 | char * | ||
73 | GNUNET_TRANSPORT_TESTING_get_test_name (const char *file) | ||
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'; | ||
94 | ret = GNUNET_strdup (filename); | ||
95 | GNUNET_free (backup); | ||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Extracts the filename from an absolute file name and removes the extension | ||
102 | * | ||
103 | * @param file absolute file name | ||
104 | * @return the result | ||
105 | */ | ||
106 | char * | ||
107 | GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file) | ||
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 | |||
119 | /** | ||
120 | * Extracts the plugin name from an absolute file name and the test name | ||
121 | * | ||
122 | * @param file absolute file name | ||
123 | * @param test test name | ||
124 | * @return the result | ||
125 | */ | ||
126 | char * | ||
127 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, | ||
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++; | ||
154 | ret = GNUNET_strdup (filename); | ||
155 | goto suc; | ||
156 | fail: | ||
157 | ret = NULL; | ||
158 | suc: | ||
159 | GNUNET_free (t); | ||
160 | GNUNET_free (e); | ||
161 | return ret; | ||
162 | } | ||
163 | |||
164 | |||
165 | /** | ||
166 | * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and | ||
167 | * if existing ".exe"-prefix and adds the peer-number | ||
168 | * | ||
169 | * @param file filename of the test, e.g. argv[0] | ||
170 | * @param count peer number | ||
171 | * @return the result | ||
172 | */ | ||
173 | char * | ||
174 | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, | ||
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'; | ||
191 | GNUNET_asprintf (&ret, | ||
192 | "%s_peer%u.conf", | ||
193 | filename, | ||
194 | count); | ||
195 | GNUNET_free (backup); | ||
196 | return ret; | ||
197 | fail: | ||
198 | GNUNET_free (backup); | ||
199 | return NULL; | ||
200 | } | ||
201 | |||
202 | |||
203 | /* end of transport-testing-filenames.c */ | ||