aboutsummaryrefslogtreecommitdiff
path: root/src/regex
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/regex
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/gnunet-daemon-regexprofiler.c339
-rw-r--r--src/regex/gnunet-regex-profiler.c1324
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c622
-rw-r--r--src/regex/gnunet-service-regex.c297
-rw-r--r--src/regex/perf-regex.c102
-rw-r--r--src/regex/plugin_block_regex.c386
-rw-r--r--src/regex/regex_api_announce.c99
-rw-r--r--src/regex/regex_api_search.c155
-rw-r--r--src/regex/regex_block_lib.c362
-rw-r--r--src/regex/regex_block_lib.h45
-rw-r--r--src/regex/regex_internal.c3122
-rw-r--r--src/regex/regex_internal.h52
-rw-r--r--src/regex/regex_internal_dht.c657
-rw-r--r--src/regex/regex_internal_lib.h56
-rw-r--r--src/regex/regex_ipc.h9
-rw-r--r--src/regex/regex_test_graph.c281
-rw-r--r--src/regex/regex_test_lib.c518
-rw-r--r--src/regex/regex_test_lib.h19
-rw-r--r--src/regex/regex_test_random.c115
-rw-r--r--src/regex/test_regex_api.c70
-rw-r--r--src/regex/test_regex_eval_api.c335
-rw-r--r--src/regex/test_regex_graph_api.c160
-rw-r--r--src/regex/test_regex_integration.c183
-rw-r--r--src/regex/test_regex_iterate_api.c270
-rw-r--r--src/regex/test_regex_proofs.c89
25 files changed, 4879 insertions, 4788 deletions
diff --git a/src/regex/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c
index b9c32f9c7..a23336808 100644
--- a/src/regex/gnunet-daemon-regexprofiler.c
+++ b/src/regex/gnunet-daemon-regexprofiler.c
@@ -62,7 +62,7 @@ static struct REGEX_INTERNAL_Announcement *announce_handle;
62/** 62/**
63 * Periodically reannounce regex. 63 * Periodically reannounce regex.
64 */ 64 */
65static struct GNUNET_SCHEDULER_Task * reannounce_task; 65static struct GNUNET_SCHEDULER_Task *reannounce_task;
66 66
67/** 67/**
68 * What's the maximum reannounce period. 68 * What's the maximum reannounce period.
@@ -78,12 +78,12 @@ static unsigned long long max_path_compression;
78 * Name of the file containing policies that this peer should announce. One 78 * Name of the file containing policies that this peer should announce. One
79 * policy per line. 79 * policy per line.
80 */ 80 */
81static char * policy_filename; 81static char *policy_filename;
82 82
83/** 83/**
84 * Prefix to add before every regex we're announcing. 84 * Prefix to add before every regex we're announcing.
85 */ 85 */
86static char * regex_prefix; 86static char *regex_prefix;
87 87
88/** 88/**
89 * Regex with prefix. 89 * Regex with prefix.
@@ -108,31 +108,31 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
108 * @param cls unused 108 * @param cls unused
109 */ 109 */
110static void 110static void
111shutdown_task(void *cls) 111shutdown_task (void *cls)
112{ 112{
113 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); 113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
114 114
115 if (NULL != announce_handle) 115 if (NULL != announce_handle)
116 { 116 {
117 REGEX_INTERNAL_announce_cancel(announce_handle); 117 REGEX_INTERNAL_announce_cancel (announce_handle);
118 announce_handle = NULL; 118 announce_handle = NULL;
119 } 119 }
120 if (NULL != reannounce_task) 120 if (NULL != reannounce_task)
121 { 121 {
122 GNUNET_free(GNUNET_SCHEDULER_cancel(reannounce_task)); 122 GNUNET_free (GNUNET_SCHEDULER_cancel (reannounce_task));
123 reannounce_task = NULL; 123 reannounce_task = NULL;
124 } 124 }
125 if (NULL != dht_handle) 125 if (NULL != dht_handle)
126 { 126 {
127 GNUNET_DHT_disconnect(dht_handle); 127 GNUNET_DHT_disconnect (dht_handle);
128 dht_handle = NULL; 128 dht_handle = NULL;
129 } 129 }
130 GNUNET_free(my_private_key); 130 GNUNET_free (my_private_key);
131 my_private_key = NULL; 131 my_private_key = NULL;
132 132
133 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 133 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
134 "Daemon for %s shutting down\n", 134 "Daemon for %s shutting down\n",
135 policy_filename); 135 policy_filename);
136} 136}
137 137
138 138
@@ -142,45 +142,46 @@ shutdown_task(void *cls)
142 * @param cls Closure (regex to announce if needed). 142 * @param cls Closure (regex to announce if needed).
143 */ 143 */
144static void 144static void
145reannounce_regex(void *cls) 145reannounce_regex (void *cls)
146{ 146{
147 char *regex = cls; 147 char *regex = cls;
148 struct GNUNET_TIME_Relative random_delay; 148 struct GNUNET_TIME_Relative random_delay;
149 149
150 reannounce_task = NULL; 150 reannounce_task = NULL;
151 if (0 == rounds--) 151 if (0 == rounds--)
152 { 152 {
153 global_ret = 0; 153 global_ret = 0;
154 GNUNET_SCHEDULER_shutdown(); 154 GNUNET_SCHEDULER_shutdown ();
155 GNUNET_free(regex); 155 GNUNET_free (regex);
156 return; 156 return;
157 } 157 }
158 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex); 158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
159 GNUNET_STATISTICS_update(stats_handle, "# regexes announced", 1, GNUNET_NO); 159 GNUNET_STATISTICS_update (stats_handle, "# regexes announced", 1, GNUNET_NO);
160 if (NULL == announce_handle && NULL != regex) 160 if ((NULL == announce_handle)&&(NULL != regex))
161 { 161 {
162 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "First time, creating regex: %s\n", 163 "First time, creating regex: %s\n",
164 regex); 164 regex);
165 announce_handle = REGEX_INTERNAL_announce(dht_handle, 165 announce_handle = REGEX_INTERNAL_announce (dht_handle,
166 my_private_key, 166 my_private_key,
167 regex, 167 regex,
168 (unsigned int)max_path_compression, 168 (unsigned
169 stats_handle); 169 int) max_path_compression,
170 } 170 stats_handle);
171 }
171 else 172 else
172 { 173 {
173 GNUNET_assert(NULL != announce_handle); 174 GNUNET_assert (NULL != announce_handle);
174 REGEX_INTERNAL_reannounce(announce_handle); 175 REGEX_INTERNAL_reannounce (announce_handle);
175 } 176 }
176 177
177 random_delay = 178 random_delay =
178 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MICROSECONDS, 179 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,
179 GNUNET_CRYPTO_random_u32( 180 GNUNET_CRYPTO_random_u32 (
180 GNUNET_CRYPTO_QUALITY_WEAK, 181 GNUNET_CRYPTO_QUALITY_WEAK,
181 reannounce_period_max.rel_value_us)); 182 reannounce_period_max.rel_value_us));
182 reannounce_task = GNUNET_SCHEDULER_add_delayed(random_delay, 183 reannounce_task = GNUNET_SCHEDULER_add_delayed (random_delay,
183 &reannounce_regex, cls); 184 &reannounce_regex, cls);
184} 185}
185 186
186 187
@@ -191,23 +192,23 @@ reannounce_regex(void *cls)
191 * @param regex regular expression to announce on this peer's cadet. 192 * @param regex regular expression to announce on this peer's cadet.
192 */ 193 */
193static void 194static void
194announce_regex(const char *regex) 195announce_regex (const char *regex)
195{ 196{
196 char *copy; 197 char *copy;
197 198
198 if (NULL == regex || 0 == strlen(regex)) 199 if ((NULL == regex)||(0 == strlen (regex)))
199 { 200 {
200 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot announce empty regex\n"); 201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot announce empty regex\n");
201 return; 202 return;
202 } 203 }
203 204
204 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 205 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
205 "Daemon for %s starting\n", 206 "Daemon for %s starting\n",
206 policy_filename); 207 policy_filename);
207 GNUNET_assert(NULL == reannounce_task); 208 GNUNET_assert (NULL == reannounce_task);
208 copy = GNUNET_strdup(regex); 209 copy = GNUNET_strdup (regex);
209 reannounce_task = GNUNET_SCHEDULER_add_now(&reannounce_regex, 210 reannounce_task = GNUNET_SCHEDULER_add_now (&reannounce_regex,
210 (void *)copy); 211 (void *) copy);
211} 212}
212 213
213 214
@@ -220,16 +221,16 @@ announce_regex(const char *regex)
220 * GNUNET_NO to stop when found 221 * GNUNET_NO to stop when found
221 */ 222 */
222static int 223static int
223scan(void *cls, const char *filename) 224scan (void *cls, const char *filename)
224{ 225{
225 long n = (long)cls; 226 long n = (long) cls;
226 static long c = 0; 227 static long c = 0;
227 228
228 if (c == n) 229 if (c == n)
229 { 230 {
230 policy_filename = GNUNET_strdup(filename); 231 policy_filename = GNUNET_strdup (filename);
231 return GNUNET_NO; 232 return GNUNET_NO;
232 } 233 }
233 c++; 234 c++;
234 return GNUNET_OK; 235 return GNUNET_OK;
235} 236}
@@ -244,9 +245,9 @@ scan(void *cls, const char *filename)
244 * @param cfg_ configuration 245 * @param cfg_ configuration
245 */ 246 */
246static void 247static void
247run(void *cls, char *const *args GNUNET_UNUSED, 248run (void *cls, char *const *args GNUNET_UNUSED,
248 const char *cfgfile GNUNET_UNUSED, 249 const char *cfgfile GNUNET_UNUSED,
249 const struct GNUNET_CONFIGURATION_Handle *cfg_) 250 const struct GNUNET_CONFIGURATION_Handle *cfg_)
250{ 251{
251 char *regex = NULL; 252 char *regex = NULL;
252 char **components; 253 char **components;
@@ -255,106 +256,109 @@ run(void *cls, char *const *args GNUNET_UNUSED,
255 256
256 cfg = cfg_; 257 cfg = cfg_;
257 258
258 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); 259 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
259 GNUNET_assert(NULL != my_private_key); 260 GNUNET_assert (NULL != my_private_key);
260 if (GNUNET_OK != 261 if (GNUNET_OK !=
261 GNUNET_CONFIGURATION_get_value_number(cfg, "REGEXPROFILER", 262 GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER",
262 "MAX_PATH_COMPRESSION", 263 "MAX_PATH_COMPRESSION",
263 &max_path_compression)) 264 &max_path_compression))
264 { 265 {
265 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
266 _ 267 _
267 ("%s service is lacking key configuration settings (%s). Exiting.\n"), 268 (
268 "regexprofiler", "max_path_compression"); 269 "%s service is lacking key configuration settings (%s). Exiting.\n"),
269 global_ret = GNUNET_SYSERR; 270 "regexprofiler", "max_path_compression");
270 GNUNET_SCHEDULER_shutdown(); 271 global_ret = GNUNET_SYSERR;
271 return; 272 GNUNET_SCHEDULER_shutdown ();
272 } 273 return;
274 }
273 if (GNUNET_OK != 275 if (GNUNET_OK !=
274 GNUNET_CONFIGURATION_get_value_string(cfg, "REGEXPROFILER", 276 GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER",
275 "POLICY_DIR", &policy_dir)) 277 "POLICY_DIR", &policy_dir))
276 { 278 {
277 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER", "POLICY_DIR"); 279 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER",
278 global_ret = GNUNET_SYSERR; 280 "POLICY_DIR");
279 GNUNET_SCHEDULER_shutdown(); 281 global_ret = GNUNET_SYSERR;
280 return; 282 GNUNET_SCHEDULER_shutdown ();
281 } 283 return;
284 }
282 if (GNUNET_OK != 285 if (GNUNET_OK !=
283 GNUNET_CONFIGURATION_get_value_number(cfg, "TESTBED", 286 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
284 "PEERID", &peer_id)) 287 "PEERID", &peer_id))
285 { 288 {
286 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "TESTBED", "PEERID"); 289 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "TESTBED", "PEERID");
287 global_ret = GNUNET_SYSERR; 290 global_ret = GNUNET_SYSERR;
288 GNUNET_free(policy_dir); 291 GNUNET_free (policy_dir);
289 GNUNET_SCHEDULER_shutdown(); 292 GNUNET_SCHEDULER_shutdown ();
290 return; 293 return;
291 } 294 }
292 295
293 if (GNUNET_OK != 296 if (GNUNET_OK !=
294 GNUNET_CONFIGURATION_get_value_string(cfg, "REGEXPROFILER", 297 GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER",
295 "REGEX_PREFIX", &regex_prefix)) 298 "REGEX_PREFIX", &regex_prefix))
296 { 299 {
297 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER", "REGEX_PREFIX"); 300 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER",
298 global_ret = GNUNET_SYSERR; 301 "REGEX_PREFIX");
299 GNUNET_free(policy_dir); 302 global_ret = GNUNET_SYSERR;
300 GNUNET_SCHEDULER_shutdown(); 303 GNUNET_free (policy_dir);
301 return; 304 GNUNET_SCHEDULER_shutdown ();
302 } 305 return;
306 }
303 307
304 if (GNUNET_OK != 308 if (GNUNET_OK !=
305 GNUNET_CONFIGURATION_get_value_time(cfg, "REGEXPROFILER", 309 GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER",
306 "REANNOUNCE_PERIOD_MAX", 310 "REANNOUNCE_PERIOD_MAX",
307 &reannounce_period_max)) 311 &reannounce_period_max))
308 { 312 {
309 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 313 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
310 "reannounce_period_max not given. Using 10 minutes.\n"); 314 "reannounce_period_max not given. Using 10 minutes.\n");
311 reannounce_period_max = 315 reannounce_period_max =
312 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10); 316 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10);
313 } 317 }
314 318
315 stats_handle = GNUNET_STATISTICS_create("regexprofiler", cfg); 319 stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg);
316 320
317 dht_handle = GNUNET_DHT_connect(cfg, 1); 321 dht_handle = GNUNET_DHT_connect (cfg, 1);
318 322
319 if (NULL == dht_handle) 323 if (NULL == dht_handle)
320 { 324 {
321 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
322 "Could not acquire dht handle. Exiting.\n"); 326 "Could not acquire dht handle. Exiting.\n");
323 global_ret = GNUNET_SYSERR; 327 global_ret = GNUNET_SYSERR;
324 GNUNET_free(policy_dir); 328 GNUNET_free (policy_dir);
325 GNUNET_SCHEDULER_shutdown(); 329 GNUNET_SCHEDULER_shutdown ();
326 return; 330 return;
327 } 331 }
328 332
329 /* Read regexes from policy files */ 333 /* Read regexes from policy files */
330 GNUNET_assert(-1 != GNUNET_DISK_directory_scan(policy_dir, &scan, 334 GNUNET_assert (-1 != GNUNET_DISK_directory_scan (policy_dir, &scan,
331 (void *)(long)peer_id)); 335 (void *) (long) peer_id));
332 if (NULL == (components = REGEX_TEST_read_from_file(policy_filename))) 336 if (NULL == (components = REGEX_TEST_read_from_file (policy_filename)))
333 { 337 {
334 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
335 "Policy file %s contains no policies. Exiting.\n", 339 "Policy file %s contains no policies. Exiting.\n",
336 policy_filename); 340 policy_filename);
337 global_ret = GNUNET_SYSERR; 341 global_ret = GNUNET_SYSERR;
338 GNUNET_free(policy_dir); 342 GNUNET_free (policy_dir);
339 GNUNET_SCHEDULER_shutdown(); 343 GNUNET_SCHEDULER_shutdown ();
340 return; 344 return;
341 } 345 }
342 GNUNET_free(policy_dir); 346 GNUNET_free (policy_dir);
343 regex = REGEX_TEST_combine(components, 16); 347 regex = REGEX_TEST_combine (components, 16);
344 REGEX_TEST_free_from_file(components); 348 REGEX_TEST_free_from_file (components);
345 349
346 /* Announcing regexes from policy_filename */ 350 /* Announcing regexes from policy_filename */
347 GNUNET_asprintf(&rx_with_pfx, 351 GNUNET_asprintf (&rx_with_pfx,
348 "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*", 352 "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*",
349 regex_prefix, 353 regex_prefix,
350 regex); 354 regex);
351 announce_regex(rx_with_pfx); 355 announce_regex (rx_with_pfx);
352 GNUNET_free(regex); 356 GNUNET_free (regex);
353 GNUNET_free(rx_with_pfx); 357 GNUNET_free (rx_with_pfx);
354 358
355 /* Scheduled the task to clean up when shutdown is called */ 359 /* Scheduled the task to clean up when shutdown is called */
356 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 360 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
357 NULL); 361 NULL);
358} 362}
359 363
360 364
@@ -366,19 +370,20 @@ run(void *cls, char *const *args GNUNET_UNUSED,
366 * @return 0 ok, 1 on error 370 * @return 0 ok, 1 on error
367 */ 371 */
368int 372int
369main(int argc, char *const *argv) 373main (int argc, char *const *argv)
370{ 374{
371 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 375 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
372 GNUNET_GETOPT_OPTION_END 376 GNUNET_GETOPT_OPTION_END
373 }; 377 };
374 378
375 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 379 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
376 return 2; 380 return 2;
377 return (GNUNET_OK == 381 return (GNUNET_OK ==
378 GNUNET_PROGRAM_run(argc, argv, "regexprofiler", 382 GNUNET_PROGRAM_run (argc, argv, "regexprofiler",
379 gettext_noop 383 gettext_noop
380 ("Daemon to announce regular expressions for the peer using cadet."), 384 (
381 options, &run, NULL)) ? global_ret : 1; 385 "Daemon to announce regular expressions for the peer using cadet."),
386 options, &run, NULL)) ? global_ret : 1;
382} 387}
383 388
384 389
@@ -388,11 +393,11 @@ main(int argc, char *const *argv)
388/** 393/**
389 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 394 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
390 */ 395 */
391void __attribute__ ((constructor)) GNUNET_ARM_memory_init() 396void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
392{ 397{
393 mallopt(M_TRIM_THRESHOLD, 4 * 1024); 398 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
394 mallopt(M_TOP_PAD, 1 * 1024); 399 mallopt (M_TOP_PAD, 1 * 1024);
395 malloc_trim(0); 400 malloc_trim (0);
396} 401}
397#endif 402#endif
398 403
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c
index 4262107d7..16b7a7f0e 100644
--- a/src/regex/gnunet-regex-profiler.c
+++ b/src/regex/gnunet-regex-profiler.c
@@ -37,12 +37,13 @@
37#include "gnunet_testbed_service.h" 37#include "gnunet_testbed_service.h"
38 38
39#define FIND_TIMEOUT \ 39#define FIND_TIMEOUT \
40 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) 40 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
41 41
42/** 42/**
43 * DLL of operations 43 * DLL of operations
44 */ 44 */
45struct DLLOperation { 45struct DLLOperation
46{
46 /** 47 /**
47 * The testbed operation handle 48 * The testbed operation handle
48 */ 49 */
@@ -68,7 +69,8 @@ struct DLLOperation {
68/** 69/**
69 * Available states during profiling 70 * Available states during profiling
70 */ 71 */
71enum State { 72enum State
73{
72 /** 74 /**
73 * Initial state 75 * Initial state
74 */ 76 */
@@ -110,7 +112,8 @@ enum State {
110/** 112/**
111 * Peer handles. 113 * Peer handles.
112 */ 114 */
113struct RegexPeer { 115struct RegexPeer
116{
114 /** 117 /**
115 * Peer id. 118 * Peer id.
116 */ 119 */
@@ -167,7 +170,7 @@ struct RegexPeer {
167 /** 170 /**
168 * Operation timeout 171 * Operation timeout
169 */ 172 */
170 struct GNUNET_SCHEDULER_Task * timeout; 173 struct GNUNET_SCHEDULER_Task *timeout;
171 174
172 /** 175 /**
173 * Deamon start 176 * Deamon start
@@ -208,12 +211,12 @@ static struct GNUNET_CONFIGURATION_Handle *cfg;
208/** 211/**
209 * Abort task identifier 212 * Abort task identifier
210 */ 213 */
211static struct GNUNET_SCHEDULER_Task * abort_task; 214static struct GNUNET_SCHEDULER_Task *abort_task;
212 215
213/** 216/**
214 * Host registration task identifier 217 * Host registration task identifier
215 */ 218 */
216static struct GNUNET_SCHEDULER_Task * register_hosts_task; 219static struct GNUNET_SCHEDULER_Task *register_hosts_task;
217 220
218/** 221/**
219 * Global event mask for all testbed events 222 * Global event mask for all testbed events
@@ -248,7 +251,7 @@ enum State state;
248/** 251/**
249 * Folder where policy files are stored. 252 * Folder where policy files are stored.
250 */ 253 */
251static char * policy_dir; 254static char *policy_dir;
252 255
253/** 256/**
254 * File with hostnames where to execute the test. 257 * File with hostnames where to execute the test.
@@ -288,7 +291,7 @@ static unsigned int next_search;
288/** 291/**
289 * Search timeout task identifier. 292 * Search timeout task identifier.
290 */ 293 */
291static struct GNUNET_SCHEDULER_Task * search_timeout_task; 294static struct GNUNET_SCHEDULER_Task *search_timeout_task;
292 295
293/** 296/**
294 * Search timeout in seconds. 297 * Search timeout in seconds.
@@ -309,7 +312,7 @@ static char *data_filename;
309 * Prefix used for regex announcing. We need to prefix the search 312 * Prefix used for regex announcing. We need to prefix the search
310 * strings with it, in order to find something. 313 * strings with it, in order to find something.
311 */ 314 */
312static char * regex_prefix; 315static char *regex_prefix;
313 316
314/** 317/**
315 * What's the maximum regex reannounce period. 318 * What's the maximum regex reannounce period.
@@ -330,8 +333,8 @@ static struct GNUNET_TIME_Relative reannounce_period_max;
330 * @param emsg error message. 333 * @param emsg error message.
331 */ 334 */
332static void 335static void
333dht_connect_cb(void *cls, struct GNUNET_TESTBED_Operation *op, 336dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
334 void *ca_result, const char *emsg); 337 void *ca_result, const char *emsg);
335 338
336/** 339/**
337 * DHT connect adapter. 340 * DHT connect adapter.
@@ -342,7 +345,7 @@ dht_connect_cb(void *cls, struct GNUNET_TESTBED_Operation *op,
342 * @return 345 * @return
343 */ 346 */
344static void * 347static void *
345dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg); 348dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
346 349
347 350
348/** 351/**
@@ -353,7 +356,7 @@ dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
353 * @param op_result service handle returned from the connect adapter 356 * @param op_result service handle returned from the connect adapter
354 */ 357 */
355static void 358static void
356dht_da(void *cls, void *op_result); 359dht_da (void *cls, void *op_result);
357 360
358 361
359/** 362/**
@@ -366,10 +369,10 @@ dht_da(void *cls, void *op_result);
366 * @param emsg error message on failure 369 * @param emsg error message on failure
367 */ 370 */
368static void 371static void
369stats_connect_cb(void *cls, 372stats_connect_cb (void *cls,
370 struct GNUNET_TESTBED_Operation *op, 373 struct GNUNET_TESTBED_Operation *op,
371 void *ca_result, 374 void *ca_result,
372 const char *emsg); 375 const char *emsg);
373 376
374 377
375/** 378/**
@@ -378,7 +381,7 @@ stats_connect_cb(void *cls,
378 * @param cls Index of the next peer in the peers array. 381 * @param cls Index of the next peer in the peers array.
379 */ 382 */
380static void 383static void
381announce_next_regex(void *cls); 384announce_next_regex (void *cls);
382 385
383 386
384/******************************************************************************/ 387/******************************************************************************/
@@ -392,7 +395,7 @@ announce_next_regex(void *cls);
392 * @param cls NULL 395 * @param cls NULL
393 */ 396 */
394static void 397static void
395do_shutdown(void *cls) 398do_shutdown (void *cls)
396{ 399{
397 struct RegexPeer *peer; 400 struct RegexPeer *peer;
398 unsigned int peer_cnt; 401 unsigned int peer_cnt;
@@ -401,75 +404,75 @@ do_shutdown(void *cls)
401 size_t size; 404 size_t size;
402 405
403 if (NULL != abort_task) 406 if (NULL != abort_task)
404 { 407 {
405 GNUNET_SCHEDULER_cancel(abort_task); 408 GNUNET_SCHEDULER_cancel (abort_task);
406 abort_task = NULL; 409 abort_task = NULL;
407 } 410 }
408 if (NULL != register_hosts_task) 411 if (NULL != register_hosts_task)
409 { 412 {
410 GNUNET_SCHEDULER_cancel(register_hosts_task); 413 GNUNET_SCHEDULER_cancel (register_hosts_task);
411 register_hosts_task = NULL; 414 register_hosts_task = NULL;
412 } 415 }
413 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) 416 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
417 {
418 peer = &peers[peer_cnt];
419
420 if ((GNUNET_YES != peer->search_str_matched) &&(NULL != data_file) )
414 { 421 {
415 peer = &peers[peer_cnt]; 422 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
416 423 size =
417 if (GNUNET_YES != peer->search_str_matched && NULL != data_file) 424 GNUNET_snprintf (output_buffer,
418 { 425 sizeof(output_buffer),
419 prof_time = GNUNET_TIME_absolute_get_duration(peer->prof_start_time); 426 "%p Search string not found: %s (%d)\n"
420 size = 427 "%p On peer: %u (%p)\n"
421 GNUNET_snprintf(output_buffer, 428 "%p After: %s\n",
422 sizeof(output_buffer), 429 peer, peer->search_str, peer->search_str_matched,
423 "%p Search string not found: %s (%d)\n" 430 peer, peer->id, peer,
424 "%p On peer: %u (%p)\n" 431 peer,
425 "%p After: %s\n", 432 GNUNET_STRINGS_relative_time_to_string (prof_time,
426 peer, peer->search_str, peer->search_str_matched, 433 GNUNET_NO));
427 peer, peer->id, peer, 434 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
428 peer, 435 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
429 GNUNET_STRINGS_relative_time_to_string(prof_time,
430 GNUNET_NO));
431 if (size != GNUNET_DISK_file_write(data_file, output_buffer, size))
432 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
433 }
434
435 if (NULL != peers[peer_cnt].op_handle)
436 GNUNET_TESTBED_operation_done(peers[peer_cnt].op_handle);
437 } 436 }
438 437
438 if (NULL != peers[peer_cnt].op_handle)
439 GNUNET_TESTBED_operation_done (peers[peer_cnt].op_handle);
440 }
441
439 if (NULL != data_file) 442 if (NULL != data_file)
440 { 443 {
441 GNUNET_DISK_file_close(data_file); 444 GNUNET_DISK_file_close (data_file);
442 data_file = NULL; 445 data_file = NULL;
443 } 446 }
444 for (search_str_cnt = 0; 447 for (search_str_cnt = 0;
445 search_str_cnt < num_peers && NULL != search_strings; 448 search_str_cnt < num_peers && NULL != search_strings;
446 search_str_cnt++) 449 search_str_cnt++)
447 { 450 {
448 GNUNET_free_non_null(search_strings[search_str_cnt]); 451 GNUNET_free_non_null (search_strings[search_str_cnt]);
449 } 452 }
450 GNUNET_free_non_null(search_strings); 453 GNUNET_free_non_null (search_strings);
451 search_strings = NULL; 454 search_strings = NULL;
452 455
453 if (NULL != reg_handle) 456 if (NULL != reg_handle)
454 { 457 {
455 GNUNET_TESTBED_cancel_registration(reg_handle); 458 GNUNET_TESTBED_cancel_registration (reg_handle);
456 reg_handle = NULL; 459 reg_handle = NULL;
457 } 460 }
458 if (NULL != mc) 461 if (NULL != mc)
459 { 462 {
460 GNUNET_TESTBED_controller_disconnect(mc); 463 GNUNET_TESTBED_controller_disconnect (mc);
461 mc = NULL; 464 mc = NULL;
462 } 465 }
463 if (NULL != mc_proc) 466 if (NULL != mc_proc)
464 { 467 {
465 GNUNET_TESTBED_controller_stop(mc_proc); 468 GNUNET_TESTBED_controller_stop (mc_proc);
466 mc_proc = NULL; 469 mc_proc = NULL;
467 } 470 }
468 if (NULL != cfg) 471 if (NULL != cfg)
469 { 472 {
470 GNUNET_CONFIGURATION_destroy(cfg); 473 GNUNET_CONFIGURATION_destroy (cfg);
471 cfg = NULL; 474 cfg = NULL;
472 } 475 }
473} 476}
474 477
475 478
@@ -479,15 +482,15 @@ do_shutdown(void *cls)
479 * @param cls NULL 482 * @param cls NULL
480 */ 483 */
481static void 484static void
482do_abort(void *cls) 485do_abort (void *cls)
483{ 486{
484 unsigned long i = (unsigned long)cls; 487 unsigned long i = (unsigned long) cls;
485 488
486 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 489 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
487 "Aborting from line %lu...\n", i); 490 "Aborting from line %lu...\n", i);
488 abort_task = NULL; 491 abort_task = NULL;
489 result = GNUNET_SYSERR; 492 result = GNUNET_SYSERR;
490 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 493 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
491} 494}
492 495
493 496
@@ -506,10 +509,10 @@ do_abort(void *cls)
506 * @return service handle to return in 'op_result', NULL on error 509 * @return service handle to return in 'op_result', NULL on error
507 */ 510 */
508static void * 511static void *
509stats_ca(void *cls, 512stats_ca (void *cls,
510 const struct GNUNET_CONFIGURATION_Handle *cfg) 513 const struct GNUNET_CONFIGURATION_Handle *cfg)
511{ 514{
512 return GNUNET_STATISTICS_create("<driver>", cfg); 515 return GNUNET_STATISTICS_create ("<driver>", cfg);
513} 516}
514 517
515 518
@@ -521,13 +524,13 @@ stats_ca(void *cls,
521 * @param op_result service handle returned from the connect adapter 524 * @param op_result service handle returned from the connect adapter
522 */ 525 */
523static void 526static void
524stats_da(void *cls, void *op_result) 527stats_da (void *cls, void *op_result)
525{ 528{
526 struct RegexPeer *peer = cls; 529 struct RegexPeer *peer = cls;
527 530
528 GNUNET_assert(op_result == peer->stats_handle); 531 GNUNET_assert (op_result == peer->stats_handle);
529 532
530 GNUNET_STATISTICS_destroy(peer->stats_handle, GNUNET_NO); 533 GNUNET_STATISTICS_destroy (peer->stats_handle, GNUNET_NO);
531 peer->stats_handle = NULL; 534 peer->stats_handle = NULL;
532} 535}
533 536
@@ -543,34 +546,34 @@ stats_da(void *cls, void *op_result)
543 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 546 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
544 */ 547 */
545static int 548static int
546stats_iterator(void *cls, 549stats_iterator (void *cls,
547 const char *subsystem, 550 const char *subsystem,
548 const char *name, 551 const char *name,
549 uint64_t value, int is_persistent) 552 uint64_t value, int is_persistent)
550{ 553{
551 struct RegexPeer *peer = cls; 554 struct RegexPeer *peer = cls;
552 char output_buffer[512]; 555 char output_buffer[512];
553 size_t size; 556 size_t size;
554 557
555 if (NULL == data_file) 558 if (NULL == data_file)
556 { 559 {
557 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 560 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
558 "%p -> %s [%s]: %llu\n", 561 "%p -> %s [%s]: %llu\n",
559 peer, 562 peer,
560 subsystem, 563 subsystem,
561 name, 564 name,
562 (unsigned long long)value); 565 (unsigned long long) value);
563 return GNUNET_OK; 566 return GNUNET_OK;
564 } 567 }
565 size = 568 size =
566 GNUNET_snprintf(output_buffer, 569 GNUNET_snprintf (output_buffer,
567 sizeof(output_buffer), 570 sizeof(output_buffer),
568 "%p [%s] %llu %s\n", 571 "%p [%s] %llu %s\n",
569 peer, 572 peer,
570 subsystem, value, name); 573 subsystem, value, name);
571 if (size != GNUNET_DISK_file_write(data_file, output_buffer, size)) 574 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
572 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 575 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
573 "Unable to write to file!\n"); 576 "Unable to write to file!\n");
574 577
575 return GNUNET_OK; 578 return GNUNET_OK;
576} 579}
@@ -585,48 +588,48 @@ stats_iterator(void *cls,
585 * successfully obtained, GNUNET_SYSERR if not. 588 * successfully obtained, GNUNET_SYSERR if not.
586 */ 589 */
587static void 590static void
588stats_cb(void *cls, 591stats_cb (void *cls,
589 int success) 592 int success)
590{ 593{
591 static unsigned int peer_cnt; 594 static unsigned int peer_cnt;
592 struct RegexPeer *peer = cls; 595 struct RegexPeer *peer = cls;
593 596
594 if (GNUNET_OK != success) 597 if (GNUNET_OK != success)
595 { 598 {
596 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 599 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
597 "Getting statistics for peer %u failed!\n", 600 "Getting statistics for peer %u failed!\n",
598 peer->id); 601 peer->id);
599 return; 602 return;
600 } 603 }
601 604
602 GNUNET_assert(NULL != peer->op_handle); 605 GNUNET_assert (NULL != peer->op_handle);
603 606
604 GNUNET_TESTBED_operation_done(peer->op_handle); 607 GNUNET_TESTBED_operation_done (peer->op_handle);
605 peer->op_handle = NULL; 608 peer->op_handle = NULL;
606 609
607 peer_cnt++; 610 peer_cnt++;
608 peer = &peers[peer_cnt]; 611 peer = &peers[peer_cnt];
609 612
610 fprintf(stderr, "s"); 613 fprintf (stderr, "s");
611 if (peer_cnt == num_peers) 614 if (peer_cnt == num_peers)
612 { 615 {
613 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 616 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
614 "\nCollecting stats finished. Shutting down.\n"); 617 "\nCollecting stats finished. Shutting down.\n");
615 GNUNET_SCHEDULER_shutdown(); 618 GNUNET_SCHEDULER_shutdown ();
616 result = GNUNET_OK; 619 result = GNUNET_OK;
617 } 620 }
618 else 621 else
619 { 622 {
620 peer->op_handle = 623 peer->op_handle =
621 GNUNET_TESTBED_service_connect(NULL, 624 GNUNET_TESTBED_service_connect (NULL,
622 peer->peer_handle, 625 peer->peer_handle,
623 "statistics", 626 "statistics",
624 &stats_connect_cb, 627 &stats_connect_cb,
625 peer, 628 peer,
626 &stats_ca, 629 &stats_ca,
627 &stats_da, 630 &stats_da,
628 peer); 631 peer);
629 } 632 }
630} 633}
631 634
632 635
@@ -640,32 +643,32 @@ stats_cb(void *cls,
640 * @param emsg error message on failure 643 * @param emsg error message on failure
641 */ 644 */
642static void 645static void
643stats_connect_cb(void *cls, 646stats_connect_cb (void *cls,
644 struct GNUNET_TESTBED_Operation *op, 647 struct GNUNET_TESTBED_Operation *op,
645 void *ca_result, 648 void *ca_result,
646 const char *emsg) 649 const char *emsg)
647{ 650{
648 struct RegexPeer *peer = cls; 651 struct RegexPeer *peer = cls;
649 652
650 if (NULL == ca_result || NULL != emsg) 653 if ((NULL == ca_result)||(NULL != emsg))
651 { 654 {
652 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
653 "Failed to connect to statistics service on peer %u: %s\n", 656 "Failed to connect to statistics service on peer %u: %s\n",
654 peer->id, emsg); 657 peer->id, emsg);
655 658
656 peer->stats_handle = NULL; 659 peer->stats_handle = NULL;
657 return; 660 return;
658 } 661 }
659 662
660 peer->stats_handle = ca_result; 663 peer->stats_handle = ca_result;
661 664
662 if (NULL == GNUNET_STATISTICS_get(peer->stats_handle, NULL, NULL, 665 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, NULL, NULL,
663 &stats_cb, 666 &stats_cb,
664 &stats_iterator, peer)) 667 &stats_iterator, peer))
665 { 668 {
666 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 669 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
667 "Could not get statistics of peer %u!\n", peer->id); 670 "Could not get statistics of peer %u!\n", peer->id);
668 } 671 }
669} 672}
670 673
671 674
@@ -676,21 +679,21 @@ stats_connect_cb(void *cls,
676 * @param cls NULL 679 * @param cls NULL
677 */ 680 */
678static void 681static void
679do_collect_stats(void *cls) 682do_collect_stats (void *cls)
680{ 683{
681 struct RegexPeer *peer = &peers[0]; 684 struct RegexPeer *peer = &peers[0];
682 685
683 GNUNET_assert(NULL != peer->peer_handle); 686 GNUNET_assert (NULL != peer->peer_handle);
684 687
685 peer->op_handle = 688 peer->op_handle =
686 GNUNET_TESTBED_service_connect(NULL, 689 GNUNET_TESTBED_service_connect (NULL,
687 peer->peer_handle, 690 peer->peer_handle,
688 "statistics", 691 "statistics",
689 &stats_connect_cb, 692 &stats_connect_cb,
690 peer, 693 peer,
691 &stats_ca, 694 &stats_ca,
692 &stats_da, 695 &stats_da,
693 peer); 696 peer);
694} 697}
695 698
696 699
@@ -705,7 +708,7 @@ do_collect_stats(void *cls)
705 * @param cls Index of the next peer in the peers array. 708 * @param cls Index of the next peer in the peers array.
706 */ 709 */
707static void 710static void
708find_string(void *cls); 711find_string (void *cls);
709 712
710 713
711/** 714/**
@@ -720,94 +723,94 @@ find_string(void *cls);
720 * @param put_path_length Length of the put_path. 723 * @param put_path_length Length of the put_path.
721 */ 724 */
722static void 725static void
723regex_found_handler(void *cls, 726regex_found_handler (void *cls,
724 const struct GNUNET_PeerIdentity *id, 727 const struct GNUNET_PeerIdentity *id,
725 const struct GNUNET_PeerIdentity *get_path, 728 const struct GNUNET_PeerIdentity *get_path,
726 unsigned int get_path_length, 729 unsigned int get_path_length,
727 const struct GNUNET_PeerIdentity *put_path, 730 const struct GNUNET_PeerIdentity *put_path,
728 unsigned int put_path_length) 731 unsigned int put_path_length)
729{ 732{
730 struct RegexPeer *peer = cls; 733 struct RegexPeer *peer = cls;
731 char output_buffer[512]; 734 char output_buffer[512];
732 size_t size; 735 size_t size;
733 736
734 if (GNUNET_YES == peer->search_str_matched) 737 if (GNUNET_YES == peer->search_str_matched)
735 { 738 {
736 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 739 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
737 "String %s on peer %u already matched!\n", 740 "String %s on peer %u already matched!\n",
738 peer->search_str, peer->id); 741 peer->search_str, peer->id);
739 return; 742 return;
740 } 743 }
741 744
742 strings_found++; 745 strings_found++;
743 parallel_searches--; 746 parallel_searches--;
744 747
745 if (NULL != peer->timeout) 748 if (NULL != peer->timeout)
746 { 749 {
747 GNUNET_SCHEDULER_cancel(peer->timeout); 750 GNUNET_SCHEDULER_cancel (peer->timeout);
748 peer->timeout = NULL; 751 peer->timeout = NULL;
749 if (GNUNET_NO == in_shutdown) 752 if (GNUNET_NO == in_shutdown)
750 GNUNET_SCHEDULER_add_now(&announce_next_regex, NULL); 753 GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
751 } 754 }
752 755
753 if (NULL == id) 756 if (NULL == id)
754 { 757 {
755 // FIXME not possible right now 758 // FIXME not possible right now
756 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 759 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
757 "String matching timed out for string %s on peer %u (%i/%i)\n", 760 "String matching timed out for string %s on peer %u (%i/%i)\n",
758 peer->search_str, peer->id, strings_found, num_peers); 761 peer->search_str, peer->id, strings_found, num_peers);
759 peer->search_str_matched = GNUNET_SYSERR; 762 peer->search_str_matched = GNUNET_SYSERR;
760 } 763 }
761 else 764 else
765 {
766 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
767
768 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
769 "String %s found on peer %u after %s (%i/%i) (%u||)\n",
770 peer->search_str, peer->id,
771 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
772 strings_found, num_peers, parallel_searches);
773
774 peer->search_str_matched = GNUNET_YES;
775
776 if (NULL != data_file)
762 { 777 {
763 prof_time = GNUNET_TIME_absolute_get_duration(peer->prof_start_time); 778 size =
764 779 GNUNET_snprintf (output_buffer,
765 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 780 sizeof(output_buffer),
766 "String %s found on peer %u after %s (%i/%i) (%u||)\n", 781 "%p Peer: %u\n"
767 peer->search_str, peer->id, 782 "%p Search string: %s\n"
768 GNUNET_STRINGS_relative_time_to_string(prof_time, GNUNET_NO), 783 "%p Search duration: %s\n\n",
769 strings_found, num_peers, parallel_searches); 784 peer, peer->id,
770 785 peer, peer->search_str,
771 peer->search_str_matched = GNUNET_YES; 786 peer,
772 787 GNUNET_STRINGS_relative_time_to_string (prof_time,
773 if (NULL != data_file) 788 GNUNET_NO));
774 { 789
775 size = 790 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
776 GNUNET_snprintf(output_buffer, 791 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
777 sizeof(output_buffer),
778 "%p Peer: %u\n"
779 "%p Search string: %s\n"
780 "%p Search duration: %s\n\n",
781 peer, peer->id,
782 peer, peer->search_str,
783 peer,
784 GNUNET_STRINGS_relative_time_to_string(prof_time,
785 GNUNET_NO));
786
787 if (size != GNUNET_DISK_file_write(data_file, output_buffer, size))
788 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
789 }
790 } 792 }
793 }
791 794
792 GNUNET_TESTBED_operation_done(peer->op_handle); 795 GNUNET_TESTBED_operation_done (peer->op_handle);
793 peer->op_handle = NULL; 796 peer->op_handle = NULL;
794 797
795 if (strings_found == num_peers) 798 if (strings_found == num_peers)
796 { 799 {
797 prof_time = GNUNET_TIME_absolute_get_duration(prof_start_time); 800 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
798 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 801 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
799 "All strings successfully matched in %s\n", 802 "All strings successfully matched in %s\n",
800 GNUNET_STRINGS_relative_time_to_string(prof_time, GNUNET_NO)); 803 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
801
802 if (NULL != search_timeout_task)
803 {
804 GNUNET_SCHEDULER_cancel(search_timeout_task);
805 search_timeout_task = NULL;
806 }
807 804
808 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Collecting stats.\n"); 805 if (NULL != search_timeout_task)
809 GNUNET_SCHEDULER_add_now(&do_collect_stats, NULL); 806 {
807 GNUNET_SCHEDULER_cancel (search_timeout_task);
808 search_timeout_task = NULL;
810 } 809 }
810
811 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Collecting stats.\n");
812 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
813 }
811} 814}
812 815
813 816
@@ -818,33 +821,33 @@ regex_found_handler(void *cls,
818 * @param cls NULL 821 * @param cls NULL
819 */ 822 */
820static void 823static void
821search_timed_out(void *cls) 824search_timed_out (void *cls)
822{ 825{
823 unsigned int i; 826 unsigned int i;
824 827
825 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 828 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
826 "Finding matches to all strings did not succeed after %s.\n", 829 "Finding matches to all strings did not succeed after %s.\n",
827 GNUNET_STRINGS_relative_time_to_string(search_timeout_time, 830 GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
828 GNUNET_NO)); 831 GNUNET_NO));
829 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 832 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
830 "Found %i of %i strings\n", strings_found, num_peers); 833 "Found %i of %i strings\n", strings_found, num_peers);
831 834
832 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 835 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
833 "Search timed out after %s." 836 "Search timed out after %s."
834 "Collecting stats and shutting down.\n", 837 "Collecting stats and shutting down.\n",
835 GNUNET_STRINGS_relative_time_to_string(search_timeout_time, 838 GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
836 GNUNET_NO)); 839 GNUNET_NO));
837 840
838 in_shutdown = GNUNET_YES; 841 in_shutdown = GNUNET_YES;
839 for (i = 0; i < num_peers; i++) 842 for (i = 0; i < num_peers; i++)
843 {
844 if (NULL != peers[i].op_handle)
840 { 845 {
841 if (NULL != peers[i].op_handle) 846 GNUNET_TESTBED_operation_done (peers[i].op_handle);
842 { 847 peers[i].op_handle = NULL;
843 GNUNET_TESTBED_operation_done(peers[i].op_handle);
844 peers[i].op_handle = NULL;
845 }
846 } 848 }
847 GNUNET_SCHEDULER_add_now(&do_collect_stats, NULL); 849 }
850 GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
848} 851}
849 852
850 853
@@ -855,17 +858,17 @@ search_timed_out(void *cls)
855 * @param cls Index of the next peer in the peers array. 858 * @param cls Index of the next peer in the peers array.
856 */ 859 */
857static void 860static void
858find_timed_out(void *cls) 861find_timed_out (void *cls)
859{ 862{
860 struct RegexPeer *p = cls; 863 struct RegexPeer *p = cls;
861 864
862 p->timeout = NULL; 865 p->timeout = NULL;
863 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 866 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
864 "Searching for string \"%s\" on peer %d timed out.\n", 867 "Searching for string \"%s\" on peer %d timed out.\n",
865 p->search_str, 868 p->search_str,
866 p->id); 869 p->id);
867 if (GNUNET_NO == in_shutdown) 870 if (GNUNET_NO == in_shutdown)
868 GNUNET_SCHEDULER_add_now(&announce_next_regex, NULL); 871 GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
869} 872}
870 873
871 874
@@ -875,34 +878,34 @@ find_timed_out(void *cls)
875 * @param cls Index of the next peer in the peers array. 878 * @param cls Index of the next peer in the peers array.
876 */ 879 */
877static void 880static void
878find_string(void *cls) 881find_string (void *cls)
879{ 882{
880 unsigned int search_peer = (unsigned int)(long)cls; 883 unsigned int search_peer = (unsigned int) (long) cls;
881 884
882 if ((search_peer >= num_peers) || 885 if ((search_peer >= num_peers) ||
883 (GNUNET_YES == in_shutdown)) 886 (GNUNET_YES == in_shutdown))
884 return; 887 return;
885 888
886 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 889 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
887 "Searching for string \"%s\" on peer %d (%u||)\n", 890 "Searching for string \"%s\" on peer %d (%u||)\n",
888 peers[search_peer].search_str, 891 peers[search_peer].search_str,
889 search_peer, 892 search_peer,
890 parallel_searches); 893 parallel_searches);
891 894
892 peers[search_peer].op_handle = 895 peers[search_peer].op_handle =
893 GNUNET_TESTBED_service_connect(NULL, 896 GNUNET_TESTBED_service_connect (NULL,
894 peers[search_peer].peer_handle, 897 peers[search_peer].peer_handle,
895 "dht", 898 "dht",
896 &dht_connect_cb, 899 &dht_connect_cb,
897 &peers[search_peer], 900 &peers[search_peer],
898 &dht_ca, 901 &dht_ca,
899 &dht_da, 902 &dht_da,
900 &peers[search_peer]); 903 &peers[search_peer]);
901 GNUNET_assert(NULL != peers[search_peer].op_handle); 904 GNUNET_assert (NULL != peers[search_peer].op_handle);
902 peers[search_peer].timeout 905 peers[search_peer].timeout
903 = GNUNET_SCHEDULER_add_delayed(FIND_TIMEOUT, 906 = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
904 &find_timed_out, 907 &find_timed_out,
905 &peers[search_peer]); 908 &peers[search_peer]);
906} 909}
907 910
908 911
@@ -914,44 +917,44 @@ find_string(void *cls)
914 * @param emsg NULL on success; otherwise an error description 917 * @param emsg NULL on success; otherwise an error description
915 */ 918 */
916static void 919static void
917daemon_started(void *cls, 920daemon_started (void *cls,
918 struct GNUNET_TESTBED_Operation *op, 921 struct GNUNET_TESTBED_Operation *op,
919 const char *emsg) 922 const char *emsg)
920{ 923{
921 struct RegexPeer *peer = (struct RegexPeer *)cls; 924 struct RegexPeer *peer = (struct RegexPeer *) cls;
922 unsigned long search_peer; 925 unsigned long search_peer;
923 unsigned int i; 926 unsigned int i;
924 927
925 GNUNET_TESTBED_operation_done(peer->daemon_op); 928 GNUNET_TESTBED_operation_done (peer->daemon_op);
926 peer->daemon_op = NULL; 929 peer->daemon_op = NULL;
927 if (NULL != emsg) 930 if (NULL != emsg)
928 { 931 {
929 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 932 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
930 "Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg); 933 "Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg);
931 GNUNET_assert(0); 934 GNUNET_assert (0);
932 } 935 }
933 else 936 else
934 { 937 {
935 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 938 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
936 "Deamon %u started successfully\n", peer->id); 939 "Deamon %u started successfully\n", peer->id);
937 } 940 }
938 941
939 /* Find a peer to look for a string matching the regex announced */ 942 /* Find a peer to look for a string matching the regex announced */
940 search_peer = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 943 search_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
941 num_peers); 944 num_peers);
942 for (i = 0; peers[search_peer].search_str != NULL; i++) 945 for (i = 0; peers[search_peer].search_str != NULL; i++)
943 { 946 {
944 search_peer = (search_peer + 1) % num_peers; 947 search_peer = (search_peer + 1) % num_peers;
945 if (i > num_peers) 948 if (i > num_peers)
946 GNUNET_assert(0); /* we ran out of peers, must be a bug */ 949 GNUNET_assert (0); /* we ran out of peers, must be a bug */
947 } 950 }
948 peers[search_peer].search_str = search_strings[peer->id]; 951 peers[search_peer].search_str = search_strings[peer->id];
949 peers[search_peer].search_str_matched = GNUNET_NO; 952 peers[search_peer].search_str_matched = GNUNET_NO;
950 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_saturating_multiply( 953 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_saturating_multiply (
951 reannounce_period_max, 954 reannounce_period_max,
952 2), 955 2),
953 &find_string, 956 &find_string,
954 (void *)search_peer); 957 (void *) search_peer);
955} 958}
956 959
957 960
@@ -963,21 +966,21 @@ daemon_started(void *cls,
963 * @param tc the task context 966 * @param tc the task context
964 */ 967 */
965static void 968static void
966do_announce(void *cls) 969do_announce (void *cls)
967{ 970{
968 unsigned int i; 971 unsigned int i;
969 972
970 if (GNUNET_YES == in_shutdown) 973 if (GNUNET_YES == in_shutdown)
971 return; 974 return;
972 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 975 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
973 "Starting announce.\n"); 976 "Starting announce.\n");
974 for (i = 0; i < init_parallel_searches; i++) 977 for (i = 0; i < init_parallel_searches; i++)
975 { 978 {
976 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 979 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
977 " scheduling announce %u\n", 980 " scheduling announce %u\n",
978 i); 981 i);
979 (void)GNUNET_SCHEDULER_add_now(&announce_next_regex, NULL); 982 (void) GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
980 } 983 }
981} 984}
982 985
983 986
@@ -987,36 +990,36 @@ do_announce(void *cls)
987 * @param cls Closure (unused). 990 * @param cls Closure (unused).
988 */ 991 */
989static void 992static void
990announce_next_regex(void *cls) 993announce_next_regex (void *cls)
991{ 994{
992 struct RegexPeer *peer; 995 struct RegexPeer *peer;
993 996
994 if (GNUNET_YES == in_shutdown) 997 if (GNUNET_YES == in_shutdown)
995 return; 998 return;
996 if (next_search >= num_peers) 999 if (next_search >= num_peers)
1000 {
1001 if (strings_found != num_peers)
997 { 1002 {
998 if (strings_found != num_peers) 1003 struct GNUNET_TIME_Relative new_delay;
999 { 1004 if (NULL != search_timeout_task)
1000 struct GNUNET_TIME_Relative new_delay; 1005 GNUNET_SCHEDULER_cancel (search_timeout_task);
1001 if (NULL != search_timeout_task) 1006 new_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15);
1002 GNUNET_SCHEDULER_cancel(search_timeout_task); 1007 search_timeout_task = GNUNET_SCHEDULER_add_delayed (new_delay,
1003 new_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15); 1008 &search_timed_out,
1004 search_timeout_task = GNUNET_SCHEDULER_add_delayed(new_delay, 1009 NULL);
1005 &search_timed_out,
1006 NULL);
1007 }
1008 return;
1009 } 1010 }
1011 return;
1012 }
1010 1013
1011 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search); 1014 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", next_search);
1012 peer = &peers[next_search]; 1015 peer = &peers[next_search];
1013 peer->daemon_op = 1016 peer->daemon_op =
1014 GNUNET_TESTBED_peer_manage_service(NULL, 1017 GNUNET_TESTBED_peer_manage_service (NULL,
1015 peer->peer_handle, 1018 peer->peer_handle,
1016 "regexprofiler", 1019 "regexprofiler",
1017 &daemon_started, 1020 &daemon_started,
1018 peer, 1021 peer,
1019 1); 1022 1);
1020 next_search++; 1023 next_search++;
1021 parallel_searches++; 1024 parallel_searches++;
1022} 1025}
@@ -1033,29 +1036,29 @@ announce_next_regex(void *cls)
1033 * @param emsg error message. 1036 * @param emsg error message.
1034 */ 1037 */
1035static void 1038static void
1036dht_connect_cb(void *cls, 1039dht_connect_cb (void *cls,
1037 struct GNUNET_TESTBED_Operation *op, 1040 struct GNUNET_TESTBED_Operation *op,
1038 void *ca_result, 1041 void *ca_result,
1039 const char *emsg) 1042 const char *emsg)
1040{ 1043{
1041 struct RegexPeer *peer = (struct RegexPeer *)cls; 1044 struct RegexPeer *peer = (struct RegexPeer *) cls;
1042 1045
1043 if (NULL != emsg || NULL == op || NULL == ca_result) 1046 if ((NULL != emsg)||(NULL == op)||(NULL == ca_result))
1044 { 1047 {
1045 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg); 1048 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg);
1046 GNUNET_assert(0); 1049 GNUNET_assert (0);
1047 } 1050 }
1048 1051
1049 GNUNET_assert(NULL != peer->dht_handle); 1052 GNUNET_assert (NULL != peer->dht_handle);
1050 GNUNET_assert(peer->op_handle == op); 1053 GNUNET_assert (peer->op_handle == op);
1051 GNUNET_assert(peer->dht_handle == ca_result); 1054 GNUNET_assert (peer->dht_handle == ca_result);
1052 1055
1053 peer->search_str_matched = GNUNET_NO; 1056 peer->search_str_matched = GNUNET_NO;
1054 peer->search_handle = REGEX_INTERNAL_search(peer->dht_handle, 1057 peer->search_handle = REGEX_INTERNAL_search (peer->dht_handle,
1055 peer->search_str, 1058 peer->search_str,
1056 &regex_found_handler, peer, 1059 &regex_found_handler, peer,
1057 NULL); 1060 NULL);
1058 peer->prof_start_time = GNUNET_TIME_absolute_get(); 1061 peer->prof_start_time = GNUNET_TIME_absolute_get ();
1059} 1062}
1060 1063
1061 1064
@@ -1068,11 +1071,11 @@ dht_connect_cb(void *cls,
1068 * @return 1071 * @return
1069 */ 1072 */
1070static void * 1073static void *
1071dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 1074dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
1072{ 1075{
1073 struct RegexPeer *peer = cls; 1076 struct RegexPeer *peer = cls;
1074 1077
1075 peer->dht_handle = GNUNET_DHT_connect(cfg, 32); 1078 peer->dht_handle = GNUNET_DHT_connect (cfg, 32);
1076 1079
1077 return peer->dht_handle; 1080 return peer->dht_handle;
1078} 1081}
@@ -1085,23 +1088,23 @@ dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
1085 * @param op_result Service handle returned from the connect adapter. 1088 * @param op_result Service handle returned from the connect adapter.
1086 */ 1089 */
1087static void 1090static void
1088dht_da(void *cls, void *op_result) 1091dht_da (void *cls, void *op_result)
1089{ 1092{
1090 struct RegexPeer *peer = (struct RegexPeer *)cls; 1093 struct RegexPeer *peer = (struct RegexPeer *) cls;
1091 1094
1092 GNUNET_assert(peer->dht_handle == op_result); 1095 GNUNET_assert (peer->dht_handle == op_result);
1093 1096
1094 if (NULL != peer->search_handle) 1097 if (NULL != peer->search_handle)
1095 { 1098 {
1096 REGEX_INTERNAL_search_cancel(peer->search_handle); 1099 REGEX_INTERNAL_search_cancel (peer->search_handle);
1097 peer->search_handle = NULL; 1100 peer->search_handle = NULL;
1098 } 1101 }
1099 1102
1100 if (NULL != peer->dht_handle) 1103 if (NULL != peer->dht_handle)
1101 { 1104 {
1102 GNUNET_DHT_disconnect(peer->dht_handle); 1105 GNUNET_DHT_disconnect (peer->dht_handle);
1103 peer->dht_handle = NULL; 1106 peer->dht_handle = NULL;
1104 } 1107 }
1105} 1108}
1106 1109
1107 1110
@@ -1119,51 +1122,52 @@ dht_da(void *cls, void *op_result)
1119 * failed 1122 * failed
1120 */ 1123 */
1121static void 1124static void
1122test_master(void *cls, 1125test_master (void *cls,
1123 struct GNUNET_TESTBED_RunHandle *h, 1126 struct GNUNET_TESTBED_RunHandle *h,
1124 unsigned int num_peers_, 1127 unsigned int num_peers_,
1125 struct GNUNET_TESTBED_Peer **testbed_peers, 1128 struct GNUNET_TESTBED_Peer **testbed_peers,
1126 unsigned int links_succeeded, 1129 unsigned int links_succeeded,
1127 unsigned int links_failed) 1130 unsigned int links_failed)
1128{ 1131{
1129 unsigned int i; 1132 unsigned int i;
1130 1133
1131 GNUNET_assert(num_peers_ == num_peers); 1134 GNUNET_assert (num_peers_ == num_peers);
1132 1135
1133 prof_time = GNUNET_TIME_absolute_get_duration(prof_start_time); 1136 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
1134 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1137 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1135 "Testbed started in %s\n", 1138 "Testbed started in %s\n",
1136 GNUNET_STRINGS_relative_time_to_string(prof_time, GNUNET_NO)); 1139 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
1137 1140
1138 if (NULL != abort_task) 1141 if (NULL != abort_task)
1139 { 1142 {
1140 GNUNET_SCHEDULER_cancel(abort_task); 1143 GNUNET_SCHEDULER_cancel (abort_task);
1141 abort_task = NULL; 1144 abort_task = NULL;
1142 } 1145 }
1143 1146
1144 for (i = 0; i < num_peers; i++) 1147 for (i = 0; i < num_peers; i++)
1145 { 1148 {
1146 peers[i].peer_handle = testbed_peers[i]; 1149 peers[i].peer_handle = testbed_peers[i];
1147 } 1150 }
1148 if (GNUNET_NO == 1151 if (GNUNET_NO ==
1149 GNUNET_CONFIGURATION_get_value_yesno(cfg, "DHT", "DISABLE_TRY_CONNECT")) 1152 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", "DISABLE_TRY_CONNECT"))
1150 { 1153 {
1151 struct GNUNET_TIME_Relative settle_time; 1154 struct GNUNET_TIME_Relative settle_time;
1152 1155
1153 settle_time = 1156 settle_time =
1154 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1157 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1155 10 * num_peers); 1158 10 * num_peers);
1156 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1159 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1157 "Waiting for DHT for %s to settle new connections.\n\n", 1160 "Waiting for DHT for %s to settle new connections.\n\n",
1158 GNUNET_STRINGS_relative_time_to_string(settle_time, GNUNET_NO)); 1161 GNUNET_STRINGS_relative_time_to_string (settle_time,
1159 GNUNET_SCHEDULER_add_delayed(settle_time, &do_announce, NULL); 1162 GNUNET_NO));
1160 } 1163 GNUNET_SCHEDULER_add_delayed (settle_time, &do_announce, NULL);
1164 }
1161 else 1165 else
1162 { 1166 {
1163 GNUNET_SCHEDULER_add_now(&do_announce, NULL); 1167 GNUNET_SCHEDULER_add_now (&do_announce, NULL);
1164 } 1168 }
1165 search_timeout_task = 1169 search_timeout_task =
1166 GNUNET_SCHEDULER_add_delayed(search_timeout_time, &search_timed_out, NULL); 1170 GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timed_out, NULL);
1167} 1171}
1168 1172
1169/** 1173/**
@@ -1173,23 +1177,23 @@ test_master(void *cls,
1173 * @param event information on what is happening 1177 * @param event information on what is happening
1174 */ 1178 */
1175static void 1179static void
1176master_controller_cb(void *cls, 1180master_controller_cb (void *cls,
1177 const struct GNUNET_TESTBED_EventInformation *event) 1181 const struct GNUNET_TESTBED_EventInformation *event)
1178{ 1182{
1179 switch (event->type) 1183 switch (event->type)
1180 { 1184 {
1181 case GNUNET_TESTBED_ET_CONNECT: 1185 case GNUNET_TESTBED_ET_CONNECT:
1182 printf("."); 1186 printf (".");
1183 break; 1187 break;
1184 1188
1185 case GNUNET_TESTBED_ET_PEER_START: 1189 case GNUNET_TESTBED_ET_PEER_START:
1186 printf("#"); 1190 printf ("#");
1187 break; 1191 break;
1188 1192
1189 default: 1193 default:
1190 break; 1194 break;
1191 } 1195 }
1192 fflush(stdout); 1196 fflush (stdout);
1193} 1197}
1194 1198
1195 1199
@@ -1208,9 +1212,9 @@ master_controller_cb(void *cls,
1208 * #GNUNET_SYSERR otherwise. 1212 * #GNUNET_SYSERR otherwise.
1209 */ 1213 */
1210static int 1214static int
1211count_and_separate_strings(char *data, 1215count_and_separate_strings (char *data,
1212 uint64_t data_size, 1216 uint64_t data_size,
1213 unsigned int str_max) 1217 unsigned int str_max)
1214{ 1218{
1215 char *buf; // Keep track of last string to skip blank lines 1219 char *buf; // Keep track of last string to skip blank lines
1216 unsigned int offset; 1220 unsigned int offset;
@@ -1220,19 +1224,19 @@ count_and_separate_strings(char *data,
1220 offset = 0; 1224 offset = 0;
1221 str_cnt = 0; 1225 str_cnt = 0;
1222 while ((offset < (data_size - 1)) && (str_cnt < str_max)) 1226 while ((offset < (data_size - 1)) && (str_cnt < str_max))
1227 {
1228 offset++;
1229 if (((data[offset] == '\n')) &&
1230 (buf != &data[offset]))
1223 { 1231 {
1224 offset++; 1232 data[offset] = '\0';
1225 if (((data[offset] == '\n')) && 1233 str_cnt++;
1226 (buf != &data[offset])) 1234 buf = &data[offset + 1];
1227 {
1228 data[offset] = '\0';
1229 str_cnt++;
1230 buf = &data[offset + 1];
1231 }
1232 else if ((data[offset] == '\n') ||
1233 (data[offset] == '\0'))
1234 buf = &data[offset + 1];
1235 } 1235 }
1236 else if ((data[offset] == '\n') ||
1237 (data[offset] == '\0'))
1238 buf = &data[offset + 1];
1239 }
1236 return str_cnt; 1240 return str_cnt;
1237} 1241}
1238 1242
@@ -1251,37 +1255,37 @@ count_and_separate_strings(char *data,
1251 * In case of error @a strings must not be freed. 1255 * In case of error @a strings must not be freed.
1252 */ 1256 */
1253static int 1257static int
1254create_string_array(char *data, uint64_t data_size, 1258create_string_array (char *data, uint64_t data_size,
1255 char ***strings, unsigned int str_cnt) 1259 char ***strings, unsigned int str_cnt)
1256{ 1260{
1257 uint64_t offset; 1261 uint64_t offset;
1258 uint64_t len; 1262 uint64_t len;
1259 unsigned int i; 1263 unsigned int i;
1260 1264
1261 *strings = GNUNET_malloc(sizeof(char *) * str_cnt); 1265 *strings = GNUNET_malloc (sizeof(char *) * str_cnt);
1262 offset = 0; 1266 offset = 0;
1263 for (i = 0; i < str_cnt; i++) 1267 for (i = 0; i < str_cnt; i++)
1268 {
1269 len = strlen (&data[offset]);
1270 if (offset + len >= data_size)
1271 {
1272 GNUNET_free (*strings);
1273 *strings = NULL;
1274 return GNUNET_SYSERR;
1275 }
1276 if (0 == len) // empty line
1264 { 1277 {
1265 len = strlen(&data[offset]); 1278 offset++;
1266 if (offset + len >= data_size) 1279 i--;
1267 { 1280 continue;
1268 GNUNET_free(*strings);
1269 *strings = NULL;
1270 return GNUNET_SYSERR;
1271 }
1272 if (0 == len) // empty line
1273 {
1274 offset++;
1275 i--;
1276 continue;
1277 }
1278
1279 GNUNET_asprintf(&(*strings)[i],
1280 "%s%s",
1281 regex_prefix,
1282 &data[offset]);
1283 offset += len + 1;
1284 } 1281 }
1282
1283 GNUNET_asprintf (&(*strings)[i],
1284 "%s%s",
1285 regex_prefix,
1286 &data[offset]);
1287 offset += len + 1;
1288 }
1285 return GNUNET_OK; 1289 return GNUNET_OK;
1286} 1290}
1287 1291
@@ -1296,9 +1300,9 @@ create_string_array(char *data, uint64_t data_size,
1296 * @return number of strings found in the file. #GNUNET_SYSERR on error. 1300 * @return number of strings found in the file. #GNUNET_SYSERR on error.
1297 */ 1301 */
1298static int 1302static int
1299load_search_strings(const char *filename, 1303load_search_strings (const char *filename,
1300 char ***strings, 1304 char ***strings,
1301 unsigned int limit) 1305 unsigned int limit)
1302{ 1306{
1303 char *data; 1307 char *data;
1304 uint64_t filesize; 1308 uint64_t filesize;
@@ -1306,54 +1310,54 @@ load_search_strings(const char *filename,
1306 1310
1307 /* Sanity checks */ 1311 /* Sanity checks */
1308 if (NULL == filename) 1312 if (NULL == filename)
1309 { 1313 {
1310 return GNUNET_SYSERR; 1314 return GNUNET_SYSERR;
1311 } 1315 }
1312 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 1316 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1313 { 1317 {
1314 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1318 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1315 "Could not find search strings file %s\n", filename); 1319 "Could not find search strings file %s\n", filename);
1316 return GNUNET_SYSERR; 1320 return GNUNET_SYSERR;
1317 } 1321 }
1318 if (GNUNET_OK != 1322 if (GNUNET_OK !=
1319 GNUNET_DISK_file_size(filename, 1323 GNUNET_DISK_file_size (filename,
1320 &filesize, 1324 &filesize,
1321 GNUNET_YES, 1325 GNUNET_YES,
1322 GNUNET_YES)) 1326 GNUNET_YES))
1323 { 1327 {
1324 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1325 "Search strings file %s cannot be read.\n", 1329 "Search strings file %s cannot be read.\n",
1326 filename); 1330 filename);
1327 return GNUNET_SYSERR; 1331 return GNUNET_SYSERR;
1328 } 1332 }
1329 if (0 == filesize) 1333 if (0 == filesize)
1330 { 1334 {
1331 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1335 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1332 "Search strings file %s is empty.\n", 1336 "Search strings file %s is empty.\n",
1333 filename); 1337 filename);
1334 return GNUNET_SYSERR; 1338 return GNUNET_SYSERR;
1335 } 1339 }
1336 1340
1337 /* Read data into memory */ 1341 /* Read data into memory */
1338 data = GNUNET_malloc(filesize + 1); 1342 data = GNUNET_malloc (filesize + 1);
1339 if (filesize != GNUNET_DISK_fn_read(filename, 1343 if (filesize != GNUNET_DISK_fn_read (filename,
1340 data, 1344 data,
1341 filesize)) 1345 filesize))
1342 { 1346 {
1343 GNUNET_free(data); 1347 GNUNET_free (data);
1344 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1348 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1345 "Could not read search strings file %s.\n", 1349 "Could not read search strings file %s.\n",
1346 filename); 1350 filename);
1347 return GNUNET_SYSERR; 1351 return GNUNET_SYSERR;
1348 } 1352 }
1349 1353
1350 /* Process buffer and build array */ 1354 /* Process buffer and build array */
1351 str_cnt = count_and_separate_strings(data, filesize, limit); 1355 str_cnt = count_and_separate_strings (data, filesize, limit);
1352 if (GNUNET_OK != create_string_array(data, filesize, strings, str_cnt)) 1356 if (GNUNET_OK != create_string_array (data, filesize, strings, str_cnt))
1353 { 1357 {
1354 str_cnt = GNUNET_SYSERR; 1358 str_cnt = GNUNET_SYSERR;
1355 } 1359 }
1356 GNUNET_free(data); 1360 GNUNET_free (data);
1357 return str_cnt; 1361 return str_cnt;
1358} 1362}
1359 1363
@@ -1367,10 +1371,10 @@ load_search_strings(const char *filename,
1367 * @param config configuration 1371 * @param config configuration
1368 */ 1372 */
1369static void 1373static void
1370run(void *cls, 1374run (void *cls,
1371 char *const *args, 1375 char *const *args,
1372 const char *cfgfile, 1376 const char *cfgfile,
1373 const struct GNUNET_CONFIGURATION_Handle *config) 1377 const struct GNUNET_CONFIGURATION_Handle *config)
1374{ 1378{
1375 unsigned int nsearchstrs; 1379 unsigned int nsearchstrs;
1376 unsigned int i; 1380 unsigned int i;
@@ -1380,161 +1384,163 @@ run(void *cls,
1380 1384
1381 /* Check config */ 1385 /* Check config */
1382 if (NULL == config) 1386 if (NULL == config)
1383 { 1387 {
1384 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1388 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1385 _("No configuration file given. Exiting\n")); 1389 _ ("No configuration file given. Exiting\n"));
1386 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 1390 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1387 return; 1391 return;
1388 } 1392 }
1389 cfg = GNUNET_CONFIGURATION_dup(config); 1393 cfg = GNUNET_CONFIGURATION_dup (config);
1390 if (GNUNET_OK != 1394 if (GNUNET_OK !=
1391 GNUNET_CONFIGURATION_get_value_string(cfg, "REGEXPROFILER", 1395 GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER",
1392 "REGEX_PREFIX", 1396 "REGEX_PREFIX",
1393 &regex_prefix)) 1397 &regex_prefix))
1394 { 1398 {
1395 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 1399 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1396 "regexprofiler", 1400 "regexprofiler",
1397 "regex_prefix"); 1401 "regex_prefix");
1398 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 1402 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1399 return; 1403 return;
1400 } 1404 }
1401 if (GNUNET_OK != 1405 if (GNUNET_OK !=
1402 GNUNET_CONFIGURATION_get_value_number(cfg, "REGEXPROFILER", 1406 GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER",
1403 "PARALLEL_SEARCHES", 1407 "PARALLEL_SEARCHES",
1404 &init_parallel_searches)) 1408 &init_parallel_searches))
1405 { 1409 {
1406 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1410 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1407 "Configuration option \"PARALLEL_SEARCHES\" missing." 1411 "Configuration option \"PARALLEL_SEARCHES\" missing."
1408 " Using default (%d)\n", 10); 1412 " Using default (%d)\n", 10);
1409 init_parallel_searches = 10; 1413 init_parallel_searches = 10;
1410 } 1414 }
1411 if (GNUNET_OK != 1415 if (GNUNET_OK !=
1412 GNUNET_CONFIGURATION_get_value_time(cfg, "REGEXPROFILER", 1416 GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER",
1413 "REANNOUNCE_PERIOD_MAX", 1417 "REANNOUNCE_PERIOD_MAX",
1414 &reannounce_period_max)) 1418 &reannounce_period_max))
1415 { 1419 {
1416 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1420 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1417 "reannounce_period_max not given. Using 10 minutes.\n"); 1421 "reannounce_period_max not given. Using 10 minutes.\n");
1418 reannounce_period_max = 1422 reannounce_period_max =
1419 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10); 1423 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10);
1420 } 1424 }
1421 1425
1422 /* Check arguments */ 1426 /* Check arguments */
1423 if (NULL == policy_dir) 1427 if (NULL == policy_dir)
1424 { 1428 {
1425 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1426 _("No policy directory specified on command line. Exiting.\n")); 1430 _ (
1427 return; 1431 "No policy directory specified on command line. Exiting.\n"));
1428 } 1432 return;
1429 if (GNUNET_YES != GNUNET_DISK_directory_test(policy_dir, GNUNET_YES)) 1433 }
1430 { 1434 if (GNUNET_YES != GNUNET_DISK_directory_test (policy_dir, GNUNET_YES))
1431 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1435 {
1432 _("Specified policies directory does not exist. Exiting.\n")); 1436 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1433 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 1437 _ ("Specified policies directory does not exist. Exiting.\n"));
1434 return; 1438 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1435 } 1439 return;
1436 if (0 >= (int)(num_peers = GNUNET_DISK_directory_scan(policy_dir, NULL, NULL))) 1440 }
1437 { 1441 if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL,
1438 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1442 NULL)))
1439 _("No files found in `%s'\n"), 1443 {
1440 policy_dir); 1444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1441 return; 1445 _ ("No files found in `%s'\n"),
1442 } 1446 policy_dir);
1443 GNUNET_CONFIGURATION_set_value_string(cfg, "REGEXPROFILER", 1447 return;
1444 "POLICY_DIR", policy_dir); 1448 }
1445 if (GNUNET_YES != GNUNET_DISK_file_test(strings_file)) 1449 GNUNET_CONFIGURATION_set_value_string (cfg, "REGEXPROFILER",
1446 { 1450 "POLICY_DIR", policy_dir);
1447 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1451 if (GNUNET_YES != GNUNET_DISK_file_test (strings_file))
1448 _("No search strings file given. Exiting.\n")); 1452 {
1449 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 1453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1450 return; 1454 _ ("No search strings file given. Exiting.\n"));
1451 } 1455 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1452 nsearchstrs = load_search_strings(strings_file, 1456 return;
1453 &search_strings, 1457 }
1454 num_peers); 1458 nsearchstrs = load_search_strings (strings_file,
1459 &search_strings,
1460 num_peers);
1455 if (num_peers != nsearchstrs) 1461 if (num_peers != nsearchstrs)
1456 { 1462 {
1457 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1463 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1458 "Error loading search strings.\n"); 1464 "Error loading search strings.\n");
1459 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1465 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1460 "File (%s) does not contain enough strings (%u/%u).\n", 1466 "File (%s) does not contain enough strings (%u/%u).\n",
1461 strings_file, nsearchstrs, num_peers); 1467 strings_file, nsearchstrs, num_peers);
1462 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 1468 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1463 return; 1469 return;
1464 } 1470 }
1465 if ((0 == num_peers) || (NULL == search_strings)) 1471 if ((0 == num_peers) || (NULL == search_strings))
1466 { 1472 {
1467 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1473 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1468 _("Error loading search strings. Exiting.\n")); 1474 _ ("Error loading search strings. Exiting.\n"));
1469 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 1475 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1470 return; 1476 return;
1471 } 1477 }
1472 for (i = 0; i < num_peers; i++) 1478 for (i = 0; i < num_peers; i++)
1473 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1474 "search string: %s\n", 1480 "search string: %s\n",
1475 search_strings[i]); 1481 search_strings[i]);
1476 1482
1477 /* Check logfile */ 1483 /* Check logfile */
1478 if ((NULL != data_filename) && 1484 if ((NULL != data_filename) &&
1479 (NULL == (data_file = 1485 (NULL == (data_file =
1480 GNUNET_DISK_file_open(data_filename, 1486 GNUNET_DISK_file_open (data_filename,
1481 GNUNET_DISK_OPEN_READWRITE | 1487 GNUNET_DISK_OPEN_READWRITE
1482 GNUNET_DISK_OPEN_TRUNCATE | 1488 | GNUNET_DISK_OPEN_TRUNCATE
1483 GNUNET_DISK_OPEN_CREATE, 1489 | GNUNET_DISK_OPEN_CREATE,
1484 GNUNET_DISK_PERM_USER_READ | 1490 GNUNET_DISK_PERM_USER_READ
1485 GNUNET_DISK_PERM_USER_WRITE)))) 1491 | GNUNET_DISK_PERM_USER_WRITE))))
1486 { 1492 {
1487 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, 1493 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1488 "open", 1494 "open",
1489 data_filename); 1495 data_filename);
1490 return; 1496 return;
1491 } 1497 }
1492 1498
1493 /* Initialize peers */ 1499 /* Initialize peers */
1494 peers = GNUNET_malloc(sizeof(struct RegexPeer) * num_peers); 1500 peers = GNUNET_malloc (sizeof(struct RegexPeer) * num_peers);
1495 for (i = 0; i < num_peers; i++) 1501 for (i = 0; i < num_peers; i++)
1496 peers[i].id = i; 1502 peers[i].id = i;
1497 1503
1498 GNUNET_CONFIGURATION_set_value_number(cfg, 1504 GNUNET_CONFIGURATION_set_value_number (cfg,
1499 "TESTBED", "OVERLAY_RANDOM_LINKS", 1505 "TESTBED", "OVERLAY_RANDOM_LINKS",
1500 num_peers * 20); 1506 num_peers * 20);
1501 GNUNET_CONFIGURATION_set_value_number(cfg, 1507 GNUNET_CONFIGURATION_set_value_number (cfg,
1502 "DHT", "FORCE_NSE", 1508 "DHT", "FORCE_NSE",
1503 (long long unsigned) 1509 (long long unsigned)
1504 (log(num_peers) / log(2.0))); 1510 (log (num_peers) / log (2.0)));
1505 event_mask = 0LL; 1511 event_mask = 0LL;
1506/* For feedback about the start process activate these and pass master_cb */ 1512/* For feedback about the start process activate these and pass master_cb */
1507 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 1513 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
1508// event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); 1514// event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
1509 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 1515 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1510// event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); 1516// event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
1511 prof_start_time = GNUNET_TIME_absolute_get(); 1517 prof_start_time = GNUNET_TIME_absolute_get ();
1512 GNUNET_TESTBED_run(hosts_file, 1518 GNUNET_TESTBED_run (hosts_file,
1513 cfg, 1519 cfg,
1514 num_peers, 1520 num_peers,
1515 event_mask, 1521 event_mask,
1516 &master_controller_cb, 1522 &master_controller_cb,
1517 NULL, /* master_controller_cb cls */ 1523 NULL, /* master_controller_cb cls */
1518 &test_master, 1524 &test_master,
1519 NULL); /* test_master cls */ 1525 NULL); /* test_master cls */
1520 if (GNUNET_OK != 1526 if (GNUNET_OK !=
1521 GNUNET_CONFIGURATION_get_value_time(cfg, "TESTBED", 1527 GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
1522 "SETUP_TIMEOUT", 1528 "SETUP_TIMEOUT",
1523 &abort_time)) 1529 &abort_time))
1524 { 1530 {
1525 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1531 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1526 "SETUP_TIMEOUT not given. Using 15 minutes.\n"); 1532 "SETUP_TIMEOUT not given. Using 15 minutes.\n");
1527 abort_time = 1533 abort_time =
1528 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15); 1534 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15);
1529 } 1535 }
1530 abort_time = GNUNET_TIME_relative_add(abort_time, GNUNET_TIME_UNIT_MINUTES); 1536 abort_time = GNUNET_TIME_relative_add (abort_time, GNUNET_TIME_UNIT_MINUTES);
1531 abort_task = 1537 abort_task =
1532 GNUNET_SCHEDULER_add_delayed(abort_time, 1538 GNUNET_SCHEDULER_add_delayed (abort_time,
1533 &do_abort, 1539 &do_abort,
1534 (void*)__LINE__); 1540 (void*) __LINE__);
1535 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1541 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1536 "setup_timeout: %s\n", 1542 "setup_timeout: %s\n",
1537 GNUNET_STRINGS_relative_time_to_string(abort_time, GNUNET_YES)); 1543 GNUNET_STRINGS_relative_time_to_string (abort_time, GNUNET_YES));
1538} 1544}
1539 1545
1540 1546
@@ -1546,52 +1552,56 @@ run(void *cls,
1546 * @return 0 on success 1552 * @return 0 on success
1547 */ 1553 */
1548int 1554int
1549main(int argc, char *const *argv) 1555main (int argc, char *const *argv)
1550{ 1556{
1551 struct GNUNET_GETOPT_CommandLineOption options[] = { 1557 struct GNUNET_GETOPT_CommandLineOption options[] = {
1552 GNUNET_GETOPT_option_filename('o', 1558 GNUNET_GETOPT_option_filename ('o',
1553 "output-file", 1559 "output-file",
1554 "FILENAME", 1560 "FILENAME",
1555 gettext_noop("name of the file for writing statistics"), 1561 gettext_noop (
1556 &data_filename), 1562 "name of the file for writing statistics"),
1557 1563 &data_filename),
1558 GNUNET_GETOPT_option_relative_time('t', 1564
1559 "matching-timeout", 1565 GNUNET_GETOPT_option_relative_time ('t',
1560 "TIMEOUT", 1566 "matching-timeout",
1561 gettext_noop("wait TIMEOUT before ending the experiment"), 1567 "TIMEOUT",
1562 &search_timeout_time), 1568 gettext_noop (
1563 1569 "wait TIMEOUT before ending the experiment"),
1564 GNUNET_GETOPT_option_filename('p', 1570 &search_timeout_time),
1565 "policy-dir", 1571
1566 "DIRECTORY", 1572 GNUNET_GETOPT_option_filename ('p',
1567 gettext_noop("directory with policy files"), 1573 "policy-dir",
1568 &policy_dir), 1574 "DIRECTORY",
1569 1575 gettext_noop ("directory with policy files"),
1570 1576 &policy_dir),
1571 GNUNET_GETOPT_option_filename('s', 1577
1572 "strings-file", 1578
1573 "FILENAME", 1579 GNUNET_GETOPT_option_filename ('s',
1574 gettext_noop("name of file with input strings"), 1580 "strings-file",
1575 &strings_file), 1581 "FILENAME",
1576 1582 gettext_noop (
1577 GNUNET_GETOPT_option_filename('H', 1583 "name of file with input strings"),
1578 "hosts-file", 1584 &strings_file),
1579 "FILENAME", 1585
1580 gettext_noop("name of file with hosts' names"), 1586 GNUNET_GETOPT_option_filename ('H',
1581 &hosts_file), 1587 "hosts-file",
1588 "FILENAME",
1589 gettext_noop (
1590 "name of file with hosts' names"),
1591 &hosts_file),
1582 1592
1583 GNUNET_GETOPT_OPTION_END 1593 GNUNET_GETOPT_OPTION_END
1584 }; 1594 };
1585 int ret; 1595 int ret;
1586 1596
1587 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 1597 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1588 return 2; 1598 return 2;
1589 result = GNUNET_SYSERR; 1599 result = GNUNET_SYSERR;
1590 ret = 1600 ret =
1591 GNUNET_PROGRAM_run(argc, argv, 1601 GNUNET_PROGRAM_run (argc, argv,
1592 "gnunet-regex-profiler", 1602 "gnunet-regex-profiler",
1593 _("Profiler for regex"), 1603 _ ("Profiler for regex"),
1594 options, &run, NULL); 1604 options, &run, NULL);
1595 if (GNUNET_OK != ret) 1605 if (GNUNET_OK != ret)
1596 return ret; 1606 return ret;
1597 if (GNUNET_OK != result) 1607 if (GNUNET_OK != result)
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index aa297d2ea..6637bafed 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -52,7 +52,8 @@
52 * Simple struct to keep track of progress, and print a 52 * Simple struct to keep track of progress, and print a
53 * nice little percentage meter for long running tasks. 53 * nice little percentage meter for long running tasks.
54 */ 54 */
55struct ProgressMeter { 55struct ProgressMeter
56{
56 /** 57 /**
57 * Total number of elements. 58 * Total number of elements.
58 */ 59 */
@@ -167,11 +168,11 @@ static char *regex_prefix;
167 * @return the progress meter 168 * @return the progress meter
168 */ 169 */
169static struct ProgressMeter * 170static struct ProgressMeter *
170create_meter(unsigned int total, char *start_string, int print) 171create_meter (unsigned int total, char *start_string, int print)
171{ 172{
172 struct ProgressMeter *ret; 173 struct ProgressMeter *ret;
173 174
174 ret = GNUNET_new(struct ProgressMeter); 175 ret = GNUNET_new (struct ProgressMeter);
175 ret->print = print; 176 ret->print = print;
176 ret->total = total; 177 ret->total = total;
177 ret->modnum = total / 4; 178 ret->modnum = total / 4;
@@ -179,9 +180,9 @@ create_meter(unsigned int total, char *start_string, int print)
179 ret->modnum = 1; 180 ret->modnum = 1;
180 ret->dotnum = (total / 50) + 1; 181 ret->dotnum = (total / 50) + 1;
181 if (start_string != NULL) 182 if (start_string != NULL)
182 ret->startup_string = GNUNET_strdup(start_string); 183 ret->startup_string = GNUNET_strdup (start_string);
183 else 184 else
184 ret->startup_string = GNUNET_strdup(""); 185 ret->startup_string = GNUNET_strdup ("");
185 186
186 return ret; 187 return ret;
187} 188}
@@ -196,33 +197,33 @@ create_meter(unsigned int total, char *start_string, int print)
196 * GNUNET_NO if more items expected 197 * GNUNET_NO if more items expected
197 */ 198 */
198static int 199static int
199update_meter(struct ProgressMeter *meter) 200update_meter (struct ProgressMeter *meter)
200{ 201{
201 if (meter->print == GNUNET_YES) 202 if (meter->print == GNUNET_YES)
203 {
204 if (meter->completed % meter->modnum == 0)
202 { 205 {
203 if (meter->completed % meter->modnum == 0) 206 if (meter->completed == 0)
204 { 207 {
205 if (meter->completed == 0) 208 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
206 { 209 }
207 fprintf(stdout, "%sProgress: [0%%", meter->startup_string); 210 else
208 } 211 fprintf (stdout, "%d%%",
209 else 212 (int) (((float) meter->completed / meter->total) * 100));
210 fprintf(stdout, "%d%%",
211 (int)(((float)meter->completed / meter->total) * 100));
212 }
213 else if (meter->completed % meter->dotnum == 0)
214 fprintf(stdout, "%s", ".");
215
216 if (meter->completed + 1 == meter->total)
217 fprintf(stdout, "%d%%]\n", 100);
218 fflush(stdout);
219 } 213 }
214 else if (meter->completed % meter->dotnum == 0)
215 fprintf (stdout, "%s", ".");
216
217 if (meter->completed + 1 == meter->total)
218 fprintf (stdout, "%d%%]\n", 100);
219 fflush (stdout);
220 }
220 meter->completed++; 221 meter->completed++;
221 222
222 if (meter->completed == meter->total) 223 if (meter->completed == meter->total)
223 return GNUNET_YES; 224 return GNUNET_YES;
224 if (meter->completed > meter->total) 225 if (meter->completed > meter->total)
225 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n"); 226 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
226 return GNUNET_NO; 227 return GNUNET_NO;
227} 228}
228 229
@@ -236,7 +237,7 @@ update_meter(struct ProgressMeter *meter)
236 * #GNUNET_SYSERR on error 237 * #GNUNET_SYSERR on error
237 */ 238 */
238static int 239static int
239reset_meter(struct ProgressMeter *meter) 240reset_meter (struct ProgressMeter *meter)
240{ 241{
241 if (meter == NULL) 242 if (meter == NULL)
242 return GNUNET_SYSERR; 243 return GNUNET_SYSERR;
@@ -252,10 +253,10 @@ reset_meter(struct ProgressMeter *meter)
252 * @param meter the meter to free 253 * @param meter the meter to free
253 */ 254 */
254static void 255static void
255free_meter(struct ProgressMeter *meter) 256free_meter (struct ProgressMeter *meter)
256{ 257{
257 GNUNET_free_non_null(meter->startup_string); 258 GNUNET_free_non_null (meter->startup_string);
258 GNUNET_free(meter); 259 GNUNET_free (meter);
259} 260}
260 261
261 262
@@ -265,18 +266,18 @@ free_meter(struct ProgressMeter *meter)
265 * @param cls NULL 266 * @param cls NULL
266 */ 267 */
267static void 268static void
268do_shutdown(void *cls) 269do_shutdown (void *cls)
269{ 270{
270 if (NULL != mysql_ctx) 271 if (NULL != mysql_ctx)
271 { 272 {
272 GNUNET_MYSQL_context_destroy(mysql_ctx); 273 GNUNET_MYSQL_context_destroy (mysql_ctx);
273 mysql_ctx = NULL; 274 mysql_ctx = NULL;
274 } 275 }
275 if (NULL != meter) 276 if (NULL != meter)
276 { 277 {
277 free_meter(meter); 278 free_meter (meter);
278 meter = NULL; 279 meter = NULL;
279 } 280 }
280} 281}
281 282
282 283
@@ -292,16 +293,16 @@ do_shutdown(void *cls)
292 * @param cls NULL 293 * @param cls NULL
293 */ 294 */
294static void 295static void
295do_abort(void *cls) 296do_abort (void *cls)
296{ 297{
297 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); 298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
298 if (NULL != scan_task) 299 if (NULL != scan_task)
299 { 300 {
300 GNUNET_SCHEDULER_cancel(scan_task); 301 GNUNET_SCHEDULER_cancel (scan_task);
301 scan_task = NULL; 302 scan_task = NULL;
302 } 303 }
303 result = GNUNET_SYSERR; 304 result = GNUNET_SYSERR;
304 GNUNET_SCHEDULER_shutdown(); 305 GNUNET_SCHEDULER_shutdown ();
305} 306}
306 307
307/** 308/**
@@ -315,131 +316,131 @@ do_abort(void *cls)
315 * @param edges edges leaving current state. 316 * @param edges edges leaving current state.
316 */ 317 */
317static void 318static void
318regex_iterator(void *cls, 319regex_iterator (void *cls,
319 const struct GNUNET_HashCode *key, 320 const struct GNUNET_HashCode *key,
320 const char *proof, 321 const char *proof,
321 int accepting, 322 int accepting,
322 unsigned int num_edges, 323 unsigned int num_edges,
323 const struct REGEX_BLOCK_Edge *edges) 324 const struct REGEX_BLOCK_Edge *edges)
324{ 325{
325 unsigned int i; 326 unsigned int i;
326 int result; 327 int result;
327 328
328 uint32_t iaccepting = (uint32_t)accepting; 329 uint32_t iaccepting = (uint32_t) accepting;
329 uint64_t total; 330 uint64_t total;
330 331
331 GNUNET_assert(NULL != mysql_ctx); 332 GNUNET_assert (NULL != mysql_ctx);
332 333
333 for (i = 0; i < num_edges; i++) 334 for (i = 0; i < num_edges; i++)
335 {
336 struct GNUNET_MY_QueryParam params_select[] = {
337 GNUNET_MY_query_param_auto_from_type (key),
338 GNUNET_MY_query_param_string (edges[i].label),
339 GNUNET_MY_query_param_end
340 };
341
342 struct GNUNET_MY_ResultSpec results_select[] = {
343 GNUNET_MY_result_spec_uint64 (&total),
344 GNUNET_MY_result_spec_end
345 };
346
347 result =
348 GNUNET_MY_exec_prepared (mysql_ctx,
349 select_stmt_handle,
350 params_select);
351
352 if (GNUNET_SYSERR == result)
353 {
354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
355 "Error executing prepared mysql select statement\n");
356 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
357 return;
358 }
359
360 result =
361 GNUNET_MY_extract_result (select_stmt_handle,
362 results_select);
363
364 if (GNUNET_SYSERR == result)
365 {
366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
367 "Error extracting result mysql select statement\n");
368 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
369 return;
370 }
371
372 if ((-1 != total) &&(total > 0) )
373 {
374 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n",
375 (unsigned long long) total,
376 GNUNET_h2s (key), edges[i].label);
377 }
378
379 struct GNUNET_MY_QueryParam params_stmt[] = {
380 GNUNET_MY_query_param_auto_from_type (&key),
381 GNUNET_MY_query_param_string (edges[i].label),
382 GNUNET_MY_query_param_auto_from_type (&edges[i].destination),
383 GNUNET_MY_query_param_uint32 (&iaccepting),
384 GNUNET_MY_query_param_end
385 };
386
387 result =
388 GNUNET_MY_exec_prepared (mysql_ctx,
389 stmt_handle,
390 params_stmt);
391
392 if (0 == result)
393 {
394 char *key_str = GNUNET_strdup (GNUNET_h2s (key));
395 char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination));
396
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n",
398 key_str,
399 edges[i].label,
400 to_key_str,
401 accepting);
402
403 GNUNET_free (key_str);
404 GNUNET_free (to_key_str);
405 num_merged_transitions++;
406 }
407 else if (-1 != total)
408 {
409 num_merged_states++;
410 }
411
412 if ((GNUNET_SYSERR == result) || ((1 != result) &&(0 != result) ))
334 { 413 {
335 struct GNUNET_MY_QueryParam params_select[] = { 414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
336 GNUNET_MY_query_param_auto_from_type(key), 415 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
337 GNUNET_MY_query_param_string(edges[i].label), 416 result);
338 GNUNET_MY_query_param_end 417 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
339 };
340
341 struct GNUNET_MY_ResultSpec results_select[] = {
342 GNUNET_MY_result_spec_uint64(&total),
343 GNUNET_MY_result_spec_end
344 };
345
346 result =
347 GNUNET_MY_exec_prepared(mysql_ctx,
348 select_stmt_handle,
349 params_select);
350
351 if (GNUNET_SYSERR == result)
352 {
353 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
354 "Error executing prepared mysql select statement\n");
355 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
356 return;
357 }
358
359 result =
360 GNUNET_MY_extract_result(select_stmt_handle,
361 results_select);
362
363 if (GNUNET_SYSERR == result)
364 {
365 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
366 "Error extracting result mysql select statement\n");
367 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
368 return;
369 }
370
371 if (-1 != total && total > 0)
372 {
373 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n",
374 (unsigned long long)total,
375 GNUNET_h2s(key), edges[i].label);
376 }
377
378 struct GNUNET_MY_QueryParam params_stmt[] = {
379 GNUNET_MY_query_param_auto_from_type(&key),
380 GNUNET_MY_query_param_string(edges[i].label),
381 GNUNET_MY_query_param_auto_from_type(&edges[i].destination),
382 GNUNET_MY_query_param_uint32(&iaccepting),
383 GNUNET_MY_query_param_end
384 };
385
386 result =
387 GNUNET_MY_exec_prepared(mysql_ctx,
388 stmt_handle,
389 params_stmt);
390
391 if (0 == result)
392 {
393 char *key_str = GNUNET_strdup(GNUNET_h2s(key));
394 char *to_key_str = GNUNET_strdup(GNUNET_h2s(&edges[i].destination));
395
396 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n",
397 key_str,
398 edges[i].label,
399 to_key_str,
400 accepting);
401
402 GNUNET_free(key_str);
403 GNUNET_free(to_key_str);
404 num_merged_transitions++;
405 }
406 else if (-1 != total)
407 {
408 num_merged_states++;
409 }
410
411 if (GNUNET_SYSERR == result || (1 != result && 0 != result))
412 {
413 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
414 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
415 result);
416 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
417 }
418 } 418 }
419 }
419 420
420 if (0 == num_edges) 421 if (0 == num_edges)
422 {
423 struct GNUNET_MY_QueryParam params_stmt[] = {
424 GNUNET_MY_query_param_auto_from_type (key),
425 GNUNET_MY_query_param_string (""),
426 GNUNET_MY_query_param_fixed_size (NULL, 0),
427 GNUNET_MY_query_param_uint32 (&iaccepting),
428 GNUNET_MY_query_param_end
429 };
430
431 result =
432 GNUNET_MY_exec_prepared (mysql_ctx,
433 stmt_handle,
434 params_stmt);
435
436 if ((1 != result) &&(0 != result) )
421 { 437 {
422 struct GNUNET_MY_QueryParam params_stmt[] = { 438 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
423 GNUNET_MY_query_param_auto_from_type(key), 439 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
424 GNUNET_MY_query_param_string(""), 440 result);
425 GNUNET_MY_query_param_fixed_size(NULL, 0), 441 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
426 GNUNET_MY_query_param_uint32(&iaccepting),
427 GNUNET_MY_query_param_end
428 };
429
430 result =
431 GNUNET_MY_exec_prepared(mysql_ctx,
432 stmt_handle,
433 params_stmt);
434
435 if (1 != result && 0 != result)
436 {
437 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
438 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
439 result);
440 GNUNET_SCHEDULER_add_now(&do_abort, NULL);
441 }
442 } 442 }
443 }
443} 444}
444 445
445 446
@@ -451,26 +452,26 @@ regex_iterator(void *cls,
451 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure. 452 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure.
452 */ 453 */
453static int 454static int
454announce_regex(const char *regex) 455announce_regex (const char *regex)
455{ 456{
456 struct REGEX_INTERNAL_Automaton *dfa; 457 struct REGEX_INTERNAL_Automaton *dfa;
457 458
458 dfa = 459 dfa =
459 REGEX_INTERNAL_construct_dfa(regex, 460 REGEX_INTERNAL_construct_dfa (regex,
460 strlen(regex), 461 strlen (regex),
461 max_path_compression); 462 max_path_compression);
462 463
463 if (NULL == dfa) 464 if (NULL == dfa)
464 { 465 {
465 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 466 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
466 "Failed to create DFA for regex %s\n", 467 "Failed to create DFA for regex %s\n",
467 regex); 468 regex);
468 GNUNET_SCHEDULER_add_now(&do_abort, NULL); 469 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
469 return GNUNET_SYSERR; 470 return GNUNET_SYSERR;
470 } 471 }
471 REGEX_INTERNAL_iterate_all_edges(dfa, 472 REGEX_INTERNAL_iterate_all_edges (dfa,
472 &regex_iterator, NULL); 473 &regex_iterator, NULL);
473 REGEX_INTERNAL_automaton_destroy(dfa); 474 REGEX_INTERNAL_automaton_destroy (dfa);
474 475
475 return GNUNET_OK; 476 return GNUNET_OK;
476} 477}
@@ -485,7 +486,7 @@ announce_regex(const char *regex)
485 * #GNUNET_SYSERR to abort iteration with error! 486 * #GNUNET_SYSERR to abort iteration with error!
486 */ 487 */
487static int 488static int
488policy_filename_cb(void *cls, const char *filename) 489policy_filename_cb (void *cls, const char *filename)
489{ 490{
490 char *regex; 491 char *regex;
491 char *data; 492 char *data;
@@ -493,70 +494,70 @@ policy_filename_cb(void *cls, const char *filename)
493 uint64_t filesize; 494 uint64_t filesize;
494 unsigned int offset; 495 unsigned int offset;
495 496
496 GNUNET_assert(NULL != filename); 497 GNUNET_assert (NULL != filename);
497 498
498 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 499 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
499 "Announcing regexes from file %s\n", 500 "Announcing regexes from file %s\n",
500 filename); 501 filename);
501 502
502 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 503 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
503 { 504 {
504 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
505 "Could not find policy file %s\n", 506 "Could not find policy file %s\n",
506 filename); 507 filename);
507 return GNUNET_OK; 508 return GNUNET_OK;
508 } 509 }
509 if (GNUNET_OK != 510 if (GNUNET_OK !=
510 GNUNET_DISK_file_size(filename, &filesize, 511 GNUNET_DISK_file_size (filename, &filesize,
511 GNUNET_YES, GNUNET_YES)) 512 GNUNET_YES, GNUNET_YES))
512 filesize = 0; 513 filesize = 0;
513 if (0 == filesize) 514 if (0 == filesize)
514 { 515 {
515 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n", 516 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n",
516 filename); 517 filename);
517 return GNUNET_OK; 518 return GNUNET_OK;
518 } 519 }
519 data = GNUNET_malloc(filesize); 520 data = GNUNET_malloc (filesize);
520 if (filesize != GNUNET_DISK_fn_read(filename, data, filesize)) 521 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
521 { 522 {
522 GNUNET_free(data); 523 GNUNET_free (data);
523 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 524 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
524 "Could not read policy file %s.\n", 525 "Could not read policy file %s.\n",
525 filename); 526 filename);
526 return GNUNET_OK; 527 return GNUNET_OK;
527 } 528 }
528 529
529 update_meter(meter); 530 update_meter (meter);
530 531
531 buf = data; 532 buf = data;
532 offset = 0; 533 offset = 0;
533 regex = NULL; 534 regex = NULL;
534 while (offset < (filesize - 1)) 535 while (offset < (filesize - 1))
536 {
537 offset++;
538 if (((data[offset] == '\n')) && (buf != &data[offset]))
535 { 539 {
536 offset++; 540 data[offset] = '|';
537 if (((data[offset] == '\n')) && (buf != &data[offset])) 541 num_policies++;
538 { 542 buf = &data[offset + 1];
539 data[offset] = '|';
540 num_policies++;
541 buf = &data[offset + 1];
542 }
543 else if ((data[offset] == '\n') || (data[offset] == '\0'))
544 buf = &data[offset + 1];
545 } 543 }
544 else if ((data[offset] == '\n') || (data[offset] == '\0'))
545 buf = &data[offset + 1];
546 }
546 data[offset] = '\0'; 547 data[offset] = '\0';
547 GNUNET_asprintf(&regex, "%s(%s)", regex_prefix, data); 548 GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data);
548 GNUNET_assert(NULL != regex); 549 GNUNET_assert (NULL != regex);
549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550 "Announcing regex: %s\n", regex); 551 "Announcing regex: %s\n", regex);
551 552
552 if (GNUNET_OK != announce_regex(regex)) 553 if (GNUNET_OK != announce_regex (regex))
553 { 554 {
554 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 "Could not announce regex %s\n", 556 "Could not announce regex %s\n",
556 regex); 557 regex);
557 } 558 }
558 GNUNET_free(regex); 559 GNUNET_free (regex);
559 GNUNET_free(data); 560 GNUNET_free (data);
560 return GNUNET_OK; 561 return GNUNET_OK;
561} 562}
562 563
@@ -567,7 +568,7 @@ policy_filename_cb(void *cls, const char *filename)
567 * @param cls NULL 568 * @param cls NULL
568 */ 569 */
569static void 570static void
570do_directory_scan(void *cls) 571do_directory_scan (void *cls)
571{ 572{
572 struct GNUNET_TIME_Absolute start_time; 573 struct GNUNET_TIME_Absolute start_time;
573 struct GNUNET_TIME_Relative duration; 574 struct GNUNET_TIME_Relative duration;
@@ -575,37 +576,37 @@ do_directory_scan(void *cls)
575 576
576 /* Create an MySQL prepared statement for the inserts */ 577 /* Create an MySQL prepared statement for the inserts */
577 scan_task = NULL; 578 scan_task = NULL;
578 GNUNET_asprintf(&stmt, INSERT_EDGE_STMT, table_name); 579 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name);
579 stmt_handle = GNUNET_MYSQL_statement_prepare(mysql_ctx, stmt); 580 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
580 GNUNET_free(stmt); 581 GNUNET_free (stmt);
581 582
582 GNUNET_asprintf(&stmt, SELECT_KEY_STMT, table_name); 583 GNUNET_asprintf (&stmt, SELECT_KEY_STMT, table_name);
583 select_stmt_handle = GNUNET_MYSQL_statement_prepare(mysql_ctx, stmt); 584 select_stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
584 GNUNET_free(stmt); 585 GNUNET_free (stmt);
585 586
586 GNUNET_assert(NULL != stmt_handle); 587 GNUNET_assert (NULL != stmt_handle);
587 588
588 meter = create_meter(num_policy_files, 589 meter = create_meter (num_policy_files,
589 "Announcing policy files\n", 590 "Announcing policy files\n",
590 GNUNET_YES); 591 GNUNET_YES);
591 start_time = GNUNET_TIME_absolute_get(); 592 start_time = GNUNET_TIME_absolute_get ();
592 GNUNET_DISK_directory_scan(policy_dir, 593 GNUNET_DISK_directory_scan (policy_dir,
593 &policy_filename_cb, 594 &policy_filename_cb,
594 stmt_handle); 595 stmt_handle);
595 duration = GNUNET_TIME_absolute_get_duration(start_time); 596 duration = GNUNET_TIME_absolute_get_duration (start_time);
596 reset_meter(meter); 597 reset_meter (meter);
597 free_meter(meter); 598 free_meter (meter);
598 meter = NULL; 599 meter = NULL;
599 600
600 printf("Announced %u files containing %u policies in %s\n" 601 printf ("Announced %u files containing %u policies in %s\n"
601 "Duplicate transitions: %llu\nMerged states: %llu\n", 602 "Duplicate transitions: %llu\nMerged states: %llu\n",
602 num_policy_files, 603 num_policy_files,
603 num_policies, 604 num_policies,
604 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_NO), 605 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO),
605 num_merged_transitions, 606 num_merged_transitions,
606 num_merged_states); 607 num_merged_states);
607 result = GNUNET_OK; 608 result = GNUNET_OK;
608 GNUNET_SCHEDULER_shutdown(); 609 GNUNET_SCHEDULER_shutdown ();
609} 610}
610 611
611 612
@@ -618,65 +619,65 @@ do_directory_scan(void *cls)
618 * @param config configuration 619 * @param config configuration
619 */ 620 */
620static void 621static void
621run(void *cls, 622run (void *cls,
622 char *const *args, 623 char *const *args,
623 const char *cfgfile, 624 const char *cfgfile,
624 const struct GNUNET_CONFIGURATION_Handle *config) 625 const struct GNUNET_CONFIGURATION_Handle *config)
625{ 626{
626 if (NULL == args[0]) 627 if (NULL == args[0])
627 { 628 {
628 fprintf(stderr, 629 fprintf (stderr,
629 _("No policy directory specified on command line. Exiting.\n")); 630 _ ("No policy directory specified on command line. Exiting.\n"));
630 result = GNUNET_SYSERR; 631 result = GNUNET_SYSERR;
631 return; 632 return;
632 } 633 }
633 if (GNUNET_YES != 634 if (GNUNET_YES !=
634 GNUNET_DISK_directory_test(args[0], GNUNET_YES)) 635 GNUNET_DISK_directory_test (args[0], GNUNET_YES))
635 { 636 {
636 fprintf(stderr, 637 fprintf (stderr,
637 _("Specified policies directory does not exist. Exiting.\n")); 638 _ ("Specified policies directory does not exist. Exiting.\n"));
638 result = GNUNET_SYSERR; 639 result = GNUNET_SYSERR;
639 return; 640 return;
640 } 641 }
641 policy_dir = args[0]; 642 policy_dir = args[0];
642 643
643 num_policy_files = GNUNET_DISK_directory_scan(policy_dir, 644 num_policy_files = GNUNET_DISK_directory_scan (policy_dir,
644 NULL, NULL); 645 NULL, NULL);
645 meter = NULL; 646 meter = NULL;
646 647
647 if (NULL == table_name) 648 if (NULL == table_name)
648 { 649 {
649 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 650 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
650 "No table name specified, using default \"NFA\".\n"); 651 "No table name specified, using default \"NFA\".\n");
651 table_name = "NFA"; 652 table_name = "NFA";
652 } 653 }
653 654
654 mysql_ctx = GNUNET_MYSQL_context_create(config, "regex-mysql"); 655 mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
655 if (NULL == mysql_ctx) 656 if (NULL == mysql_ctx)
656 { 657 {
657 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
658 "Failed to create mysql context\n"); 659 "Failed to create mysql context\n");
659 result = GNUNET_SYSERR; 660 result = GNUNET_SYSERR;
660 return; 661 return;
661 } 662 }
662 663
663 if (GNUNET_OK != 664 if (GNUNET_OK !=
664 GNUNET_CONFIGURATION_get_value_string(config, 665 GNUNET_CONFIGURATION_get_value_string (config,
665 "regex-mysql", 666 "regex-mysql",
666 "REGEX_PREFIX", 667 "REGEX_PREFIX",
667 &regex_prefix)) 668 &regex_prefix))
668 { 669 {
669 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 670 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
670 "regex-mysql", 671 "regex-mysql",
671 "REGEX_PREFIX"); 672 "REGEX_PREFIX");
672 result = GNUNET_SYSERR; 673 result = GNUNET_SYSERR;
673 return; 674 return;
674 } 675 }
675 676
676 result = GNUNET_OK; 677 result = GNUNET_OK;
677 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 678 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
678 NULL); 679 NULL);
679 scan_task = GNUNET_SCHEDULER_add_now(&do_directory_scan, NULL); 680 scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL);
680} 681}
681 682
682 683
@@ -688,33 +689,34 @@ run(void *cls,
688 * @return 0 on success 689 * @return 0 on success
689 */ 690 */
690int 691int
691main(int argc, char *const *argv) 692main (int argc, char *const *argv)
692{ 693{
693 struct GNUNET_GETOPT_CommandLineOption options[] = { 694 struct GNUNET_GETOPT_CommandLineOption options[] = {
694 GNUNET_GETOPT_option_string('t', 695 GNUNET_GETOPT_option_string ('t',
695 "table", 696 "table",
696 "TABLENAME", 697 "TABLENAME",
697 gettext_noop("name of the table to write DFAs"), 698 gettext_noop (
698 &table_name), 699 "name of the table to write DFAs"),
699 700 &table_name),
700 GNUNET_GETOPT_option_uint('p', 701
701 "max-path-compression", 702 GNUNET_GETOPT_option_uint ('p',
702 "MAX_PATH_COMPRESSION", 703 "max-path-compression",
703 gettext_noop("maximum path compression length"), 704 "MAX_PATH_COMPRESSION",
704 &max_path_compression), 705 gettext_noop ("maximum path compression length"),
706 &max_path_compression),
705 707
706 GNUNET_GETOPT_OPTION_END 708 GNUNET_GETOPT_OPTION_END
707 }; 709 };
708 int ret; 710 int ret;
709 711
710 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 712 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
711 return 2; 713 return 2;
712 714
713 result = GNUNET_SYSERR; 715 result = GNUNET_SYSERR;
714 ret = 716 ret =
715 GNUNET_PROGRAM_run(argc, argv, 717 GNUNET_PROGRAM_run (argc, argv,
716 "gnunet-regex-simulationprofiler [OPTIONS] policy-dir", 718 "gnunet-regex-simulationprofiler [OPTIONS] policy-dir",
717 _("Profiler for regex library"), options, &run, NULL); 719 _ ("Profiler for regex library"), options, &run, NULL);
718 if (GNUNET_OK != ret) 720 if (GNUNET_OK != ret)
719 return ret; 721 return ret;
720 if (GNUNET_OK != result) 722 if (GNUNET_OK != result)
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c
index 90ea91780..19250d427 100644
--- a/src/regex/gnunet-service-regex.c
+++ b/src/regex/gnunet-service-regex.c
@@ -33,7 +33,8 @@
33/** 33/**
34 * Information about one of our clients. 34 * Information about one of our clients.
35 */ 35 */
36struct ClientEntry { 36struct ClientEntry
37{
37 /** 38 /**
38 * Queue for transmissions to @e client. 39 * Queue for transmissions to @e client.
39 */ 40 */
@@ -88,14 +89,14 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
88 * @param cls unused 89 * @param cls unused
89 */ 90 */
90static void 91static void
91cleanup_task(void *cls) 92cleanup_task (void *cls)
92{ 93{
93 GNUNET_DHT_disconnect(dht); 94 GNUNET_DHT_disconnect (dht);
94 dht = NULL; 95 dht = NULL;
95 GNUNET_STATISTICS_destroy(stats, 96 GNUNET_STATISTICS_destroy (stats,
96 GNUNET_NO); 97 GNUNET_NO);
97 stats = NULL; 98 stats = NULL;
98 GNUNET_free(my_private_key); 99 GNUNET_free (my_private_key);
99 my_private_key = NULL; 100 my_private_key = NULL;
100} 101}
101 102
@@ -107,14 +108,14 @@ cleanup_task(void *cls)
107 * announcement 108 * announcement
108 */ 109 */
109static void 110static void
110reannounce(void *cls) 111reannounce (void *cls)
111{ 112{
112 struct ClientEntry *ce = cls; 113 struct ClientEntry *ce = cls;
113 114
114 REGEX_INTERNAL_reannounce(ce->ah); 115 REGEX_INTERNAL_reannounce (ce->ah);
115 ce->refresh_task = GNUNET_SCHEDULER_add_delayed(ce->frequency, 116 ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency,
116 &reannounce, 117 &reannounce,
117 ce); 118 ce);
118} 119}
119 120
120 121
@@ -126,18 +127,18 @@ reannounce(void *cls)
126 * @return #GNUNET_OK if @am is well-formed 127 * @return #GNUNET_OK if @am is well-formed
127 */ 128 */
128static int 129static int
129check_announce(void *cls, 130check_announce (void *cls,
130 const struct AnnounceMessage *am) 131 const struct AnnounceMessage *am)
131{ 132{
132 struct ClientEntry *ce = cls; 133 struct ClientEntry *ce = cls;
133 134
134 GNUNET_MQ_check_zero_termination(am); 135 GNUNET_MQ_check_zero_termination (am);
135 if (NULL != ce->ah) 136 if (NULL != ce->ah)
136 { 137 {
137 /* only one announcement per client allowed */ 138 /* only one announcement per client allowed */
138 GNUNET_break(0); 139 GNUNET_break (0);
139 return GNUNET_SYSERR; 140 return GNUNET_SYSERR;
140 } 141 }
141 return GNUNET_OK; 142 return GNUNET_OK;
142} 143}
143 144
@@ -149,36 +150,36 @@ check_announce(void *cls,
149 * @param am the actual message 150 * @param am the actual message
150 */ 151 */
151static void 152static void
152handle_announce(void *cls, 153handle_announce (void *cls,
153 const struct AnnounceMessage *am) 154 const struct AnnounceMessage *am)
154{ 155{
155 struct ClientEntry *ce = cls; 156 struct ClientEntry *ce = cls;
156 const char *regex; 157 const char *regex;
157 158
158 regex = (const char *)&am[1]; 159 regex = (const char *) &am[1];
159 ce->frequency = GNUNET_TIME_relative_ntoh(am->refresh_delay); 160 ce->frequency = GNUNET_TIME_relative_ntoh (am->refresh_delay);
160 ce->refresh_task = GNUNET_SCHEDULER_add_delayed(ce->frequency, 161 ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency,
161 &reannounce, 162 &reannounce,
162 ce); 163 ce);
163 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Starting to announce regex `%s' every %s\n", 165 "Starting to announce regex `%s' every %s\n",
165 regex, 166 regex,
166 GNUNET_STRINGS_relative_time_to_string(ce->frequency, 167 GNUNET_STRINGS_relative_time_to_string (ce->frequency,
167 GNUNET_NO)); 168 GNUNET_NO));
168 ce->ah = REGEX_INTERNAL_announce(dht, 169 ce->ah = REGEX_INTERNAL_announce (dht,
169 my_private_key, 170 my_private_key,
170 regex, 171 regex,
171 ntohs(am->compression), 172 ntohs (am->compression),
172 stats); 173 stats);
173 if (NULL == ce->ah) 174 if (NULL == ce->ah)
174 { 175 {
175 GNUNET_break(0); 176 GNUNET_break (0);
176 GNUNET_SCHEDULER_cancel(ce->refresh_task); 177 GNUNET_SCHEDULER_cancel (ce->refresh_task);
177 ce->refresh_task = NULL; 178 ce->refresh_task = NULL;
178 GNUNET_SERVICE_client_drop(ce->client); 179 GNUNET_SERVICE_client_drop (ce->client);
179 return; 180 return;
180 } 181 }
181 GNUNET_SERVICE_client_continue(ce->client); 182 GNUNET_SERVICE_client_continue (ce->client);
182} 183}
183 184
184 185
@@ -193,12 +194,12 @@ handle_announce(void *cls,
193 * @param put_path_length Length of the @a put_path. 194 * @param put_path_length Length of the @a put_path.
194 */ 195 */
195static void 196static void
196handle_search_result(void *cls, 197handle_search_result (void *cls,
197 const struct GNUNET_PeerIdentity *id, 198 const struct GNUNET_PeerIdentity *id,
198 const struct GNUNET_PeerIdentity *get_path, 199 const struct GNUNET_PeerIdentity *get_path,
199 unsigned int get_path_length, 200 unsigned int get_path_length,
200 const struct GNUNET_PeerIdentity *put_path, 201 const struct GNUNET_PeerIdentity *put_path,
201 unsigned int put_path_length) 202 unsigned int put_path_length)
202{ 203{
203 struct ClientEntry *ce = cls; 204 struct ClientEntry *ce = cls;
204 struct GNUNET_MQ_Envelope *env; 205 struct GNUNET_MQ_Envelope *env;
@@ -208,28 +209,30 @@ handle_search_result(void *cls,
208 209
209 if ((get_path_length >= 65536) || 210 if ((get_path_length >= 65536) ||
210 (put_path_length >= 65536) || 211 (put_path_length >= 65536) ||
211 ((get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity)) 212 ( ((get_path_length + put_path_length) * sizeof(struct
212 + sizeof(struct ResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) 213 GNUNET_PeerIdentity))
213 { 214 + sizeof(struct ResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) )
214 GNUNET_break(0); 215 {
215 return; 216 GNUNET_break (0);
216 } 217 return;
217 size = (get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity); 218 }
218 env = GNUNET_MQ_msg_extra(result, 219 size = (get_path_length + put_path_length) * sizeof(struct
219 size, 220 GNUNET_PeerIdentity);
220 GNUNET_MESSAGE_TYPE_REGEX_RESULT); 221 env = GNUNET_MQ_msg_extra (result,
221 result->get_path_length = htons((uint16_t)get_path_length); 222 size,
222 result->put_path_length = htons((uint16_t)put_path_length); 223 GNUNET_MESSAGE_TYPE_REGEX_RESULT);
224 result->get_path_length = htons ((uint16_t) get_path_length);
225 result->put_path_length = htons ((uint16_t) put_path_length);
223 result->id = *id; 226 result->id = *id;
224 gp = &result->id; 227 gp = &result->id;
225 GNUNET_memcpy(&gp[1], 228 GNUNET_memcpy (&gp[1],
226 get_path, 229 get_path,
227 get_path_length * sizeof(struct GNUNET_PeerIdentity)); 230 get_path_length * sizeof(struct GNUNET_PeerIdentity));
228 GNUNET_memcpy(&gp[1 + get_path_length], 231 GNUNET_memcpy (&gp[1 + get_path_length],
229 put_path, 232 put_path,
230 put_path_length * sizeof(struct GNUNET_PeerIdentity)); 233 put_path_length * sizeof(struct GNUNET_PeerIdentity));
231 GNUNET_MQ_send(ce->mq, 234 GNUNET_MQ_send (ce->mq,
232 env); 235 env);
233} 236}
234 237
235 238
@@ -240,26 +243,26 @@ handle_search_result(void *cls,
240 * @param message the actual message 243 * @param message the actual message
241 */ 244 */
242static int 245static int
243check_search(void *cls, 246check_search (void *cls,
244 const struct RegexSearchMessage *sm) 247 const struct RegexSearchMessage *sm)
245{ 248{
246 struct ClientEntry *ce = cls; 249 struct ClientEntry *ce = cls;
247 const char *string; 250 const char *string;
248 uint16_t size; 251 uint16_t size;
249 252
250 size = ntohs(sm->header.size) - sizeof(*sm); 253 size = ntohs (sm->header.size) - sizeof(*sm);
251 string = (const char *)&sm[1]; 254 string = (const char *) &sm[1];
252 if ('\0' != string[size - 1]) 255 if ('\0' != string[size - 1])
253 { 256 {
254 GNUNET_break(0); 257 GNUNET_break (0);
255 return GNUNET_SYSERR; 258 return GNUNET_SYSERR;
256 } 259 }
257 if (NULL != ce->sh) 260 if (NULL != ce->sh)
258 { 261 {
259 /* only one search allowed per client */ 262 /* only one search allowed per client */
260 GNUNET_break(0); 263 GNUNET_break (0);
261 return GNUNET_SYSERR; 264 return GNUNET_SYSERR;
262 } 265 }
263 return GNUNET_OK; 266 return GNUNET_OK;
264} 267}
265 268
@@ -271,28 +274,28 @@ check_search(void *cls,
271 * @param message the actual message 274 * @param message the actual message
272 */ 275 */
273static void 276static void
274handle_search(void *cls, 277handle_search (void *cls,
275 const struct RegexSearchMessage *sm) 278 const struct RegexSearchMessage *sm)
276{ 279{
277 struct ClientEntry *ce = cls; 280 struct ClientEntry *ce = cls;
278 const char *string; 281 const char *string;
279 282
280 string = (const char *)&sm[1]; 283 string = (const char *) &sm[1];
281 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
282 "Starting to search for `%s'\n", 285 "Starting to search for `%s'\n",
283 string); 286 string);
284 ce->sh = REGEX_INTERNAL_search(dht, 287 ce->sh = REGEX_INTERNAL_search (dht,
285 string, 288 string,
286 &handle_search_result, 289 &handle_search_result,
287 ce, 290 ce,
288 stats); 291 stats);
289 if (NULL == ce->sh) 292 if (NULL == ce->sh)
290 { 293 {
291 GNUNET_break(0); 294 GNUNET_break (0);
292 GNUNET_SERVICE_client_drop(ce->client); 295 GNUNET_SERVICE_client_drop (ce->client);
293 return; 296 return;
294 } 297 }
295 GNUNET_SERVICE_client_continue(ce->client); 298 GNUNET_SERVICE_client_continue (ce->client);
296} 299}
297 300
298 301
@@ -304,27 +307,27 @@ handle_search(void *cls,
304 * @param service the initialized service 307 * @param service the initialized service
305 */ 308 */
306static void 309static void
307run(void *cls, 310run (void *cls,
308 const struct GNUNET_CONFIGURATION_Handle *cfg, 311 const struct GNUNET_CONFIGURATION_Handle *cfg,
309 struct GNUNET_SERVICE_Handle *service) 312 struct GNUNET_SERVICE_Handle *service)
310{ 313{
311 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); 314 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
312 if (NULL == my_private_key) 315 if (NULL == my_private_key)
313 { 316 {
314 GNUNET_SCHEDULER_shutdown(); 317 GNUNET_SCHEDULER_shutdown ();
315 return; 318 return;
316 } 319 }
317 dht = GNUNET_DHT_connect(cfg, 1024); 320 dht = GNUNET_DHT_connect (cfg, 1024);
318 if (NULL == dht) 321 if (NULL == dht)
319 { 322 {
320 GNUNET_free(my_private_key); 323 GNUNET_free (my_private_key);
321 my_private_key = NULL; 324 my_private_key = NULL;
322 GNUNET_SCHEDULER_shutdown(); 325 GNUNET_SCHEDULER_shutdown ();
323 return; 326 return;
324 } 327 }
325 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, 328 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
326 NULL); 329 NULL);
327 stats = GNUNET_STATISTICS_create("regex", cfg); 330 stats = GNUNET_STATISTICS_create ("regex", cfg);
328} 331}
329 332
330 333
@@ -337,13 +340,13 @@ run(void *cls,
337 * @return @a c 340 * @return @a c
338 */ 341 */
339static void * 342static void *
340client_connect_cb(void *cls, 343client_connect_cb (void *cls,
341 struct GNUNET_SERVICE_Client *c, 344 struct GNUNET_SERVICE_Client *c,
342 struct GNUNET_MQ_Handle *mq) 345 struct GNUNET_MQ_Handle *mq)
343{ 346{
344 struct ClientEntry *ce; 347 struct ClientEntry *ce;
345 348
346 ce = GNUNET_new(struct ClientEntry); 349 ce = GNUNET_new (struct ClientEntry);
347 ce->client = c; 350 ce->client = c;
348 ce->mq = mq; 351 ce->mq = mq;
349 return ce; 352 return ce;
@@ -358,28 +361,28 @@ client_connect_cb(void *cls,
358 * @param internal_cls should be equal to @a c 361 * @param internal_cls should be equal to @a c
359 */ 362 */
360static void 363static void
361client_disconnect_cb(void *cls, 364client_disconnect_cb (void *cls,
362 struct GNUNET_SERVICE_Client *c, 365 struct GNUNET_SERVICE_Client *c,
363 void *internal_cls) 366 void *internal_cls)
364{ 367{
365 struct ClientEntry *ce = internal_cls; 368 struct ClientEntry *ce = internal_cls;
366 369
367 if (NULL != ce->refresh_task) 370 if (NULL != ce->refresh_task)
368 { 371 {
369 GNUNET_SCHEDULER_cancel(ce->refresh_task); 372 GNUNET_SCHEDULER_cancel (ce->refresh_task);
370 ce->refresh_task = NULL; 373 ce->refresh_task = NULL;
371 } 374 }
372 if (NULL != ce->ah) 375 if (NULL != ce->ah)
373 { 376 {
374 REGEX_INTERNAL_announce_cancel(ce->ah); 377 REGEX_INTERNAL_announce_cancel (ce->ah);
375 ce->ah = NULL; 378 ce->ah = NULL;
376 } 379 }
377 if (NULL != ce->sh) 380 if (NULL != ce->sh)
378 { 381 {
379 REGEX_INTERNAL_search_cancel(ce->sh); 382 REGEX_INTERNAL_search_cancel (ce->sh);
380 ce->sh = NULL; 383 ce->sh = NULL;
381 } 384 }
382 GNUNET_free(ce); 385 GNUNET_free (ce);
383} 386}
384 387
385 388
@@ -393,15 +396,15 @@ GNUNET_SERVICE_MAIN
393 &client_connect_cb, 396 &client_connect_cb,
394 &client_disconnect_cb, 397 &client_disconnect_cb,
395 NULL, 398 NULL,
396 GNUNET_MQ_hd_var_size(announce, 399 GNUNET_MQ_hd_var_size (announce,
397 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE, 400 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE,
398 struct AnnounceMessage, 401 struct AnnounceMessage,
399 NULL), 402 NULL),
400 GNUNET_MQ_hd_var_size(search, 403 GNUNET_MQ_hd_var_size (search,
401 GNUNET_MESSAGE_TYPE_REGEX_SEARCH, 404 GNUNET_MESSAGE_TYPE_REGEX_SEARCH,
402 struct RegexSearchMessage, 405 struct RegexSearchMessage,
403 NULL), 406 NULL),
404 GNUNET_MQ_handler_end()); 407 GNUNET_MQ_handler_end ());
405 408
406 409
407/* end of gnunet-service-regex.c */ 410/* end of gnunet-service-regex.c */
diff --git a/src/regex/perf-regex.c b/src/regex/perf-regex.c
index 25960dc9f..d41887f6b 100644
--- a/src/regex/perf-regex.c
+++ b/src/regex/perf-regex.c
@@ -42,23 +42,23 @@
42 * @param edges edges leaving current state. 42 * @param edges edges leaving current state.
43 */ 43 */
44static void 44static void
45print_edge(void *cls, 45print_edge (void *cls,
46 const struct GNUNET_HashCode *key, 46 const struct GNUNET_HashCode *key,
47 const char *proof, 47 const char *proof,
48 int accepting, 48 int accepting,
49 unsigned int num_edges, 49 unsigned int num_edges,
50 const struct REGEX_BLOCK_Edge *edges) 50 const struct REGEX_BLOCK_Edge *edges)
51{ 51{
52 unsigned int i; 52 unsigned int i;
53 53
54 printf("%s: %s, proof: `%s'\n", 54 printf ("%s: %s, proof: `%s'\n",
55 GNUNET_h2s(key), 55 GNUNET_h2s (key),
56 accepting ? "ACCEPTING" : "", 56 accepting ? "ACCEPTING" : "",
57 proof); 57 proof);
58 for (i = 0; i < num_edges; i++) 58 for (i = 0; i < num_edges; i++)
59 printf(" `%s': %s\n", 59 printf (" `%s': %s\n",
60 edges[i].label, 60 edges[i].label,
61 GNUNET_h2s(&edges[i].destination)); 61 GNUNET_h2s (&edges[i].destination));
62} 62}
63 63
64 64
@@ -73,9 +73,9 @@ print_edge(void *cls,
73 * @return 0 ok, 1 on error 73 * @return 0 ok, 1 on error
74 */ 74 */
75int 75int
76main(int argc, char *const *argv) 76main (int argc, char *const *argv)
77{ 77{
78 struct REGEX_INTERNAL_Automaton* dfa; 78 struct REGEX_INTERNAL_Automaton*dfa;
79 char **regexes; 79 char **regexes;
80 char *buffer; 80 char *buffer;
81 char *regex; 81 char *regex;
@@ -83,45 +83,45 @@ main(int argc, char *const *argv)
83 unsigned int alphabet_size; 83 unsigned int alphabet_size;
84 long size; 84 long size;
85 85
86 GNUNET_log_setup("perf-regex", "DEBUG", NULL); 86 GNUNET_log_setup ("perf-regex", "DEBUG", NULL);
87 if (4 != argc) 87 if (4 != argc)
88 { 88 {
89 fprintf(stderr, 89 fprintf (stderr,
90 "Usage: %s REGEX_FILE ALPHABET_SIZE COMPRESSION\n", 90 "Usage: %s REGEX_FILE ALPHABET_SIZE COMPRESSION\n",
91 argv[0]); 91 argv[0]);
92 return 1; 92 return 1;
93 } 93 }
94 regexes = REGEX_TEST_read_from_file(argv[1]); 94 regexes = REGEX_TEST_read_from_file (argv[1]);
95 if (NULL == regexes) 95 if (NULL == regexes)
96 { 96 {
97 fprintf(stderr, 97 fprintf (stderr,
98 "Failed to read regexes from `%s'\n", 98 "Failed to read regexes from `%s'\n",
99 argv[1]); 99 argv[1]);
100 return 2; 100 return 2;
101 } 101 }
102 alphabet_size = atoi(argv[2]); 102 alphabet_size = atoi (argv[2]);
103 compression = atoi(argv[3]); 103 compression = atoi (argv[3]);
104 printf("********* PERF-REGEX *********'\n"); 104 printf ("********* PERF-REGEX *********'\n");
105 printf("Using:\n file '%s'\n Alphabet size %u\n compression %d\n", 105 printf ("Using:\n file '%s'\n Alphabet size %u\n compression %d\n",
106 argv[1], alphabet_size, compression); 106 argv[1], alphabet_size, compression);
107 fflush(stdout); 107 fflush (stdout);
108 buffer = REGEX_TEST_combine(regexes, alphabet_size); 108 buffer = REGEX_TEST_combine (regexes, alphabet_size);
109 GNUNET_asprintf(&regex, "GNUNET_REGEX_PROFILER_(%s)(0|1)*", buffer); 109 GNUNET_asprintf (&regex, "GNUNET_REGEX_PROFILER_(%s)(0|1)*", buffer);
110 size = strlen(regex); 110 size = strlen (regex);
111 111
112 fprintf(stderr, 112 fprintf (stderr,
113 "Combined regex (%ld bytes):\n%s\n", 113 "Combined regex (%ld bytes):\n%s\n",
114 size, 114 size,
115 regex); 115 regex);
116 dfa = REGEX_INTERNAL_construct_dfa(regex, size, compression); 116 dfa = REGEX_INTERNAL_construct_dfa (regex, size, compression);
117 printf("********* ALL EDGES *********'\n"); 117 printf ("********* ALL EDGES *********'\n");
118 REGEX_INTERNAL_iterate_all_edges(dfa, &print_edge, NULL); 118 REGEX_INTERNAL_iterate_all_edges (dfa, &print_edge, NULL);
119 printf("\n\n********* REACHABLE EDGES *********'\n"); 119 printf ("\n\n********* REACHABLE EDGES *********'\n");
120 REGEX_INTERNAL_iterate_reachable_edges(dfa, &print_edge, NULL); 120 REGEX_INTERNAL_iterate_reachable_edges (dfa, &print_edge, NULL);
121 REGEX_INTERNAL_automaton_destroy(dfa); 121 REGEX_INTERNAL_automaton_destroy (dfa);
122 GNUNET_free(buffer); 122 GNUNET_free (buffer);
123 REGEX_TEST_free_from_file(regexes); 123 REGEX_TEST_free_from_file (regexes);
124 GNUNET_free(regex); 124 GNUNET_free (regex);
125 return 0; 125 return 0;
126} 126}
127 127
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c
index 9467c02b9..e8ff158dd 100644
--- a/src/regex/plugin_block_regex.c
+++ b/src/regex/plugin_block_regex.c
@@ -57,37 +57,38 @@
57 * by this @a type of block (this is not an error) 57 * by this @a type of block (this is not an error)
58 */ 58 */
59static struct GNUNET_BLOCK_Group * 59static struct GNUNET_BLOCK_Group *
60block_plugin_regex_create_group(void *cls, 60block_plugin_regex_create_group (void *cls,
61 enum GNUNET_BLOCK_Type type, 61 enum GNUNET_BLOCK_Type type,
62 uint32_t nonce, 62 uint32_t nonce,
63 const void *raw_data, 63 const void *raw_data,
64 size_t raw_data_size, 64 size_t raw_data_size,
65 va_list va) 65 va_list va)
66{ 66{
67 unsigned int bf_size; 67 unsigned int bf_size;
68 const char *guard; 68 const char *guard;
69 69
70 guard = va_arg(va, const char *); 70 guard = va_arg (va, const char *);
71 if (0 == strcmp(guard, 71 if (0 == strcmp (guard,
72 "seen-set-size")) 72 "seen-set-size"))
73 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), 73 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned
74 BLOOMFILTER_K); 74 int),
75 else if (0 == strcmp(guard, 75 BLOOMFILTER_K);
76 "filter-size")) 76 else if (0 == strcmp (guard,
77 bf_size = va_arg(va, unsigned int); 77 "filter-size"))
78 bf_size = va_arg (va, unsigned int);
78 else 79 else
79 { 80 {
80 GNUNET_break(0); 81 GNUNET_break (0);
81 bf_size = REGEX_BF_SIZE; 82 bf_size = REGEX_BF_SIZE;
82 } 83 }
83 GNUNET_break(NULL == va_arg(va, const char *)); 84 GNUNET_break (NULL == va_arg (va, const char *));
84 return GNUNET_BLOCK_GROUP_bf_create(cls, 85 return GNUNET_BLOCK_GROUP_bf_create (cls,
85 bf_size, 86 bf_size,
86 BLOOMFILTER_K, 87 BLOOMFILTER_K,
87 type, 88 type,
88 nonce, 89 nonce,
89 raw_data, 90 raw_data,
90 raw_data_size); 91 raw_data_size);
91} 92}
92 93
93 94
@@ -111,74 +112,74 @@ block_plugin_regex_create_group(void *cls,
111 * @return characterization of result 112 * @return characterization of result
112 */ 113 */
113static enum GNUNET_BLOCK_EvaluationResult 114static enum GNUNET_BLOCK_EvaluationResult
114evaluate_block_regex(void *cls, 115evaluate_block_regex (void *cls,
115 enum GNUNET_BLOCK_Type type, 116 enum GNUNET_BLOCK_Type type,
116 struct GNUNET_BLOCK_Group *bg, 117 struct GNUNET_BLOCK_Group *bg,
117 enum GNUNET_BLOCK_EvaluationOptions eo, 118 enum GNUNET_BLOCK_EvaluationOptions eo,
118 const struct GNUNET_HashCode *query, 119 const struct GNUNET_HashCode *query,
119 const void *xquery, 120 const void *xquery,
120 size_t xquery_size, 121 size_t xquery_size,
121 const void *reply_block, 122 const void *reply_block,
122 size_t reply_block_size) 123 size_t reply_block_size)
123{ 124{
124 struct GNUNET_HashCode chash; 125 struct GNUNET_HashCode chash;
125 126
126 if (NULL == reply_block) 127 if (NULL == reply_block)
127 { 128 {
128 if (0 != xquery_size) 129 if (0 != xquery_size)
129 {
130 const char *s;
131
132 s = (const char *)xquery;
133 if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */
134 {
135 GNUNET_break_op(0);
136 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
137 }
138 }
139 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
140 }
141 if (0 != xquery_size)
142 { 130 {
143 const char *s; 131 const char *s;
144 132
145 s = (const char *)xquery; 133 s = (const char *) xquery;
146 if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */ 134 if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */
147 { 135 {
148 GNUNET_break_op(0); 136 GNUNET_break_op (0);
149 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 137 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
150 } 138 }
151 } 139 }
152 else if (NULL != query) 140 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
141 }
142 if (0 != xquery_size)
143 {
144 const char *s;
145
146 s = (const char *) xquery;
147 if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */
153 { 148 {
154 /* xquery is required for regex GETs, at least an empty string */ 149 GNUNET_break_op (0);
155 GNUNET_break_op(0);
156 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "type %d, query %p, xquery %p\n",
157 type, query, xquery);
158 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 150 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
159 } 151 }
160 switch (REGEX_BLOCK_check(reply_block, 152 }
161 reply_block_size, 153 else if (NULL != query)
162 query, 154 {
163 xquery)) 155 /* xquery is required for regex GETs, at least an empty string */
164 { 156 GNUNET_break_op (0);
165 case GNUNET_SYSERR: 157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "type %d, query %p, xquery %p\n",
166 GNUNET_break_op(0); 158 type, query, xquery);
167 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 159 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
168 160 }
169 case GNUNET_NO: 161 switch (REGEX_BLOCK_check (reply_block,
170 /* xquery missmatch, can happen */ 162 reply_block_size,
171 return GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT; 163 query,
172 164 xquery))
173 default: 165 {
174 break; 166 case GNUNET_SYSERR:
175 } 167 GNUNET_break_op (0);
176 GNUNET_CRYPTO_hash(reply_block, 168 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
177 reply_block_size, 169
178 &chash); 170 case GNUNET_NO:
171 /* xquery missmatch, can happen */
172 return GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT;
173
174 default:
175 break;
176 }
177 GNUNET_CRYPTO_hash (reply_block,
178 reply_block_size,
179 &chash);
179 if (GNUNET_YES == 180 if (GNUNET_YES ==
180 GNUNET_BLOCK_GROUP_bf_test_and_set(bg, 181 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
181 &chash)) 182 &chash))
182 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 183 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
183 return GNUNET_BLOCK_EVALUATION_OK_MORE; 184 return GNUNET_BLOCK_EVALUATION_OK_MORE;
184} 185}
@@ -204,60 +205,62 @@ evaluate_block_regex(void *cls,
204 * @return characterization of result 205 * @return characterization of result
205 */ 206 */
206static enum GNUNET_BLOCK_EvaluationResult 207static enum GNUNET_BLOCK_EvaluationResult
207evaluate_block_regex_accept(void *cls, 208evaluate_block_regex_accept (void *cls,
208 enum GNUNET_BLOCK_Type type, 209 enum GNUNET_BLOCK_Type type,
209 struct GNUNET_BLOCK_Group *bg, 210 struct GNUNET_BLOCK_Group *bg,
210 enum GNUNET_BLOCK_EvaluationOptions eo, 211 enum GNUNET_BLOCK_EvaluationOptions eo,
211 const struct GNUNET_HashCode *query, 212 const struct GNUNET_HashCode *query,
212 const void *xquery, 213 const void *xquery,
213 size_t xquery_size, const void *reply_block, 214 size_t xquery_size, const void *reply_block,
214 size_t reply_block_size) 215 size_t reply_block_size)
215{ 216{
216 const struct RegexAcceptBlock *rba; 217 const struct RegexAcceptBlock *rba;
217 struct GNUNET_HashCode chash; 218 struct GNUNET_HashCode chash;
218 219
219 if (0 != xquery_size) 220 if (0 != xquery_size)
220 { 221 {
221 GNUNET_break_op(0); 222 GNUNET_break_op (0);
222 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 223 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
223 } 224 }
224 if (NULL == reply_block) 225 if (NULL == reply_block)
225 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 226 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
226 if (sizeof(struct RegexAcceptBlock) != reply_block_size) 227 if (sizeof(struct RegexAcceptBlock) != reply_block_size)
227 { 228 {
228 GNUNET_break_op(0); 229 GNUNET_break_op (0);
229 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 230 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
230 } 231 }
231 rba = reply_block; 232 rba = reply_block;
232 if (ntohl(rba->purpose.size) != 233 if (ntohl (rba->purpose.size) !=
233 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 234 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
234 sizeof(struct GNUNET_TIME_AbsoluteNBO) + 235 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
235 sizeof(struct GNUNET_HashCode)) 236 + sizeof(struct GNUNET_HashCode))
236 { 237 {
237 GNUNET_break_op(0); 238 GNUNET_break_op (0);
238 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 239 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
239 } 240 }
240 if (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(rba->expiration_time)).rel_value_us) 241 if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (
241 { 242 rba->expiration_time)).
242 /* technically invalid, but can happen without an error, so 243 rel_value_us)
243 we're nice by reporting it as a 'duplicate' */ 244 {
244 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 245 /* technically invalid, but can happen without an error, so
245 } 246 we're nice by reporting it as a 'duplicate' */
247 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
248 }
246 if (GNUNET_OK != 249 if (GNUNET_OK !=
247 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT, 250 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT,
248 &rba->purpose, 251 &rba->purpose,
249 &rba->signature, 252 &rba->signature,
250 &rba->peer.public_key)) 253 &rba->peer.public_key))
251 { 254 {
252 GNUNET_break_op(0); 255 GNUNET_break_op (0);
253 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 256 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
254 } 257 }
255 GNUNET_CRYPTO_hash(reply_block, 258 GNUNET_CRYPTO_hash (reply_block,
256 reply_block_size, 259 reply_block_size,
257 &chash); 260 &chash);
258 if (GNUNET_YES == 261 if (GNUNET_YES ==
259 GNUNET_BLOCK_GROUP_bf_test_and_set(bg, 262 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
260 &chash)) 263 &chash))
261 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 264 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
262 return GNUNET_BLOCK_EVALUATION_OK_MORE; 265 return GNUNET_BLOCK_EVALUATION_OK_MORE;
263} 266}
@@ -283,44 +286,44 @@ evaluate_block_regex_accept(void *cls,
283 * @return characterization of result 286 * @return characterization of result
284 */ 287 */
285static enum GNUNET_BLOCK_EvaluationResult 288static enum GNUNET_BLOCK_EvaluationResult
286block_plugin_regex_evaluate(void *cls, 289block_plugin_regex_evaluate (void *cls,
287 struct GNUNET_BLOCK_Context *ctx, 290 struct GNUNET_BLOCK_Context *ctx,
288 enum GNUNET_BLOCK_Type type, 291 enum GNUNET_BLOCK_Type type,
289 struct GNUNET_BLOCK_Group *bg, 292 struct GNUNET_BLOCK_Group *bg,
290 enum GNUNET_BLOCK_EvaluationOptions eo, 293 enum GNUNET_BLOCK_EvaluationOptions eo,
291 const struct GNUNET_HashCode *query, 294 const struct GNUNET_HashCode *query,
292 const void *xquery, 295 const void *xquery,
293 size_t xquery_size, 296 size_t xquery_size,
294 const void *reply_block, 297 const void *reply_block,
295 size_t reply_block_size) 298 size_t reply_block_size)
296{ 299{
297 enum GNUNET_BLOCK_EvaluationResult result; 300 enum GNUNET_BLOCK_EvaluationResult result;
298 301
299 switch (type) 302 switch (type)
300 { 303 {
301 case GNUNET_BLOCK_TYPE_REGEX: 304 case GNUNET_BLOCK_TYPE_REGEX:
302 result = evaluate_block_regex(cls, 305 result = evaluate_block_regex (cls,
303 type, 306 type,
304 bg, 307 bg,
305 eo, 308 eo,
306 query, 309 query,
307 xquery, xquery_size, 310 xquery, xquery_size,
308 reply_block, reply_block_size); 311 reply_block, reply_block_size);
309 break; 312 break;
310 313
311 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: 314 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT:
312 result = evaluate_block_regex_accept(cls, 315 result = evaluate_block_regex_accept (cls,
313 type, 316 type,
314 bg, 317 bg,
315 eo, 318 eo,
316 query, 319 query,
317 xquery, xquery_size, 320 xquery, xquery_size,
318 reply_block, reply_block_size); 321 reply_block, reply_block_size);
319 break; 322 break;
320 323
321 default: 324 default:
322 result = GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 325 result = GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
323 } 326 }
324 return result; 327 return result;
325} 328}
326 329
@@ -337,37 +340,37 @@ block_plugin_regex_evaluate(void *cls,
337 * (or if extracting a key from a block of this type does not work) 340 * (or if extracting a key from a block of this type does not work)
338 */ 341 */
339static int 342static int
340block_plugin_regex_get_key(void *cls, 343block_plugin_regex_get_key (void *cls,
341 enum GNUNET_BLOCK_Type type, 344 enum GNUNET_BLOCK_Type type,
342 const void *block, 345 const void *block,
343 size_t block_size, 346 size_t block_size,
344 struct GNUNET_HashCode *key) 347 struct GNUNET_HashCode *key)
345{ 348{
346 switch (type) 349 switch (type)
350 {
351 case GNUNET_BLOCK_TYPE_REGEX:
352 if (GNUNET_OK !=
353 REGEX_BLOCK_get_key (block, block_size,
354 key))
355 {
356 GNUNET_break_op (0);
357 return GNUNET_NO;
358 }
359 return GNUNET_OK;
360
361 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT:
362 if (sizeof(struct RegexAcceptBlock) != block_size)
347 { 363 {
348 case GNUNET_BLOCK_TYPE_REGEX: 364 GNUNET_break_op (0);
349 if (GNUNET_OK != 365 return GNUNET_NO;
350 REGEX_BLOCK_get_key(block, block_size,
351 key))
352 {
353 GNUNET_break_op(0);
354 return GNUNET_NO;
355 }
356 return GNUNET_OK;
357
358 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT:
359 if (sizeof(struct RegexAcceptBlock) != block_size)
360 {
361 GNUNET_break_op(0);
362 return GNUNET_NO;
363 }
364 *key = ((struct RegexAcceptBlock *)block)->key;
365 return GNUNET_OK;
366
367 default:
368 GNUNET_break(0);
369 return GNUNET_SYSERR;
370 } 366 }
367 *key = ((struct RegexAcceptBlock *) block)->key;
368 return GNUNET_OK;
369
370 default:
371 GNUNET_break (0);
372 return GNUNET_SYSERR;
373 }
371} 374}
372 375
373 376
@@ -375,17 +378,16 @@ block_plugin_regex_get_key(void *cls,
375 * Entry point for the plugin. 378 * Entry point for the plugin.
376 */ 379 */
377void * 380void *
378libgnunet_plugin_block_regex_init(void *cls) 381libgnunet_plugin_block_regex_init (void *cls)
379{ 382{
380 static enum GNUNET_BLOCK_Type types[] = 383 static enum GNUNET_BLOCK_Type types[] = {
381 {
382 GNUNET_BLOCK_TYPE_REGEX, 384 GNUNET_BLOCK_TYPE_REGEX,
383 GNUNET_BLOCK_TYPE_REGEX_ACCEPT, 385 GNUNET_BLOCK_TYPE_REGEX_ACCEPT,
384 GNUNET_BLOCK_TYPE_ANY /* end of list */ 386 GNUNET_BLOCK_TYPE_ANY /* end of list */
385 }; 387 };
386 struct GNUNET_BLOCK_PluginFunctions *api; 388 struct GNUNET_BLOCK_PluginFunctions *api;
387 389
388 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); 390 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
389 api->evaluate = &block_plugin_regex_evaluate; 391 api->evaluate = &block_plugin_regex_evaluate;
390 api->get_key = &block_plugin_regex_get_key; 392 api->get_key = &block_plugin_regex_get_key;
391 api->create_group = &block_plugin_regex_create_group; 393 api->create_group = &block_plugin_regex_create_group;
@@ -398,11 +400,11 @@ libgnunet_plugin_block_regex_init(void *cls)
398 * Exit point from the plugin. 400 * Exit point from the plugin.
399 */ 401 */
400void * 402void *
401libgnunet_plugin_block_regex_done(void *cls) 403libgnunet_plugin_block_regex_done (void *cls)
402{ 404{
403 struct GNUNET_BLOCK_PluginFunctions *api = cls; 405 struct GNUNET_BLOCK_PluginFunctions *api = cls;
404 406
405 GNUNET_free(api); 407 GNUNET_free (api);
406 return NULL; 408 return NULL;
407} 409}
408 410
diff --git a/src/regex/regex_api_announce.c b/src/regex/regex_api_announce.c
index 3b5801994..318d73263 100644
--- a/src/regex/regex_api_announce.c
+++ b/src/regex/regex_api_announce.c
@@ -29,12 +29,13 @@
29#include "gnunet_regex_service.h" 29#include "gnunet_regex_service.h"
30#include "regex_ipc.h" 30#include "regex_ipc.h"
31 31
32#define LOG(kind, ...) GNUNET_log_from(kind, "regex-api", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "regex-api", __VA_ARGS__)
33 33
34/** 34/**
35 * Handle to store cached data about a regex announce. 35 * Handle to store cached data about a regex announce.
36 */ 36 */
37struct GNUNET_REGEX_Announcement { 37struct GNUNET_REGEX_Announcement
38{
38 /** 39 /**
39 * Connection to the regex service. 40 * Connection to the regex service.
40 */ 41 */
@@ -69,7 +70,7 @@ struct GNUNET_REGEX_Announcement {
69 * @param a REGEX to announce. 70 * @param a REGEX to announce.
70 */ 71 */
71static void 72static void
72announce_reconnect(struct GNUNET_REGEX_Announcement *a); 73announce_reconnect (struct GNUNET_REGEX_Announcement *a);
73 74
74 75
75/** 76/**
@@ -80,14 +81,14 @@ announce_reconnect(struct GNUNET_REGEX_Announcement *a);
80 * @param error error code 81 * @param error error code
81 */ 82 */
82static void 83static void
83announce_mq_error_handler(void *cls, 84announce_mq_error_handler (void *cls,
84 enum GNUNET_MQ_Error error) 85 enum GNUNET_MQ_Error error)
85{ 86{
86 struct GNUNET_REGEX_Announcement *a = cls; 87 struct GNUNET_REGEX_Announcement *a = cls;
87 88
88 GNUNET_MQ_destroy(a->mq); 89 GNUNET_MQ_destroy (a->mq);
89 a->mq = NULL; 90 a->mq = NULL;
90 announce_reconnect(a); 91 announce_reconnect (a);
91} 92}
92 93
93 94
@@ -97,31 +98,31 @@ announce_mq_error_handler(void *cls,
97 * @param a REGEX to announce. 98 * @param a REGEX to announce.
98 */ 99 */
99static void 100static void
100announce_reconnect(struct GNUNET_REGEX_Announcement *a) 101announce_reconnect (struct GNUNET_REGEX_Announcement *a)
101{ 102{
102 struct GNUNET_MQ_Envelope *env; 103 struct GNUNET_MQ_Envelope *env;
103 struct AnnounceMessage *am; 104 struct AnnounceMessage *am;
104 size_t slen; 105 size_t slen;
105 106
106 a->mq = GNUNET_CLIENT_connect(a->cfg, 107 a->mq = GNUNET_CLIENT_connect (a->cfg,
107 "regex", 108 "regex",
108 NULL, 109 NULL,
109 &announce_mq_error_handler, 110 &announce_mq_error_handler,
110 a); 111 a);
111 if (NULL == a->mq) 112 if (NULL == a->mq)
112 return; 113 return;
113 slen = strlen(a->regex) + 1; 114 slen = strlen (a->regex) + 1;
114 env = GNUNET_MQ_msg_extra(am, 115 env = GNUNET_MQ_msg_extra (am,
115 slen, 116 slen,
116 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE); 117 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE);
117 am->compression = htons(a->compression); 118 am->compression = htons (a->compression);
118 am->reserved = htons(0); 119 am->reserved = htons (0);
119 am->refresh_delay = GNUNET_TIME_relative_hton(a->refresh_delay); 120 am->refresh_delay = GNUNET_TIME_relative_hton (a->refresh_delay);
120 GNUNET_memcpy(&am[1], 121 GNUNET_memcpy (&am[1],
121 a->regex, 122 a->regex,
122 slen); 123 slen);
123 GNUNET_MQ_send(a->mq, 124 GNUNET_MQ_send (a->mq,
124 env); 125 env);
125} 126}
126 127
127 128
@@ -136,35 +137,35 @@ announce_reconnect(struct GNUNET_REGEX_Announcement *a)
136 * Must be freed by calling #GNUNET_REGEX_announce_cancel(). 137 * Must be freed by calling #GNUNET_REGEX_announce_cancel().
137 */ 138 */
138struct GNUNET_REGEX_Announcement * 139struct GNUNET_REGEX_Announcement *
139GNUNET_REGEX_announce(const struct GNUNET_CONFIGURATION_Handle *cfg, 140GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg,
140 const char *regex, 141 const char *regex,
141 struct GNUNET_TIME_Relative refresh_delay, 142 struct GNUNET_TIME_Relative refresh_delay,
142 uint16_t compression) 143 uint16_t compression)
143{ 144{
144 struct GNUNET_REGEX_Announcement *a; 145 struct GNUNET_REGEX_Announcement *a;
145 size_t slen; 146 size_t slen;
146 147
147 slen = strlen(regex) + 1; 148 slen = strlen (regex) + 1;
148 if (slen + sizeof(struct AnnounceMessage) >= GNUNET_MAX_MESSAGE_SIZE) 149 if (slen + sizeof(struct AnnounceMessage) >= GNUNET_MAX_MESSAGE_SIZE)
149 { 150 {
150 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 151 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
151 _("Regex `%s' is too long!\n"), 152 _ ("Regex `%s' is too long!\n"),
152 regex); 153 regex);
153 GNUNET_break(0); 154 GNUNET_break (0);
154 return NULL; 155 return NULL;
155 } 156 }
156 a = GNUNET_new(struct GNUNET_REGEX_Announcement); 157 a = GNUNET_new (struct GNUNET_REGEX_Announcement);
157 a->cfg = cfg; 158 a->cfg = cfg;
158 a->refresh_delay = refresh_delay; 159 a->refresh_delay = refresh_delay;
159 a->compression = compression; 160 a->compression = compression;
160 a->regex = GNUNET_strdup(regex); 161 a->regex = GNUNET_strdup (regex);
161 announce_reconnect(a); 162 announce_reconnect (a);
162 if (NULL == a->mq) 163 if (NULL == a->mq)
163 { 164 {
164 GNUNET_free(a->regex); 165 GNUNET_free (a->regex);
165 GNUNET_free(a); 166 GNUNET_free (a);
166 return NULL; 167 return NULL;
167 } 168 }
168 return a; 169 return a;
169} 170}
170 171
@@ -175,11 +176,11 @@ GNUNET_REGEX_announce(const struct GNUNET_CONFIGURATION_Handle *cfg,
175 * @param a handle returned by a previous #GNUNET_REGEX_announce() call. 176 * @param a handle returned by a previous #GNUNET_REGEX_announce() call.
176 */ 177 */
177void 178void
178GNUNET_REGEX_announce_cancel(struct GNUNET_REGEX_Announcement *a) 179GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_Announcement *a)
179{ 180{
180 GNUNET_MQ_destroy(a->mq); 181 GNUNET_MQ_destroy (a->mq);
181 GNUNET_free(a->regex); 182 GNUNET_free (a->regex);
182 GNUNET_free(a); 183 GNUNET_free (a);
183} 184}
184 185
185/* end of regex_api_announce.c */ 186/* end of regex_api_announce.c */
diff --git a/src/regex/regex_api_search.c b/src/regex/regex_api_search.c
index 6a6a49a81..960719cbd 100644
--- a/src/regex/regex_api_search.c
+++ b/src/regex/regex_api_search.c
@@ -30,13 +30,14 @@
30#include "gnunet_regex_service.h" 30#include "gnunet_regex_service.h"
31#include "regex_ipc.h" 31#include "regex_ipc.h"
32 32
33#define LOG(kind, ...) GNUNET_log_from(kind, "regex-api", __VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from (kind, "regex-api", __VA_ARGS__)
34 34
35 35
36/** 36/**
37 * Handle to store data about a regex search. 37 * Handle to store data about a regex search.
38 */ 38 */
39struct GNUNET_REGEX_Search { 39struct GNUNET_REGEX_Search
40{
40 /** 41 /**
41 * Connection to the regex service. 42 * Connection to the regex service.
42 */ 43 */
@@ -70,7 +71,7 @@ struct GNUNET_REGEX_Search {
70 * @param s context for the search search for 71 * @param s context for the search search for
71 */ 72 */
72static void 73static void
73search_reconnect(struct GNUNET_REGEX_Search *s); 74search_reconnect (struct GNUNET_REGEX_Search *s);
74 75
75 76
76/** 77/**
@@ -82,18 +83,18 @@ search_reconnect(struct GNUNET_REGEX_Search *s);
82 * @return #GNUNET_SYSERR if @a rm is not well-formed. 83 * @return #GNUNET_SYSERR if @a rm is not well-formed.
83 */ 84 */
84static int 85static int
85check_search_response(void *cls, 86check_search_response (void *cls,
86 const struct ResultMessage *result) 87 const struct ResultMessage *result)
87{ 88{
88 uint16_t size = ntohs(result->header.size) - sizeof(*result); 89 uint16_t size = ntohs (result->header.size) - sizeof(*result);
89 uint16_t gpl = ntohs(result->get_path_length); 90 uint16_t gpl = ntohs (result->get_path_length);
90 uint16_t ppl = ntohs(result->put_path_length); 91 uint16_t ppl = ntohs (result->put_path_length);
91 92
92 if (size != (gpl + ppl) * sizeof(struct GNUNET_PeerIdentity)) 93 if (size != (gpl + ppl) * sizeof(struct GNUNET_PeerIdentity))
93 { 94 {
94 GNUNET_break(0); 95 GNUNET_break (0);
95 return GNUNET_SYSERR; 96 return GNUNET_SYSERR;
96 } 97 }
97 return GNUNET_OK; 98 return GNUNET_OK;
98} 99}
99 100
@@ -106,24 +107,24 @@ check_search_response(void *cls,
106 * @param result the message 107 * @param result the message
107 */ 108 */
108static void 109static void
109handle_search_response(void *cls, 110handle_search_response (void *cls,
110 const struct ResultMessage *result) 111 const struct ResultMessage *result)
111{ 112{
112 struct GNUNET_REGEX_Search *s = cls; 113 struct GNUNET_REGEX_Search *s = cls;
113 uint16_t gpl = ntohs(result->get_path_length); 114 uint16_t gpl = ntohs (result->get_path_length);
114 uint16_t ppl = ntohs(result->put_path_length); 115 uint16_t ppl = ntohs (result->put_path_length);
115 const struct GNUNET_PeerIdentity *pid; 116 const struct GNUNET_PeerIdentity *pid;
116 117
117 pid = &result->id; 118 pid = &result->id;
118 LOG(GNUNET_ERROR_TYPE_DEBUG, 119 LOG (GNUNET_ERROR_TYPE_DEBUG,
119 "Got regex result %s\n", 120 "Got regex result %s\n",
120 GNUNET_i2s(pid)); 121 GNUNET_i2s (pid));
121 s->callback(s->callback_cls, 122 s->callback (s->callback_cls,
122 pid, 123 pid,
123 &pid[1], 124 &pid[1],
124 gpl, 125 gpl,
125 &pid[1 + gpl], 126 &pid[1 + gpl],
126 ppl); 127 ppl);
127} 128}
128 129
129 130
@@ -135,14 +136,14 @@ handle_search_response(void *cls,
135 * @param error error code 136 * @param error error code
136 */ 137 */
137static void 138static void
138mq_error_handler(void *cls, 139mq_error_handler (void *cls,
139 enum GNUNET_MQ_Error error) 140 enum GNUNET_MQ_Error error)
140{ 141{
141 struct GNUNET_REGEX_Search *s = cls; 142 struct GNUNET_REGEX_Search *s = cls;
142 143
143 GNUNET_MQ_destroy(s->mq); 144 GNUNET_MQ_destroy (s->mq);
144 s->mq = NULL; 145 s->mq = NULL;
145 search_reconnect(s); 146 search_reconnect (s);
146} 147}
147 148
148 149
@@ -152,35 +153,35 @@ mq_error_handler(void *cls,
152 * @param s context for the search search for 153 * @param s context for the search search for
153 */ 154 */
154static void 155static void
155search_reconnect(struct GNUNET_REGEX_Search *s) 156search_reconnect (struct GNUNET_REGEX_Search *s)
156{ 157{
157 struct GNUNET_MQ_MessageHandler handlers[] = { 158 struct GNUNET_MQ_MessageHandler handlers[] = {
158 GNUNET_MQ_hd_var_size(search_response, 159 GNUNET_MQ_hd_var_size (search_response,
159 GNUNET_MESSAGE_TYPE_REGEX_RESULT, 160 GNUNET_MESSAGE_TYPE_REGEX_RESULT,
160 struct ResultMessage, 161 struct ResultMessage,
161 s), 162 s),
162 GNUNET_MQ_handler_end() 163 GNUNET_MQ_handler_end ()
163 }; 164 };
164 size_t slen = strlen(s->string) + 1; 165 size_t slen = strlen (s->string) + 1;
165 struct GNUNET_MQ_Envelope *env; 166 struct GNUNET_MQ_Envelope *env;
166 struct RegexSearchMessage *rsm; 167 struct RegexSearchMessage *rsm;
167 168
168 GNUNET_assert(NULL == s->mq); 169 GNUNET_assert (NULL == s->mq);
169 s->mq = GNUNET_CLIENT_connect(s->cfg, 170 s->mq = GNUNET_CLIENT_connect (s->cfg,
170 "regex", 171 "regex",
171 handlers, 172 handlers,
172 &mq_error_handler, 173 &mq_error_handler,
173 s); 174 s);
174 if (NULL == s->mq) 175 if (NULL == s->mq)
175 return; 176 return;
176 env = GNUNET_MQ_msg_extra(rsm, 177 env = GNUNET_MQ_msg_extra (rsm,
177 slen, 178 slen,
178 GNUNET_MESSAGE_TYPE_REGEX_SEARCH); 179 GNUNET_MESSAGE_TYPE_REGEX_SEARCH);
179 GNUNET_memcpy(&rsm[1], 180 GNUNET_memcpy (&rsm[1],
180 s->string, 181 s->string,
181 slen); 182 slen);
182 GNUNET_MQ_send(s->mq, 183 GNUNET_MQ_send (s->mq,
183 env); 184 env);
184} 185}
185 186
186 187
@@ -197,37 +198,37 @@ search_reconnect(struct GNUNET_REGEX_Search *s)
197 * Must be freed by calling #GNUNET_REGEX_search_cancel(). 198 * Must be freed by calling #GNUNET_REGEX_search_cancel().
198 */ 199 */
199struct GNUNET_REGEX_Search * 200struct GNUNET_REGEX_Search *
200GNUNET_REGEX_search(const struct GNUNET_CONFIGURATION_Handle *cfg, 201GNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg,
201 const char *string, 202 const char *string,
202 GNUNET_REGEX_Found callback, 203 GNUNET_REGEX_Found callback,
203 void *callback_cls) 204 void *callback_cls)
204{ 205{
205 struct GNUNET_REGEX_Search *s; 206 struct GNUNET_REGEX_Search *s;
206 size_t slen = strlen(string) + 1; 207 size_t slen = strlen (string) + 1;
207 208
208 if (slen + sizeof(struct RegexSearchMessage) >= GNUNET_MAX_MESSAGE_SIZE) 209 if (slen + sizeof(struct RegexSearchMessage) >= GNUNET_MAX_MESSAGE_SIZE)
209 { 210 {
210 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 211 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
211 _("Search string `%s' is too long!\n"), 212 _ ("Search string `%s' is too long!\n"),
212 string); 213 string);
213 GNUNET_break(0); 214 GNUNET_break (0);
214 return NULL; 215 return NULL;
215 } 216 }
216 LOG(GNUNET_ERROR_TYPE_DEBUG, 217 LOG (GNUNET_ERROR_TYPE_DEBUG,
217 "Starting regex search for %s\n", 218 "Starting regex search for %s\n",
218 string); 219 string);
219 s = GNUNET_new(struct GNUNET_REGEX_Search); 220 s = GNUNET_new (struct GNUNET_REGEX_Search);
220 s->cfg = cfg; 221 s->cfg = cfg;
221 s->string = GNUNET_strdup(string); 222 s->string = GNUNET_strdup (string);
222 s->callback = callback; 223 s->callback = callback;
223 s->callback_cls = callback_cls; 224 s->callback_cls = callback_cls;
224 search_reconnect(s); 225 search_reconnect (s);
225 if (NULL == s->mq) 226 if (NULL == s->mq)
226 { 227 {
227 GNUNET_free(s->string); 228 GNUNET_free (s->string);
228 GNUNET_free(s); 229 GNUNET_free (s);
229 return NULL; 230 return NULL;
230 } 231 }
231 return s; 232 return s;
232} 233}
233 234
@@ -238,11 +239,11 @@ GNUNET_REGEX_search(const struct GNUNET_CONFIGURATION_Handle *cfg,
238 * @param s Handle returned by a previous #GNUNET_REGEX_search() call. 239 * @param s Handle returned by a previous #GNUNET_REGEX_search() call.
239 */ 240 */
240void 241void
241GNUNET_REGEX_search_cancel(struct GNUNET_REGEX_Search *s) 242GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s)
242{ 243{
243 GNUNET_MQ_destroy(s->mq); 244 GNUNET_MQ_destroy (s->mq);
244 GNUNET_free(s->string); 245 GNUNET_free (s->string);
245 GNUNET_free(s); 246 GNUNET_free (s);
246} 247}
247 248
248 249
diff --git a/src/regex/regex_block_lib.c b/src/regex/regex_block_lib.c
index f0feb3628..2c6752e09 100644
--- a/src/regex/regex_block_lib.c
+++ b/src/regex/regex_block_lib.c
@@ -27,14 +27,15 @@
27#include "regex_block_lib.h" 27#include "regex_block_lib.h"
28#include "gnunet_constants.h" 28#include "gnunet_constants.h"
29 29
30#define LOG(kind, ...) GNUNET_log_from(kind, "regex-bck", __VA_ARGS__) 30#define LOG(kind, ...) GNUNET_log_from (kind, "regex-bck", __VA_ARGS__)
31 31
32GNUNET_NETWORK_STRUCT_BEGIN 32GNUNET_NETWORK_STRUCT_BEGIN
33 33
34/** 34/**
35 * Information for each edge. 35 * Information for each edge.
36 */ 36 */
37struct EdgeInfo { 37struct EdgeInfo
38{
38 /** 39 /**
39 * Index of the destination of this edge in the 40 * Index of the destination of this edge in the
40 * unique destinations array. 41 * unique destinations array.
@@ -52,7 +53,8 @@ struct EdgeInfo {
52/** 53/**
53 * @brief Block to announce a regex state. 54 * @brief Block to announce a regex state.
54 */ 55 */
55struct RegexBlock { 56struct RegexBlock
57{
56 /** 58 /**
57 * Length of the proof regex string. 59 * Length of the proof regex string.
58 */ 60 */
@@ -96,15 +98,15 @@ GNUNET_NETWORK_STRUCT_END
96 * @return #GNUNET_YES if the block is accepting, #GNUNET_NO if not 98 * @return #GNUNET_YES if the block is accepting, #GNUNET_NO if not
97 */ 99 */
98int 100int
99GNUNET_BLOCK_is_accepting(const struct RegexBlock *block, 101GNUNET_BLOCK_is_accepting (const struct RegexBlock *block,
100 size_t size) 102 size_t size)
101{ 103{
102 if (size < sizeof(struct RegexBlock)) 104 if (size < sizeof(struct RegexBlock))
103 { 105 {
104 GNUNET_break_op(0); 106 GNUNET_break_op (0);
105 return GNUNET_SYSERR; 107 return GNUNET_SYSERR;
106 } 108 }
107 return ntohs(block->is_accepting); 109 return ntohs (block->is_accepting);
108} 110}
109 111
110 112
@@ -117,27 +119,28 @@ GNUNET_BLOCK_is_accepting(const struct RegexBlock *block,
117 * @return #GNUNET_OK if the proof is valid for the given key. 119 * @return #GNUNET_OK if the proof is valid for the given key.
118 */ 120 */
119int 121int
120REGEX_BLOCK_check_proof(const char *proof, 122REGEX_BLOCK_check_proof (const char *proof,
121 size_t proof_len, 123 size_t proof_len,
122 const struct GNUNET_HashCode *key) 124 const struct GNUNET_HashCode *key)
123{ 125{
124 struct GNUNET_HashCode key_check; 126 struct GNUNET_HashCode key_check;
125 127
126 if ((NULL == proof) || (NULL == key)) 128 if ((NULL == proof) || (NULL == key))
127 { 129 {
128 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n"); 130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n");
129 return GNUNET_NO; 131 return GNUNET_NO;
130 } 132 }
131 GNUNET_CRYPTO_hash(proof, proof_len, &key_check); 133 GNUNET_CRYPTO_hash (proof, proof_len, &key_check);
132 return (0 == 134 return (0 ==
133 GNUNET_CRYPTO_hash_cmp(key, &key_check)) ? GNUNET_OK : GNUNET_NO; 135 GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO;
134} 136}
135 137
136 138
137/** 139/**
138 * Struct to keep track of the xquery while iterating all the edges in a block. 140 * Struct to keep track of the xquery while iterating all the edges in a block.
139 */ 141 */
140struct CheckEdgeContext { 142struct CheckEdgeContext
143{
141 /** 144 /**
142 * Xquery: string we are looking for. 145 * Xquery: string we are looking for.
143 */ 146 */
@@ -161,24 +164,24 @@ struct CheckEdgeContext {
161 * @return #GNUNET_YES, to keep iterating 164 * @return #GNUNET_YES, to keep iterating
162 */ 165 */
163static int 166static int
164check_edge(void *cls, 167check_edge (void *cls,
165 const char *token, 168 const char *token,
166 size_t len, 169 size_t len,
167 const struct GNUNET_HashCode *key) 170 const struct GNUNET_HashCode *key)
168{ 171{
169 struct CheckEdgeContext *ctx = cls; 172 struct CheckEdgeContext *ctx = cls;
170 173
171 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
172 "edge %.*s [%u]: %s\n", 175 "edge %.*s [%u]: %s\n",
173 (int)len, 176 (int) len,
174 token, 177 token,
175 (unsigned int)len, 178 (unsigned int) len,
176 GNUNET_h2s(key)); 179 GNUNET_h2s (key));
177 if (NULL == ctx->xquery) 180 if (NULL == ctx->xquery)
178 return GNUNET_YES; 181 return GNUNET_YES;
179 if (strlen(ctx->xquery) < len) 182 if (strlen (ctx->xquery) < len)
180 return GNUNET_YES; /* too long */ 183 return GNUNET_YES; /* too long */
181 if (0 == strncmp(ctx->xquery, token, len)) 184 if (0 == strncmp (ctx->xquery, token, len))
182 ctx->found = GNUNET_OK; 185 ctx->found = GNUNET_OK;
183 return GNUNET_YES; /* keep checking for malformed data! */ 186 return GNUNET_YES; /* keep checking for malformed data! */
184} 187}
@@ -197,48 +200,48 @@ check_edge(void *cls,
197 * #GNUNET_SYSERR if the block is invalid. 200 * #GNUNET_SYSERR if the block is invalid.
198 */ 201 */
199int 202int
200REGEX_BLOCK_check(const struct RegexBlock *block, 203REGEX_BLOCK_check (const struct RegexBlock *block,
201 size_t size, 204 size_t size,
202 const struct GNUNET_HashCode *query, 205 const struct GNUNET_HashCode *query,
203 const char *xquery) 206 const char *xquery)
204{ 207{
205 struct GNUNET_HashCode key; 208 struct GNUNET_HashCode key;
206 struct CheckEdgeContext ctx; 209 struct CheckEdgeContext ctx;
207 int res; 210 int res;
208 211
209 LOG(GNUNET_ERROR_TYPE_DEBUG, 212 LOG (GNUNET_ERROR_TYPE_DEBUG,
210 "Block check\n"); 213 "Block check\n");
211 if (GNUNET_OK != 214 if (GNUNET_OK !=
212 REGEX_BLOCK_get_key(block, size, 215 REGEX_BLOCK_get_key (block, size,
213 &key)) 216 &key))
214 { 217 {
215 GNUNET_break_op(0); 218 GNUNET_break_op (0);
216 return GNUNET_SYSERR; 219 return GNUNET_SYSERR;
217 } 220 }
218 if (NULL != query && 221 if ((NULL != query)&&
219 0 != GNUNET_memcmp(&key, 222 (0 != GNUNET_memcmp (&key,
220 query)) 223 query)) )
221 { 224 {
222 GNUNET_break_op(0); 225 GNUNET_break_op (0);
223 return GNUNET_SYSERR; 226 return GNUNET_SYSERR;
224 } 227 }
225 if ((GNUNET_YES == ntohs(block->is_accepting)) && 228 if ((GNUNET_YES == ntohs (block->is_accepting)) &&
226 ((NULL == xquery) || ('\0' == xquery[0]))) 229 ((NULL == xquery) || ('\0' == xquery[0])))
227 { 230 {
228 LOG(GNUNET_ERROR_TYPE_DEBUG, 231 LOG (GNUNET_ERROR_TYPE_DEBUG,
229 " out! Is accepting: %u, xquery %p\n", 232 " out! Is accepting: %u, xquery %p\n",
230 ntohs(block->is_accepting), 233 ntohs (block->is_accepting),
231 xquery); 234 xquery);
232 return GNUNET_OK; 235 return GNUNET_OK;
233 } 236 }
234 ctx.xquery = xquery; 237 ctx.xquery = xquery;
235 ctx.found = GNUNET_NO; 238 ctx.found = GNUNET_NO;
236 res = REGEX_BLOCK_iterate(block, size, &check_edge, &ctx); 239 res = REGEX_BLOCK_iterate (block, size, &check_edge, &ctx);
237 if (GNUNET_SYSERR == res) 240 if (GNUNET_SYSERR == res)
238 return GNUNET_SYSERR; 241 return GNUNET_SYSERR;
239 if (NULL == xquery) 242 if (NULL == xquery)
240 return GNUNET_YES; 243 return GNUNET_YES;
241 LOG(GNUNET_ERROR_TYPE_DEBUG, "Result %d\n", ctx.found); 244 LOG (GNUNET_ERROR_TYPE_DEBUG, "Result %d\n", ctx.found);
242 return ctx.found; 245 return ctx.found;
243} 246}
244 247
@@ -252,9 +255,9 @@ REGEX_BLOCK_check(const struct RegexBlock *block,
252 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block is malformed 255 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block is malformed
253 */ 256 */
254int 257int
255REGEX_BLOCK_get_key(const struct RegexBlock *block, 258REGEX_BLOCK_get_key (const struct RegexBlock *block,
256 size_t block_len, 259 size_t block_len,
257 struct GNUNET_HashCode *key) 260 struct GNUNET_HashCode *key)
258{ 261{
259 uint16_t len; 262 uint16_t len;
260 const struct GNUNET_HashCode *destinations; 263 const struct GNUNET_HashCode *destinations;
@@ -264,22 +267,24 @@ REGEX_BLOCK_get_key(const struct RegexBlock *block,
264 size_t total; 267 size_t total;
265 268
266 if (block_len < sizeof(struct RegexBlock)) 269 if (block_len < sizeof(struct RegexBlock))
267 { 270 {
268 GNUNET_break_op(0); 271 GNUNET_break_op (0);
269 return GNUNET_SYSERR; 272 return GNUNET_SYSERR;
270 } 273 }
271 num_destinations = ntohs(block->num_destinations); 274 num_destinations = ntohs (block->num_destinations);
272 num_edges = ntohs(block->num_edges); 275 num_edges = ntohs (block->num_edges);
273 len = ntohs(block->proof_len); 276 len = ntohs (block->proof_len);
274 destinations = (const struct GNUNET_HashCode *)&block[1]; 277 destinations = (const struct GNUNET_HashCode *) &block[1];
275 edges = (const struct EdgeInfo *)&destinations[num_destinations]; 278 edges = (const struct EdgeInfo *) &destinations[num_destinations];
276 total = sizeof(struct RegexBlock) + num_destinations * sizeof(struct GNUNET_HashCode) + num_edges * sizeof(struct EdgeInfo) + len; 279 total = sizeof(struct RegexBlock) + num_destinations * sizeof(struct
280 GNUNET_HashCode)
281 + num_edges * sizeof(struct EdgeInfo) + len;
277 if (block_len < total) 282 if (block_len < total)
278 { 283 {
279 GNUNET_break_op(0); 284 GNUNET_break_op (0);
280 return GNUNET_SYSERR; 285 return GNUNET_SYSERR;
281 } 286 }
282 GNUNET_CRYPTO_hash(&edges[num_edges], len, key); 287 GNUNET_CRYPTO_hash (&edges[num_edges], len, key);
283 return GNUNET_OK; 288 return GNUNET_OK;
284} 289}
285 290
@@ -300,10 +305,10 @@ REGEX_BLOCK_get_key(const struct RegexBlock *block,
300 * be errors in further edges. 305 * be errors in further edges.
301 */ 306 */
302int 307int
303REGEX_BLOCK_iterate(const struct RegexBlock *block, 308REGEX_BLOCK_iterate (const struct RegexBlock *block,
304 size_t size, 309 size_t size,
305 REGEX_INTERNAL_EgdeIterator iterator, 310 REGEX_INTERNAL_EgdeIterator iterator,
306 void *iter_cls) 311 void *iter_cls)
307{ 312{
308 uint16_t len; 313 uint16_t len;
309 const struct GNUNET_HashCode *destinations; 314 const struct GNUNET_HashCode *destinations;
@@ -315,54 +320,57 @@ REGEX_BLOCK_iterate(const struct RegexBlock *block,
315 unsigned int n; 320 unsigned int n;
316 size_t off; 321 size_t off;
317 322
318 LOG(GNUNET_ERROR_TYPE_DEBUG, "Block iterate\n"); 323 LOG (GNUNET_ERROR_TYPE_DEBUG, "Block iterate\n");
319 if (size < sizeof(struct RegexBlock)) 324 if (size < sizeof(struct RegexBlock))
320 { 325 {
321 GNUNET_break_op(0); 326 GNUNET_break_op (0);
322 return GNUNET_SYSERR; 327 return GNUNET_SYSERR;
323 } 328 }
324 num_destinations = ntohs(block->num_destinations); 329 num_destinations = ntohs (block->num_destinations);
325 num_edges = ntohs(block->num_edges); 330 num_edges = ntohs (block->num_edges);
326 len = ntohs(block->proof_len); 331 len = ntohs (block->proof_len);
327 destinations = (const struct GNUNET_HashCode *)&block[1]; 332 destinations = (const struct GNUNET_HashCode *) &block[1];
328 edges = (const struct EdgeInfo *)&destinations[num_destinations]; 333 edges = (const struct EdgeInfo *) &destinations[num_destinations];
329 aux = (const char *)&edges[num_edges]; 334 aux = (const char *) &edges[num_edges];
330 total = sizeof(struct RegexBlock) + num_destinations * sizeof(struct GNUNET_HashCode) + num_edges * sizeof(struct EdgeInfo) + len; 335 total = sizeof(struct RegexBlock) + num_destinations * sizeof(struct
336 GNUNET_HashCode)
337 + num_edges * sizeof(struct EdgeInfo) + len;
331 if (size < total) 338 if (size < total)
332 { 339 {
333 GNUNET_break_op(0); 340 GNUNET_break_op (0);
334 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
335 } 342 }
336 for (n = 0; n < num_edges; n++) 343 for (n = 0; n < num_edges; n++)
337 total += ntohs(edges[n].token_length); 344 total += ntohs (edges[n].token_length);
338 if (size != total) 345 if (size != total)
339 { 346 {
340 fprintf(stderr, "Expected %u, got %u\n", 347 fprintf (stderr, "Expected %u, got %u\n",
341 (unsigned int)size, 348 (unsigned int) size,
342 (unsigned int)total); 349 (unsigned int) total);
343 GNUNET_break_op(0); 350 GNUNET_break_op (0);
344 return GNUNET_SYSERR; 351 return GNUNET_SYSERR;
345 } 352 }
346 off = len; 353 off = len;
347 LOG(GNUNET_ERROR_TYPE_DEBUG, 354 LOG (GNUNET_ERROR_TYPE_DEBUG,
348 "Start iterating block of size %u, proof %u, off %u edges %u\n", 355 "Start iterating block of size %u, proof %u, off %u edges %u\n",
349 size, len, off, n); 356 size, len, off, n);
350 /* &aux[off] always points to our token */ 357 /* &aux[off] always points to our token */
351 for (n = 0; n < num_edges; n++) 358 for (n = 0; n < num_edges; n++)
352 { 359 {
353 LOG(GNUNET_ERROR_TYPE_DEBUG, 360 LOG (GNUNET_ERROR_TYPE_DEBUG,
354 "Edge %u/%u, off %u tokenlen %u (%.*s)\n", 361 "Edge %u/%u, off %u tokenlen %u (%.*s)\n",
355 n + 1, num_edges, off, 362 n + 1, num_edges, off,
356 ntohs(edges[n].token_length), ntohs(edges[n].token_length), 363 ntohs (edges[n].token_length), ntohs (edges[n].token_length),
357 &aux[off]); 364 &aux[off]);
358 if (NULL != iterator) 365 if (NULL != iterator)
359 if (GNUNET_NO == iterator(iter_cls, 366 if (GNUNET_NO == iterator (iter_cls,
360 &aux[off], 367 &aux[off],
361 ntohs(edges[n].token_length), 368 ntohs (edges[n].token_length),
362 &destinations[ntohs(edges[n].destination_index)])) 369 &destinations[ntohs (
363 return GNUNET_OK; 370 edges[n].destination_index)]))
364 off += ntohs(edges[n].token_length); 371 return GNUNET_OK;
365 } 372 off += ntohs (edges[n].token_length);
373 }
366 return GNUNET_OK; 374 return GNUNET_OK;
367} 375}
368 376
@@ -378,11 +386,11 @@ REGEX_BLOCK_iterate(const struct RegexBlock *block,
378 * @return the regex block, NULL on error 386 * @return the regex block, NULL on error
379 */ 387 */
380struct RegexBlock * 388struct RegexBlock *
381REGEX_BLOCK_create(const char *proof, 389REGEX_BLOCK_create (const char *proof,
382 unsigned int num_edges, 390 unsigned int num_edges,
383 const struct REGEX_BLOCK_Edge *edges, 391 const struct REGEX_BLOCK_Edge *edges,
384 int accepting, 392 int accepting,
385 size_t *rsize) 393 size_t *rsize)
386{ 394{
387 struct RegexBlock *block; 395 struct RegexBlock *block;
388 struct GNUNET_HashCode destinations[1024]; /* 1024 = 64k/64 bytes/key == absolute MAX */ 396 struct GNUNET_HashCode destinations[1024]; /* 1024 = 64k/64 bytes/key == absolute MAX */
@@ -398,64 +406,66 @@ REGEX_BLOCK_create(const char *proof,
398 unsigned int i; 406 unsigned int i;
399 char *aux; 407 char *aux;
400 408
401 len = strlen(proof); 409 len = strlen (proof);
402 if (len > UINT16_MAX) 410 if (len > UINT16_MAX)
403 { 411 {
404 GNUNET_break(0); 412 GNUNET_break (0);
405 return NULL; 413 return NULL;
406 } 414 }
407 unique_destinations = 0; 415 unique_destinations = 0;
408 total = sizeof(struct RegexBlock) + len; 416 total = sizeof(struct RegexBlock) + len;
409 for (i = 0; i < num_edges; i++) 417 for (i = 0; i < num_edges; i++)
418 {
419 slen = strlen (edges[i].label);
420 if (slen > UINT16_MAX)
410 { 421 {
411 slen = strlen(edges[i].label); 422 GNUNET_break (0);
412 if (slen > UINT16_MAX) 423 return NULL;
413 {
414 GNUNET_break(0);
415 return NULL;
416 }
417 total += slen;
418 for (j = 0; j < unique_destinations; j++)
419 if (0 == memcmp(&destinations[j],
420 &edges[i].destination,
421 sizeof(struct GNUNET_HashCode)))
422 break;
423 if (j >= 1024)
424 {
425 GNUNET_break(0);
426 return NULL;
427 }
428 destination_indices[i] = j;
429 if (j == unique_destinations)
430 destinations[unique_destinations++] = edges[i].destination;
431 } 424 }
432 total += num_edges * sizeof(struct EdgeInfo) + unique_destinations * sizeof(struct GNUNET_HashCode); 425 total += slen;
433 if (total >= GNUNET_CONSTANTS_MAX_BLOCK_SIZE) 426 for (j = 0; j < unique_destinations; j++)
427 if (0 == memcmp (&destinations[j],
428 &edges[i].destination,
429 sizeof(struct GNUNET_HashCode)))
430 break;
431 if (j >= 1024)
434 { 432 {
435 GNUNET_break(0); 433 GNUNET_break (0);
436 return NULL; 434 return NULL;
437 } 435 }
438 block = GNUNET_malloc(total); 436 destination_indices[i] = j;
439 block->proof_len = htons(len); 437 if (j == unique_destinations)
440 block->is_accepting = htons(accepting); 438 destinations[unique_destinations++] = edges[i].destination;
441 block->num_edges = htons(num_edges); 439 }
442 block->num_destinations = htons(unique_destinations); 440 total += num_edges * sizeof(struct EdgeInfo) + unique_destinations
443 dests = (struct GNUNET_HashCode *)&block[1]; 441 * sizeof(struct GNUNET_HashCode);
444 GNUNET_memcpy(dests, destinations, sizeof(struct GNUNET_HashCode) * unique_destinations); 442 if (total >= GNUNET_CONSTANTS_MAX_BLOCK_SIZE)
445 edgeinfos = (struct EdgeInfo *)&dests[unique_destinations]; 443 {
446 aux = (char *)&edgeinfos[num_edges]; 444 GNUNET_break (0);
445 return NULL;
446 }
447 block = GNUNET_malloc (total);
448 block->proof_len = htons (len);
449 block->is_accepting = htons (accepting);
450 block->num_edges = htons (num_edges);
451 block->num_destinations = htons (unique_destinations);
452 dests = (struct GNUNET_HashCode *) &block[1];
453 GNUNET_memcpy (dests, destinations, sizeof(struct GNUNET_HashCode)
454 * unique_destinations);
455 edgeinfos = (struct EdgeInfo *) &dests[unique_destinations];
456 aux = (char *) &edgeinfos[num_edges];
447 off = len; 457 off = len;
448 GNUNET_memcpy(aux, proof, len); 458 GNUNET_memcpy (aux, proof, len);
449 for (i = 0; i < num_edges; i++) 459 for (i = 0; i < num_edges; i++)
450 { 460 {
451 slen = strlen(edges[i].label); 461 slen = strlen (edges[i].label);
452 edgeinfos[i].token_length = htons((uint16_t)slen); 462 edgeinfos[i].token_length = htons ((uint16_t) slen);
453 edgeinfos[i].destination_index = htons(destination_indices[i]); 463 edgeinfos[i].destination_index = htons (destination_indices[i]);
454 GNUNET_memcpy(&aux[off], 464 GNUNET_memcpy (&aux[off],
455 edges[i].label, 465 edges[i].label,
456 slen); 466 slen);
457 off += slen; 467 off += slen;
458 } 468 }
459 *rsize = total; 469 *rsize = total;
460 return block; 470 return block;
461} 471}
diff --git a/src/regex/regex_block_lib.h b/src/regex/regex_block_lib.h
index 6b2d3bf26..3368e3456 100644
--- a/src/regex/regex_block_lib.h
+++ b/src/regex/regex_block_lib.h
@@ -49,7 +49,8 @@ struct RegexBlock;
49/** 49/**
50 * Edge representation. 50 * Edge representation.
51 */ 51 */
52struct REGEX_BLOCK_Edge { 52struct REGEX_BLOCK_Edge
53{
53 /** 54 /**
54 * Label of the edge. FIXME: might want to not consume exactly 55 * Label of the edge. FIXME: might want to not consume exactly
55 * multiples of 8 bits, need length! 56 * multiples of 8 bits, need length!
@@ -72,9 +73,9 @@ struct REGEX_BLOCK_Edge {
72 * @return #GNUNET_OK if the proof is valid for the given key. 73 * @return #GNUNET_OK if the proof is valid for the given key.
73 */ 74 */
74int 75int
75REGEX_BLOCK_check_proof(const char *proof, 76REGEX_BLOCK_check_proof (const char *proof,
76 size_t proof_len, 77 size_t proof_len,
77 const struct GNUNET_HashCode *key); 78 const struct GNUNET_HashCode *key);
78 79
79 80
80/** 81/**
@@ -90,10 +91,10 @@ REGEX_BLOCK_check_proof(const char *proof,
90 * #GNUNET_SYSERR if the block is invalid. 91 * #GNUNET_SYSERR if the block is invalid.
91 */ 92 */
92int 93int
93REGEX_BLOCK_check(const struct RegexBlock *block, 94REGEX_BLOCK_check (const struct RegexBlock *block,
94 size_t size, 95 size_t size,
95 const struct GNUNET_HashCode *query, 96 const struct GNUNET_HashCode *query,
96 const char *xquery); 97 const char *xquery);
97 98
98 99
99/* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */ 100/* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */
@@ -130,10 +131,10 @@ typedef int
130 * be errors in further edges. 131 * be errors in further edges.
131 */ 132 */
132int 133int
133REGEX_BLOCK_iterate(const struct RegexBlock *block, 134REGEX_BLOCK_iterate (const struct RegexBlock *block,
134 size_t size, 135 size_t size,
135 REGEX_INTERNAL_EgdeIterator iterator, 136 REGEX_INTERNAL_EgdeIterator iterator,
136 void *iter_cls); 137 void *iter_cls);
137 138
138 139
139/** 140/**
@@ -145,9 +146,9 @@ REGEX_BLOCK_iterate(const struct RegexBlock *block,
145 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block is malformed 146 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block is malformed
146 */ 147 */
147int 148int
148REGEX_BLOCK_get_key(const struct RegexBlock *block, 149REGEX_BLOCK_get_key (const struct RegexBlock *block,
149 size_t block_len, 150 size_t block_len,
150 struct GNUNET_HashCode *key); 151 struct GNUNET_HashCode *key);
151 152
152 153
153/** 154/**
@@ -158,8 +159,8 @@ REGEX_BLOCK_get_key(const struct RegexBlock *block,
158 * @return #GNUNET_YES if the block is accepting, #GNUNET_NO if not 159 * @return #GNUNET_YES if the block is accepting, #GNUNET_NO if not
159 */ 160 */
160int 161int
161GNUNET_BLOCK_is_accepting(const struct RegexBlock *block, 162GNUNET_BLOCK_is_accepting (const struct RegexBlock *block,
162 size_t block_len); 163 size_t block_len);
163 164
164 165
165/** 166/**
@@ -173,11 +174,11 @@ GNUNET_BLOCK_is_accepting(const struct RegexBlock *block,
173 * @return the regex block, NULL on error 174 * @return the regex block, NULL on error
174 */ 175 */
175struct RegexBlock * 176struct RegexBlock *
176REGEX_BLOCK_create(const char *proof, 177REGEX_BLOCK_create (const char *proof,
177 unsigned int num_edges, 178 unsigned int num_edges,
178 const struct REGEX_BLOCK_Edge *edges, 179 const struct REGEX_BLOCK_Edge *edges,
179 int accepting, 180 int accepting,
180 size_t *rsize); 181 size_t *rsize);
181 182
182 183
183#if 0 /* keep Emacsens' auto-indent happy */ 184#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/regex/regex_internal.c b/src/regex/regex_internal.c
index 34f0d9c42..78c2de8ab 100644
--- a/src/regex/regex_internal.c
+++ b/src/regex/regex_internal.c
@@ -39,7 +39,8 @@
39/** 39/**
40 * Set of states using MDLL API. 40 * Set of states using MDLL API.
41 */ 41 */
42struct REGEX_INTERNAL_StateSet_MDLL { 42struct REGEX_INTERNAL_StateSet_MDLL
43{
43 /** 44 /**
44 * MDLL of states. 45 * MDLL of states.
45 */ 46 */
@@ -64,11 +65,11 @@ struct REGEX_INTERNAL_StateSet_MDLL {
64 * @param state state to be appended 65 * @param state state to be appended
65 */ 66 */
66static void 67static void
67state_set_append(struct REGEX_INTERNAL_StateSet *set, 68state_set_append (struct REGEX_INTERNAL_StateSet *set,
68 struct REGEX_INTERNAL_State *state) 69 struct REGEX_INTERNAL_State *state)
69{ 70{
70 if (set->off == set->size) 71 if (set->off == set->size)
71 GNUNET_array_grow(set->states, set->size, set->size * 2 + 4); 72 GNUNET_array_grow (set->states, set->size, set->size * 2 + 4);
72 set->states[set->off++] = state; 73 set->states[set->off++] = state;
73} 74}
74 75
@@ -82,14 +83,14 @@ state_set_append(struct REGEX_INTERNAL_StateSet *set,
82 * @return 0 if the strings are the same or both NULL, 1 or -1 if not. 83 * @return 0 if the strings are the same or both NULL, 1 or -1 if not.
83 */ 84 */
84static int 85static int
85nullstrcmp(const char *str1, const char *str2) 86nullstrcmp (const char *str1, const char *str2)
86{ 87{
87 if ((NULL == str1) != (NULL == str2)) 88 if ((NULL == str1) != (NULL == str2))
88 return -1; 89 return -1;
89 if ((NULL == str1) && (NULL == str2)) 90 if ((NULL == str1) && (NULL == str2))
90 return 0; 91 return 0;
91 92
92 return strcmp(str1, str2); 93 return strcmp (str1, str2);
93} 94}
94 95
95 96
@@ -103,40 +104,40 @@ nullstrcmp(const char *str1, const char *str2)
103 * @param to_state state to where the transition should point to 104 * @param to_state state to where the transition should point to
104 */ 105 */
105static void 106static void
106state_add_transition(struct REGEX_INTERNAL_Context *ctx, 107state_add_transition (struct REGEX_INTERNAL_Context *ctx,
107 struct REGEX_INTERNAL_State *from_state, 108 struct REGEX_INTERNAL_State *from_state,
108 const char *label, 109 const char *label,
109 struct REGEX_INTERNAL_State *to_state) 110 struct REGEX_INTERNAL_State *to_state)
110{ 111{
111 struct REGEX_INTERNAL_Transition *t; 112 struct REGEX_INTERNAL_Transition *t;
112 struct REGEX_INTERNAL_Transition *oth; 113 struct REGEX_INTERNAL_Transition *oth;
113 114
114 if (NULL == from_state) 115 if (NULL == from_state)
115 { 116 {
116 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not create Transition.\n"); 117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create Transition.\n");
117 return; 118 return;
118 } 119 }
119 120
120 /* Do not add duplicate state transitions */ 121 /* Do not add duplicate state transitions */
121 for (t = from_state->transitions_head; NULL != t; t = t->next) 122 for (t = from_state->transitions_head; NULL != t; t = t->next)
122 { 123 {
123 if (t->to_state == to_state && 0 == nullstrcmp(t->label, label) && 124 if ((t->to_state == to_state) &&(0 == nullstrcmp (t->label, label)) &&
124 t->from_state == from_state) 125 (t->from_state == from_state) )
125 return; 126 return;
126 } 127 }
127 128
128 /* sort transitions by label */ 129 /* sort transitions by label */
129 for (oth = from_state->transitions_head; NULL != oth; oth = oth->next) 130 for (oth = from_state->transitions_head; NULL != oth; oth = oth->next)
130 { 131 {
131 if (0 < nullstrcmp(oth->label, label)) 132 if (0 < nullstrcmp (oth->label, label))
132 break; 133 break;
133 } 134 }
134 135
135 t = GNUNET_new(struct REGEX_INTERNAL_Transition); 136 t = GNUNET_new (struct REGEX_INTERNAL_Transition);
136 if (NULL != ctx) 137 if (NULL != ctx)
137 t->id = ctx->transition_id++; 138 t->id = ctx->transition_id++;
138 if (NULL != label) 139 if (NULL != label)
139 t->label = GNUNET_strdup(label); 140 t->label = GNUNET_strdup (label);
140 else 141 else
141 t->label = NULL; 142 t->label = NULL;
142 t->to_state = to_state; 143 t->to_state = to_state;
@@ -144,10 +145,10 @@ state_add_transition(struct REGEX_INTERNAL_Context *ctx,
144 145
145 /* Add outgoing transition to 'from_state' */ 146 /* Add outgoing transition to 'from_state' */
146 from_state->transition_count++; 147 from_state->transition_count++;
147 GNUNET_CONTAINER_DLL_insert_before(from_state->transitions_head, 148 GNUNET_CONTAINER_DLL_insert_before (from_state->transitions_head,
148 from_state->transitions_tail, 149 from_state->transitions_tail,
149 oth, 150 oth,
150 t); 151 t);
151} 152}
152 153
153 154
@@ -158,23 +159,23 @@ state_add_transition(struct REGEX_INTERNAL_Context *ctx,
158 * @param transition transition that should be removed from state 'state'. 159 * @param transition transition that should be removed from state 'state'.
159 */ 160 */
160static void 161static void
161state_remove_transition(struct REGEX_INTERNAL_State *state, 162state_remove_transition (struct REGEX_INTERNAL_State *state,
162 struct REGEX_INTERNAL_Transition *transition) 163 struct REGEX_INTERNAL_Transition *transition)
163{ 164{
164 if (NULL == state || NULL == transition) 165 if ((NULL == state)||(NULL == transition))
165 return; 166 return;
166 167
167 if (transition->from_state != state) 168 if (transition->from_state != state)
168 return; 169 return;
169 170
170 GNUNET_free_non_null(transition->label); 171 GNUNET_free_non_null (transition->label);
171 172
172 state->transition_count--; 173 state->transition_count--;
173 GNUNET_CONTAINER_DLL_remove(state->transitions_head, 174 GNUNET_CONTAINER_DLL_remove (state->transitions_head,
174 state->transitions_tail, 175 state->transitions_tail,
175 transition); 176 transition);
176 177
177 GNUNET_free(transition); 178 GNUNET_free (transition);
178} 179}
179 180
180 181
@@ -189,10 +190,10 @@ state_remove_transition(struct REGEX_INTERNAL_State *state,
189 * less than, equal to, or greater than the second. 190 * less than, equal to, or greater than the second.
190 */ 191 */
191static int 192static int
192state_compare(const void *a, const void *b) 193state_compare (const void *a, const void *b)
193{ 194{
194 struct REGEX_INTERNAL_State **s1 = (struct REGEX_INTERNAL_State **)a; 195 struct REGEX_INTERNAL_State **s1 = (struct REGEX_INTERNAL_State **) a;
195 struct REGEX_INTERNAL_State **s2 = (struct REGEX_INTERNAL_State **)b; 196 struct REGEX_INTERNAL_State **s2 = (struct REGEX_INTERNAL_State **) b;
196 197
197 return (*s1)->id - (*s2)->id; 198 return (*s1)->id - (*s2)->id;
198} 199}
@@ -208,7 +209,7 @@ state_compare(const void *a, const void *b)
208 * @return number of edges. 209 * @return number of edges.
209 */ 210 */
210static unsigned int 211static unsigned int
211state_get_edges(struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges) 212state_get_edges (struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges)
212{ 213{
213 struct REGEX_INTERNAL_Transition *t; 214 struct REGEX_INTERNAL_Transition *t;
214 unsigned int count; 215 unsigned int count;
@@ -219,14 +220,14 @@ state_get_edges(struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges)
219 count = 0; 220 count = 0;
220 221
221 for (t = s->transitions_head; NULL != t; t = t->next) 222 for (t = s->transitions_head; NULL != t; t = t->next)
223 {
224 if (NULL != t->to_state)
222 { 225 {
223 if (NULL != t->to_state) 226 edges[count].label = t->label;
224 { 227 edges[count].destination = t->to_state->hash;
225 edges[count].label = t->label; 228 count++;
226 edges[count].destination = t->to_state->hash;
227 count++;
228 }
229 } 229 }
230 }
230 return count; 231 return count;
231} 232}
232 233
@@ -240,13 +241,13 @@ state_get_edges(struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges)
240 * @return 0 if the sets are equal, otherwise non-zero 241 * @return 0 if the sets are equal, otherwise non-zero
241 */ 242 */
242static int 243static int
243state_set_compare(struct REGEX_INTERNAL_StateSet *sset1, 244state_set_compare (struct REGEX_INTERNAL_StateSet *sset1,
244 struct REGEX_INTERNAL_StateSet *sset2) 245 struct REGEX_INTERNAL_StateSet *sset2)
245{ 246{
246 int result; 247 int result;
247 unsigned int i; 248 unsigned int i;
248 249
249 if (NULL == sset1 || NULL == sset2) 250 if ((NULL == sset1)||(NULL == sset2))
250 return 1; 251 return 1;
251 252
252 result = sset1->off - sset2->off; 253 result = sset1->off - sset2->off;
@@ -255,7 +256,7 @@ state_set_compare(struct REGEX_INTERNAL_StateSet *sset1,
255 if (result > 0) 256 if (result > 0)
256 return 1; 257 return 1;
257 for (i = 0; i < sset1->off; i++) 258 for (i = 0; i < sset1->off; i++)
258 if (0 != (result = state_compare(&sset1->states[i], &sset2->states[i]))) 259 if (0 != (result = state_compare (&sset1->states[i], &sset2->states[i])))
259 break; 260 break;
260 return result; 261 return result;
261} 262}
@@ -267,9 +268,9 @@ state_set_compare(struct REGEX_INTERNAL_StateSet *sset1,
267 * @param set set to be cleared 268 * @param set set to be cleared
268 */ 269 */
269static void 270static void
270state_set_clear(struct REGEX_INTERNAL_StateSet *set) 271state_set_clear (struct REGEX_INTERNAL_StateSet *set)
271{ 272{
272 GNUNET_array_grow(set->states, set->size, 0); 273 GNUNET_array_grow (set->states, set->size, 0);
273 set->off = 0; 274 set->off = 0;
274} 275}
275 276
@@ -281,7 +282,7 @@ state_set_clear(struct REGEX_INTERNAL_StateSet *set)
281 * @param a automaton to be cleared 282 * @param a automaton to be cleared
282 */ 283 */
283static void 284static void
284automaton_fragment_clear(struct REGEX_INTERNAL_Automaton *a) 285automaton_fragment_clear (struct REGEX_INTERNAL_Automaton *a)
285{ 286{
286 if (NULL == a) 287 if (NULL == a)
287 return; 288 return;
@@ -291,7 +292,7 @@ automaton_fragment_clear(struct REGEX_INTERNAL_Automaton *a)
291 a->states_head = NULL; 292 a->states_head = NULL;
292 a->states_tail = NULL; 293 a->states_tail = NULL;
293 a->state_count = 0; 294 a->state_count = 0;
294 GNUNET_free(a); 295 GNUNET_free (a);
295} 296}
296 297
297 298
@@ -301,7 +302,7 @@ automaton_fragment_clear(struct REGEX_INTERNAL_Automaton *a)
301 * @param s state that should be destroyed 302 * @param s state that should be destroyed
302 */ 303 */
303static void 304static void
304automaton_destroy_state(struct REGEX_INTERNAL_State *s) 305automaton_destroy_state (struct REGEX_INTERNAL_State *s)
305{ 306{
306 struct REGEX_INTERNAL_Transition *t; 307 struct REGEX_INTERNAL_Transition *t;
307 struct REGEX_INTERNAL_Transition *next_t; 308 struct REGEX_INTERNAL_Transition *next_t;
@@ -309,16 +310,16 @@ automaton_destroy_state(struct REGEX_INTERNAL_State *s)
309 if (NULL == s) 310 if (NULL == s)
310 return; 311 return;
311 312
312 GNUNET_free_non_null(s->name); 313 GNUNET_free_non_null (s->name);
313 GNUNET_free_non_null(s->proof); 314 GNUNET_free_non_null (s->proof);
314 state_set_clear(&s->nfa_set); 315 state_set_clear (&s->nfa_set);
315 for (t = s->transitions_head; NULL != t; t = next_t) 316 for (t = s->transitions_head; NULL != t; t = next_t)
316 { 317 {
317 next_t = t->next; 318 next_t = t->next;
318 state_remove_transition(s, t); 319 state_remove_transition (s, t);
319 } 320 }
320 321
321 GNUNET_free(s); 322 GNUNET_free (s);
322} 323}
323 324
324 325
@@ -331,33 +332,33 @@ automaton_destroy_state(struct REGEX_INTERNAL_State *s)
331 * @param s state to remove 332 * @param s state to remove
332 */ 333 */
333static void 334static void
334automaton_remove_state(struct REGEX_INTERNAL_Automaton *a, 335automaton_remove_state (struct REGEX_INTERNAL_Automaton *a,
335 struct REGEX_INTERNAL_State *s) 336 struct REGEX_INTERNAL_State *s)
336{ 337{
337 struct REGEX_INTERNAL_State *s_check; 338 struct REGEX_INTERNAL_State *s_check;
338 struct REGEX_INTERNAL_Transition *t_check; 339 struct REGEX_INTERNAL_Transition *t_check;
339 struct REGEX_INTERNAL_Transition *t_check_next; 340 struct REGEX_INTERNAL_Transition *t_check_next;
340 341
341 if (NULL == a || NULL == s) 342 if ((NULL == a)||(NULL == s))
342 return; 343 return;
343 344
344 /* remove all transitions leading to this state */ 345 /* remove all transitions leading to this state */
345 for (s_check = a->states_head; NULL != s_check; s_check = s_check->next) 346 for (s_check = a->states_head; NULL != s_check; s_check = s_check->next)
347 {
348 for (t_check = s_check->transitions_head; NULL != t_check;
349 t_check = t_check_next)
346 { 350 {
347 for (t_check = s_check->transitions_head; NULL != t_check; 351 t_check_next = t_check->next;
348 t_check = t_check_next) 352 if (t_check->to_state == s)
349 { 353 state_remove_transition (s_check, t_check);
350 t_check_next = t_check->next;
351 if (t_check->to_state == s)
352 state_remove_transition(s_check, t_check);
353 }
354 } 354 }
355 }
355 356
356 /* remove state */ 357 /* remove state */
357 GNUNET_CONTAINER_DLL_remove(a->states_head, a->states_tail, s); 358 GNUNET_CONTAINER_DLL_remove (a->states_head, a->states_tail, s);
358 a->state_count--; 359 a->state_count--;
359 360
360 automaton_destroy_state(s); 361 automaton_destroy_state (s);
361} 362}
362 363
363 364
@@ -371,10 +372,10 @@ automaton_remove_state(struct REGEX_INTERNAL_Automaton *a,
371 * @param s2 second state, will be destroyed 372 * @param s2 second state, will be destroyed
372 */ 373 */
373static void 374static void
374automaton_merge_states(struct REGEX_INTERNAL_Context *ctx, 375automaton_merge_states (struct REGEX_INTERNAL_Context *ctx,
375 struct REGEX_INTERNAL_Automaton *a, 376 struct REGEX_INTERNAL_Automaton *a,
376 struct REGEX_INTERNAL_State *s1, 377 struct REGEX_INTERNAL_State *s1,
377 struct REGEX_INTERNAL_State *s2) 378 struct REGEX_INTERNAL_State *s2)
378{ 379{
379 struct REGEX_INTERNAL_State *s_check; 380 struct REGEX_INTERNAL_State *s_check;
380 struct REGEX_INTERNAL_Transition *t_check; 381 struct REGEX_INTERNAL_Transition *t_check;
@@ -388,47 +389,47 @@ automaton_merge_states(struct REGEX_INTERNAL_Context *ctx,
388 /* 1. Make all transitions pointing to s2 point to s1, unless this transition 389 /* 1. Make all transitions pointing to s2 point to s1, unless this transition
389 * does not already exists, if it already exists remove transition. */ 390 * does not already exists, if it already exists remove transition. */
390 for (s_check = a->states_head; NULL != s_check; s_check = s_check->next) 391 for (s_check = a->states_head; NULL != s_check; s_check = s_check->next)
392 {
393 for (t_check = s_check->transitions_head; NULL != t_check; t_check = t_next)
391 { 394 {
392 for (t_check = s_check->transitions_head; NULL != t_check; t_check = t_next) 395 t_next = t_check->next;
393 {
394 t_next = t_check->next;
395 396
396 if (s2 == t_check->to_state) 397 if (s2 == t_check->to_state)
397 { 398 {
398 is_dup = GNUNET_NO; 399 is_dup = GNUNET_NO;
399 for (t = t_check->from_state->transitions_head; NULL != t; t = t->next) 400 for (t = t_check->from_state->transitions_head; NULL != t; t = t->next)
400 { 401 {
401 if (t->to_state == s1 && 0 == strcmp(t_check->label, t->label)) 402 if ((t->to_state == s1) &&(0 == strcmp (t_check->label, t->label)) )
402 is_dup = GNUNET_YES; 403 is_dup = GNUNET_YES;
403 }
404 if (GNUNET_NO == is_dup)
405 t_check->to_state = s1;
406 else
407 state_remove_transition(t_check->from_state, t_check);
408 }
409 } 404 }
405 if (GNUNET_NO == is_dup)
406 t_check->to_state = s1;
407 else
408 state_remove_transition (t_check->from_state, t_check);
409 }
410 } 410 }
411 }
411 412
412 /* 2. Add all transitions from s2 to sX to s1 */ 413 /* 2. Add all transitions from s2 to sX to s1 */
413 for (t_check = s2->transitions_head; NULL != t_check; t_check = t_check->next) 414 for (t_check = s2->transitions_head; NULL != t_check; t_check = t_check->next)
414 { 415 {
415 if (t_check->to_state != s1) 416 if (t_check->to_state != s1)
416 state_add_transition(ctx, s1, t_check->label, t_check->to_state); 417 state_add_transition (ctx, s1, t_check->label, t_check->to_state);
417 } 418 }
418 419
419 /* 3. Rename s1 to {s1,s2} */ 420 /* 3. Rename s1 to {s1,s2} */
420#if REGEX_DEBUG_DFA 421#if REGEX_DEBUG_DFA
421 char *new_name; 422 char *new_name;
422 423
423 new_name = s1->name; 424 new_name = s1->name;
424 GNUNET_asprintf(&s1->name, "{%s,%s}", new_name, s2->name); 425 GNUNET_asprintf (&s1->name, "{%s,%s}", new_name, s2->name);
425 GNUNET_free(new_name); 426 GNUNET_free (new_name);
426#endif 427#endif
427 428
428 /* remove state */ 429 /* remove state */
429 GNUNET_CONTAINER_DLL_remove(a->states_head, a->states_tail, s2); 430 GNUNET_CONTAINER_DLL_remove (a->states_head, a->states_tail, s2);
430 a->state_count--; 431 a->state_count--;
431 automaton_destroy_state(s2); 432 automaton_destroy_state (s2);
432} 433}
433 434
434 435
@@ -440,10 +441,10 @@ automaton_merge_states(struct REGEX_INTERNAL_Context *ctx,
440 * @param s state that should be added 441 * @param s state that should be added
441 */ 442 */
442static void 443static void
443automaton_add_state(struct REGEX_INTERNAL_Automaton *a, 444automaton_add_state (struct REGEX_INTERNAL_Automaton *a,
444 struct REGEX_INTERNAL_State *s) 445 struct REGEX_INTERNAL_State *s)
445{ 446{
446 GNUNET_CONTAINER_DLL_insert(a->states_head, a->states_tail, s); 447 GNUNET_CONTAINER_DLL_insert (a->states_head, a->states_tail, s);
447 a->state_count++; 448 a->state_count++;
448} 449}
449 450
@@ -463,13 +464,13 @@ automaton_add_state(struct REGEX_INTERNAL_Automaton *a,
463 * @param action_cls closure for action. 464 * @param action_cls closure for action.
464 */ 465 */
465static void 466static void
466automaton_state_traverse(struct REGEX_INTERNAL_State *s, 467automaton_state_traverse (struct REGEX_INTERNAL_State *s,
467 int *marks, 468 int *marks,
468 unsigned int *count, 469 unsigned int *count,
469 REGEX_INTERNAL_traverse_check check, 470 REGEX_INTERNAL_traverse_check check,
470 void *check_cls, 471 void *check_cls,
471 REGEX_INTERNAL_traverse_action action, 472 REGEX_INTERNAL_traverse_action action,
472 void *action_cls) 473 void *action_cls)
473{ 474{
474 struct REGEX_INTERNAL_Transition *t; 475 struct REGEX_INTERNAL_Transition *t;
475 476
@@ -479,24 +480,24 @@ automaton_state_traverse(struct REGEX_INTERNAL_State *s,
479 marks[s->traversal_id] = GNUNET_YES; 480 marks[s->traversal_id] = GNUNET_YES;
480 481
481 if (NULL != action) 482 if (NULL != action)
482 action(action_cls, *count, s); 483 action (action_cls, *count, s);
483 484
484 (*count)++; 485 (*count)++;
485 486
486 for (t = s->transitions_head; NULL != t; t = t->next) 487 for (t = s->transitions_head; NULL != t; t = t->next)
488 {
489 if ((NULL == check) ||
490 ((NULL != check) &&(GNUNET_YES == check (check_cls, s, t)) ))
487 { 491 {
488 if (NULL == check || 492 automaton_state_traverse (t->to_state,
489 (NULL != check && GNUNET_YES == check(check_cls, s, t))) 493 marks,
490 { 494 count,
491 automaton_state_traverse(t->to_state, 495 check,
492 marks, 496 check_cls,
493 count, 497 action,
494 check, 498 action_cls);
495 check_cls,
496 action,
497 action_cls);
498 }
499 } 499 }
500 }
500} 501}
501 502
502 503
@@ -514,27 +515,27 @@ automaton_state_traverse(struct REGEX_INTERNAL_State *s,
514 * @param action_cls closure for @a action 515 * @param action_cls closure for @a action
515 */ 516 */
516void 517void
517REGEX_INTERNAL_automaton_traverse(const struct REGEX_INTERNAL_Automaton *a, 518REGEX_INTERNAL_automaton_traverse (const struct REGEX_INTERNAL_Automaton *a,
518 struct REGEX_INTERNAL_State *start, 519 struct REGEX_INTERNAL_State *start,
519 REGEX_INTERNAL_traverse_check check, 520 REGEX_INTERNAL_traverse_check check,
520 void *check_cls, 521 void *check_cls,
521 REGEX_INTERNAL_traverse_action action, 522 REGEX_INTERNAL_traverse_action action,
522 void *action_cls) 523 void *action_cls)
523{ 524{
524 unsigned int count; 525 unsigned int count;
525 struct REGEX_INTERNAL_State *s; 526 struct REGEX_INTERNAL_State *s;
526 527
527 if (NULL == a || 0 == a->state_count) 528 if ((NULL == a)||(0 == a->state_count))
528 return; 529 return;
529 530
530 int marks[a->state_count]; 531 int marks[a->state_count];
531 532
532 for (count = 0, s = a->states_head; NULL != s && count < a->state_count; 533 for (count = 0, s = a->states_head; NULL != s && count < a->state_count;
533 s = s->next, count++) 534 s = s->next, count++)
534 { 535 {
535 s->traversal_id = count; 536 s->traversal_id = count;
536 marks[s->traversal_id] = GNUNET_NO; 537 marks[s->traversal_id] = GNUNET_NO;
537 } 538 }
538 539
539 count = 0; 540 count = 0;
540 541
@@ -543,20 +544,21 @@ REGEX_INTERNAL_automaton_traverse(const struct REGEX_INTERNAL_Automaton *a,
543 else 544 else
544 s = start; 545 s = start;
545 546
546 automaton_state_traverse(s, 547 automaton_state_traverse (s,
547 marks, 548 marks,
548 &count, 549 &count,
549 check, 550 check,
550 check_cls, 551 check_cls,
551 action, 552 action,
552 action_cls); 553 action_cls);
553} 554}
554 555
555 556
556/** 557/**
557 * String container for faster string operations. 558 * String container for faster string operations.
558 */ 559 */
559struct StringBuffer { 560struct StringBuffer
561{
560 /** 562 /**
561 * Buffer holding the string (may start in the middle!); 563 * Buffer holding the string (may start in the middle!);
562 * NOT 0-terminated! 564 * NOT 0-terminated!
@@ -605,7 +607,7 @@ struct StringBuffer {
605 * @return 0 if the strings are the same or both NULL, 1 or -1 if not. 607 * @return 0 if the strings are the same or both NULL, 1 or -1 if not.
606 */ 608 */
607static int 609static int
608sb_nullstrcmp(const struct StringBuffer *s1, const struct StringBuffer *s2) 610sb_nullstrcmp (const struct StringBuffer *s1, const struct StringBuffer *s2)
609{ 611{
610 if ((GNUNET_YES == s1->null_flag) && (GNUNET_YES == s2->null_flag)) 612 if ((GNUNET_YES == s1->null_flag) && (GNUNET_YES == s2->null_flag))
611 return 0; 613 return 0;
@@ -615,7 +617,7 @@ sb_nullstrcmp(const struct StringBuffer *s1, const struct StringBuffer *s2)
615 return -1; 617 return -1;
616 if (0 == s1->slen) 618 if (0 == s1->slen)
617 return 0; 619 return 0;
618 return memcmp(s1->sbuf, s2->sbuf, s1->slen); 620 return memcmp (s1->sbuf, s2->sbuf, s1->slen);
619} 621}
620 622
621 623
@@ -628,13 +630,13 @@ sb_nullstrcmp(const struct StringBuffer *s1, const struct StringBuffer *s2)
628 * @return 0 if the strings are the same, 1 or -1 if not. 630 * @return 0 if the strings are the same, 1 or -1 if not.
629 */ 631 */
630static int 632static int
631sb_strcmp(const struct StringBuffer *s1, const struct StringBuffer *s2) 633sb_strcmp (const struct StringBuffer *s1, const struct StringBuffer *s2)
632{ 634{
633 if (s1->slen != s2->slen) 635 if (s1->slen != s2->slen)
634 return -1; 636 return -1;
635 if (0 == s1->slen) 637 if (0 == s1->slen)
636 return 0; 638 return 0;
637 return memcmp(s1->sbuf, s2->sbuf, s1->slen); 639 return memcmp (s1->sbuf, s2->sbuf, s1->slen);
638} 640}
639 641
640 642
@@ -646,17 +648,17 @@ sb_strcmp(const struct StringBuffer *s1, const struct StringBuffer *s2)
646 * @param nlen target length for the buffer, must be at least ret->slen 648 * @param nlen target length for the buffer, must be at least ret->slen
647 */ 649 */
648static void 650static void
649sb_realloc(struct StringBuffer *ret, size_t nlen) 651sb_realloc (struct StringBuffer *ret, size_t nlen)
650{ 652{
651 char *old; 653 char *old;
652 654
653 GNUNET_assert(nlen >= ret->slen); 655 GNUNET_assert (nlen >= ret->slen);
654 old = ret->abuf; 656 old = ret->abuf;
655 ret->abuf = GNUNET_malloc(nlen); 657 ret->abuf = GNUNET_malloc (nlen);
656 ret->blen = nlen; 658 ret->blen = nlen;
657 GNUNET_memcpy(ret->abuf, ret->sbuf, ret->slen); 659 GNUNET_memcpy (ret->abuf, ret->sbuf, ret->slen);
658 ret->sbuf = ret->abuf; 660 ret->sbuf = ret->abuf;
659 GNUNET_free_non_null(old); 661 GNUNET_free_non_null (old);
660} 662}
661 663
662 664
@@ -667,14 +669,14 @@ sb_realloc(struct StringBuffer *ret, size_t nlen)
667 * @param sarg string to append 669 * @param sarg string to append
668 */ 670 */
669static void 671static void
670sb_append(struct StringBuffer *ret, const struct StringBuffer *sarg) 672sb_append (struct StringBuffer *ret, const struct StringBuffer *sarg)
671{ 673{
672 if (GNUNET_YES == ret->null_flag) 674 if (GNUNET_YES == ret->null_flag)
673 ret->slen = 0; 675 ret->slen = 0;
674 ret->null_flag = GNUNET_NO; 676 ret->null_flag = GNUNET_NO;
675 if (ret->blen < sarg->slen + ret->slen) 677 if (ret->blen < sarg->slen + ret->slen)
676 sb_realloc(ret, ret->blen + sarg->slen + 128); 678 sb_realloc (ret, ret->blen + sarg->slen + 128);
677 GNUNET_memcpy(&ret->sbuf[ret->slen], sarg->sbuf, sarg->slen); 679 GNUNET_memcpy (&ret->sbuf[ret->slen], sarg->sbuf, sarg->slen);
678 ret->slen += sarg->slen; 680 ret->slen += sarg->slen;
679} 681}
680 682
@@ -686,16 +688,16 @@ sb_append(struct StringBuffer *ret, const struct StringBuffer *sarg)
686 * @param cstr string to append 688 * @param cstr string to append
687 */ 689 */
688static void 690static void
689sb_append_cstr(struct StringBuffer *ret, const char *cstr) 691sb_append_cstr (struct StringBuffer *ret, const char *cstr)
690{ 692{
691 size_t cstr_len = strlen(cstr); 693 size_t cstr_len = strlen (cstr);
692 694
693 if (GNUNET_YES == ret->null_flag) 695 if (GNUNET_YES == ret->null_flag)
694 ret->slen = 0; 696 ret->slen = 0;
695 ret->null_flag = GNUNET_NO; 697 ret->null_flag = GNUNET_NO;
696 if (ret->blen < cstr_len + ret->slen) 698 if (ret->blen < cstr_len + ret->slen)
697 sb_realloc(ret, ret->blen + cstr_len + 128); 699 sb_realloc (ret, ret->blen + cstr_len + 128);
698 GNUNET_memcpy(&ret->sbuf[ret->slen], cstr, cstr_len); 700 GNUNET_memcpy (&ret->sbuf[ret->slen], cstr, cstr_len);
699 ret->slen += cstr_len; 701 ret->slen += cstr_len;
700} 702}
701 703
@@ -711,20 +713,20 @@ sb_append_cstr(struct StringBuffer *ret, const char *cstr)
711 * @param extra_chars how long will the result be, in addition to 'sarg' length 713 * @param extra_chars how long will the result be, in addition to 'sarg' length
712 */ 714 */
713static void 715static void
714sb_wrap(struct StringBuffer *ret, const char *format, size_t extra_chars) 716sb_wrap (struct StringBuffer *ret, const char *format, size_t extra_chars)
715{ 717{
716 char *temp; 718 char *temp;
717 719
718 if (GNUNET_YES == ret->null_flag) 720 if (GNUNET_YES == ret->null_flag)
719 ret->slen = 0; 721 ret->slen = 0;
720 ret->null_flag = GNUNET_NO; 722 ret->null_flag = GNUNET_NO;
721 temp = GNUNET_malloc(ret->slen + extra_chars + 1); 723 temp = GNUNET_malloc (ret->slen + extra_chars + 1);
722 GNUNET_snprintf(temp, 724 GNUNET_snprintf (temp,
723 ret->slen + extra_chars + 1, 725 ret->slen + extra_chars + 1,
724 format, 726 format,
725 (int)ret->slen, 727 (int) ret->slen,
726 ret->sbuf); 728 ret->sbuf);
727 GNUNET_free_non_null(ret->abuf); 729 GNUNET_free_non_null (ret->abuf);
728 ret->abuf = temp; 730 ret->abuf = temp;
729 ret->sbuf = temp; 731 ret->sbuf = temp;
730 ret->blen = ret->slen + extra_chars + 1; 732 ret->blen = ret->slen + extra_chars + 1;
@@ -742,17 +744,17 @@ sb_wrap(struct StringBuffer *ret, const char *format, size_t extra_chars)
742 * @param sarg string to print into the format 744 * @param sarg string to print into the format
743 */ 745 */
744static void 746static void
745sb_printf1(struct StringBuffer *ret, 747sb_printf1 (struct StringBuffer *ret,
746 const char *format, 748 const char *format,
747 size_t extra_chars, 749 size_t extra_chars,
748 const struct StringBuffer *sarg) 750 const struct StringBuffer *sarg)
749{ 751{
750 if (ret->blen < sarg->slen + extra_chars + 1) 752 if (ret->blen < sarg->slen + extra_chars + 1)
751 sb_realloc(ret, sarg->slen + extra_chars + 1); 753 sb_realloc (ret, sarg->slen + extra_chars + 1);
752 ret->null_flag = GNUNET_NO; 754 ret->null_flag = GNUNET_NO;
753 ret->sbuf = ret->abuf; 755 ret->sbuf = ret->abuf;
754 ret->slen = sarg->slen + extra_chars; 756 ret->slen = sarg->slen + extra_chars;
755 GNUNET_snprintf(ret->sbuf, ret->blen, format, (int)sarg->slen, sarg->sbuf); 757 GNUNET_snprintf (ret->sbuf, ret->blen, format, (int) sarg->slen, sarg->sbuf);
756} 758}
757 759
758 760
@@ -766,24 +768,24 @@ sb_printf1(struct StringBuffer *ret,
766 * @param sarg2 second string to print into the format 768 * @param sarg2 second string to print into the format
767 */ 769 */
768static void 770static void
769sb_printf2(struct StringBuffer *ret, 771sb_printf2 (struct StringBuffer *ret,
770 const char *format, 772 const char *format,
771 size_t extra_chars, 773 size_t extra_chars,
772 const struct StringBuffer *sarg1, 774 const struct StringBuffer *sarg1,
773 const struct StringBuffer *sarg2) 775 const struct StringBuffer *sarg2)
774{ 776{
775 if (ret->blen < sarg1->slen + sarg2->slen + extra_chars + 1) 777 if (ret->blen < sarg1->slen + sarg2->slen + extra_chars + 1)
776 sb_realloc(ret, sarg1->slen + sarg2->slen + extra_chars + 1); 778 sb_realloc (ret, sarg1->slen + sarg2->slen + extra_chars + 1);
777 ret->null_flag = GNUNET_NO; 779 ret->null_flag = GNUNET_NO;
778 ret->slen = sarg1->slen + sarg2->slen + extra_chars; 780 ret->slen = sarg1->slen + sarg2->slen + extra_chars;
779 ret->sbuf = ret->abuf; 781 ret->sbuf = ret->abuf;
780 GNUNET_snprintf(ret->sbuf, 782 GNUNET_snprintf (ret->sbuf,
781 ret->blen, 783 ret->blen,
782 format, 784 format,
783 (int)sarg1->slen, 785 (int) sarg1->slen,
784 sarg1->sbuf, 786 sarg1->sbuf,
785 (int)sarg2->slen, 787 (int) sarg2->slen,
786 sarg2->sbuf); 788 sarg2->sbuf);
787} 789}
788 790
789 791
@@ -799,27 +801,27 @@ sb_printf2(struct StringBuffer *ret,
799 * @param sarg3 third string to print into the format 801 * @param sarg3 third string to print into the format
800 */ 802 */
801static void 803static void
802sb_printf3(struct StringBuffer *ret, 804sb_printf3 (struct StringBuffer *ret,
803 const char *format, 805 const char *format,
804 size_t extra_chars, 806 size_t extra_chars,
805 const struct StringBuffer *sarg1, 807 const struct StringBuffer *sarg1,
806 const struct StringBuffer *sarg2, 808 const struct StringBuffer *sarg2,
807 const struct StringBuffer *sarg3) 809 const struct StringBuffer *sarg3)
808{ 810{
809 if (ret->blen < sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1) 811 if (ret->blen < sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1)
810 sb_realloc(ret, sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1); 812 sb_realloc (ret, sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1);
811 ret->null_flag = GNUNET_NO; 813 ret->null_flag = GNUNET_NO;
812 ret->slen = sarg1->slen + sarg2->slen + sarg3->slen + extra_chars; 814 ret->slen = sarg1->slen + sarg2->slen + sarg3->slen + extra_chars;
813 ret->sbuf = ret->abuf; 815 ret->sbuf = ret->abuf;
814 GNUNET_snprintf(ret->sbuf, 816 GNUNET_snprintf (ret->sbuf,
815 ret->blen, 817 ret->blen,
816 format, 818 format,
817 (int)sarg1->slen, 819 (int) sarg1->slen,
818 sarg1->sbuf, 820 sarg1->sbuf,
819 (int)sarg2->slen, 821 (int) sarg2->slen,
820 sarg2->sbuf, 822 sarg2->sbuf,
821 (int)sarg3->slen, 823 (int) sarg3->slen,
822 sarg3->sbuf); 824 sarg3->sbuf);
823} 825}
824 826
825 827
@@ -830,9 +832,9 @@ sb_printf3(struct StringBuffer *ret,
830 * should not be individually allocated) 832 * should not be individually allocated)
831 */ 833 */
832static void 834static void
833sb_free(struct StringBuffer *sb) 835sb_free (struct StringBuffer *sb)
834{ 836{
835 GNUNET_array_grow(sb->abuf, sb->blen, 0); 837 GNUNET_array_grow (sb->abuf, sb->blen, 0);
836 sb->slen = 0; 838 sb->slen = 0;
837 sb->sbuf = NULL; 839 sb->sbuf = NULL;
838 sb->null_flag = GNUNET_YES; 840 sb->null_flag = GNUNET_YES;
@@ -846,19 +848,19 @@ sb_free(struct StringBuffer *sb)
846 * @param out output string 848 * @param out output string
847 */ 849 */
848static void 850static void
849sb_strdup(struct StringBuffer *out, const struct StringBuffer *in) 851sb_strdup (struct StringBuffer *out, const struct StringBuffer *in)
850 852
851{ 853{
852 out->null_flag = in->null_flag; 854 out->null_flag = in->null_flag;
853 if (GNUNET_YES == out->null_flag) 855 if (GNUNET_YES == out->null_flag)
854 return; 856 return;
855 if (out->blen < in->slen) 857 if (out->blen < in->slen)
856 { 858 {
857 GNUNET_array_grow(out->abuf, out->blen, in->slen); 859 GNUNET_array_grow (out->abuf, out->blen, in->slen);
858 } 860 }
859 out->sbuf = out->abuf; 861 out->sbuf = out->abuf;
860 out->slen = in->slen; 862 out->slen = in->slen;
861 GNUNET_memcpy(out->sbuf, in->sbuf, out->slen); 863 GNUNET_memcpy (out->sbuf, in->sbuf, out->slen);
862} 864}
863 865
864 866
@@ -869,21 +871,21 @@ sb_strdup(struct StringBuffer *out, const struct StringBuffer *in)
869 * @param out output string 871 * @param out output string
870 */ 872 */
871static void 873static void
872sb_strdup_cstr(struct StringBuffer *out, const char *cstr) 874sb_strdup_cstr (struct StringBuffer *out, const char *cstr)
873{ 875{
874 if (NULL == cstr) 876 if (NULL == cstr)
875 { 877 {
876 out->null_flag = GNUNET_YES; 878 out->null_flag = GNUNET_YES;
877 return; 879 return;
878 } 880 }
879 out->null_flag = GNUNET_NO; 881 out->null_flag = GNUNET_NO;
880 out->slen = strlen(cstr); 882 out->slen = strlen (cstr);
881 if (out->blen < out->slen) 883 if (out->blen < out->slen)
882 { 884 {
883 GNUNET_array_grow(out->abuf, out->blen, out->slen); 885 GNUNET_array_grow (out->abuf, out->blen, out->slen);
884 } 886 }
885 out->sbuf = out->abuf; 887 out->sbuf = out->abuf;
886 GNUNET_memcpy(out->sbuf, cstr, out->slen); 888 GNUNET_memcpy (out->sbuf, cstr, out->slen);
887} 889}
888 890
889 891
@@ -896,7 +898,7 @@ sb_strdup_cstr(struct StringBuffer *out, const char *cstr)
896 * @return #GNUNET_YES if parentheses are needed, #GNUNET_NO otherwise 898 * @return #GNUNET_YES if parentheses are needed, #GNUNET_NO otherwise
897 */ 899 */
898static int 900static int
899needs_parentheses(const struct StringBuffer *str) 901needs_parentheses (const struct StringBuffer *str)
900{ 902{
901 size_t slen; 903 size_t slen;
902 const char *op; 904 const char *op;
@@ -914,23 +916,23 @@ needs_parentheses(const struct StringBuffer *str)
914 cnt = 1; 916 cnt = 1;
915 pos++; 917 pos++;
916 while (cnt > 0) 918 while (cnt > 0)
919 {
920 cl = memchr (pos, ')', end - pos);
921 if (NULL == cl)
917 { 922 {
918 cl = memchr(pos, ')', end - pos); 923 GNUNET_break (0);
919 if (NULL == cl) 924 return GNUNET_YES;
920 { 925 }
921 GNUNET_break(0); 926 /* while '(' before ')', count opening parens */
922 return GNUNET_YES; 927 while ((NULL != (op = memchr (pos, '(', end - pos))) && (op < cl))
923 } 928 {
924 /* while '(' before ')', count opening parens */ 929 cnt++;
925 while ((NULL != (op = memchr(pos, '(', end - pos))) && (op < cl)) 930 pos = op + 1;
926 {
927 cnt++;
928 pos = op + 1;
929 }
930 /* got ')' first */
931 cnt--;
932 pos = cl + 1;
933 } 931 }
932 /* got ')' first */
933 cnt--;
934 pos = cl + 1;
935 }
934 return (*pos == '\0') ? GNUNET_NO : GNUNET_YES; 936 return (*pos == '\0') ? GNUNET_NO : GNUNET_YES;
935} 937}
936 938
@@ -945,7 +947,7 @@ needs_parentheses(const struct StringBuffer *str)
945 * epsilon could be found, NULL if 'str' was NULL 947 * epsilon could be found, NULL if 'str' was NULL
946 */ 948 */
947static void 949static void
948remove_parentheses(struct StringBuffer *str) 950remove_parentheses (struct StringBuffer *str)
949{ 951{
950 size_t slen; 952 size_t slen;
951 const char *pos; 953 const char *pos;
@@ -964,30 +966,30 @@ remove_parentheses(struct StringBuffer *str)
964 cnt = 0; 966 cnt = 0;
965 pos = &sbuf[1]; 967 pos = &sbuf[1];
966 end = &sbuf[slen - 1]; 968 end = &sbuf[slen - 1];
967 op = memchr(pos, '(', end - pos); 969 op = memchr (pos, '(', end - pos);
968 cp = memchr(pos, ')', end - pos); 970 cp = memchr (pos, ')', end - pos);
969 while (NULL != cp) 971 while (NULL != cp)
972 {
973 while ((NULL != op) && (op < cp))
970 { 974 {
971 while ((NULL != op) && (op < cp)) 975 cnt++;
972 { 976 pos = op + 1;
973 cnt++; 977 op = memchr (pos, '(', end - pos);
974 pos = op + 1;
975 op = memchr(pos, '(', end - pos);
976 }
977 while ((NULL != cp) && ((NULL == op) || (cp < op)))
978 {
979 if (0 == cnt)
980 return; /* can't strip parens */
981 cnt--;
982 pos = cp + 1;
983 cp = memchr(pos, ')', end - pos);
984 }
985 } 978 }
986 if (0 != cnt) 979 while ((NULL != cp) && ((NULL == op) || (cp < op)))
987 { 980 {
988 GNUNET_break(0); 981 if (0 == cnt)
989 return; 982 return; /* can't strip parens */
983 cnt--;
984 pos = cp + 1;
985 cp = memchr (pos, ')', end - pos);
990 } 986 }
987 }
988 if (0 != cnt)
989 {
990 GNUNET_break (0);
991 return;
992 }
991 str->sbuf++; 993 str->sbuf++;
992 str->slen -= 2; 994 str->slen -= 2;
993} 995}
@@ -1002,7 +1004,7 @@ remove_parentheses(struct StringBuffer *str)
1002 * @return 0 if str has no epsilon, 1 if str starts with '(|' and ends with ')' 1004 * @return 0 if str has no epsilon, 1 if str starts with '(|' and ends with ')'
1003 */ 1005 */
1004static int 1006static int
1005has_epsilon(const struct StringBuffer *str) 1007has_epsilon (const struct StringBuffer *str)
1006{ 1008{
1007 return (GNUNET_YES != str->null_flag) && (0 < str->slen) && 1009 return (GNUNET_YES != str->null_flag) && (0 < str->slen) &&
1008 ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) && 1010 ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) &&
@@ -1020,27 +1022,27 @@ has_epsilon(const struct StringBuffer *str)
1020 * epsilon could be found, NULL if 'str' was NULL 1022 * epsilon could be found, NULL if 'str' was NULL
1021 */ 1023 */
1022static void 1024static void
1023remove_epsilon(const struct StringBuffer *str, struct StringBuffer *ret) 1025remove_epsilon (const struct StringBuffer *str, struct StringBuffer *ret)
1024{ 1026{
1025 if (GNUNET_YES == str->null_flag) 1027 if (GNUNET_YES == str->null_flag)
1026 { 1028 {
1027 ret->null_flag = GNUNET_YES; 1029 ret->null_flag = GNUNET_YES;
1028 return; 1030 return;
1029 } 1031 }
1030 if ((str->slen > 1) && ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) && 1032 if ((str->slen > 1) && ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) &&
1031 (')' == str->sbuf[str->slen - 1])) 1033 (')' == str->sbuf[str->slen - 1]))
1034 {
1035 /* remove epsilon */
1036 if (ret->blen < str->slen - 3)
1032 { 1037 {
1033 /* remove epsilon */ 1038 GNUNET_array_grow (ret->abuf, ret->blen, str->slen - 3);
1034 if (ret->blen < str->slen - 3)
1035 {
1036 GNUNET_array_grow(ret->abuf, ret->blen, str->slen - 3);
1037 }
1038 ret->sbuf = ret->abuf;
1039 ret->slen = str->slen - 3;
1040 GNUNET_memcpy(ret->sbuf, &str->sbuf[2], ret->slen);
1041 return;
1042 } 1039 }
1043 sb_strdup(ret, str); 1040 ret->sbuf = ret->abuf;
1041 ret->slen = str->slen - 3;
1042 GNUNET_memcpy (ret->sbuf, &str->sbuf[2], ret->slen);
1043 return;
1044 }
1045 sb_strdup (ret, str);
1044} 1046}
1045 1047
1046 1048
@@ -1054,18 +1056,18 @@ remove_epsilon(const struct StringBuffer *str, struct StringBuffer *ret)
1054 * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise 1056 * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise
1055 */ 1057 */
1056static int 1058static int
1057sb_strncmp(const struct StringBuffer *str1, 1059sb_strncmp (const struct StringBuffer *str1,
1058 const struct StringBuffer *str2, 1060 const struct StringBuffer *str2,
1059 size_t n) 1061 size_t n)
1060{ 1062{
1061 size_t max; 1063 size_t max;
1062 1064
1063 if ((str1->slen != str2->slen) && ((str1->slen < n) || (str2->slen < n))) 1065 if ((str1->slen != str2->slen) && ((str1->slen < n) || (str2->slen < n)))
1064 return -1; 1066 return -1;
1065 max = GNUNET_MAX(str1->slen, str2->slen); 1067 max = GNUNET_MAX (str1->slen, str2->slen);
1066 if (max > n) 1068 if (max > n)
1067 max = n; 1069 max = n;
1068 return memcmp(str1->sbuf, str2->sbuf, max); 1070 return memcmp (str1->sbuf, str2->sbuf, max);
1069} 1071}
1070 1072
1071 1073
@@ -1079,11 +1081,11 @@ sb_strncmp(const struct StringBuffer *str1,
1079 * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise 1081 * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise
1080 */ 1082 */
1081static int 1083static int
1082sb_strncmp_cstr(const struct StringBuffer *str1, const char *str2, size_t n) 1084sb_strncmp_cstr (const struct StringBuffer *str1, const char *str2, size_t n)
1083{ 1085{
1084 if (str1->slen < n) 1086 if (str1->slen < n)
1085 return -1; 1087 return -1;
1086 return memcmp(str1->sbuf, str2, n); 1088 return memcmp (str1->sbuf, str2, n);
1087} 1089}
1088 1090
1089 1091
@@ -1095,10 +1097,10 @@ sb_strncmp_cstr(const struct StringBuffer *str1, const char *str2, size_t n)
1095 * @param n desired target length 1097 * @param n desired target length
1096 */ 1098 */
1097static void 1099static void
1098sb_init(struct StringBuffer *sb, size_t n) 1100sb_init (struct StringBuffer *sb, size_t n)
1099{ 1101{
1100 sb->null_flag = GNUNET_NO; 1102 sb->null_flag = GNUNET_NO;
1101 sb->abuf = sb->sbuf = (0 == n) ? NULL : GNUNET_malloc(n); 1103 sb->abuf = sb->sbuf = (0 == n) ? NULL : GNUNET_malloc (n);
1102 sb->blen = n; 1104 sb->blen = n;
1103 sb->slen = 0; 1105 sb->slen = 0;
1104} 1106}
@@ -1114,14 +1116,14 @@ sb_init(struct StringBuffer *sb, size_t n)
1114 * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise 1116 * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise
1115 */ 1117 */
1116static int 1118static int
1117sb_strkcmp(const struct StringBuffer *str1, 1119sb_strkcmp (const struct StringBuffer *str1,
1118 const struct StringBuffer *str2, 1120 const struct StringBuffer *str2,
1119 size_t k) 1121 size_t k)
1120{ 1122{
1121 if ((GNUNET_YES == str1->null_flag) || (GNUNET_YES == str2->null_flag) || 1123 if ((GNUNET_YES == str1->null_flag) || (GNUNET_YES == str2->null_flag) ||
1122 (k > str1->slen) || (str1->slen - k != str2->slen)) 1124 (k > str1->slen) || (str1->slen - k != str2->slen))
1123 return -1; 1125 return -1;
1124 return memcmp(&str1->sbuf[k], str2->sbuf, str2->slen); 1126 return memcmp (&str1->sbuf[k], str2->sbuf, str2->slen);
1125} 1127}
1126 1128
1127 1129
@@ -1134,9 +1136,9 @@ sb_strkcmp(const struct StringBuffer *str1,
1134 * @param s current state. 1136 * @param s current state.
1135 */ 1137 */
1136static void 1138static void
1137number_states(void *cls, 1139number_states (void *cls,
1138 const unsigned int count, 1140 const unsigned int count,
1139 struct REGEX_INTERNAL_State *s) 1141 struct REGEX_INTERNAL_State *s)
1140{ 1142{
1141 struct REGEX_INTERNAL_State **states = cls; 1143 struct REGEX_INTERNAL_State **states = cls;
1142 1144
@@ -1147,7 +1149,7 @@ number_states(void *cls,
1147 1149
1148 1150
1149#define PRIS(a) \ 1151#define PRIS(a) \
1150 ((GNUNET_YES == a.null_flag) ? 6 : (int)a.slen), \ 1152 ((GNUNET_YES == a.null_flag) ? 6 : (int) a.slen), \
1151 ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf) 1153 ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf)
1152 1154
1153 1155
@@ -1166,13 +1168,13 @@ number_states(void *cls,
1166 * @param R_cur_r optimization -- kept between iterations to avoid realloc 1168 * @param R_cur_r optimization -- kept between iterations to avoid realloc
1167 */ 1169 */
1168static void 1170static void
1169automaton_create_proofs_simplify(const struct StringBuffer *R_last_ij, 1171automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij,
1170 const struct StringBuffer *R_last_ik, 1172 const struct StringBuffer *R_last_ik,
1171 const struct StringBuffer *R_last_kk, 1173 const struct StringBuffer *R_last_kk,
1172 const struct StringBuffer *R_last_kj, 1174 const struct StringBuffer *R_last_kj,
1173 struct StringBuffer *R_cur_ij, 1175 struct StringBuffer *R_cur_ij,
1174 struct StringBuffer *R_cur_l, 1176 struct StringBuffer *R_cur_l,
1175 struct StringBuffer *R_cur_r) 1177 struct StringBuffer *R_cur_r)
1176{ 1178{
1177 struct StringBuffer R_temp_ij; 1179 struct StringBuffer R_temp_ij;
1178 struct StringBuffer R_temp_ik; 1180 struct StringBuffer R_temp_ik;
@@ -1200,27 +1202,27 @@ automaton_create_proofs_simplify(const struct StringBuffer *R_last_ij,
1200 if ((GNUNET_YES == R_last_ij->null_flag) && 1202 if ((GNUNET_YES == R_last_ij->null_flag) &&
1201 ((GNUNET_YES == R_last_ik->null_flag) || 1203 ((GNUNET_YES == R_last_ik->null_flag) ||
1202 (GNUNET_YES == R_last_kj->null_flag))) 1204 (GNUNET_YES == R_last_kj->null_flag)))
1203 { 1205 {
1204 /* R^{(k)}_{ij} = N | N */ 1206 /* R^{(k)}_{ij} = N | N */
1205 R_cur_ij->null_flag = GNUNET_YES; 1207 R_cur_ij->null_flag = GNUNET_YES;
1206 R_cur_ij->synced = GNUNET_NO; 1208 R_cur_ij->synced = GNUNET_NO;
1207 return; 1209 return;
1208 } 1210 }
1209 1211
1210 if ((GNUNET_YES == R_last_ik->null_flag) || 1212 if ((GNUNET_YES == R_last_ik->null_flag) ||
1211 (GNUNET_YES == R_last_kj->null_flag)) 1213 (GNUNET_YES == R_last_kj->null_flag))
1214 {
1215 /* R^{(k)}_{ij} = R^{(k-1)}_{ij} | N */
1216 if (GNUNET_YES == R_last_ij->synced)
1212 { 1217 {
1213 /* R^{(k)}_{ij} = R^{(k-1)}_{ij} | N */
1214 if (GNUNET_YES == R_last_ij->synced)
1215 {
1216 R_cur_ij->synced = GNUNET_YES;
1217 R_cur_ij->null_flag = GNUNET_NO;
1218 return;
1219 }
1220 R_cur_ij->synced = GNUNET_YES; 1218 R_cur_ij->synced = GNUNET_YES;
1221 sb_strdup(R_cur_ij, R_last_ij); 1219 R_cur_ij->null_flag = GNUNET_NO;
1222 return; 1220 return;
1223 } 1221 }
1222 R_cur_ij->synced = GNUNET_YES;
1223 sb_strdup (R_cur_ij, R_last_ij);
1224 return;
1225 }
1224 R_cur_ij->synced = GNUNET_NO; 1226 R_cur_ij->synced = GNUNET_NO;
1225 1227
1226 /* $R^{(k)}_{ij} = N | R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj} OR 1228 /* $R^{(k)}_{ij} = N | R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj} OR
@@ -1232,334 +1234,334 @@ automaton_create_proofs_simplify(const struct StringBuffer *R_last_ij,
1232 R_cur_l->slen = 0; 1234 R_cur_l->slen = 0;
1233 1235
1234 /* cache results from strcmp, we might need these many times */ 1236 /* cache results from strcmp, we might need these many times */
1235 ij_kj_cmp = sb_nullstrcmp(R_last_ij, R_last_kj); 1237 ij_kj_cmp = sb_nullstrcmp (R_last_ij, R_last_kj);
1236 ij_ik_cmp = sb_nullstrcmp(R_last_ij, R_last_ik); 1238 ij_ik_cmp = sb_nullstrcmp (R_last_ij, R_last_ik);
1237 ik_kk_cmp = sb_nullstrcmp(R_last_ik, R_last_kk); 1239 ik_kk_cmp = sb_nullstrcmp (R_last_ik, R_last_kk);
1238 kk_kj_cmp = sb_nullstrcmp(R_last_kk, R_last_kj); 1240 kk_kj_cmp = sb_nullstrcmp (R_last_kk, R_last_kj);
1239 1241
1240 /* Assign R_temp_(ik|kk|kj) to R_last[][] and remove epsilon as well 1242 /* Assign R_temp_(ik|kk|kj) to R_last[][] and remove epsilon as well
1241 * as parentheses, so we can better compare the contents */ 1243 * as parentheses, so we can better compare the contents */
1242 1244
1243 memset(&R_temp_ij, 0, sizeof(struct StringBuffer)); 1245 memset (&R_temp_ij, 0, sizeof(struct StringBuffer));
1244 memset(&R_temp_ik, 0, sizeof(struct StringBuffer)); 1246 memset (&R_temp_ik, 0, sizeof(struct StringBuffer));
1245 memset(&R_temp_kk, 0, sizeof(struct StringBuffer)); 1247 memset (&R_temp_kk, 0, sizeof(struct StringBuffer));
1246 memset(&R_temp_kj, 0, sizeof(struct StringBuffer)); 1248 memset (&R_temp_kj, 0, sizeof(struct StringBuffer));
1247 remove_epsilon(R_last_ik, &R_temp_ik); 1249 remove_epsilon (R_last_ik, &R_temp_ik);
1248 remove_epsilon(R_last_kk, &R_temp_kk); 1250 remove_epsilon (R_last_kk, &R_temp_kk);
1249 remove_epsilon(R_last_kj, &R_temp_kj); 1251 remove_epsilon (R_last_kj, &R_temp_kj);
1250 remove_parentheses(&R_temp_ik); 1252 remove_parentheses (&R_temp_ik);
1251 remove_parentheses(&R_temp_kk); 1253 remove_parentheses (&R_temp_kk);
1252 remove_parentheses(&R_temp_kj); 1254 remove_parentheses (&R_temp_kj);
1253 clean_ik_kk_cmp = sb_nullstrcmp(R_last_ik, &R_temp_kk); 1255 clean_ik_kk_cmp = sb_nullstrcmp (R_last_ik, &R_temp_kk);
1254 clean_kk_kj_cmp = sb_nullstrcmp(&R_temp_kk, R_last_kj); 1256 clean_kk_kj_cmp = sb_nullstrcmp (&R_temp_kk, R_last_kj);
1255 1257
1256 /* construct R_cur_l (and, if necessary R_cur_r) */ 1258 /* construct R_cur_l (and, if necessary R_cur_r) */
1257 if (GNUNET_YES != R_last_ij->null_flag) 1259 if (GNUNET_YES != R_last_ij->null_flag)
1260 {
1261 /* Assign R_temp_ij to R_last_ij and remove epsilon as well
1262 * as parentheses, so we can better compare the contents */
1263 remove_epsilon (R_last_ij, &R_temp_ij);
1264 remove_parentheses (&R_temp_ij);
1265
1266 if ((0 == sb_strcmp (&R_temp_ij, &R_temp_ik)) &&
1267 (0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) &&
1268 (0 == sb_strcmp (&R_temp_kk, &R_temp_kj)))
1258 { 1269 {
1259 /* Assign R_temp_ij to R_last_ij and remove epsilon as well 1270 if (0 == R_temp_ij.slen)
1260 * as parentheses, so we can better compare the contents */ 1271 {
1261 remove_epsilon(R_last_ij, &R_temp_ij); 1272 R_cur_r->null_flag = GNUNET_NO;
1262 remove_parentheses(&R_temp_ij); 1273 }
1263 1274 else if ((0 == sb_strncmp_cstr (R_last_ij, "(|", 2)) ||
1264 if ((0 == sb_strcmp(&R_temp_ij, &R_temp_ik)) && 1275 ((0 == sb_strncmp_cstr (R_last_ik, "(|", 2)) &&
1265 (0 == sb_strcmp(&R_temp_ik, &R_temp_kk)) && 1276 (0 == sb_strncmp_cstr (R_last_kj, "(|", 2)) ))
1266 (0 == sb_strcmp(&R_temp_kk, &R_temp_kj))) 1277 {
1267 { 1278 /*
1268 if (0 == R_temp_ij.slen) 1279 * a|(e|a)a*(e|a) = a*
1269 { 1280 * a|(e|a)(e|a)*(e|a) = a*
1270 R_cur_r->null_flag = GNUNET_NO; 1281 * (e|a)|aa*a = a*
1271 } 1282 * (e|a)|aa*(e|a) = a*
1272 else if ((0 == sb_strncmp_cstr(R_last_ij, "(|", 2)) || 1283 * (e|a)|(e|a)a*a = a*
1273 (0 == sb_strncmp_cstr(R_last_ik, "(|", 2) && 1284 * (e|a)|(e|a)a*(e|a) = a*
1274 0 == sb_strncmp_cstr(R_last_kj, "(|", 2))) 1285 * (e|a)|(e|a)(e|a)*(e|a) = a*
1275 { 1286 */
1276 /* 1287 if (GNUNET_YES == needs_parentheses (&R_temp_ij))
1277 * a|(e|a)a*(e|a) = a* 1288 sb_printf1 (R_cur_r, "(%.*s)*", 3, &R_temp_ij);
1278 * a|(e|a)(e|a)*(e|a) = a* 1289 else
1279 * (e|a)|aa*a = a* 1290 sb_printf1 (R_cur_r, "%.*s*", 1, &R_temp_ij);
1280 * (e|a)|aa*(e|a) = a* 1291 }
1281 * (e|a)|(e|a)a*a = a* 1292 else
1282 * (e|a)|(e|a)a*(e|a) = a* 1293 {
1283 * (e|a)|(e|a)(e|a)*(e|a) = a* 1294 /*
1284 */ 1295 * a|aa*a = a+
1285 if (GNUNET_YES == needs_parentheses(&R_temp_ij)) 1296 * a|(e|a)a*a = a+
1286 sb_printf1(R_cur_r, "(%.*s)*", 3, &R_temp_ij); 1297 * a|aa*(e|a) = a+
1287 else 1298 * a|(e|a)(e|a)*a = a+
1288 sb_printf1(R_cur_r, "%.*s*", 1, &R_temp_ij); 1299 * a|a(e|a)*(e|a) = a+
1289 } 1300 */
1290 else 1301 if (GNUNET_YES == needs_parentheses (&R_temp_ij))
1291 { 1302 sb_printf1 (R_cur_r, "(%.*s)+", 3, &R_temp_ij);
1292 /* 1303 else
1293 * a|aa*a = a+ 1304 sb_printf1 (R_cur_r, "%.*s+", 1, &R_temp_ij);
1294 * a|(e|a)a*a = a+ 1305 }
1295 * a|aa*(e|a) = a+ 1306 }
1296 * a|(e|a)(e|a)*a = a+ 1307 else if ((0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) &&
1297 * a|a(e|a)*(e|a) = a+ 1308 (0 != clean_ik_kk_cmp))
1298 */ 1309 {
1299 if (GNUNET_YES == needs_parentheses(&R_temp_ij)) 1310 /* a|ab*b = ab* */
1300 sb_printf1(R_cur_r, "(%.*s)+", 3, &R_temp_ij); 1311 if (0 == R_last_kk->slen)
1301 else 1312 sb_strdup (R_cur_r, R_last_ij);
1302 sb_printf1(R_cur_r, "%.*s+", 1, &R_temp_ij); 1313 else if (GNUNET_YES == needs_parentheses (&R_temp_kk))
1303 } 1314 sb_printf2 (R_cur_r, "%.*s(%.*s)*", 3, R_last_ij, &R_temp_kk);
1304 } 1315 else
1305 else if ((0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) && 1316 sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, R_last_kk);
1306 (0 != clean_ik_kk_cmp)) 1317 R_cur_l->null_flag = GNUNET_YES;
1307 { 1318 }
1308 /* a|ab*b = ab* */ 1319 else if ((0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) &&
1309 if (0 == R_last_kk->slen) 1320 (0 != clean_kk_kj_cmp))
1310 sb_strdup(R_cur_r, R_last_ij); 1321 {
1311 else if (GNUNET_YES == needs_parentheses(&R_temp_kk)) 1322 /* a|bb*a = b*a */
1312 sb_printf2(R_cur_r, "%.*s(%.*s)*", 3, R_last_ij, &R_temp_kk); 1323 if (R_last_kk->slen < 1)
1313 else 1324 {
1314 sb_printf2(R_cur_r, "%.*s%.*s*", 1, R_last_ij, R_last_kk); 1325 sb_strdup (R_cur_r, R_last_kj);
1315 R_cur_l->null_flag = GNUNET_YES; 1326 }
1316 } 1327 else if (GNUNET_YES == needs_parentheses (&R_temp_kk))
1317 else if ((0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) && 1328 sb_printf2 (R_cur_r, "(%.*s)*%.*s", 3, &R_temp_kk, R_last_kj);
1318 (0 != clean_kk_kj_cmp)) 1329 else
1319 { 1330 sb_printf2 (R_cur_r, "%.*s*%.*s", 1, &R_temp_kk, R_last_kj);
1320 /* a|bb*a = b*a */
1321 if (R_last_kk->slen < 1)
1322 {
1323 sb_strdup(R_cur_r, R_last_kj);
1324 }
1325 else if (GNUNET_YES == needs_parentheses(&R_temp_kk))
1326 sb_printf2(R_cur_r, "(%.*s)*%.*s", 3, &R_temp_kk, R_last_kj);
1327 else
1328 sb_printf2(R_cur_r, "%.*s*%.*s", 1, &R_temp_kk, R_last_kj);
1329 1331
1330 R_cur_l->null_flag = GNUNET_YES; 1332 R_cur_l->null_flag = GNUNET_YES;
1331 } 1333 }
1332 else if ((0 == ij_ik_cmp) && (0 == kk_kj_cmp) && 1334 else if ((0 == ij_ik_cmp) && (0 == kk_kj_cmp) &&
1333 (!has_epsilon(R_last_ij)) && has_epsilon(R_last_kk)) 1335 (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk))
1334 { 1336 {
1335 /* a|a(e|b)*(e|b) = a|ab* = a|a|ab|abb|abbb|... = ab* */ 1337 /* a|a(e|b)*(e|b) = a|ab* = a|a|ab|abb|abbb|... = ab* */
1336 if (needs_parentheses(&R_temp_kk)) 1338 if (needs_parentheses (&R_temp_kk))
1337 sb_printf2(R_cur_r, "%.*s(%.*s)*", 3, R_last_ij, &R_temp_kk); 1339 sb_printf2 (R_cur_r, "%.*s(%.*s)*", 3, R_last_ij, &R_temp_kk);
1338 else
1339 sb_printf2(R_cur_r, "%.*s%.*s*", 1, R_last_ij, &R_temp_kk);
1340 R_cur_l->null_flag = GNUNET_YES;
1341 }
1342 else if ((0 == ij_kj_cmp) && (0 == ik_kk_cmp) &&
1343 (!has_epsilon(R_last_ij)) && has_epsilon(R_last_kk))
1344 {
1345 /* a|(e|b)(e|b)*a = a|b*a = a|a|ba|bba|bbba|... = b*a */
1346 if (needs_parentheses(&R_temp_kk))
1347 sb_printf2(R_cur_r, "(%.*s)*%.*s", 3, &R_temp_kk, R_last_ij);
1348 else
1349 sb_printf2(R_cur_r, "%.*s*%.*s", 1, &R_temp_kk, R_last_ij);
1350 R_cur_l->null_flag = GNUNET_YES;
1351 }
1352 else 1340 else
1353 { 1341 sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, &R_temp_kk);
1354 sb_strdup(R_cur_l, R_last_ij); 1342 R_cur_l->null_flag = GNUNET_YES;
1355 remove_parentheses(R_cur_l);
1356 }
1357 } 1343 }
1358 else 1344 else if ((0 == ij_kj_cmp) && (0 == ik_kk_cmp) &&
1345 (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk))
1359 { 1346 {
1360 /* we have no left side */ 1347 /* a|(e|b)(e|b)*a = a|b*a = a|a|ba|bba|bbba|... = b*a */
1348 if (needs_parentheses (&R_temp_kk))
1349 sb_printf2 (R_cur_r, "(%.*s)*%.*s", 3, &R_temp_kk, R_last_ij);
1350 else
1351 sb_printf2 (R_cur_r, "%.*s*%.*s", 1, &R_temp_kk, R_last_ij);
1361 R_cur_l->null_flag = GNUNET_YES; 1352 R_cur_l->null_flag = GNUNET_YES;
1362 } 1353 }
1354 else
1355 {
1356 sb_strdup (R_cur_l, R_last_ij);
1357 remove_parentheses (R_cur_l);
1358 }
1359 }
1360 else
1361 {
1362 /* we have no left side */
1363 R_cur_l->null_flag = GNUNET_YES;
1364 }
1363 1365
1364 /* construct R_cur_r, if not already constructed */ 1366 /* construct R_cur_r, if not already constructed */
1365 if (GNUNET_YES == R_cur_r->null_flag) 1367 if (GNUNET_YES == R_cur_r->null_flag)
1368 {
1369 length = R_temp_kk.slen - R_last_ik->slen;
1370
1371 /* a(ba)*bx = (ab)+x */
1372 if ((length > 0) && (GNUNET_YES != R_last_kk->null_flag) &&
1373 (0 < R_last_kk->slen) && (GNUNET_YES != R_last_kj->null_flag) &&
1374 (0 < R_last_kj->slen) && (GNUNET_YES != R_last_ik->null_flag) &&
1375 (0 < R_last_ik->slen) &&
1376 (0 == sb_strkcmp (&R_temp_kk, R_last_ik, length)) &&
1377 (0 == sb_strncmp (&R_temp_kk, R_last_kj, length)))
1378 {
1379 struct StringBuffer temp_a;
1380 struct StringBuffer temp_b;
1381
1382 sb_init (&temp_a, length);
1383 sb_init (&temp_b, R_last_kj->slen - length);
1384
1385 length_l = length;
1386 temp_a.sbuf = temp_a.abuf;
1387 GNUNET_memcpy (temp_a.sbuf, R_last_kj->sbuf, length_l);
1388 temp_a.slen = length_l;
1389
1390 length_r = R_last_kj->slen - length;
1391 temp_b.sbuf = temp_b.abuf;
1392 GNUNET_memcpy (temp_b.sbuf, &R_last_kj->sbuf[length], length_r);
1393 temp_b.slen = length_r;
1394
1395 /* e|(ab)+ = (ab)* */
1396 if ((GNUNET_YES != R_cur_l->null_flag) && (0 == R_cur_l->slen) &&
1397 (0 == temp_b.slen))
1398 {
1399 sb_printf2 (R_cur_r, "(%.*s%.*s)*", 3, R_last_ik, &temp_a);
1400 sb_free (R_cur_l);
1401 R_cur_l->null_flag = GNUNET_YES;
1402 }
1403 else
1404 {
1405 sb_printf3 (R_cur_r, "(%.*s%.*s)+%.*s", 3, R_last_ik, &temp_a, &temp_b);
1406 }
1407 sb_free (&temp_a);
1408 sb_free (&temp_b);
1409 }
1410 else if ((0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) &&
1411 (0 == sb_strcmp (&R_temp_kk, &R_temp_kj)) )
1366 { 1412 {
1367 length = R_temp_kk.slen - R_last_ik->slen;
1368
1369 /* a(ba)*bx = (ab)+x */
1370 if ((length > 0) && (GNUNET_YES != R_last_kk->null_flag) &&
1371 (0 < R_last_kk->slen) && (GNUNET_YES != R_last_kj->null_flag) &&
1372 (0 < R_last_kj->slen) && (GNUNET_YES != R_last_ik->null_flag) &&
1373 (0 < R_last_ik->slen) &&
1374 (0 == sb_strkcmp(&R_temp_kk, R_last_ik, length)) &&
1375 (0 == sb_strncmp(&R_temp_kk, R_last_kj, length)))
1376 {
1377 struct StringBuffer temp_a;
1378 struct StringBuffer temp_b;
1379
1380 sb_init(&temp_a, length);
1381 sb_init(&temp_b, R_last_kj->slen - length);
1382
1383 length_l = length;
1384 temp_a.sbuf = temp_a.abuf;
1385 GNUNET_memcpy(temp_a.sbuf, R_last_kj->sbuf, length_l);
1386 temp_a.slen = length_l;
1387
1388 length_r = R_last_kj->slen - length;
1389 temp_b.sbuf = temp_b.abuf;
1390 GNUNET_memcpy(temp_b.sbuf, &R_last_kj->sbuf[length], length_r);
1391 temp_b.slen = length_r;
1392
1393 /* e|(ab)+ = (ab)* */
1394 if ((GNUNET_YES != R_cur_l->null_flag) && (0 == R_cur_l->slen) &&
1395 (0 == temp_b.slen))
1396 {
1397 sb_printf2(R_cur_r, "(%.*s%.*s)*", 3, R_last_ik, &temp_a);
1398 sb_free(R_cur_l);
1399 R_cur_l->null_flag = GNUNET_YES;
1400 }
1401 else
1402 {
1403 sb_printf3(R_cur_r, "(%.*s%.*s)+%.*s", 3, R_last_ik, &temp_a, &temp_b);
1404 }
1405 sb_free(&temp_a);
1406 sb_free(&temp_b);
1407 }
1408 else if (0 == sb_strcmp(&R_temp_ik, &R_temp_kk) &&
1409 0 == sb_strcmp(&R_temp_kk, &R_temp_kj))
1410 {
1411 /*
1412 * (e|a)a*(e|a) = a*
1413 * (e|a)(e|a)*(e|a) = a*
1414 */
1415 if (has_epsilon(R_last_ik) && has_epsilon(R_last_kj))
1416 {
1417 if (needs_parentheses(&R_temp_kk))
1418 sb_printf1(R_cur_r, "(%.*s)*", 3, &R_temp_kk);
1419 else
1420 sb_printf1(R_cur_r, "%.*s*", 1, &R_temp_kk);
1421 }
1422 /* aa*a = a+a */
1423 else if ((0 == clean_ik_kk_cmp) && (0 == clean_kk_kj_cmp) &&
1424 (!has_epsilon(R_last_ik)))
1425 {
1426 if (needs_parentheses(&R_temp_kk))
1427 sb_printf2(R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, &R_temp_kk);
1428 else
1429 sb_printf2(R_cur_r, "%.*s+%.*s", 1, &R_temp_kk, &R_temp_kk);
1430 }
1431 /*
1432 * (e|a)a*a = a+
1433 * aa*(e|a) = a+
1434 * a(e|a)*(e|a) = a+
1435 * (e|a)a*a = a+
1436 */
1437 else
1438 {
1439 eps_check = (has_epsilon(R_last_ik) + has_epsilon(R_last_kk) +
1440 has_epsilon(R_last_kj));
1441
1442 if (1 == eps_check)
1443 {
1444 if (needs_parentheses(&R_temp_kk))
1445 sb_printf1(R_cur_r, "(%.*s)+", 3, &R_temp_kk);
1446 else
1447 sb_printf1(R_cur_r, "%.*s+", 1, &R_temp_kk);
1448 }
1449 }
1450 }
1451 /* 1413 /*
1452 * aa*b = a+b 1414 * (e|a)a*(e|a) = a*
1453 * (e|a)(e|a)*b = a*b 1415 * (e|a)(e|a)*(e|a) = a*
1454 */ 1416 */
1455 else if (0 == sb_strcmp(&R_temp_ik, &R_temp_kk)) 1417 if (has_epsilon (R_last_ik) && has_epsilon (R_last_kj))
1456 { 1418 {
1457 if (has_epsilon(R_last_ik)) 1419 if (needs_parentheses (&R_temp_kk))
1458 { 1420 sb_printf1 (R_cur_r, "(%.*s)*", 3, &R_temp_kk);
1459 if (needs_parentheses(&R_temp_kk)) 1421 else
1460 sb_printf2(R_cur_r, "(%.*s)*%.*s", 3, &R_temp_kk, R_last_kj); 1422 sb_printf1 (R_cur_r, "%.*s*", 1, &R_temp_kk);
1461 else 1423 }
1462 sb_printf2(R_cur_r, "%.*s*%.*s", 1, &R_temp_kk, R_last_kj); 1424 /* aa*a = a+a */
1463 } 1425 else if ((0 == clean_ik_kk_cmp) && (0 == clean_kk_kj_cmp) &&
1464 else 1426 (! has_epsilon (R_last_ik)))
1465 { 1427 {
1466 if (needs_parentheses(&R_temp_kk)) 1428 if (needs_parentheses (&R_temp_kk))
1467 sb_printf2(R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, R_last_kj); 1429 sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, &R_temp_kk);
1468 else 1430 else
1469 sb_printf2(R_cur_r, "%.*s+%.*s", 1, &R_temp_kk, R_last_kj); 1431 sb_printf2 (R_cur_r, "%.*s+%.*s", 1, &R_temp_kk, &R_temp_kk);
1470 } 1432 }
1471 }
1472 /* 1433 /*
1473 * ba*a = ba+ 1434 * (e|a)a*a = a+
1474 * b(e|a)*(e|a) = ba* 1435 * aa*(e|a) = a+
1436 * a(e|a)*(e|a) = a+
1437 * (e|a)a*a = a+
1475 */ 1438 */
1476 else if (0 == sb_strcmp(&R_temp_kk, &R_temp_kj)) 1439 else
1440 {
1441 eps_check = (has_epsilon (R_last_ik) + has_epsilon (R_last_kk)
1442 + has_epsilon (R_last_kj));
1443
1444 if (1 == eps_check)
1477 { 1445 {
1478 if (has_epsilon(R_last_kj)) 1446 if (needs_parentheses (&R_temp_kk))
1479 { 1447 sb_printf1 (R_cur_r, "(%.*s)+", 3, &R_temp_kk);
1480 if (needs_parentheses(&R_temp_kk))
1481 sb_printf2(R_cur_r, "%.*s(%.*s)*", 3, R_last_ik, &R_temp_kk);
1482 else
1483 sb_printf2(R_cur_r, "%.*s%.*s*", 1, R_last_ik, &R_temp_kk);
1484 }
1485 else 1448 else
1486 { 1449 sb_printf1 (R_cur_r, "%.*s+", 1, &R_temp_kk);
1487 if (needs_parentheses(&R_temp_kk))
1488 sb_printf2(R_cur_r, "(%.*s)+%.*s", 3, R_last_ik, &R_temp_kk);
1489 else
1490 sb_printf2(R_cur_r, "%.*s+%.*s", 1, R_last_ik, &R_temp_kk);
1491 }
1492 } 1450 }
1451 }
1452 }
1453 /*
1454 * aa*b = a+b
1455 * (e|a)(e|a)*b = a*b
1456 */
1457 else if (0 == sb_strcmp (&R_temp_ik, &R_temp_kk))
1458 {
1459 if (has_epsilon (R_last_ik))
1460 {
1461 if (needs_parentheses (&R_temp_kk))
1462 sb_printf2 (R_cur_r, "(%.*s)*%.*s", 3, &R_temp_kk, R_last_kj);
1463 else
1464 sb_printf2 (R_cur_r, "%.*s*%.*s", 1, &R_temp_kk, R_last_kj);
1465 }
1466 else
1467 {
1468 if (needs_parentheses (&R_temp_kk))
1469 sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, R_last_kj);
1470 else
1471 sb_printf2 (R_cur_r, "%.*s+%.*s", 1, &R_temp_kk, R_last_kj);
1472 }
1473 }
1474 /*
1475 * ba*a = ba+
1476 * b(e|a)*(e|a) = ba*
1477 */
1478 else if (0 == sb_strcmp (&R_temp_kk, &R_temp_kj))
1479 {
1480 if (has_epsilon (R_last_kj))
1481 {
1482 if (needs_parentheses (&R_temp_kk))
1483 sb_printf2 (R_cur_r, "%.*s(%.*s)*", 3, R_last_ik, &R_temp_kk);
1484 else
1485 sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ik, &R_temp_kk);
1486 }
1493 else 1487 else
1488 {
1489 if (needs_parentheses (&R_temp_kk))
1490 sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, R_last_ik, &R_temp_kk);
1491 else
1492 sb_printf2 (R_cur_r, "%.*s+%.*s", 1, R_last_ik, &R_temp_kk);
1493 }
1494 }
1495 else
1496 {
1497 if (0 < R_temp_kk.slen)
1498 {
1499 if (needs_parentheses (&R_temp_kk))
1494 { 1500 {
1495 if (0 < R_temp_kk.slen) 1501 sb_printf3 (R_cur_r,
1496 { 1502 "%.*s(%.*s)*%.*s",
1497 if (needs_parentheses(&R_temp_kk)) 1503 3,
1498 { 1504 R_last_ik,
1499 sb_printf3(R_cur_r, 1505 &R_temp_kk,
1500 "%.*s(%.*s)*%.*s", 1506 R_last_kj);
1501 3, 1507 }
1502 R_last_ik, 1508 else
1503 &R_temp_kk, 1509 {
1504 R_last_kj); 1510 sb_printf3 (R_cur_r,
1505 } 1511 "%.*s%.*s*%.*s",
1506 else 1512 1,
1507 { 1513 R_last_ik,
1508 sb_printf3(R_cur_r, 1514 &R_temp_kk,
1509 "%.*s%.*s*%.*s", 1515 R_last_kj);
1510 1,
1511 R_last_ik,
1512 &R_temp_kk,
1513 R_last_kj);
1514 }
1515 }
1516 else
1517 {
1518 sb_printf2(R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj);
1519 }
1520 } 1516 }
1517 }
1518 else
1519 {
1520 sb_printf2 (R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj);
1521 }
1521 } 1522 }
1522 sb_free(&R_temp_ij); 1523 }
1523 sb_free(&R_temp_ik); 1524 sb_free (&R_temp_ij);
1524 sb_free(&R_temp_kk); 1525 sb_free (&R_temp_ik);
1525 sb_free(&R_temp_kj); 1526 sb_free (&R_temp_kk);
1527 sb_free (&R_temp_kj);
1526 1528
1527 if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag)) 1529 if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag))
1528 { 1530 {
1529 R_cur_ij->null_flag = GNUNET_YES; 1531 R_cur_ij->null_flag = GNUNET_YES;
1530 return; 1532 return;
1531 } 1533 }
1532 1534
1533 if ((GNUNET_YES != R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag)) 1535 if ((GNUNET_YES != R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag))
1534 { 1536 {
1535 struct StringBuffer tmp; 1537 struct StringBuffer tmp;
1536 1538
1537 tmp = *R_cur_ij; 1539 tmp = *R_cur_ij;
1538 *R_cur_ij = *R_cur_l; 1540 *R_cur_ij = *R_cur_l;
1539 *R_cur_l = tmp; 1541 *R_cur_l = tmp;
1540 return; 1542 return;
1541 } 1543 }
1542 1544
1543 if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES != R_cur_r->null_flag)) 1545 if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES != R_cur_r->null_flag))
1544 { 1546 {
1545 struct StringBuffer tmp; 1547 struct StringBuffer tmp;
1546 1548
1547 tmp = *R_cur_ij; 1549 tmp = *R_cur_ij;
1548 *R_cur_ij = *R_cur_r; 1550 *R_cur_ij = *R_cur_r;
1549 *R_cur_r = tmp; 1551 *R_cur_r = tmp;
1550 return; 1552 return;
1551 } 1553 }
1552 1554
1553 if (0 == sb_nullstrcmp(R_cur_l, R_cur_r)) 1555 if (0 == sb_nullstrcmp (R_cur_l, R_cur_r))
1554 { 1556 {
1555 struct StringBuffer tmp; 1557 struct StringBuffer tmp;
1556 1558
1557 tmp = *R_cur_ij; 1559 tmp = *R_cur_ij;
1558 *R_cur_ij = *R_cur_l; 1560 *R_cur_ij = *R_cur_l;
1559 *R_cur_l = tmp; 1561 *R_cur_l = tmp;
1560 return; 1562 return;
1561 } 1563 }
1562 sb_printf2(R_cur_ij, "(%.*s|%.*s)", 3, R_cur_l, R_cur_r); 1564 sb_printf2 (R_cur_ij, "(%.*s|%.*s)", 3, R_cur_l, R_cur_r);
1563} 1565}
1564 1566
1565 1567
@@ -1575,7 +1577,7 @@ automaton_create_proofs_simplify(const struct StringBuffer *R_last_ij,
1575 * @param a automaton for which to assign proofs and hashes, must not be NULL 1577 * @param a automaton for which to assign proofs and hashes, must not be NULL
1576 */ 1578 */
1577static int 1579static int
1578automaton_create_proofs(struct REGEX_INTERNAL_Automaton *a) 1580automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a)
1579{ 1581{
1580 unsigned int n = a->state_count; 1582 unsigned int n = a->state_count;
1581 struct REGEX_INTERNAL_State *states[n]; 1583 struct REGEX_INTERNAL_State *states[n];
@@ -1590,143 +1592,143 @@ automaton_create_proofs(struct REGEX_INTERNAL_Automaton *a)
1590 unsigned int j; 1592 unsigned int j;
1591 unsigned int k; 1593 unsigned int k;
1592 1594
1593 R_last = GNUNET_malloc_large(sizeof(struct StringBuffer) * n * n); 1595 R_last = GNUNET_malloc_large (sizeof(struct StringBuffer) * n * n);
1594 R_cur = GNUNET_malloc_large(sizeof(struct StringBuffer) * n * n); 1596 R_cur = GNUNET_malloc_large (sizeof(struct StringBuffer) * n * n);
1595 if ((NULL == R_last) || (NULL == R_cur)) 1597 if ((NULL == R_last) || (NULL == R_cur))
1596 { 1598 {
1597 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "malloc"); 1599 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
1598 GNUNET_free_non_null(R_cur); 1600 GNUNET_free_non_null (R_cur);
1599 GNUNET_free_non_null(R_last); 1601 GNUNET_free_non_null (R_last);
1600 return GNUNET_SYSERR; 1602 return GNUNET_SYSERR;
1601 } 1603 }
1602 1604
1603 /* create depth-first numbering of the states, initializes 'state' */ 1605 /* create depth-first numbering of the states, initializes 'state' */
1604 REGEX_INTERNAL_automaton_traverse(a, 1606 REGEX_INTERNAL_automaton_traverse (a,
1605 a->start, 1607 a->start,
1606 NULL, 1608 NULL,
1607 NULL, 1609 NULL,
1608 &number_states, 1610 &number_states,
1609 states); 1611 states);
1610 1612
1611 for (i = 0; i < n; i++) 1613 for (i = 0; i < n; i++)
1612 GNUNET_assert(NULL != states[i]); 1614 GNUNET_assert (NULL != states[i]);
1613 for (i = 0; i < n; i++) 1615 for (i = 0; i < n; i++)
1614 for (j = 0; j < n; j++) 1616 for (j = 0; j < n; j++)
1615 R_last[i * n + j].null_flag = GNUNET_YES; 1617 R_last[i * n + j].null_flag = GNUNET_YES;
1616 1618
1617 /* Compute regular expressions of length "1" between each pair of states */ 1619 /* Compute regular expressions of length "1" between each pair of states */
1618 for (i = 0; i < n; i++) 1620 for (i = 0; i < n; i++)
1621 {
1622 for (t = states[i]->transitions_head; NULL != t; t = t->next)
1619 { 1623 {
1620 for (t = states[i]->transitions_head; NULL != t; t = t->next) 1624 j = t->to_state->dfs_id;
1621 { 1625 if (GNUNET_YES == R_last[i * n + j].null_flag)
1622 j = t->to_state->dfs_id; 1626 {
1623 if (GNUNET_YES == R_last[i * n + j].null_flag) 1627 sb_strdup_cstr (&R_last[i * n + j], t->label);
1624 { 1628 }
1625 sb_strdup_cstr(&R_last[i * n + j], t->label);
1626 }
1627 else
1628 {
1629 sb_append_cstr(&R_last[i * n + j], "|");
1630 sb_append_cstr(&R_last[i * n + j], t->label);
1631 }
1632 }
1633 /* add self-loop: i is reachable from i via epsilon-transition */
1634 if (GNUNET_YES == R_last[i * n + i].null_flag)
1635 {
1636 R_last[i * n + i].slen = 0;
1637 R_last[i * n + i].null_flag = GNUNET_NO;
1638 }
1639 else 1629 else
1640 { 1630 {
1641 sb_wrap(&R_last[i * n + i], "(|%.*s)", 3); 1631 sb_append_cstr (&R_last[i * n + j], "|");
1642 } 1632 sb_append_cstr (&R_last[i * n + j], t->label);
1633 }
1643 } 1634 }
1635 /* add self-loop: i is reachable from i via epsilon-transition */
1636 if (GNUNET_YES == R_last[i * n + i].null_flag)
1637 {
1638 R_last[i * n + i].slen = 0;
1639 R_last[i * n + i].null_flag = GNUNET_NO;
1640 }
1641 else
1642 {
1643 sb_wrap (&R_last[i * n + i], "(|%.*s)", 3);
1644 }
1645 }
1644 for (i = 0; i < n; i++) 1646 for (i = 0; i < n; i++)
1645 for (j = 0; j < n; j++) 1647 for (j = 0; j < n; j++)
1646 if (needs_parentheses(&R_last[i * n + j])) 1648 if (needs_parentheses (&R_last[i * n + j]))
1647 sb_wrap(&R_last[i * n + j], "(%.*s)", 2); 1649 sb_wrap (&R_last[i * n + j], "(%.*s)", 2);
1648 /* Compute regular expressions of length "k" between each pair of states per 1650 /* Compute regular expressions of length "k" between each pair of states per
1649 * induction */ 1651 * induction */
1650 memset(&R_cur_l, 0, sizeof(struct StringBuffer)); 1652 memset (&R_cur_l, 0, sizeof(struct StringBuffer));
1651 memset(&R_cur_r, 0, sizeof(struct StringBuffer)); 1653 memset (&R_cur_r, 0, sizeof(struct StringBuffer));
1652 for (k = 0; k < n; k++) 1654 for (k = 0; k < n; k++)
1655 {
1656 for (i = 0; i < n; i++)
1653 { 1657 {
1654 for (i = 0; i < n; i++) 1658 for (j = 0; j < n; j++)
1655 { 1659 {
1656 for (j = 0; j < n; j++) 1660 /* Basis for the recursion:
1657 { 1661 * $R^{(k)}_{ij} = R^{(k-1)}_{ij} | R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj}
1658 /* Basis for the recursion: 1662 * R_last == R^{(k-1)}, R_cur == R^{(k)}
1659 * $R^{(k)}_{ij} = R^{(k-1)}_{ij} | R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj} 1663 */
1660 * R_last == R^{(k-1)}, R_cur == R^{(k)} 1664
1661 */ 1665 /* Create R_cur[i][j] and simplify the expression */
1662 1666 automaton_create_proofs_simplify (&R_last[i * n + j],
1663 /* Create R_cur[i][j] and simplify the expression */ 1667 &R_last[i * n + k],
1664 automaton_create_proofs_simplify(&R_last[i * n + j], 1668 &R_last[k * n + k],
1665 &R_last[i * n + k], 1669 &R_last[k * n + j],
1666 &R_last[k * n + k], 1670 &R_cur[i * n + j],
1667 &R_last[k * n + j], 1671 &R_cur_l,
1668 &R_cur[i * n + j], 1672 &R_cur_r);
1669 &R_cur_l, 1673 }
1670 &R_cur_r);
1671 }
1672 }
1673 /* set R_last = R_cur */
1674 R_swap = R_last;
1675 R_last = R_cur;
1676 R_cur = R_swap;
1677 /* clear 'R_cur' for next iteration */
1678 for (i = 0; i < n; i++)
1679 for (j = 0; j < n; j++)
1680 R_cur[i * n + j].null_flag = GNUNET_YES;
1681 } 1674 }
1682 sb_free(&R_cur_l); 1675 /* set R_last = R_cur */
1683 sb_free(&R_cur_r); 1676 R_swap = R_last;
1677 R_last = R_cur;
1678 R_cur = R_swap;
1679 /* clear 'R_cur' for next iteration */
1680 for (i = 0; i < n; i++)
1681 for (j = 0; j < n; j++)
1682 R_cur[i * n + j].null_flag = GNUNET_YES;
1683 }
1684 sb_free (&R_cur_l);
1685 sb_free (&R_cur_r);
1684 /* assign proofs and hashes */ 1686 /* assign proofs and hashes */
1685 for (i = 0; i < n; i++) 1687 for (i = 0; i < n; i++)
1688 {
1689 if (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag)
1686 { 1690 {
1687 if (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) 1691 states[i]->proof = GNUNET_strndup (R_last[a->start->dfs_id * n + i].sbuf,
1688 { 1692 R_last[a->start->dfs_id * n + i].slen);
1689 states[i]->proof = GNUNET_strndup(R_last[a->start->dfs_id * n + i].sbuf, 1693 GNUNET_CRYPTO_hash (states[i]->proof,
1690 R_last[a->start->dfs_id * n + i].slen); 1694 strlen (states[i]->proof),
1691 GNUNET_CRYPTO_hash(states[i]->proof, 1695 &states[i]->hash);
1692 strlen(states[i]->proof),
1693 &states[i]->hash);
1694 }
1695 } 1696 }
1697 }
1696 1698
1697 /* complete regex for whole DFA: union of all pairs (start state/accepting 1699 /* complete regex for whole DFA: union of all pairs (start state/accepting
1698 * state(s)). */ 1700 * state(s)). */
1699 sb_init(&complete_regex, 16 * n); 1701 sb_init (&complete_regex, 16 * n);
1700 for (i = 0; i < n; i++) 1702 for (i = 0; i < n; i++)
1703 {
1704 if (states[i]->accepting)
1701 { 1705 {
1702 if (states[i]->accepting) 1706 if ((0 == complete_regex.slen) &&
1703 { 1707 (0 < R_last[a->start->dfs_id * n + i].slen))
1704 if ((0 == complete_regex.slen) && 1708 {
1705 (0 < R_last[a->start->dfs_id * n + i].slen)) 1709 sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]);
1706 { 1710 }
1707 sb_append(&complete_regex, &R_last[a->start->dfs_id * n + i]); 1711 else if ((GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) &&
1708 } 1712 (0 < R_last[a->start->dfs_id * n + i].slen))
1709 else if ((GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) && 1713 {
1710 (0 < R_last[a->start->dfs_id * n + i].slen)) 1714 sb_append_cstr (&complete_regex, "|");
1711 { 1715 sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]);
1712 sb_append_cstr(&complete_regex, "|"); 1716 }
1713 sb_append(&complete_regex, &R_last[a->start->dfs_id * n + i]);
1714 }
1715 }
1716 } 1717 }
1718 }
1717 a->canonical_regex = 1719 a->canonical_regex =
1718 GNUNET_strndup(complete_regex.sbuf, complete_regex.slen); 1720 GNUNET_strndup (complete_regex.sbuf, complete_regex.slen);
1719 1721
1720 /* cleanup */ 1722 /* cleanup */
1721 sb_free(&complete_regex); 1723 sb_free (&complete_regex);
1722 for (i = 0; i < n; i++) 1724 for (i = 0; i < n; i++)
1723 for (j = 0; j < n; j++) 1725 for (j = 0; j < n; j++)
1724 { 1726 {
1725 sb_free(&R_cur[i * n + j]); 1727 sb_free (&R_cur[i * n + j]);
1726 sb_free(&R_last[i * n + j]); 1728 sb_free (&R_last[i * n + j]);
1727 } 1729 }
1728 GNUNET_free(R_cur); 1730 GNUNET_free (R_cur);
1729 GNUNET_free(R_last); 1731 GNUNET_free (R_last);
1730 return GNUNET_OK; 1732 return GNUNET_OK;
1731} 1733}
1732 1734
@@ -1741,8 +1743,8 @@ automaton_create_proofs(struct REGEX_INTERNAL_Automaton *a)
1741 * @return new DFA state 1743 * @return new DFA state
1742 */ 1744 */
1743static struct REGEX_INTERNAL_State * 1745static struct REGEX_INTERNAL_State *
1744dfa_state_create(struct REGEX_INTERNAL_Context *ctx, 1746dfa_state_create (struct REGEX_INTERNAL_Context *ctx,
1745 struct REGEX_INTERNAL_StateSet *nfa_states) 1747 struct REGEX_INTERNAL_StateSet *nfa_states)
1746{ 1748{
1747 struct REGEX_INTERNAL_State *s; 1749 struct REGEX_INTERNAL_State *s;
1748 char *pos; 1750 char *pos;
@@ -1751,16 +1753,16 @@ dfa_state_create(struct REGEX_INTERNAL_Context *ctx,
1751 struct REGEX_INTERNAL_Transition *ctran; 1753 struct REGEX_INTERNAL_Transition *ctran;
1752 unsigned int i; 1754 unsigned int i;
1753 1755
1754 s = GNUNET_new(struct REGEX_INTERNAL_State); 1756 s = GNUNET_new (struct REGEX_INTERNAL_State);
1755 s->id = ctx->state_id++; 1757 s->id = ctx->state_id++;
1756 s->index = -1; 1758 s->index = -1;
1757 s->lowlink = -1; 1759 s->lowlink = -1;
1758 1760
1759 if (NULL == nfa_states) 1761 if (NULL == nfa_states)
1760 { 1762 {
1761 GNUNET_asprintf(&s->name, "s%i", s->id); 1763 GNUNET_asprintf (&s->name, "s%i", s->id);
1762 return s; 1764 return s;
1763 } 1765 }
1764 1766
1765 s->nfa_set = *nfa_states; 1767 s->nfa_set = *nfa_states;
1766 1768
@@ -1769,30 +1771,30 @@ dfa_state_create(struct REGEX_INTERNAL_Context *ctx,
1769 1771
1770 /* Create a name based on 'nfa_states' */ 1772 /* Create a name based on 'nfa_states' */
1771 len = nfa_states->off * 14 + 4; 1773 len = nfa_states->off * 14 + 4;
1772 s->name = GNUNET_malloc(len); 1774 s->name = GNUNET_malloc (len);
1773 strcat(s->name, "{"); 1775 strcat (s->name, "{");
1774 pos = s->name + 1; 1776 pos = s->name + 1;
1775 1777
1776 for (i = 0; i < nfa_states->off; i++) 1778 for (i = 0; i < nfa_states->off; i++)
1777 { 1779 {
1778 cstate = nfa_states->states[i]; 1780 cstate = nfa_states->states[i];
1779 GNUNET_snprintf(pos, pos - s->name + len, "%i,", cstate->id); 1781 GNUNET_snprintf (pos, pos - s->name + len, "%i,", cstate->id);
1780 pos += strlen(pos); 1782 pos += strlen (pos);
1781 1783
1782 /* Add a transition for each distinct label to NULL state */ 1784 /* Add a transition for each distinct label to NULL state */
1783 for (ctran = cstate->transitions_head; NULL != ctran; ctran = ctran->next) 1785 for (ctran = cstate->transitions_head; NULL != ctran; ctran = ctran->next)
1784 if (NULL != ctran->label) 1786 if (NULL != ctran->label)
1785 state_add_transition(ctx, s, ctran->label, NULL); 1787 state_add_transition (ctx, s, ctran->label, NULL);
1786 1788
1787 /* If the nfa_states contain an accepting state, the new dfa state is also 1789 /* If the nfa_states contain an accepting state, the new dfa state is also
1788 * accepting. */ 1790 * accepting. */
1789 if (cstate->accepting) 1791 if (cstate->accepting)
1790 s->accepting = 1; 1792 s->accepting = 1;
1791 } 1793 }
1792 pos[-1] = '}'; 1794 pos[-1] = '}';
1793 s->name = GNUNET_realloc(s->name, strlen(s->name) + 1); 1795 s->name = GNUNET_realloc (s->name, strlen (s->name) + 1);
1794 1796
1795 memset(nfa_states, 0, sizeof(struct REGEX_INTERNAL_StateSet)); 1797 memset (nfa_states, 0, sizeof(struct REGEX_INTERNAL_StateSet));
1796 return s; 1798 return s;
1797} 1799}
1798 1800
@@ -1811,7 +1813,7 @@ dfa_state_create(struct REGEX_INTERNAL_Context *ctx,
1811 * @return length of the substring comsumed from 'str' 1813 * @return length of the substring comsumed from 'str'
1812 */ 1814 */
1813static unsigned int 1815static unsigned int
1814dfa_move(struct REGEX_INTERNAL_State **s, const char *str) 1816dfa_move (struct REGEX_INTERNAL_State **s, const char *str)
1815{ 1817{
1816 struct REGEX_INTERNAL_Transition *t; 1818 struct REGEX_INTERNAL_Transition *t;
1817 struct REGEX_INTERNAL_State *new_s; 1819 struct REGEX_INTERNAL_State *new_s;
@@ -1824,18 +1826,18 @@ dfa_move(struct REGEX_INTERNAL_State **s, const char *str)
1824 new_s = NULL; 1826 new_s = NULL;
1825 max_len = 0; 1827 max_len = 0;
1826 for (t = (*s)->transitions_head; NULL != t; t = t->next) 1828 for (t = (*s)->transitions_head; NULL != t; t = t->next)
1827 { 1829 {
1828 len = strlen(t->label); 1830 len = strlen (t->label);
1829 1831
1830 if (0 == strncmp(t->label, str, len)) 1832 if (0 == strncmp (t->label, str, len))
1831 { 1833 {
1832 if (len >= max_len) 1834 if (len >= max_len)
1833 { 1835 {
1834 max_len = len; 1836 max_len = len;
1835 new_s = t->to_state; 1837 new_s = t->to_state;
1836 } 1838 }
1837 }
1838 } 1839 }
1840 }
1839 1841
1840 *s = new_s; 1842 *s = new_s;
1841 return max_len; 1843 return max_len;
@@ -1852,9 +1854,9 @@ dfa_move(struct REGEX_INTERNAL_State **s, const char *str)
1852 * @param s state where the marked attribute will be set to #GNUNET_YES. 1854 * @param s state where the marked attribute will be set to #GNUNET_YES.
1853 */ 1855 */
1854static void 1856static void
1855mark_states(void *cls, 1857mark_states (void *cls,
1856 const unsigned int count, 1858 const unsigned int count,
1857 struct REGEX_INTERNAL_State *s) 1859 struct REGEX_INTERNAL_State *s)
1858{ 1860{
1859 s->marked = GNUNET_YES; 1861 s->marked = GNUNET_YES;
1860} 1862}
@@ -1867,7 +1869,7 @@ mark_states(void *cls,
1867 * @param a DFA automaton 1869 * @param a DFA automaton
1868 */ 1870 */
1869static void 1871static void
1870dfa_remove_unreachable_states(struct REGEX_INTERNAL_Automaton *a) 1872dfa_remove_unreachable_states (struct REGEX_INTERNAL_Automaton *a)
1871{ 1873{
1872 struct REGEX_INTERNAL_State *s; 1874 struct REGEX_INTERNAL_State *s;
1873 struct REGEX_INTERNAL_State *s_next; 1875 struct REGEX_INTERNAL_State *s_next;
@@ -1877,20 +1879,20 @@ dfa_remove_unreachable_states(struct REGEX_INTERNAL_Automaton *a)
1877 s->marked = GNUNET_NO; 1879 s->marked = GNUNET_NO;
1878 1880
1879 /* 2. traverse dfa from start state and mark all visited states */ 1881 /* 2. traverse dfa from start state and mark all visited states */
1880 REGEX_INTERNAL_automaton_traverse(a, 1882 REGEX_INTERNAL_automaton_traverse (a,
1881 a->start, 1883 a->start,
1882 NULL, 1884 NULL,
1883 NULL, 1885 NULL,
1884 &mark_states, 1886 &mark_states,
1885 NULL); 1887 NULL);
1886 1888
1887 /* 3. delete all states that were not visited */ 1889 /* 3. delete all states that were not visited */
1888 for (s = a->states_head; NULL != s; s = s_next) 1890 for (s = a->states_head; NULL != s; s = s_next)
1889 { 1891 {
1890 s_next = s->next; 1892 s_next = s->next;
1891 if (GNUNET_NO == s->marked) 1893 if (GNUNET_NO == s->marked)
1892 automaton_remove_state(a, s); 1894 automaton_remove_state (a, s);
1893 } 1895 }
1894} 1896}
1895 1897
1896 1898
@@ -1901,38 +1903,38 @@ dfa_remove_unreachable_states(struct REGEX_INTERNAL_Automaton *a)
1901 * @param a DFA automaton 1903 * @param a DFA automaton
1902 */ 1904 */
1903static void 1905static void
1904dfa_remove_dead_states(struct REGEX_INTERNAL_Automaton *a) 1906dfa_remove_dead_states (struct REGEX_INTERNAL_Automaton *a)
1905{ 1907{
1906 struct REGEX_INTERNAL_State *s; 1908 struct REGEX_INTERNAL_State *s;
1907 struct REGEX_INTERNAL_State *s_next; 1909 struct REGEX_INTERNAL_State *s_next;
1908 struct REGEX_INTERNAL_Transition *t; 1910 struct REGEX_INTERNAL_Transition *t;
1909 int dead; 1911 int dead;
1910 1912
1911 GNUNET_assert(DFA == a->type); 1913 GNUNET_assert (DFA == a->type);
1912 1914
1913 for (s = a->states_head; NULL != s; s = s_next) 1915 for (s = a->states_head; NULL != s; s = s_next)
1914 { 1916 {
1915 s_next = s->next; 1917 s_next = s->next;
1916 1918
1917 if (s->accepting) 1919 if (s->accepting)
1918 continue; 1920 continue;
1919 1921
1920 dead = 1; 1922 dead = 1;
1921 for (t = s->transitions_head; NULL != t; t = t->next) 1923 for (t = s->transitions_head; NULL != t; t = t->next)
1922 { 1924 {
1923 if (NULL != t->to_state && t->to_state != s) 1925 if ((NULL != t->to_state) &&(t->to_state != s) )
1924 { 1926 {
1925 dead = 0; 1927 dead = 0;
1926 break; 1928 break;
1927 } 1929 }
1928 } 1930 }
1929 1931
1930 if (0 == dead) 1932 if (0 == dead)
1931 continue; 1933 continue;
1932 1934
1933 /* state s is dead, remove it */ 1935 /* state s is dead, remove it */
1934 automaton_remove_state(a, s); 1936 automaton_remove_state (a, s);
1935 } 1937 }
1936} 1938}
1937 1939
1938 1940
@@ -1944,8 +1946,8 @@ dfa_remove_dead_states(struct REGEX_INTERNAL_Automaton *a)
1944 * @return #GNUNET_OK on success 1946 * @return #GNUNET_OK on success
1945 */ 1947 */
1946static int 1948static int
1947dfa_merge_nondistinguishable_states(struct REGEX_INTERNAL_Context *ctx, 1949dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx,
1948 struct REGEX_INTERNAL_Automaton *a) 1950 struct REGEX_INTERNAL_Automaton *a)
1949{ 1951{
1950 uint32_t *table; 1952 uint32_t *table;
1951 struct REGEX_INTERNAL_State *s1; 1953 struct REGEX_INTERNAL_State *s1;
@@ -1962,20 +1964,20 @@ dfa_merge_nondistinguishable_states(struct REGEX_INTERNAL_Context *ctx,
1962 unsigned long long idx1; 1964 unsigned long long idx1;
1963 1965
1964 if ((NULL == a) || (0 == a->state_count)) 1966 if ((NULL == a) || (0 == a->state_count))
1965 { 1967 {
1966 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1968 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1967 "Could not merge nondistinguishable states, automaton was NULL.\n"); 1969 "Could not merge nondistinguishable states, automaton was NULL.\n");
1968 return GNUNET_SYSERR; 1970 return GNUNET_SYSERR;
1969 } 1971 }
1970 1972
1971 state_cnt = a->state_count; 1973 state_cnt = a->state_count;
1972 table = GNUNET_malloc_large( 1974 table = GNUNET_malloc_large (
1973 (sizeof(uint32_t) * state_cnt * state_cnt / 32) + sizeof(uint32_t)); 1975 (sizeof(uint32_t) * state_cnt * state_cnt / 32) + sizeof(uint32_t));
1974 if (NULL == table) 1976 if (NULL == table)
1975 { 1977 {
1976 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "malloc"); 1978 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
1977 return GNUNET_SYSERR; 1979 return GNUNET_SYSERR;
1978 } 1980 }
1979 1981
1980 for (i = 0, s1 = a->states_head; NULL != s1; s1 = s1->next) 1982 for (i = 0, s1 = a->states_head; NULL != s1; s1 = s1->next)
1981 s1->marked = i++; 1983 s1->marked = i++;
@@ -1983,74 +1985,74 @@ dfa_merge_nondistinguishable_states(struct REGEX_INTERNAL_Context *ctx,
1983 /* Mark all pairs of accepting/!accepting states */ 1985 /* Mark all pairs of accepting/!accepting states */
1984 for (s1 = a->states_head; NULL != s1; s1 = s1->next) 1986 for (s1 = a->states_head; NULL != s1; s1 = s1->next)
1985 for (s2 = a->states_head; NULL != s2; s2 = s2->next) 1987 for (s2 = a->states_head; NULL != s2; s2 = s2->next)
1986 if ((s1->accepting && !s2->accepting) || 1988 if ((s1->accepting && ! s2->accepting) ||
1987 (!s1->accepting && s2->accepting)) 1989 (! s1->accepting && s2->accepting))
1988 { 1990 {
1989 idx = (unsigned long long)s1->marked * state_cnt + s2->marked; 1991 idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
1990 table[idx / 32] |= (1U << (idx % 32)); 1992 table[idx / 32] |= (1U << (idx % 32));
1991 } 1993 }
1992 1994
1993 /* Find all equal states */ 1995 /* Find all equal states */
1994 change = 1; 1996 change = 1;
1995 while (0 != change) 1997 while (0 != change)
1998 {
1999 change = 0;
2000 for (s1 = a->states_head; NULL != s1; s1 = s1->next)
1996 { 2001 {
1997 change = 0; 2002 for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next)
1998 for (s1 = a->states_head; NULL != s1; s1 = s1->next) 2003 {
2004 idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
2005 if (0 != (table[idx / 32] & (1U << (idx % 32))))
2006 continue;
2007 num_equal_edges = 0;
2008 for (t1 = s1->transitions_head; NULL != t1; t1 = t1->next)
1999 { 2009 {
2000 for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next) 2010 for (t2 = s2->transitions_head; NULL != t2; t2 = t2->next)
2011 {
2012 if (0 == strcmp (t1->label, t2->label))
2001 { 2013 {
2002 idx = (unsigned long long)s1->marked * state_cnt + s2->marked; 2014 num_equal_edges++;
2003 if (0 != (table[idx / 32] & (1U << (idx % 32)))) 2015 /* same edge, but targets definitively different, so we're different
2004 continue; 2016 as well */
2005 num_equal_edges = 0; 2017 if (t1->to_state->marked > t2->to_state->marked)
2006 for (t1 = s1->transitions_head; NULL != t1; t1 = t1->next) 2018 idx1 = (unsigned long long) t1->to_state->marked * state_cnt
2007 { 2019 + t2->to_state->marked;
2008 for (t2 = s2->transitions_head; NULL != t2; t2 = t2->next) 2020 else
2009 { 2021 idx1 = (unsigned long long) t2->to_state->marked * state_cnt
2010 if (0 == strcmp(t1->label, t2->label)) 2022 + t1->to_state->marked;
2011 { 2023 if (0 != (table[idx1 / 32] & (1U << (idx1 % 32))))
2012 num_equal_edges++; 2024 {
2013 /* same edge, but targets definitively different, so we're different 2025 table[idx / 32] |= (1U << (idx % 32));
2014 as well */ 2026 change = 1; /* changed a marker, need to run again */
2015 if (t1->to_state->marked > t2->to_state->marked) 2027 }
2016 idx1 = (unsigned long long)t1->to_state->marked * state_cnt +
2017 t2->to_state->marked;
2018 else
2019 idx1 = (unsigned long long)t2->to_state->marked * state_cnt +
2020 t1->to_state->marked;
2021 if (0 != (table[idx1 / 32] & (1U << (idx1 % 32))))
2022 {
2023 table[idx / 32] |= (1U << (idx % 32));
2024 change = 1; /* changed a marker, need to run again */
2025 }
2026 }
2027 }
2028 }
2029 if ((num_equal_edges != s1->transition_count) ||
2030 (num_equal_edges != s2->transition_count))
2031 {
2032 /* Make sure ALL edges of possible equal states are the same */
2033 table[idx / 32] |= (1U << (idx % 32));
2034 change = 1; /* changed a marker, need to run again */
2035 }
2036 } 2028 }
2029 }
2037 } 2030 }
2031 if ((num_equal_edges != s1->transition_count) ||
2032 (num_equal_edges != s2->transition_count))
2033 {
2034 /* Make sure ALL edges of possible equal states are the same */
2035 table[idx / 32] |= (1U << (idx % 32));
2036 change = 1; /* changed a marker, need to run again */
2037 }
2038 }
2038 } 2039 }
2040 }
2039 2041
2040 /* Merge states that are equal */ 2042 /* Merge states that are equal */
2041 for (s1 = a->states_head; NULL != s1; s1 = s1_next) 2043 for (s1 = a->states_head; NULL != s1; s1 = s1_next)
2044 {
2045 s1_next = s1->next;
2046 for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2_next)
2042 { 2047 {
2043 s1_next = s1->next; 2048 s2_next = s2->next;
2044 for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2_next) 2049 idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
2045 { 2050 if (0 == (table[idx / 32] & (1U << (idx % 32))))
2046 s2_next = s2->next; 2051 automaton_merge_states (ctx, a, s1, s2);
2047 idx = (unsigned long long)s1->marked * state_cnt + s2->marked;
2048 if (0 == (table[idx / 32] & (1U << (idx % 32))))
2049 automaton_merge_states(ctx, a, s1, s2);
2050 }
2051 } 2052 }
2053 }
2052 2054
2053 GNUNET_free(table); 2055 GNUNET_free (table);
2054 return GNUNET_OK; 2056 return GNUNET_OK;
2055} 2057}
2056 2058
@@ -2064,22 +2066,22 @@ dfa_merge_nondistinguishable_states(struct REGEX_INTERNAL_Context *ctx,
2064 * @return GNUNET_OK on success 2066 * @return GNUNET_OK on success
2065 */ 2067 */
2066static int 2068static int
2067dfa_minimize(struct REGEX_INTERNAL_Context *ctx, 2069dfa_minimize (struct REGEX_INTERNAL_Context *ctx,
2068 struct REGEX_INTERNAL_Automaton *a) 2070 struct REGEX_INTERNAL_Automaton *a)
2069{ 2071{
2070 if (NULL == a) 2072 if (NULL == a)
2071 return GNUNET_SYSERR; 2073 return GNUNET_SYSERR;
2072 2074
2073 GNUNET_assert(DFA == a->type); 2075 GNUNET_assert (DFA == a->type);
2074 2076
2075 /* 1. remove unreachable states */ 2077 /* 1. remove unreachable states */
2076 dfa_remove_unreachable_states(a); 2078 dfa_remove_unreachable_states (a);
2077 2079
2078 /* 2. remove dead states */ 2080 /* 2. remove dead states */
2079 dfa_remove_dead_states(a); 2081 dfa_remove_dead_states (a);
2080 2082
2081 /* 3. Merge nondistinguishable states */ 2083 /* 3. Merge nondistinguishable states */
2082 if (GNUNET_OK != dfa_merge_nondistinguishable_states(ctx, a)) 2084 if (GNUNET_OK != dfa_merge_nondistinguishable_states (ctx, a))
2083 return GNUNET_SYSERR; 2085 return GNUNET_SYSERR;
2084 return GNUNET_OK; 2086 return GNUNET_OK;
2085} 2087}
@@ -2088,7 +2090,8 @@ dfa_minimize(struct REGEX_INTERNAL_Context *ctx,
2088/** 2090/**
2089 * Context for adding strided transitions to a DFA. 2091 * Context for adding strided transitions to a DFA.
2090 */ 2092 */
2091struct REGEX_INTERNAL_Strided_Context { 2093struct REGEX_INTERNAL_Strided_Context
2094{
2092 /** 2095 /**
2093 * Length of the strides. 2096 * Length of the strides.
2094 */ 2097 */
@@ -2118,50 +2121,50 @@ struct REGEX_INTERNAL_Strided_Context {
2118 * @param s current state in the depth-first traversal 2121 * @param s current state in the depth-first traversal
2119 */ 2122 */
2120static void 2123static void
2121dfa_add_multi_strides_helper(void *cls, 2124dfa_add_multi_strides_helper (void *cls,
2122 const unsigned int depth, 2125 const unsigned int depth,
2123 char *label, 2126 char *label,
2124 struct REGEX_INTERNAL_State *start, 2127 struct REGEX_INTERNAL_State *start,
2125 struct REGEX_INTERNAL_State *s) 2128 struct REGEX_INTERNAL_State *s)
2126{ 2129{
2127 struct REGEX_INTERNAL_Strided_Context *ctx = cls; 2130 struct REGEX_INTERNAL_Strided_Context *ctx = cls;
2128 struct REGEX_INTERNAL_Transition *t; 2131 struct REGEX_INTERNAL_Transition *t;
2129 char *new_label; 2132 char *new_label;
2130 2133
2131 if (depth == ctx->stride) 2134 if (depth == ctx->stride)
2132 { 2135 {
2133 t = GNUNET_new(struct REGEX_INTERNAL_Transition); 2136 t = GNUNET_new (struct REGEX_INTERNAL_Transition);
2134 t->label = GNUNET_strdup(label); 2137 t->label = GNUNET_strdup (label);
2135 t->to_state = s; 2138 t->to_state = s;
2136 t->from_state = start; 2139 t->from_state = start;
2137 GNUNET_CONTAINER_DLL_insert(ctx->transitions_head, 2140 GNUNET_CONTAINER_DLL_insert (ctx->transitions_head,
2138 ctx->transitions_tail, 2141 ctx->transitions_tail,
2139 t); 2142 t);
2140 } 2143 }
2141 else 2144 else
2145 {
2146 for (t = s->transitions_head; NULL != t; t = t->next)
2142 { 2147 {
2143 for (t = s->transitions_head; NULL != t; t = t->next) 2148 /* Do not consider self-loops, because it end's up in too many
2144 { 2149 * transitions */
2145 /* Do not consider self-loops, because it end's up in too many 2150 if (t->to_state == t->from_state)
2146 * transitions */ 2151 continue;
2147 if (t->to_state == t->from_state)
2148 continue;
2149 2152
2150 if (NULL != label) 2153 if (NULL != label)
2151 { 2154 {
2152 GNUNET_asprintf(&new_label, "%s%s", label, t->label); 2155 GNUNET_asprintf (&new_label, "%s%s", label, t->label);
2153 } 2156 }
2154 else 2157 else
2155 new_label = GNUNET_strdup(t->label); 2158 new_label = GNUNET_strdup (t->label);
2156 2159
2157 dfa_add_multi_strides_helper(cls, 2160 dfa_add_multi_strides_helper (cls,
2158 (depth + 1), 2161 (depth + 1),
2159 new_label, 2162 new_label,
2160 start, 2163 start,
2161 t->to_state); 2164 t->to_state);
2162 }
2163 } 2165 }
2164 GNUNET_free_non_null(label); 2166 }
2167 GNUNET_free_non_null (label);
2165} 2168}
2166 2169
2167 2170
@@ -2174,11 +2177,11 @@ dfa_add_multi_strides_helper(void *cls,
2174 * @param s current state. 2177 * @param s current state.
2175 */ 2178 */
2176static void 2179static void
2177dfa_add_multi_strides(void *cls, 2180dfa_add_multi_strides (void *cls,
2178 const unsigned int count, 2181 const unsigned int count,
2179 struct REGEX_INTERNAL_State *s) 2182 struct REGEX_INTERNAL_State *s)
2180{ 2183{
2181 dfa_add_multi_strides_helper(cls, 0, NULL, s, s); 2184 dfa_add_multi_strides_helper (cls, 0, NULL, s, s);
2182} 2185}
2183 2186
2184 2187
@@ -2190,34 +2193,34 @@ dfa_add_multi_strides(void *cls,
2190 * @param stride_len length of the strides. 2193 * @param stride_len length of the strides.
2191 */ 2194 */
2192void 2195void
2193REGEX_INTERNAL_dfa_add_multi_strides(struct REGEX_INTERNAL_Context *regex_ctx, 2196REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx,
2194 struct REGEX_INTERNAL_Automaton *dfa, 2197 struct REGEX_INTERNAL_Automaton *dfa,
2195 const unsigned int stride_len) 2198 const unsigned int stride_len)
2196{ 2199{
2197 struct REGEX_INTERNAL_Strided_Context ctx = { stride_len, NULL, NULL }; 2200 struct REGEX_INTERNAL_Strided_Context ctx = { stride_len, NULL, NULL };
2198 struct REGEX_INTERNAL_Transition *t; 2201 struct REGEX_INTERNAL_Transition *t;
2199 struct REGEX_INTERNAL_Transition *t_next; 2202 struct REGEX_INTERNAL_Transition *t_next;
2200 2203
2201 if (1 > stride_len || GNUNET_YES == dfa->is_multistrided) 2204 if ((1 > stride_len)||(GNUNET_YES == dfa->is_multistrided))
2202 return; 2205 return;
2203 2206
2204 /* Compute the new transitions of given stride_len */ 2207 /* Compute the new transitions of given stride_len */
2205 REGEX_INTERNAL_automaton_traverse(dfa, 2208 REGEX_INTERNAL_automaton_traverse (dfa,
2206 dfa->start, 2209 dfa->start,
2207 NULL, 2210 NULL,
2208 NULL, 2211 NULL,
2209 &dfa_add_multi_strides, 2212 &dfa_add_multi_strides,
2210 &ctx); 2213 &ctx);
2211 2214
2212 /* Add all the new transitions to the automaton. */ 2215 /* Add all the new transitions to the automaton. */
2213 for (t = ctx.transitions_head; NULL != t; t = t_next) 2216 for (t = ctx.transitions_head; NULL != t; t = t_next)
2214 { 2217 {
2215 t_next = t->next; 2218 t_next = t->next;
2216 state_add_transition(regex_ctx, t->from_state, t->label, t->to_state); 2219 state_add_transition (regex_ctx, t->from_state, t->label, t->to_state);
2217 GNUNET_CONTAINER_DLL_remove(ctx.transitions_head, ctx.transitions_tail, t); 2220 GNUNET_CONTAINER_DLL_remove (ctx.transitions_head, ctx.transitions_tail, t);
2218 GNUNET_free_non_null(t->label); 2221 GNUNET_free_non_null (t->label);
2219 GNUNET_free(t); 2222 GNUNET_free (t);
2220 } 2223 }
2221 2224
2222 /* Mark this automaton as multistrided */ 2225 /* Mark this automaton as multistrided */
2223 dfa->is_multistrided = GNUNET_YES; 2226 dfa->is_multistrided = GNUNET_YES;
@@ -2237,70 +2240,70 @@ REGEX_INTERNAL_dfa_add_multi_strides(struct REGEX_INTERNAL_Context *regex_ctx,
2237 * @param transitions_tail transitions DLL. 2240 * @param transitions_tail transitions DLL.
2238 */ 2241 */
2239void 2242void
2240dfa_compress_paths_helper(struct REGEX_INTERNAL_Automaton *dfa, 2243dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa,
2241 struct REGEX_INTERNAL_State *start, 2244 struct REGEX_INTERNAL_State *start,
2242 struct REGEX_INTERNAL_State *cur, 2245 struct REGEX_INTERNAL_State *cur,
2243 char *label, 2246 char *label,
2244 unsigned int max_len, 2247 unsigned int max_len,
2245 struct REGEX_INTERNAL_Transition **transitions_head, 2248 struct REGEX_INTERNAL_Transition **transitions_head,
2246 struct REGEX_INTERNAL_Transition **transitions_tail) 2249 struct REGEX_INTERNAL_Transition **transitions_tail)
2247{ 2250{
2248 struct REGEX_INTERNAL_Transition *t; 2251 struct REGEX_INTERNAL_Transition *t;
2249 char *new_label; 2252 char *new_label;
2250 2253
2251 2254
2252 if (NULL != label && 2255 if ((NULL != label)&&
2253 ((cur->incoming_transition_count > 1 || GNUNET_YES == cur->accepting || 2256 (((cur->incoming_transition_count > 1)||(GNUNET_YES == cur->accepting)||
2254 GNUNET_YES == cur->marked) || 2257 (GNUNET_YES == cur->marked) ) ||
2255 (start != dfa->start && max_len > 0 && max_len == strlen(label)) || 2258 ((start != dfa->start)&&(max_len > 0)&&(max_len == strlen (label))) ||
2256 (start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen(label)))) 2259 ((start == dfa->start)&&(GNUNET_REGEX_INITIAL_BYTES == strlen (label)))))
2257 { 2260 {
2258 t = GNUNET_new(struct REGEX_INTERNAL_Transition); 2261 t = GNUNET_new (struct REGEX_INTERNAL_Transition);
2259 t->label = GNUNET_strdup(label); 2262 t->label = GNUNET_strdup (label);
2260 t->to_state = cur; 2263 t->to_state = cur;
2261 t->from_state = start; 2264 t->from_state = start;
2262 GNUNET_CONTAINER_DLL_insert(*transitions_head, *transitions_tail, t); 2265 GNUNET_CONTAINER_DLL_insert (*transitions_head, *transitions_tail, t);
2263 2266
2264 if (GNUNET_NO == cur->marked) 2267 if (GNUNET_NO == cur->marked)
2265 { 2268 {
2266 dfa_compress_paths_helper(dfa, 2269 dfa_compress_paths_helper (dfa,
2267 cur, 2270 cur,
2268 cur, 2271 cur,
2269 NULL, 2272 NULL,
2270 max_len, 2273 max_len,
2271 transitions_head, 2274 transitions_head,
2272 transitions_tail); 2275 transitions_tail);
2273 }
2274 return;
2275 } 2276 }
2277 return;
2278 }
2276 else if (cur != start) 2279 else if (cur != start)
2277 cur->contained = GNUNET_YES; 2280 cur->contained = GNUNET_YES;
2278 2281
2279 if (GNUNET_YES == cur->marked && cur != start) 2282 if ((GNUNET_YES == cur->marked)&&(cur != start))
2280 return; 2283 return;
2281 2284
2282 cur->marked = GNUNET_YES; 2285 cur->marked = GNUNET_YES;
2283 2286
2284 2287
2285 for (t = cur->transitions_head; NULL != t; t = t->next) 2288 for (t = cur->transitions_head; NULL != t; t = t->next)
2286 { 2289 {
2287 if (NULL != label) 2290 if (NULL != label)
2288 GNUNET_asprintf(&new_label, "%s%s", label, t->label); 2291 GNUNET_asprintf (&new_label, "%s%s", label, t->label);
2289 else 2292 else
2290 new_label = GNUNET_strdup(t->label); 2293 new_label = GNUNET_strdup (t->label);
2291 2294
2292 if (t->to_state != cur) 2295 if (t->to_state != cur)
2293 { 2296 {
2294 dfa_compress_paths_helper(dfa, 2297 dfa_compress_paths_helper (dfa,
2295 start, 2298 start,
2296 t->to_state, 2299 t->to_state,
2297 new_label, 2300 new_label,
2298 max_len, 2301 max_len,
2299 transitions_head, 2302 transitions_head,
2300 transitions_tail); 2303 transitions_tail);
2301 }
2302 GNUNET_free(new_label);
2303 } 2304 }
2305 GNUNET_free (new_label);
2306 }
2304} 2307}
2305 2308
2306 2309
@@ -2313,9 +2316,9 @@ dfa_compress_paths_helper(struct REGEX_INTERNAL_Automaton *dfa,
2313 * @param max_len maximal length of the compressed paths. 2316 * @param max_len maximal length of the compressed paths.
2314 */ 2317 */
2315static void 2318static void
2316dfa_compress_paths(struct REGEX_INTERNAL_Context *regex_ctx, 2319dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx,
2317 struct REGEX_INTERNAL_Automaton *dfa, 2320 struct REGEX_INTERNAL_Automaton *dfa,
2318 unsigned int max_len) 2321 unsigned int max_len)
2319{ 2322{
2320 struct REGEX_INTERNAL_State *s; 2323 struct REGEX_INTERNAL_State *s;
2321 struct REGEX_INTERNAL_State *s_next; 2324 struct REGEX_INTERNAL_State *s_next;
@@ -2329,47 +2332,47 @@ dfa_compress_paths(struct REGEX_INTERNAL_Context *regex_ctx,
2329 2332
2330 /* Count the incoming transitions on each state. */ 2333 /* Count the incoming transitions on each state. */
2331 for (s = dfa->states_head; NULL != s; s = s->next) 2334 for (s = dfa->states_head; NULL != s; s = s->next)
2335 {
2336 for (t = s->transitions_head; NULL != t; t = t->next)
2332 { 2337 {
2333 for (t = s->transitions_head; NULL != t; t = t->next) 2338 if (NULL != t->to_state)
2334 { 2339 t->to_state->incoming_transition_count++;
2335 if (NULL != t->to_state)
2336 t->to_state->incoming_transition_count++;
2337 }
2338 } 2340 }
2341 }
2339 2342
2340 /* Unmark all states. */ 2343 /* Unmark all states. */
2341 for (s = dfa->states_head; NULL != s; s = s->next) 2344 for (s = dfa->states_head; NULL != s; s = s->next)
2342 { 2345 {
2343 s->marked = GNUNET_NO; 2346 s->marked = GNUNET_NO;
2344 s->contained = GNUNET_NO; 2347 s->contained = GNUNET_NO;
2345 } 2348 }
2346 2349
2347 /* Add strides and mark states that can be deleted. */ 2350 /* Add strides and mark states that can be deleted. */
2348 dfa_compress_paths_helper(dfa, 2351 dfa_compress_paths_helper (dfa,
2349 dfa->start, 2352 dfa->start,
2350 dfa->start, 2353 dfa->start,
2351 NULL, 2354 NULL,
2352 max_len, 2355 max_len,
2353 &transitions_head, 2356 &transitions_head,
2354 &transitions_tail); 2357 &transitions_tail);
2355 2358
2356 /* Add all the new transitions to the automaton. */ 2359 /* Add all the new transitions to the automaton. */
2357 for (t = transitions_head; NULL != t; t = t_next) 2360 for (t = transitions_head; NULL != t; t = t_next)
2358 { 2361 {
2359 t_next = t->next; 2362 t_next = t->next;
2360 state_add_transition(regex_ctx, t->from_state, t->label, t->to_state); 2363 state_add_transition (regex_ctx, t->from_state, t->label, t->to_state);
2361 GNUNET_CONTAINER_DLL_remove(transitions_head, transitions_tail, t); 2364 GNUNET_CONTAINER_DLL_remove (transitions_head, transitions_tail, t);
2362 GNUNET_free_non_null(t->label); 2365 GNUNET_free_non_null (t->label);
2363 GNUNET_free(t); 2366 GNUNET_free (t);
2364 } 2367 }
2365 2368
2366 /* Remove marked states (including their incoming and outgoing transitions). */ 2369 /* Remove marked states (including their incoming and outgoing transitions). */
2367 for (s = dfa->states_head; NULL != s; s = s_next) 2370 for (s = dfa->states_head; NULL != s; s = s_next)
2368 { 2371 {
2369 s_next = s->next; 2372 s_next = s->next;
2370 if (GNUNET_YES == s->contained) 2373 if (GNUNET_YES == s->contained)
2371 automaton_remove_state(dfa, s); 2374 automaton_remove_state (dfa, s);
2372 } 2375 }
2373} 2376}
2374 2377
2375 2378
@@ -2383,23 +2386,23 @@ dfa_compress_paths(struct REGEX_INTERNAL_Context *regex_ctx,
2383 * @return new NFA fragment 2386 * @return new NFA fragment
2384 */ 2387 */
2385static struct REGEX_INTERNAL_Automaton * 2388static struct REGEX_INTERNAL_Automaton *
2386nfa_fragment_create(struct REGEX_INTERNAL_State *start, 2389nfa_fragment_create (struct REGEX_INTERNAL_State *start,
2387 struct REGEX_INTERNAL_State *end) 2390 struct REGEX_INTERNAL_State *end)
2388{ 2391{
2389 struct REGEX_INTERNAL_Automaton *n; 2392 struct REGEX_INTERNAL_Automaton *n;
2390 2393
2391 n = GNUNET_new(struct REGEX_INTERNAL_Automaton); 2394 n = GNUNET_new (struct REGEX_INTERNAL_Automaton);
2392 2395
2393 n->type = NFA; 2396 n->type = NFA;
2394 n->start = NULL; 2397 n->start = NULL;
2395 n->end = NULL; 2398 n->end = NULL;
2396 n->state_count = 0; 2399 n->state_count = 0;
2397 2400
2398 if (NULL == start || NULL == end) 2401 if ((NULL == start)||(NULL == end))
2399 return n; 2402 return n;
2400 2403
2401 automaton_add_state(n, end); 2404 automaton_add_state (n, end);
2402 automaton_add_state(n, start); 2405 automaton_add_state (n, start);
2403 2406
2404 n->state_count = 2; 2407 n->state_count = 2;
2405 2408
@@ -2418,30 +2421,30 @@ nfa_fragment_create(struct REGEX_INTERNAL_State *start,
2418 * @param states_tail tail of the DLL of states 2421 * @param states_tail tail of the DLL of states
2419 */ 2422 */
2420static void 2423static void
2421nfa_add_states(struct REGEX_INTERNAL_Automaton *n, 2424nfa_add_states (struct REGEX_INTERNAL_Automaton *n,
2422 struct REGEX_INTERNAL_State *states_head, 2425 struct REGEX_INTERNAL_State *states_head,
2423 struct REGEX_INTERNAL_State *states_tail) 2426 struct REGEX_INTERNAL_State *states_tail)
2424{ 2427{
2425 struct REGEX_INTERNAL_State *s; 2428 struct REGEX_INTERNAL_State *s;
2426 2429
2427 if (NULL == n || NULL == states_head) 2430 if ((NULL == n)||(NULL == states_head))
2428 { 2431 {
2429 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not add states\n"); 2432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not add states\n");
2430 return; 2433 return;
2431 } 2434 }
2432 2435
2433 if (NULL == n->states_head) 2436 if (NULL == n->states_head)
2434 { 2437 {
2435 n->states_head = states_head; 2438 n->states_head = states_head;
2436 n->states_tail = states_tail; 2439 n->states_tail = states_tail;
2437 return; 2440 return;
2438 } 2441 }
2439 2442
2440 if (NULL != states_head) 2443 if (NULL != states_head)
2441 { 2444 {
2442 n->states_tail->next = states_head; 2445 n->states_tail->next = states_head;
2443 n->states_tail = states_tail; 2446 n->states_tail = states_tail;
2444 } 2447 }
2445 2448
2446 for (s = states_head; NULL != s; s = s->next) 2449 for (s = states_head; NULL != s; s = s->next)
2447 n->state_count++; 2450 n->state_count++;
@@ -2457,11 +2460,11 @@ nfa_add_states(struct REGEX_INTERNAL_Automaton *n,
2457 * @return new NFA state 2460 * @return new NFA state
2458 */ 2461 */
2459static struct REGEX_INTERNAL_State * 2462static struct REGEX_INTERNAL_State *
2460nfa_state_create(struct REGEX_INTERNAL_Context *ctx, int accepting) 2463nfa_state_create (struct REGEX_INTERNAL_Context *ctx, int accepting)
2461{ 2464{
2462 struct REGEX_INTERNAL_State *s; 2465 struct REGEX_INTERNAL_State *s;
2463 2466
2464 s = GNUNET_new(struct REGEX_INTERNAL_State); 2467 s = GNUNET_new (struct REGEX_INTERNAL_State);
2465 s->id = ctx->state_id++; 2468 s->id = ctx->state_id++;
2466 s->accepting = accepting; 2469 s->accepting = accepting;
2467 s->marked = GNUNET_NO; 2470 s->marked = GNUNET_NO;
@@ -2470,7 +2473,7 @@ nfa_state_create(struct REGEX_INTERNAL_Context *ctx, int accepting)
2470 s->lowlink = -1; 2473 s->lowlink = -1;
2471 s->scc_id = 0; 2474 s->scc_id = 0;
2472 s->name = NULL; 2475 s->name = NULL;
2473 GNUNET_asprintf(&s->name, "s%i", s->id); 2476 GNUNET_asprintf (&s->name, "s%i", s->id);
2474 2477
2475 return s; 2478 return s;
2476} 2479}
@@ -2486,10 +2489,10 @@ nfa_state_create(struct REGEX_INTERNAL_Context *ctx, int accepting)
2486 * pass NULL for epsilon transition 2489 * pass NULL for epsilon transition
2487 */ 2490 */
2488static void 2491static void
2489nfa_closure_set_create(struct REGEX_INTERNAL_StateSet *ret, 2492nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret,
2490 struct REGEX_INTERNAL_Automaton *nfa, 2493 struct REGEX_INTERNAL_Automaton *nfa,
2491 struct REGEX_INTERNAL_StateSet *states, 2494 struct REGEX_INTERNAL_StateSet *states,
2492 const char *label) 2495 const char *label)
2493{ 2496{
2494 struct REGEX_INTERNAL_State *s; 2497 struct REGEX_INTERNAL_State *s;
2495 unsigned int i; 2498 unsigned int i;
@@ -2498,58 +2501,58 @@ nfa_closure_set_create(struct REGEX_INTERNAL_StateSet *ret,
2498 struct REGEX_INTERNAL_State *currentstate; 2501 struct REGEX_INTERNAL_State *currentstate;
2499 struct REGEX_INTERNAL_Transition *ctran; 2502 struct REGEX_INTERNAL_Transition *ctran;
2500 2503
2501 memset(ret, 0, sizeof(struct REGEX_INTERNAL_StateSet)); 2504 memset (ret, 0, sizeof(struct REGEX_INTERNAL_StateSet));
2502 if (NULL == states) 2505 if (NULL == states)
2503 return; 2506 return;
2504 2507
2505 for (i = 0; i < states->off; i++) 2508 for (i = 0; i < states->off; i++)
2506 { 2509 {
2507 s = states->states[i]; 2510 s = states->states[i];
2508 2511
2509 /* Add start state to closure only for epsilon closure */ 2512 /* Add start state to closure only for epsilon closure */
2510 if (NULL == label) 2513 if (NULL == label)
2511 state_set_append(ret, s); 2514 state_set_append (ret, s);
2512 2515
2513 /* initialize work stack */ 2516 /* initialize work stack */
2514 cls_stack.head = NULL; 2517 cls_stack.head = NULL;
2515 cls_stack.tail = NULL; 2518 cls_stack.tail = NULL;
2516 GNUNET_CONTAINER_MDLL_insert(ST, cls_stack.head, cls_stack.tail, s); 2519 GNUNET_CONTAINER_MDLL_insert (ST, cls_stack.head, cls_stack.tail, s);
2517 cls_stack.len = 1; 2520 cls_stack.len = 1;
2518 2521
2519 while (NULL != (currentstate = cls_stack.tail)) 2522 while (NULL != (currentstate = cls_stack.tail))
2520 { 2523 {
2521 GNUNET_CONTAINER_MDLL_remove(ST, 2524 GNUNET_CONTAINER_MDLL_remove (ST,
2522 cls_stack.head, 2525 cls_stack.head,
2523 cls_stack.tail, 2526 cls_stack.tail,
2524 currentstate); 2527 currentstate);
2525 cls_stack.len--; 2528 cls_stack.len--;
2526 for (ctran = currentstate->transitions_head; NULL != ctran; 2529 for (ctran = currentstate->transitions_head; NULL != ctran;
2527 ctran = ctran->next) 2530 ctran = ctran->next)
2528 { 2531 {
2529 if (NULL == (clsstate = ctran->to_state)) 2532 if (NULL == (clsstate = ctran->to_state))
2530 continue; 2533 continue;
2531 if (0 != clsstate->contained) 2534 if (0 != clsstate->contained)
2532 continue; 2535 continue;
2533 if (0 != nullstrcmp(label, ctran->label)) 2536 if (0 != nullstrcmp (label, ctran->label))
2534 continue; 2537 continue;
2535 state_set_append(ret, clsstate); 2538 state_set_append (ret, clsstate);
2536 GNUNET_CONTAINER_MDLL_insert_tail(ST, 2539 GNUNET_CONTAINER_MDLL_insert_tail (ST,
2537 cls_stack.head, 2540 cls_stack.head,
2538 cls_stack.tail, 2541 cls_stack.tail,
2539 clsstate); 2542 clsstate);
2540 cls_stack.len++; 2543 cls_stack.len++;
2541 clsstate->contained = 1; 2544 clsstate->contained = 1;
2542 } 2545 }
2543 }
2544 } 2546 }
2547 }
2545 for (i = 0; i < ret->off; i++) 2548 for (i = 0; i < ret->off; i++)
2546 ret->states[i]->contained = 0; 2549 ret->states[i]->contained = 0;
2547 2550
2548 if (ret->off > 1) 2551 if (ret->off > 1)
2549 qsort(ret->states, 2552 qsort (ret->states,
2550 ret->off, 2553 ret->off,
2551 sizeof(struct REGEX_INTERNAL_State *), 2554 sizeof(struct REGEX_INTERNAL_State *),
2552 &state_compare); 2555 &state_compare);
2553} 2556}
2554 2557
2555 2558
@@ -2559,33 +2562,33 @@ nfa_closure_set_create(struct REGEX_INTERNAL_StateSet *ret,
2559 * @param ctx context 2562 * @param ctx context
2560 */ 2563 */
2561static void 2564static void
2562nfa_add_concatenation(struct REGEX_INTERNAL_Context *ctx) 2565nfa_add_concatenation (struct REGEX_INTERNAL_Context *ctx)
2563{ 2566{
2564 struct REGEX_INTERNAL_Automaton *a; 2567 struct REGEX_INTERNAL_Automaton *a;
2565 struct REGEX_INTERNAL_Automaton *b; 2568 struct REGEX_INTERNAL_Automaton *b;
2566 struct REGEX_INTERNAL_Automaton *new_nfa; 2569 struct REGEX_INTERNAL_Automaton *new_nfa;
2567 2570
2568 b = ctx->stack_tail; 2571 b = ctx->stack_tail;
2569 GNUNET_assert(NULL != b); 2572 GNUNET_assert (NULL != b);
2570 GNUNET_CONTAINER_DLL_remove(ctx->stack_head, ctx->stack_tail, b); 2573 GNUNET_CONTAINER_DLL_remove (ctx->stack_head, ctx->stack_tail, b);
2571 a = ctx->stack_tail; 2574 a = ctx->stack_tail;
2572 GNUNET_assert(NULL != a); 2575 GNUNET_assert (NULL != a);
2573 GNUNET_CONTAINER_DLL_remove(ctx->stack_head, ctx->stack_tail, a); 2576 GNUNET_CONTAINER_DLL_remove (ctx->stack_head, ctx->stack_tail, a);
2574 2577
2575 state_add_transition(ctx, a->end, NULL, b->start); 2578 state_add_transition (ctx, a->end, NULL, b->start);
2576 a->end->accepting = 0; 2579 a->end->accepting = 0;
2577 b->end->accepting = 1; 2580 b->end->accepting = 1;
2578 2581
2579 new_nfa = nfa_fragment_create(NULL, NULL); 2582 new_nfa = nfa_fragment_create (NULL, NULL);
2580 nfa_add_states(new_nfa, a->states_head, a->states_tail); 2583 nfa_add_states (new_nfa, a->states_head, a->states_tail);
2581 nfa_add_states(new_nfa, b->states_head, b->states_tail); 2584 nfa_add_states (new_nfa, b->states_head, b->states_tail);
2582 new_nfa->start = a->start; 2585 new_nfa->start = a->start;
2583 new_nfa->end = b->end; 2586 new_nfa->end = b->end;
2584 new_nfa->state_count += a->state_count + b->state_count; 2587 new_nfa->state_count += a->state_count + b->state_count;
2585 automaton_fragment_clear(a); 2588 automaton_fragment_clear (a);
2586 automaton_fragment_clear(b); 2589 automaton_fragment_clear (b);
2587 2590
2588 GNUNET_CONTAINER_DLL_insert_tail(ctx->stack_head, ctx->stack_tail, new_nfa); 2591 GNUNET_CONTAINER_DLL_insert_tail (ctx->stack_head, ctx->stack_tail, new_nfa);
2589} 2592}
2590 2593
2591 2594
@@ -2595,7 +2598,7 @@ nfa_add_concatenation(struct REGEX_INTERNAL_Context *ctx)
2595 * @param ctx context 2598 * @param ctx context
2596 */ 2599 */
2597static void 2600static void
2598nfa_add_star_op(struct REGEX_INTERNAL_Context *ctx) 2601nfa_add_star_op (struct REGEX_INTERNAL_Context *ctx)
2599{ 2602{
2600 struct REGEX_INTERNAL_Automaton *a; 2603 struct REGEX_INTERNAL_Automaton *a;
2601 struct REGEX_INTERNAL_Automaton *new_nfa; 2604 struct REGEX_INTERNAL_Automaton *new_nfa;
@@ -2605,31 +2608,31 @@ nfa_add_star_op(struct REGEX_INTERNAL_Context *ctx)
2605 a = ctx->stack_tail; 2608 a = ctx->stack_tail;
2606 2609
2607 if (NULL == a) 2610 if (NULL == a)
2608 { 2611 {
2609 GNUNET_log( 2612 GNUNET_log (
2610 GNUNET_ERROR_TYPE_ERROR, 2613 GNUNET_ERROR_TYPE_ERROR,
2611 "nfa_add_star_op failed, because there was no element on the stack"); 2614 "nfa_add_star_op failed, because there was no element on the stack");
2612 return; 2615 return;
2613 } 2616 }
2614 2617
2615 GNUNET_CONTAINER_DLL_remove(ctx->stack_head, ctx->stack_tail, a); 2618 GNUNET_CONTAINER_DLL_remove (ctx->stack_head, ctx->stack_tail, a);
2616 2619
2617 start = nfa_state_create(ctx, 0); 2620 start = nfa_state_create (ctx, 0);
2618 end = nfa_state_create(ctx, 1); 2621 end = nfa_state_create (ctx, 1);
2619 2622
2620 state_add_transition(ctx, start, NULL, a->start); 2623 state_add_transition (ctx, start, NULL, a->start);
2621 state_add_transition(ctx, start, NULL, end); 2624 state_add_transition (ctx, start, NULL, end);
2622 state_add_transition(ctx, a->end, NULL, a->start); 2625 state_add_transition (ctx, a->end, NULL, a->start);
2623 state_add_transition(ctx, a->end, NULL, end); 2626 state_add_transition (ctx, a->end, NULL, end);
2624 2627
2625 a->end->accepting = 0; 2628 a->end->accepting = 0;
2626 end->accepting = 1; 2629 end->accepting = 1;
2627 2630
2628 new_nfa = nfa_fragment_create(start, end); 2631 new_nfa = nfa_fragment_create (start, end);
2629 nfa_add_states(new_nfa, a->states_head, a->states_tail); 2632 nfa_add_states (new_nfa, a->states_head, a->states_tail);
2630 automaton_fragment_clear(a); 2633 automaton_fragment_clear (a);
2631 2634
2632 GNUNET_CONTAINER_DLL_insert_tail(ctx->stack_head, ctx->stack_tail, new_nfa); 2635 GNUNET_CONTAINER_DLL_insert_tail (ctx->stack_head, ctx->stack_tail, new_nfa);
2633} 2636}
2634 2637
2635 2638
@@ -2639,25 +2642,25 @@ nfa_add_star_op(struct REGEX_INTERNAL_Context *ctx)
2639 * @param ctx context 2642 * @param ctx context
2640 */ 2643 */
2641static void 2644static void
2642nfa_add_plus_op(struct REGEX_INTERNAL_Context *ctx) 2645nfa_add_plus_op (struct REGEX_INTERNAL_Context *ctx)
2643{ 2646{
2644 struct REGEX_INTERNAL_Automaton *a; 2647 struct REGEX_INTERNAL_Automaton *a;
2645 2648
2646 a = ctx->stack_tail; 2649 a = ctx->stack_tail;
2647 2650
2648 if (NULL == a) 2651 if (NULL == a)
2649 { 2652 {
2650 GNUNET_log( 2653 GNUNET_log (
2651 GNUNET_ERROR_TYPE_ERROR, 2654 GNUNET_ERROR_TYPE_ERROR,
2652 "nfa_add_plus_op failed, because there was no element on the stack"); 2655 "nfa_add_plus_op failed, because there was no element on the stack");
2653 return; 2656 return;
2654 } 2657 }
2655 2658
2656 GNUNET_CONTAINER_DLL_remove(ctx->stack_head, ctx->stack_tail, a); 2659 GNUNET_CONTAINER_DLL_remove (ctx->stack_head, ctx->stack_tail, a);
2657 2660
2658 state_add_transition(ctx, a->end, NULL, a->start); 2661 state_add_transition (ctx, a->end, NULL, a->start);
2659 2662
2660 GNUNET_CONTAINER_DLL_insert_tail(ctx->stack_head, ctx->stack_tail, a); 2663 GNUNET_CONTAINER_DLL_insert_tail (ctx->stack_head, ctx->stack_tail, a);
2661} 2664}
2662 2665
2663 2666
@@ -2667,7 +2670,7 @@ nfa_add_plus_op(struct REGEX_INTERNAL_Context *ctx)
2667 * @param ctx context 2670 * @param ctx context
2668 */ 2671 */
2669static void 2672static void
2670nfa_add_question_op(struct REGEX_INTERNAL_Context *ctx) 2673nfa_add_question_op (struct REGEX_INTERNAL_Context *ctx)
2671{ 2674{
2672 struct REGEX_INTERNAL_Automaton *a; 2675 struct REGEX_INTERNAL_Automaton *a;
2673 struct REGEX_INTERNAL_Automaton *new_nfa; 2676 struct REGEX_INTERNAL_Automaton *new_nfa;
@@ -2676,28 +2679,28 @@ nfa_add_question_op(struct REGEX_INTERNAL_Context *ctx)
2676 2679
2677 a = ctx->stack_tail; 2680 a = ctx->stack_tail;
2678 if (NULL == a) 2681 if (NULL == a)
2679 { 2682 {
2680 GNUNET_log( 2683 GNUNET_log (
2681 GNUNET_ERROR_TYPE_ERROR, 2684 GNUNET_ERROR_TYPE_ERROR,
2682 "nfa_add_question_op failed, because there was no element on the stack"); 2685 "nfa_add_question_op failed, because there was no element on the stack");
2683 return; 2686 return;
2684 } 2687 }
2685 2688
2686 GNUNET_CONTAINER_DLL_remove(ctx->stack_head, ctx->stack_tail, a); 2689 GNUNET_CONTAINER_DLL_remove (ctx->stack_head, ctx->stack_tail, a);
2687 2690
2688 start = nfa_state_create(ctx, 0); 2691 start = nfa_state_create (ctx, 0);
2689 end = nfa_state_create(ctx, 1); 2692 end = nfa_state_create (ctx, 1);
2690 2693
2691 state_add_transition(ctx, start, NULL, a->start); 2694 state_add_transition (ctx, start, NULL, a->start);
2692 state_add_transition(ctx, start, NULL, end); 2695 state_add_transition (ctx, start, NULL, end);
2693 state_add_transition(ctx, a->end, NULL, end); 2696 state_add_transition (ctx, a->end, NULL, end);
2694 2697
2695 a->end->accepting = 0; 2698 a->end->accepting = 0;
2696 2699
2697 new_nfa = nfa_fragment_create(start, end); 2700 new_nfa = nfa_fragment_create (start, end);
2698 nfa_add_states(new_nfa, a->states_head, a->states_tail); 2701 nfa_add_states (new_nfa, a->states_head, a->states_tail);
2699 GNUNET_CONTAINER_DLL_insert_tail(ctx->stack_head, ctx->stack_tail, new_nfa); 2702 GNUNET_CONTAINER_DLL_insert_tail (ctx->stack_head, ctx->stack_tail, new_nfa);
2700 automaton_fragment_clear(a); 2703 automaton_fragment_clear (a);
2701} 2704}
2702 2705
2703 2706
@@ -2708,7 +2711,7 @@ nfa_add_question_op(struct REGEX_INTERNAL_Context *ctx)
2708 * @param ctx context 2711 * @param ctx context
2709 */ 2712 */
2710static void 2713static void
2711nfa_add_alternation(struct REGEX_INTERNAL_Context *ctx) 2714nfa_add_alternation (struct REGEX_INTERNAL_Context *ctx)
2712{ 2715{
2713 struct REGEX_INTERNAL_Automaton *a; 2716 struct REGEX_INTERNAL_Automaton *a;
2714 struct REGEX_INTERNAL_Automaton *b; 2717 struct REGEX_INTERNAL_Automaton *b;
@@ -2717,31 +2720,31 @@ nfa_add_alternation(struct REGEX_INTERNAL_Context *ctx)
2717 struct REGEX_INTERNAL_State *end; 2720 struct REGEX_INTERNAL_State *end;
2718 2721
2719 b = ctx->stack_tail; 2722 b = ctx->stack_tail;
2720 GNUNET_assert(NULL != b); 2723 GNUNET_assert (NULL != b);
2721 GNUNET_CONTAINER_DLL_remove(ctx->stack_head, ctx->stack_tail, b); 2724 GNUNET_CONTAINER_DLL_remove (ctx->stack_head, ctx->stack_tail, b);
2722 a = ctx->stack_tail; 2725 a = ctx->stack_tail;
2723 GNUNET_assert(NULL != a); 2726 GNUNET_assert (NULL != a);
2724 GNUNET_CONTAINER_DLL_remove(ctx->stack_head, ctx->stack_tail, a); 2727 GNUNET_CONTAINER_DLL_remove (ctx->stack_head, ctx->stack_tail, a);
2725 2728
2726 start = nfa_state_create(ctx, 0); 2729 start = nfa_state_create (ctx, 0);
2727 end = nfa_state_create(ctx, 1); 2730 end = nfa_state_create (ctx, 1);
2728 state_add_transition(ctx, start, NULL, a->start); 2731 state_add_transition (ctx, start, NULL, a->start);
2729 state_add_transition(ctx, start, NULL, b->start); 2732 state_add_transition (ctx, start, NULL, b->start);
2730 2733
2731 state_add_transition(ctx, a->end, NULL, end); 2734 state_add_transition (ctx, a->end, NULL, end);
2732 state_add_transition(ctx, b->end, NULL, end); 2735 state_add_transition (ctx, b->end, NULL, end);
2733 2736
2734 a->end->accepting = 0; 2737 a->end->accepting = 0;
2735 b->end->accepting = 0; 2738 b->end->accepting = 0;
2736 end->accepting = 1; 2739 end->accepting = 1;
2737 2740
2738 new_nfa = nfa_fragment_create(start, end); 2741 new_nfa = nfa_fragment_create (start, end);
2739 nfa_add_states(new_nfa, a->states_head, a->states_tail); 2742 nfa_add_states (new_nfa, a->states_head, a->states_tail);
2740 nfa_add_states(new_nfa, b->states_head, b->states_tail); 2743 nfa_add_states (new_nfa, b->states_head, b->states_tail);
2741 automaton_fragment_clear(a); 2744 automaton_fragment_clear (a);
2742 automaton_fragment_clear(b); 2745 automaton_fragment_clear (b);
2743 2746
2744 GNUNET_CONTAINER_DLL_insert_tail(ctx->stack_head, ctx->stack_tail, new_nfa); 2747 GNUNET_CONTAINER_DLL_insert_tail (ctx->stack_head, ctx->stack_tail, new_nfa);
2745} 2748}
2746 2749
2747 2750
@@ -2752,20 +2755,20 @@ nfa_add_alternation(struct REGEX_INTERNAL_Context *ctx)
2752 * @param label label for nfa transition 2755 * @param label label for nfa transition
2753 */ 2756 */
2754static void 2757static void
2755nfa_add_label(struct REGEX_INTERNAL_Context *ctx, const char *label) 2758nfa_add_label (struct REGEX_INTERNAL_Context *ctx, const char *label)
2756{ 2759{
2757 struct REGEX_INTERNAL_Automaton *n; 2760 struct REGEX_INTERNAL_Automaton *n;
2758 struct REGEX_INTERNAL_State *start; 2761 struct REGEX_INTERNAL_State *start;
2759 struct REGEX_INTERNAL_State *end; 2762 struct REGEX_INTERNAL_State *end;
2760 2763
2761 GNUNET_assert(NULL != ctx); 2764 GNUNET_assert (NULL != ctx);
2762 2765
2763 start = nfa_state_create(ctx, 0); 2766 start = nfa_state_create (ctx, 0);
2764 end = nfa_state_create(ctx, 1); 2767 end = nfa_state_create (ctx, 1);
2765 state_add_transition(ctx, start, label, end); 2768 state_add_transition (ctx, start, label, end);
2766 n = nfa_fragment_create(start, end); 2769 n = nfa_fragment_create (start, end);
2767 GNUNET_assert(NULL != n); 2770 GNUNET_assert (NULL != n);
2768 GNUNET_CONTAINER_DLL_insert_tail(ctx->stack_head, ctx->stack_tail, n); 2771 GNUNET_CONTAINER_DLL_insert_tail (ctx->stack_head, ctx->stack_tail, n);
2769} 2772}
2770 2773
2771 2774
@@ -2775,13 +2778,13 @@ nfa_add_label(struct REGEX_INTERNAL_Context *ctx, const char *label)
2775 * @param ctx context 2778 * @param ctx context
2776 */ 2779 */
2777static void 2780static void
2778REGEX_INTERNAL_context_init(struct REGEX_INTERNAL_Context *ctx) 2781REGEX_INTERNAL_context_init (struct REGEX_INTERNAL_Context *ctx)
2779{ 2782{
2780 if (NULL == ctx) 2783 if (NULL == ctx)
2781 { 2784 {
2782 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Context was NULL!"); 2785 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Context was NULL!");
2783 return; 2786 return;
2784 } 2787 }
2785 ctx->state_id = 0; 2788 ctx->state_id = 0;
2786 ctx->transition_id = 0; 2789 ctx->transition_id = 0;
2787 ctx->stack_head = NULL; 2790 ctx->stack_head = NULL;
@@ -2798,7 +2801,7 @@ REGEX_INTERNAL_context_init(struct REGEX_INTERNAL_Context *ctx)
2798 * @return NFA, needs to be freed using REGEX_INTERNAL_destroy_automaton 2801 * @return NFA, needs to be freed using REGEX_INTERNAL_destroy_automaton
2799 */ 2802 */
2800struct REGEX_INTERNAL_Automaton * 2803struct REGEX_INTERNAL_Automaton *
2801REGEX_INTERNAL_construct_nfa(const char *regex, const size_t len) 2804REGEX_INTERNAL_construct_nfa (const char *regex, const size_t len)
2802{ 2805{
2803 struct REGEX_INTERNAL_Context ctx; 2806 struct REGEX_INTERNAL_Context ctx;
2804 struct REGEX_INTERNAL_Automaton *nfa; 2807 struct REGEX_INTERNAL_Automaton *nfa;
@@ -2811,19 +2814,20 @@ REGEX_INTERNAL_construct_nfa(const char *regex, const size_t len)
2811 unsigned int poff; 2814 unsigned int poff;
2812 unsigned int psize; 2815 unsigned int psize;
2813 2816
2814 struct { 2817 struct
2818 {
2815 int altcount; 2819 int altcount;
2816 int atomcount; 2820 int atomcount;
2817 } * p; 2821 } *p;
2818 2822
2819 if (NULL == regex || 0 == strlen(regex) || 0 == len) 2823 if ((NULL == regex)||(0 == strlen (regex))||(0 == len))
2820 { 2824 {
2821 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2825 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2822 "Could not parse regex. Empty regex string provided.\n"); 2826 "Could not parse regex. Empty regex string provided.\n");
2823 2827
2824 return NULL; 2828 return NULL;
2825 } 2829 }
2826 REGEX_INTERNAL_context_init(&ctx); 2830 REGEX_INTERNAL_context_init (&ctx);
2827 2831
2828 regexp = regex; 2832 regexp = regex;
2829 curlabel[1] = '\0'; 2833 curlabel[1] = '\0';
@@ -2835,129 +2839,129 @@ REGEX_INTERNAL_construct_nfa(const char *regex, const size_t len)
2835 psize = 0; 2839 psize = 0;
2836 2840
2837 for (count = 0; count < len && *regexp; count++, regexp++) 2841 for (count = 0; count < len && *regexp; count++, regexp++)
2842 {
2843 switch (*regexp)
2838 { 2844 {
2839 switch (*regexp) 2845 case '(':
2840 { 2846 if (atomcount > 1)
2841 case '(': 2847 {
2842 if (atomcount > 1) 2848 --atomcount;
2843 { 2849 nfa_add_concatenation (&ctx);
2844 --atomcount; 2850 }
2845 nfa_add_concatenation(&ctx); 2851 if (poff == psize)
2846 } 2852 GNUNET_array_grow (p, psize, psize * 2 + 4); /* FIXME why *2 +4? */
2847 if (poff == psize) 2853 p[poff].altcount = altcount;
2848 GNUNET_array_grow(p, psize, psize * 2 + 4); /* FIXME why *2 +4? */ 2854 p[poff].atomcount = atomcount;
2849 p[poff].altcount = altcount; 2855 poff++;
2850 p[poff].atomcount = atomcount; 2856 altcount = 0;
2851 poff++; 2857 atomcount = 0;
2852 altcount = 0; 2858 break;
2853 atomcount = 0;
2854 break;
2855
2856 case '|':
2857 if (0 == atomcount)
2858 {
2859 error_msg = "Cannot append '|' to nothing";
2860 goto error;
2861 }
2862 while (--atomcount > 0)
2863 nfa_add_concatenation(&ctx);
2864 altcount++;
2865 break;
2866 2859
2867 case ')': 2860 case '|':
2868 if (0 == poff) 2861 if (0 == atomcount)
2869 { 2862 {
2870 error_msg = "Missing opening '('"; 2863 error_msg = "Cannot append '|' to nothing";
2871 goto error; 2864 goto error;
2872 } 2865 }
2873 if (0 == atomcount) 2866 while (--atomcount > 0)
2874 { 2867 nfa_add_concatenation (&ctx);
2875 /* Ignore this: "()" */ 2868 altcount++;
2876 poff--; 2869 break;
2877 altcount = p[poff].altcount;
2878 atomcount = p[poff].atomcount;
2879 break;
2880 }
2881 while (--atomcount > 0)
2882 nfa_add_concatenation(&ctx);
2883 for (; altcount > 0; altcount--)
2884 nfa_add_alternation(&ctx);
2885 poff--;
2886 altcount = p[poff].altcount;
2887 atomcount = p[poff].atomcount;
2888 atomcount++;
2889 break;
2890
2891 case '*':
2892 if (atomcount == 0)
2893 {
2894 error_msg = "Cannot append '*' to nothing";
2895 goto error;
2896 }
2897 nfa_add_star_op(&ctx);
2898 break;
2899 2870
2900 case '+': 2871 case ')':
2901 if (atomcount == 0) 2872 if (0 == poff)
2902 { 2873 {
2903 error_msg = "Cannot append '+' to nothing"; 2874 error_msg = "Missing opening '('";
2904 goto error; 2875 goto error;
2905 } 2876 }
2906 nfa_add_plus_op(&ctx); 2877 if (0 == atomcount)
2907 break; 2878 {
2879 /* Ignore this: "()" */
2880 poff--;
2881 altcount = p[poff].altcount;
2882 atomcount = p[poff].atomcount;
2883 break;
2884 }
2885 while (--atomcount > 0)
2886 nfa_add_concatenation (&ctx);
2887 for (; altcount > 0; altcount--)
2888 nfa_add_alternation (&ctx);
2889 poff--;
2890 altcount = p[poff].altcount;
2891 atomcount = p[poff].atomcount;
2892 atomcount++;
2893 break;
2908 2894
2909 case '?': 2895 case '*':
2910 if (atomcount == 0) 2896 if (atomcount == 0)
2911 { 2897 {
2912 error_msg = "Cannot append '?' to nothing"; 2898 error_msg = "Cannot append '*' to nothing";
2913 goto error; 2899 goto error;
2914 } 2900 }
2915 nfa_add_question_op(&ctx); 2901 nfa_add_star_op (&ctx);
2916 break; 2902 break;
2917 2903
2918 default: 2904 case '+':
2919 if (atomcount > 1) 2905 if (atomcount == 0)
2920 { 2906 {
2921 --atomcount; 2907 error_msg = "Cannot append '+' to nothing";
2922 nfa_add_concatenation(&ctx); 2908 goto error;
2923 } 2909 }
2924 curlabel[0] = *regexp; 2910 nfa_add_plus_op (&ctx);
2925 nfa_add_label(&ctx, curlabel); 2911 break;
2926 atomcount++; 2912
2927 break; 2913 case '?':
2928 } 2914 if (atomcount == 0)
2915 {
2916 error_msg = "Cannot append '?' to nothing";
2917 goto error;
2918 }
2919 nfa_add_question_op (&ctx);
2920 break;
2921
2922 default:
2923 if (atomcount > 1)
2924 {
2925 --atomcount;
2926 nfa_add_concatenation (&ctx);
2927 }
2928 curlabel[0] = *regexp;
2929 nfa_add_label (&ctx, curlabel);
2930 atomcount++;
2931 break;
2929 } 2932 }
2933 }
2930 if (0 != poff) 2934 if (0 != poff)
2931 { 2935 {
2932 error_msg = "Unbalanced parenthesis"; 2936 error_msg = "Unbalanced parenthesis";
2933 goto error; 2937 goto error;
2934 } 2938 }
2935 while (--atomcount > 0) 2939 while (--atomcount > 0)
2936 nfa_add_concatenation(&ctx); 2940 nfa_add_concatenation (&ctx);
2937 for (; altcount > 0; altcount--) 2941 for (; altcount > 0; altcount--)
2938 nfa_add_alternation(&ctx); 2942 nfa_add_alternation (&ctx);
2939 2943
2940 GNUNET_array_grow(p, psize, 0); 2944 GNUNET_array_grow (p, psize, 0);
2941 2945
2942 nfa = ctx.stack_tail; 2946 nfa = ctx.stack_tail;
2943 GNUNET_CONTAINER_DLL_remove(ctx.stack_head, ctx.stack_tail, nfa); 2947 GNUNET_CONTAINER_DLL_remove (ctx.stack_head, ctx.stack_tail, nfa);
2944 2948
2945 if (NULL != ctx.stack_head) 2949 if (NULL != ctx.stack_head)
2946 { 2950 {
2947 error_msg = "Creating the NFA failed. NFA stack was not empty!"; 2951 error_msg = "Creating the NFA failed. NFA stack was not empty!";
2948 goto error; 2952 goto error;
2949 } 2953 }
2950 2954
2951 /* Remember the regex that was used to generate this NFA */ 2955 /* Remember the regex that was used to generate this NFA */
2952 nfa->regex = GNUNET_strdup(regex); 2956 nfa->regex = GNUNET_strdup (regex);
2953 2957
2954 /* create depth-first numbering of the states for pretty printing */ 2958 /* create depth-first numbering of the states for pretty printing */
2955 REGEX_INTERNAL_automaton_traverse(nfa, 2959 REGEX_INTERNAL_automaton_traverse (nfa,
2956 NULL, 2960 NULL,
2957 NULL, 2961 NULL,
2958 NULL, 2962 NULL,
2959 &number_states, 2963 &number_states,
2960 NULL); 2964 NULL);
2961 2965
2962 /* No multistriding added so far */ 2966 /* No multistriding added so far */
2963 nfa->is_multistrided = GNUNET_NO; 2967 nfa->is_multistrided = GNUNET_NO;
@@ -2965,17 +2969,17 @@ REGEX_INTERNAL_construct_nfa(const char *regex, const size_t len)
2965 return nfa; 2969 return nfa;
2966 2970
2967error: 2971error:
2968 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not parse regex: `%s'\n", regex); 2972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not parse regex: `%s'\n", regex);
2969 if (NULL != error_msg) 2973 if (NULL != error_msg)
2970 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", error_msg); 2974 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", error_msg);
2971 2975
2972 GNUNET_free_non_null(p); 2976 GNUNET_free_non_null (p);
2973 2977
2974 while (NULL != (nfa = ctx.stack_head)) 2978 while (NULL != (nfa = ctx.stack_head))
2975 { 2979 {
2976 GNUNET_CONTAINER_DLL_remove(ctx.stack_head, ctx.stack_tail, nfa); 2980 GNUNET_CONTAINER_DLL_remove (ctx.stack_head, ctx.stack_tail, nfa);
2977 REGEX_INTERNAL_automaton_destroy(nfa); 2981 REGEX_INTERNAL_automaton_destroy (nfa);
2978 } 2982 }
2979 2983
2980 return NULL; 2984 return NULL;
2981} 2985}
@@ -2991,10 +2995,10 @@ error:
2991 * for starting. 2995 * for starting.
2992 */ 2996 */
2993static void 2997static void
2994construct_dfa_states(struct REGEX_INTERNAL_Context *ctx, 2998construct_dfa_states (struct REGEX_INTERNAL_Context *ctx,
2995 struct REGEX_INTERNAL_Automaton *nfa, 2999 struct REGEX_INTERNAL_Automaton *nfa,
2996 struct REGEX_INTERNAL_Automaton *dfa, 3000 struct REGEX_INTERNAL_Automaton *dfa,
2997 struct REGEX_INTERNAL_State *dfa_state) 3001 struct REGEX_INTERNAL_State *dfa_state)
2998{ 3002{
2999 struct REGEX_INTERNAL_Transition *ctran; 3003 struct REGEX_INTERNAL_Transition *ctran;
3000 struct REGEX_INTERNAL_State *new_dfa_state; 3004 struct REGEX_INTERNAL_State *new_dfa_state;
@@ -3004,37 +3008,37 @@ construct_dfa_states(struct REGEX_INTERNAL_Context *ctx,
3004 struct REGEX_INTERNAL_StateSet nfa_set; 3008 struct REGEX_INTERNAL_StateSet nfa_set;
3005 3009
3006 for (ctran = dfa_state->transitions_head; NULL != ctran; ctran = ctran->next) 3010 for (ctran = dfa_state->transitions_head; NULL != ctran; ctran = ctran->next)
3007 { 3011 {
3008 if (NULL == ctran->label || NULL != ctran->to_state) 3012 if ((NULL == ctran->label) ||(NULL != ctran->to_state) )
3009 continue; 3013 continue;
3010 3014
3011 nfa_closure_set_create(&tmp, nfa, &dfa_state->nfa_set, ctran->label); 3015 nfa_closure_set_create (&tmp, nfa, &dfa_state->nfa_set, ctran->label);
3012 nfa_closure_set_create(&nfa_set, nfa, &tmp, NULL); 3016 nfa_closure_set_create (&nfa_set, nfa, &tmp, NULL);
3013 state_set_clear(&tmp); 3017 state_set_clear (&tmp);
3014 3018
3015 state_contains = NULL; 3019 state_contains = NULL;
3016 for (state_iter = dfa->states_head; NULL != state_iter; 3020 for (state_iter = dfa->states_head; NULL != state_iter;
3017 state_iter = state_iter->next) 3021 state_iter = state_iter->next)
3018 { 3022 {
3019 if (0 == state_set_compare(&state_iter->nfa_set, &nfa_set)) 3023 if (0 == state_set_compare (&state_iter->nfa_set, &nfa_set))
3020 { 3024 {
3021 state_contains = state_iter; 3025 state_contains = state_iter;
3022 break; 3026 break;
3023 } 3027 }
3024 }
3025 if (NULL == state_contains)
3026 {
3027 new_dfa_state = dfa_state_create(ctx, &nfa_set);
3028 automaton_add_state(dfa, new_dfa_state);
3029 ctran->to_state = new_dfa_state;
3030 construct_dfa_states(ctx, nfa, dfa, new_dfa_state);
3031 }
3032 else
3033 {
3034 ctran->to_state = state_contains;
3035 state_set_clear(&nfa_set);
3036 }
3037 } 3028 }
3029 if (NULL == state_contains)
3030 {
3031 new_dfa_state = dfa_state_create (ctx, &nfa_set);
3032 automaton_add_state (dfa, new_dfa_state);
3033 ctran->to_state = new_dfa_state;
3034 construct_dfa_states (ctx, nfa, dfa, new_dfa_state);
3035 }
3036 else
3037 {
3038 ctran->to_state = state_contains;
3039 state_set_clear (&nfa_set);
3040 }
3041 }
3038} 3042}
3039 3043
3040 3044
@@ -3056,9 +3060,9 @@ construct_dfa_states(struct REGEX_INTERNAL_Context *ctx,
3056 * @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy. 3060 * @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy.
3057 */ 3061 */
3058struct REGEX_INTERNAL_Automaton * 3062struct REGEX_INTERNAL_Automaton *
3059REGEX_INTERNAL_construct_dfa(const char *regex, 3063REGEX_INTERNAL_construct_dfa (const char *regex,
3060 const size_t len, 3064 const size_t len,
3061 unsigned int max_path_len) 3065 unsigned int max_path_len)
3062{ 3066{
3063 struct REGEX_INTERNAL_Context ctx; 3067 struct REGEX_INTERNAL_Context ctx;
3064 struct REGEX_INTERNAL_Automaton *dfa; 3068 struct REGEX_INTERNAL_Automaton *dfa;
@@ -3066,50 +3070,50 @@ REGEX_INTERNAL_construct_dfa(const char *regex,
3066 struct REGEX_INTERNAL_StateSet nfa_start_eps_cls; 3070 struct REGEX_INTERNAL_StateSet nfa_start_eps_cls;
3067 struct REGEX_INTERNAL_StateSet singleton_set; 3071 struct REGEX_INTERNAL_StateSet singleton_set;
3068 3072
3069 REGEX_INTERNAL_context_init(&ctx); 3073 REGEX_INTERNAL_context_init (&ctx);
3070 3074
3071 /* Create NFA */ 3075 /* Create NFA */
3072 nfa = REGEX_INTERNAL_construct_nfa(regex, len); 3076 nfa = REGEX_INTERNAL_construct_nfa (regex, len);
3073 3077
3074 if (NULL == nfa) 3078 if (NULL == nfa)
3075 { 3079 {
3076 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3080 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3077 "Could not create DFA, because NFA creation failed\n"); 3081 "Could not create DFA, because NFA creation failed\n");
3078 return NULL; 3082 return NULL;
3079 } 3083 }
3080 3084
3081 dfa = GNUNET_new(struct REGEX_INTERNAL_Automaton); 3085 dfa = GNUNET_new (struct REGEX_INTERNAL_Automaton);
3082 dfa->type = DFA; 3086 dfa->type = DFA;
3083 dfa->regex = GNUNET_strdup(regex); 3087 dfa->regex = GNUNET_strdup (regex);
3084 3088
3085 /* Create DFA start state from epsilon closure */ 3089 /* Create DFA start state from epsilon closure */
3086 memset(&singleton_set, 0, sizeof(struct REGEX_INTERNAL_StateSet)); 3090 memset (&singleton_set, 0, sizeof(struct REGEX_INTERNAL_StateSet));
3087 state_set_append(&singleton_set, nfa->start); 3091 state_set_append (&singleton_set, nfa->start);
3088 nfa_closure_set_create(&nfa_start_eps_cls, nfa, &singleton_set, NULL); 3092 nfa_closure_set_create (&nfa_start_eps_cls, nfa, &singleton_set, NULL);
3089 state_set_clear(&singleton_set); 3093 state_set_clear (&singleton_set);
3090 dfa->start = dfa_state_create(&ctx, &nfa_start_eps_cls); 3094 dfa->start = dfa_state_create (&ctx, &nfa_start_eps_cls);
3091 automaton_add_state(dfa, dfa->start); 3095 automaton_add_state (dfa, dfa->start);
3092 3096
3093 construct_dfa_states(&ctx, nfa, dfa, dfa->start); 3097 construct_dfa_states (&ctx, nfa, dfa, dfa->start);
3094 REGEX_INTERNAL_automaton_destroy(nfa); 3098 REGEX_INTERNAL_automaton_destroy (nfa);
3095 3099
3096 /* Minimize DFA */ 3100 /* Minimize DFA */
3097 if (GNUNET_OK != dfa_minimize(&ctx, dfa)) 3101 if (GNUNET_OK != dfa_minimize (&ctx, dfa))
3098 { 3102 {
3099 REGEX_INTERNAL_automaton_destroy(dfa); 3103 REGEX_INTERNAL_automaton_destroy (dfa);
3100 return NULL; 3104 return NULL;
3101 } 3105 }
3102 3106
3103 /* Create proofs and hashes for all states */ 3107 /* Create proofs and hashes for all states */
3104 if (GNUNET_OK != automaton_create_proofs(dfa)) 3108 if (GNUNET_OK != automaton_create_proofs (dfa))
3105 { 3109 {
3106 REGEX_INTERNAL_automaton_destroy(dfa); 3110 REGEX_INTERNAL_automaton_destroy (dfa);
3107 return NULL; 3111 return NULL;
3108 } 3112 }
3109 3113
3110 /* Compress linear DFA paths */ 3114 /* Compress linear DFA paths */
3111 if (1 != max_path_len) 3115 if (1 != max_path_len)
3112 dfa_compress_paths(&ctx, dfa, max_path_len); 3116 dfa_compress_paths (&ctx, dfa, max_path_len);
3113 3117
3114 return dfa; 3118 return dfa;
3115} 3119}
@@ -3122,7 +3126,7 @@ REGEX_INTERNAL_construct_dfa(const char *regex,
3122 * @param a automaton to be destroyed 3126 * @param a automaton to be destroyed
3123 */ 3127 */
3124void 3128void
3125REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a) 3129REGEX_INTERNAL_automaton_destroy (struct REGEX_INTERNAL_Automaton *a)
3126{ 3130{
3127 struct REGEX_INTERNAL_State *s; 3131 struct REGEX_INTERNAL_State *s;
3128 struct REGEX_INTERNAL_State *next_state; 3132 struct REGEX_INTERNAL_State *next_state;
@@ -3130,17 +3134,17 @@ REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
3130 if (NULL == a) 3134 if (NULL == a)
3131 return; 3135 return;
3132 3136
3133 GNUNET_free_non_null(a->regex); 3137 GNUNET_free_non_null (a->regex);
3134 GNUNET_free_non_null(a->canonical_regex); 3138 GNUNET_free_non_null (a->canonical_regex);
3135 3139
3136 for (s = a->states_head; NULL != s; s = next_state) 3140 for (s = a->states_head; NULL != s; s = next_state)
3137 { 3141 {
3138 next_state = s->next; 3142 next_state = s->next;
3139 GNUNET_CONTAINER_DLL_remove(a->states_head, a->states_tail, s); 3143 GNUNET_CONTAINER_DLL_remove (a->states_head, a->states_tail, s);
3140 automaton_destroy_state(s); 3144 automaton_destroy_state (s);
3141 } 3145 }
3142 3146
3143 GNUNET_free(a); 3147 GNUNET_free (a);
3144} 3148}
3145 3149
3146 3150
@@ -3153,34 +3157,34 @@ REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
3153 * @return 0 if string matches, non-0 otherwise 3157 * @return 0 if string matches, non-0 otherwise
3154 */ 3158 */
3155static int 3159static int
3156evaluate_dfa(struct REGEX_INTERNAL_Automaton *a, const char *string) 3160evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, const char *string)
3157{ 3161{
3158 const char *strp; 3162 const char *strp;
3159 struct REGEX_INTERNAL_State *s; 3163 struct REGEX_INTERNAL_State *s;
3160 unsigned int step_len; 3164 unsigned int step_len;
3161 3165
3162 if (DFA != a->type) 3166 if (DFA != a->type)
3163 { 3167 {
3164 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3165 "Tried to evaluate DFA, but NFA automaton given"); 3169 "Tried to evaluate DFA, but NFA automaton given");
3166 return -1; 3170 return -1;
3167 } 3171 }
3168 3172
3169 s = a->start; 3173 s = a->start;
3170 3174
3171 /* If the string is empty but the starting state is accepting, we accept. */ 3175 /* If the string is empty but the starting state is accepting, we accept. */
3172 if ((NULL == string || 0 == strlen(string)) && s->accepting) 3176 if (((NULL == string)||(0 == strlen (string))) && s->accepting)
3173 return 0; 3177 return 0;
3174 3178
3175 for (strp = string; NULL != strp && *strp; strp += step_len) 3179 for (strp = string; NULL != strp && *strp; strp += step_len)
3176 { 3180 {
3177 step_len = dfa_move(&s, strp); 3181 step_len = dfa_move (&s, strp);
3178 3182
3179 if (NULL == s) 3183 if (NULL == s)
3180 break; 3184 break;
3181 } 3185 }
3182 3186
3183 if (NULL != s && s->accepting) 3187 if ((NULL != s)&& s->accepting)
3184 return 0; 3188 return 0;
3185 3189
3186 return 1; 3190 return 1;
@@ -3195,7 +3199,7 @@ evaluate_dfa(struct REGEX_INTERNAL_Automaton *a, const char *string)
3195 * @return 0 if string matches, non-0 otherwise 3199 * @return 0 if string matches, non-0 otherwise
3196 */ 3200 */
3197static int 3201static int
3198evaluate_nfa(struct REGEX_INTERNAL_Automaton *a, const char *string) 3202evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, const char *string)
3199{ 3203{
3200 const char *strp; 3204 const char *strp;
3201 char str[2]; 3205 char str[2];
@@ -3207,43 +3211,43 @@ evaluate_nfa(struct REGEX_INTERNAL_Automaton *a, const char *string)
3207 int result; 3211 int result;
3208 3212
3209 if (NFA != a->type) 3213 if (NFA != a->type)
3210 { 3214 {
3211 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3212 "Tried to evaluate NFA, but DFA automaton given"); 3216 "Tried to evaluate NFA, but DFA automaton given");
3213 return -1; 3217 return -1;
3214 } 3218 }
3215 3219
3216 /* If the string is empty but the starting state is accepting, we accept. */ 3220 /* If the string is empty but the starting state is accepting, we accept. */
3217 if ((NULL == string || 0 == strlen(string)) && a->start->accepting) 3221 if (((NULL == string)||(0 == strlen (string))) && a->start->accepting)
3218 return 0; 3222 return 0;
3219 3223
3220 result = 1; 3224 result = 1;
3221 memset(&singleton_set, 0, sizeof(struct REGEX_INTERNAL_StateSet)); 3225 memset (&singleton_set, 0, sizeof(struct REGEX_INTERNAL_StateSet));
3222 state_set_append(&singleton_set, a->start); 3226 state_set_append (&singleton_set, a->start);
3223 nfa_closure_set_create(&sset, a, &singleton_set, NULL); 3227 nfa_closure_set_create (&sset, a, &singleton_set, NULL);
3224 state_set_clear(&singleton_set); 3228 state_set_clear (&singleton_set);
3225 3229
3226 str[1] = '\0'; 3230 str[1] = '\0';
3227 for (strp = string; NULL != strp && *strp; strp++) 3231 for (strp = string; NULL != strp && *strp; strp++)
3228 { 3232 {
3229 str[0] = *strp; 3233 str[0] = *strp;
3230 nfa_closure_set_create(&new_sset, a, &sset, str); 3234 nfa_closure_set_create (&new_sset, a, &sset, str);
3231 state_set_clear(&sset); 3235 state_set_clear (&sset);
3232 nfa_closure_set_create(&sset, a, &new_sset, 0); 3236 nfa_closure_set_create (&sset, a, &new_sset, 0);
3233 state_set_clear(&new_sset); 3237 state_set_clear (&new_sset);
3234 } 3238 }
3235 3239
3236 for (i = 0; i < sset.off; i++) 3240 for (i = 0; i < sset.off; i++)
3241 {
3242 s = sset.states[i];
3243 if ((NULL != s) && (s->accepting))
3237 { 3244 {
3238 s = sset.states[i]; 3245 result = 0;
3239 if ((NULL != s) && (s->accepting)) 3246 break;
3240 {
3241 result = 0;
3242 break;
3243 }
3244 } 3247 }
3248 }
3245 3249
3246 state_set_clear(&sset); 3250 state_set_clear (&sset);
3247 return result; 3251 return result;
3248} 3252}
3249 3253
@@ -3256,26 +3260,26 @@ evaluate_nfa(struct REGEX_INTERNAL_Automaton *a, const char *string)
3256 * @return 0 if string matches, non-0 otherwise 3260 * @return 0 if string matches, non-0 otherwise
3257 */ 3261 */
3258int 3262int
3259REGEX_INTERNAL_eval(struct REGEX_INTERNAL_Automaton *a, const char *string) 3263REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, const char *string)
3260{ 3264{
3261 int result; 3265 int result;
3262 3266
3263 switch (a->type) 3267 switch (a->type)
3264 { 3268 {
3265 case DFA: 3269 case DFA:
3266 result = evaluate_dfa(a, string); 3270 result = evaluate_dfa (a, string);
3267 break; 3271 break;
3268 3272
3269 case NFA: 3273 case NFA:
3270 result = evaluate_nfa(a, string); 3274 result = evaluate_nfa (a, string);
3271 break; 3275 break;
3272 3276
3273 default: 3277 default:
3274 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3275 "Evaluating regex failed, automaton has no type!\n"); 3279 "Evaluating regex failed, automaton has no type!\n");
3276 result = GNUNET_SYSERR; 3280 result = GNUNET_SYSERR;
3277 break; 3281 break;
3278 } 3282 }
3279 3283
3280 return result; 3284 return result;
3281} 3285}
@@ -3293,7 +3297,7 @@ REGEX_INTERNAL_eval(struct REGEX_INTERNAL_Automaton *a, const char *string)
3293 * @return 3297 * @return
3294 */ 3298 */
3295const char * 3299const char *
3296REGEX_INTERNAL_get_canonical_regex(struct REGEX_INTERNAL_Automaton *a) 3300REGEX_INTERNAL_get_canonical_regex (struct REGEX_INTERNAL_Automaton *a)
3297{ 3301{
3298 if (NULL == a) 3302 if (NULL == a)
3299 return NULL; 3303 return NULL;
@@ -3310,7 +3314,7 @@ REGEX_INTERNAL_get_canonical_regex(struct REGEX_INTERNAL_Automaton *a)
3310 * @return number of transitions in the given automaton. 3314 * @return number of transitions in the given automaton.
3311 */ 3315 */
3312unsigned int 3316unsigned int
3313REGEX_INTERNAL_get_transition_count(struct REGEX_INTERNAL_Automaton *a) 3317REGEX_INTERNAL_get_transition_count (struct REGEX_INTERNAL_Automaton *a)
3314{ 3318{
3315 unsigned int t_count; 3319 unsigned int t_count;
3316 struct REGEX_INTERNAL_State *s; 3320 struct REGEX_INTERNAL_State *s;
@@ -3337,20 +3341,20 @@ REGEX_INTERNAL_get_transition_count(struct REGEX_INTERNAL_Automaton *a)
3337 * to construct the key 3341 * to construct the key
3338 */ 3342 */
3339size_t 3343size_t
3340REGEX_INTERNAL_get_first_key(const char *input_string, 3344REGEX_INTERNAL_get_first_key (const char *input_string,
3341 size_t string_len, 3345 size_t string_len,
3342 struct GNUNET_HashCode *key) 3346 struct GNUNET_HashCode *key)
3343{ 3347{
3344 size_t size; 3348 size_t size;
3345 3349
3346 size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len 3350 size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len
3347 : GNUNET_REGEX_INITIAL_BYTES; 3351 : GNUNET_REGEX_INITIAL_BYTES;
3348 if (NULL == input_string) 3352 if (NULL == input_string)
3349 { 3353 {
3350 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n"); 3354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n");
3351 return 0; 3355 return 0;
3352 } 3356 }
3353 GNUNET_CRYPTO_hash(input_string, size, key); 3357 GNUNET_CRYPTO_hash (input_string, size, key);
3354 3358
3355 return size; 3359 return size;
3356} 3360}
@@ -3367,12 +3371,12 @@ REGEX_INTERNAL_get_first_key(const char *input_string,
3367 * @param iterator_cls closure for the @a iterator function. 3371 * @param iterator_cls closure for the @a iterator function.
3368 */ 3372 */
3369static void 3373static void
3370iterate_initial_edge(unsigned int min_len, 3374iterate_initial_edge (unsigned int min_len,
3371 unsigned int max_len, 3375 unsigned int max_len,
3372 char *consumed_string, 3376 char *consumed_string,
3373 struct REGEX_INTERNAL_State *state, 3377 struct REGEX_INTERNAL_State *state,
3374 REGEX_INTERNAL_KeyIterator iterator, 3378 REGEX_INTERNAL_KeyIterator iterator,
3375 void *iterator_cls) 3379 void *iterator_cls)
3376{ 3380{
3377 char *temp; 3381 char *temp;
3378 struct REGEX_INTERNAL_Transition *t; 3382 struct REGEX_INTERNAL_Transition *t;
@@ -3384,91 +3388,91 @@ iterate_initial_edge(unsigned int min_len,
3384 unsigned int cur_len; 3388 unsigned int cur_len;
3385 3389
3386 if (NULL != consumed_string) 3390 if (NULL != consumed_string)
3387 cur_len = strlen(consumed_string); 3391 cur_len = strlen (consumed_string);
3388 else 3392 else
3389 cur_len = 0; 3393 cur_len = 0;
3390 3394
3391 if (((cur_len >= min_len) || (GNUNET_YES == state->accepting)) && 3395 if (((cur_len >= min_len) || (GNUNET_YES == state->accepting)) &&
3392 (cur_len > 0) && (NULL != consumed_string)) 3396 (cur_len > 0) && (NULL != consumed_string))
3397 {
3398 if (cur_len <= max_len)
3393 { 3399 {
3394 if (cur_len <= max_len) 3400 if ((NULL != state->proof) &&
3395 { 3401 (0 != strcmp (consumed_string, state->proof)))
3396 if ((NULL != state->proof) && 3402 {
3397 (0 != strcmp(consumed_string, state->proof))) 3403 (void) state_get_edges (state, edges);
3398 { 3404 GNUNET_CRYPTO_hash (consumed_string, strlen (consumed_string), &hash);
3399 (void)state_get_edges(state, edges); 3405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3400 GNUNET_CRYPTO_hash(consumed_string, strlen(consumed_string), &hash); 3406 "Start state for string `%s' is %s\n",
3401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3407 consumed_string,
3402 "Start state for string `%s' is %s\n", 3408 GNUNET_h2s (&hash));
3403 consumed_string, 3409 iterator (iterator_cls,
3404 GNUNET_h2s(&hash)); 3410 &hash,
3405 iterator(iterator_cls, 3411 consumed_string,
3406 &hash, 3412 state->accepting,
3407 consumed_string, 3413 num_edges,
3408 state->accepting, 3414 edges);
3409 num_edges, 3415 }
3410 edges);
3411 }
3412 3416
3413 if ((GNUNET_YES == state->accepting) && (cur_len > 1) && 3417 if ((GNUNET_YES == state->accepting) && (cur_len > 1) &&
3414 (state->transition_count < 1) && (cur_len < max_len)) 3418 (state->transition_count < 1) && (cur_len < max_len))
3415 { 3419 {
3416 /* Special case for regex consisting of just a string that is shorter than 3420 /* Special case for regex consisting of just a string that is shorter than
3417 * max_len */ 3421 * max_len */
3418 edge[0].label = &consumed_string[cur_len - 1]; 3422 edge[0].label = &consumed_string[cur_len - 1];
3419 edge[0].destination = state->hash; 3423 edge[0].destination = state->hash;
3420 temp = GNUNET_strdup(consumed_string); 3424 temp = GNUNET_strdup (consumed_string);
3421 temp[cur_len - 1] = '\0'; 3425 temp[cur_len - 1] = '\0';
3422 GNUNET_CRYPTO_hash(temp, cur_len - 1, &hash_new); 3426 GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new);
3423 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3424 "Start state for short string `%s' is %s\n", 3428 "Start state for short string `%s' is %s\n",
3425 temp, 3429 temp,
3426 GNUNET_h2s(&hash_new)); 3430 GNUNET_h2s (&hash_new));
3427 iterator(iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge); 3431 iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge);
3428 GNUNET_free(temp); 3432 GNUNET_free (temp);
3429 } 3433 }
3430 } 3434 }
3431 else /* cur_len > max_len */ 3435 else /* cur_len > max_len */
3432 { 3436 {
3433 /* Case where the concatenated labels are longer than max_len, then split. */ 3437 /* Case where the concatenated labels are longer than max_len, then split. */
3434 edge[0].label = &consumed_string[max_len]; 3438 edge[0].label = &consumed_string[max_len];
3435 edge[0].destination = state->hash; 3439 edge[0].destination = state->hash;
3436 temp = GNUNET_strdup(consumed_string); 3440 temp = GNUNET_strdup (consumed_string);
3437 temp[max_len] = '\0'; 3441 temp[max_len] = '\0';
3438 GNUNET_CRYPTO_hash(temp, max_len, &hash); 3442 GNUNET_CRYPTO_hash (temp, max_len, &hash);
3439 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3440 "Start state at split edge `%s'-`%s` is %s\n", 3444 "Start state at split edge `%s'-`%s` is %s\n",
3441 temp, 3445 temp,
3442 edge[0].label, 3446 edge[0].label,
3443 GNUNET_h2s(&hash_new)); 3447 GNUNET_h2s (&hash_new));
3444 iterator(iterator_cls, &hash, temp, GNUNET_NO, 1, edge); 3448 iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge);
3445 GNUNET_free(temp); 3449 GNUNET_free (temp);
3446 }
3447 } 3450 }
3451 }
3448 3452
3449 if (cur_len < max_len) 3453 if (cur_len < max_len)
3454 {
3455 for (t = state->transitions_head; NULL != t; t = t->next)
3450 { 3456 {
3451 for (t = state->transitions_head; NULL != t; t = t->next) 3457 if (NULL != strchr (t->label, (int) '.'))
3452 { 3458 {
3453 if (NULL != strchr(t->label, (int)'.')) 3459 /* Wildcards not allowed during starting states */
3454 { 3460 GNUNET_break (0);
3455 /* Wildcards not allowed during starting states */ 3461 continue;
3456 GNUNET_break(0); 3462 }
3457 continue; 3463 if (NULL != consumed_string)
3458 } 3464 GNUNET_asprintf (&temp, "%s%s", consumed_string, t->label);
3459 if (NULL != consumed_string) 3465 else
3460 GNUNET_asprintf(&temp, "%s%s", consumed_string, t->label); 3466 GNUNET_asprintf (&temp, "%s", t->label);
3461 else 3467 iterate_initial_edge (min_len,
3462 GNUNET_asprintf(&temp, "%s", t->label); 3468 max_len,
3463 iterate_initial_edge(min_len, 3469 temp,
3464 max_len, 3470 t->to_state,
3465 temp, 3471 iterator,
3466 t->to_state, 3472 iterator_cls);
3467 iterator, 3473 GNUNET_free (temp);
3468 iterator_cls);
3469 GNUNET_free(temp);
3470 }
3471 } 3474 }
3475 }
3472} 3476}
3473 3477
3474 3478
@@ -3481,41 +3485,41 @@ iterate_initial_edge(unsigned int min_len,
3481 * @param iterator_cls closure. 3485 * @param iterator_cls closure.
3482 */ 3486 */
3483void 3487void
3484REGEX_INTERNAL_iterate_all_edges(struct REGEX_INTERNAL_Automaton *a, 3488REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a,
3485 REGEX_INTERNAL_KeyIterator iterator, 3489 REGEX_INTERNAL_KeyIterator iterator,
3486 void *iterator_cls) 3490 void *iterator_cls)
3487{ 3491{
3488 struct REGEX_INTERNAL_State *s; 3492 struct REGEX_INTERNAL_State *s;
3489 3493
3490 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n"); 3494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n");
3491 iterate_initial_edge(GNUNET_REGEX_INITIAL_BYTES, 3495 iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES,
3492 GNUNET_REGEX_INITIAL_BYTES, 3496 GNUNET_REGEX_INITIAL_BYTES,
3493 NULL, 3497 NULL,
3494 a->start, 3498 a->start,
3495 iterator, 3499 iterator,
3496 iterator_cls); 3500 iterator_cls);
3497 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n"); 3501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n");
3498 for (s = a->states_head; NULL != s; s = s->next) 3502 for (s = a->states_head; NULL != s; s = s->next)
3499 { 3503 {
3500 struct REGEX_BLOCK_Edge edges[s->transition_count]; 3504 struct REGEX_BLOCK_Edge edges[s->transition_count];
3501 unsigned int num_edges; 3505 unsigned int num_edges;
3502 3506
3503 num_edges = state_get_edges(s, edges); 3507 num_edges = state_get_edges (s, edges);
3504 if (((NULL != s->proof) && (0 < strlen(s->proof))) || s->accepting) 3508 if (((NULL != s->proof) && (0 < strlen (s->proof))) || s->accepting)
3505 { 3509 {
3506 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3507 "Creating DFA edges at `%s' under key %s\n", 3511 "Creating DFA edges at `%s' under key %s\n",
3508 s->proof, 3512 s->proof,
3509 GNUNET_h2s(&s->hash)); 3513 GNUNET_h2s (&s->hash));
3510 iterator(iterator_cls, 3514 iterator (iterator_cls,
3511 &s->hash, 3515 &s->hash,
3512 s->proof, 3516 s->proof,
3513 s->accepting, 3517 s->accepting,
3514 num_edges, 3518 num_edges,
3515 edges); 3519 edges);
3516 }
3517 s->marked = GNUNET_NO;
3518 } 3520 }
3521 s->marked = GNUNET_NO;
3522 }
3519} 3523}
3520 3524
3521 3525
@@ -3525,7 +3529,8 @@ REGEX_INTERNAL_iterate_all_edges(struct REGEX_INTERNAL_Automaton *a,
3525 * Contains the same info as the Regex Iterator parametes except the key, 3529 * Contains the same info as the Regex Iterator parametes except the key,
3526 * which comes directly from the HashMap iterator. 3530 * which comes directly from the HashMap iterator.
3527 */ 3531 */
3528struct temporal_state_store { 3532struct temporal_state_store
3533{
3529 int reachable; 3534 int reachable;
3530 char *proof; 3535 char *proof;
3531 int accepting; 3536 int accepting;
@@ -3537,7 +3542,8 @@ struct temporal_state_store {
3537/** 3542/**
3538 * Store regex iterator and cls in one place to pass to the hashmap iterator. 3543 * Store regex iterator and cls in one place to pass to the hashmap iterator.
3539 */ 3544 */
3540struct client_iterator { 3545struct client_iterator
3546{
3541 REGEX_INTERNAL_KeyIterator iterator; 3547 REGEX_INTERNAL_KeyIterator iterator;
3542 void *iterator_cls; 3548 void *iterator_cls;
3543}; 3549};
@@ -3555,31 +3561,31 @@ struct client_iterator {
3555 * @param edges edges leaving current state. 3561 * @param edges edges leaving current state.
3556 */ 3562 */
3557static void 3563static void
3558store_all_states(void *cls, 3564store_all_states (void *cls,
3559 const struct GNUNET_HashCode *key, 3565 const struct GNUNET_HashCode *key,
3560 const char *proof, 3566 const char *proof,
3561 int accepting, 3567 int accepting,
3562 unsigned int num_edges, 3568 unsigned int num_edges,
3563 const struct REGEX_BLOCK_Edge *edges) 3569 const struct REGEX_BLOCK_Edge *edges)
3564{ 3570{
3565 struct GNUNET_CONTAINER_MultiHashMap *hm = cls; 3571 struct GNUNET_CONTAINER_MultiHashMap *hm = cls;
3566 struct temporal_state_store *tmp; 3572 struct temporal_state_store *tmp;
3567 size_t edges_size; 3573 size_t edges_size;
3568 3574
3569 tmp = GNUNET_new(struct temporal_state_store); 3575 tmp = GNUNET_new (struct temporal_state_store);
3570 tmp->reachable = GNUNET_NO; 3576 tmp->reachable = GNUNET_NO;
3571 tmp->proof = GNUNET_strdup(proof); 3577 tmp->proof = GNUNET_strdup (proof);
3572 tmp->accepting = accepting; 3578 tmp->accepting = accepting;
3573 tmp->num_edges = num_edges; 3579 tmp->num_edges = num_edges;
3574 edges_size = sizeof(struct REGEX_BLOCK_Edge) * num_edges; 3580 edges_size = sizeof(struct REGEX_BLOCK_Edge) * num_edges;
3575 tmp->edges = GNUNET_malloc(edges_size); 3581 tmp->edges = GNUNET_malloc (edges_size);
3576 GNUNET_memcpy(tmp->edges, edges, edges_size); 3582 GNUNET_memcpy (tmp->edges, edges, edges_size);
3577 GNUNET_assert(GNUNET_YES == 3583 GNUNET_assert (GNUNET_YES ==
3578 GNUNET_CONTAINER_multihashmap_put( 3584 GNUNET_CONTAINER_multihashmap_put (
3579 hm, 3585 hm,
3580 key, 3586 key,
3581 tmp, 3587 tmp,
3582 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 3588 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
3583} 3589}
3584 3590
3585 3591
@@ -3592,8 +3598,8 @@ store_all_states(void *cls,
3592 * @param hm HashMap which stores all the states indexed by key. 3598 * @param hm HashMap which stores all the states indexed by key.
3593 */ 3599 */
3594static void 3600static void
3595mark_as_reachable(struct temporal_state_store *state, 3601mark_as_reachable (struct temporal_state_store *state,
3596 struct GNUNET_CONTAINER_MultiHashMap *hm) 3602 struct GNUNET_CONTAINER_MultiHashMap *hm)
3597{ 3603{
3598 struct temporal_state_store *child; 3604 struct temporal_state_store *child;
3599 unsigned int i; 3605 unsigned int i;
@@ -3604,16 +3610,16 @@ mark_as_reachable(struct temporal_state_store *state,
3604 3610
3605 state->reachable = GNUNET_YES; 3611 state->reachable = GNUNET_YES;
3606 for (i = 0; i < state->num_edges; i++) 3612 for (i = 0; i < state->num_edges; i++)
3613 {
3614 child =
3615 GNUNET_CONTAINER_multihashmap_get (hm, &state->edges[i].destination);
3616 if (NULL == child)
3607 { 3617 {
3608 child = 3618 GNUNET_break (0);
3609 GNUNET_CONTAINER_multihashmap_get(hm, &state->edges[i].destination); 3619 continue;
3610 if (NULL == child)
3611 {
3612 GNUNET_break(0);
3613 continue;
3614 }
3615 mark_as_reachable(child, hm);
3616 } 3620 }
3621 mark_as_reachable (child, hm);
3622 }
3617} 3623}
3618 3624
3619 3625
@@ -3627,9 +3633,9 @@ mark_as_reachable(struct temporal_state_store *state,
3627 * #GNUNET_NO if not. 3633 * #GNUNET_NO if not.
3628 */ 3634 */
3629static int 3635static int
3630reachability_iterator(void *cls, 3636reachability_iterator (void *cls,
3631 const struct GNUNET_HashCode *key, 3637 const struct GNUNET_HashCode *key,
3632 void *value) 3638 void *value)
3633{ 3639{
3634 struct GNUNET_CONTAINER_MultiHashMap *hm = cls; 3640 struct GNUNET_CONTAINER_MultiHashMap *hm = cls;
3635 struct temporal_state_store *state = value; 3641 struct temporal_state_store *state = value;
@@ -3638,12 +3644,12 @@ reachability_iterator(void *cls,
3638 /* already visited and marked */ 3644 /* already visited and marked */
3639 return GNUNET_YES; 3645 return GNUNET_YES;
3640 3646
3641 if (GNUNET_REGEX_INITIAL_BYTES > strlen(state->proof) && 3647 if ((GNUNET_REGEX_INITIAL_BYTES > strlen (state->proof))&&
3642 GNUNET_NO == state->accepting) 3648 (GNUNET_NO == state->accepting) )
3643 /* not directly reachable */ 3649 /* not directly reachable */
3644 return GNUNET_YES; 3650 return GNUNET_YES;
3645 3651
3646 mark_as_reachable(state, hm); 3652 mark_as_reachable (state, hm);
3647 return GNUNET_YES; 3653 return GNUNET_YES;
3648} 3654}
3649 3655
@@ -3659,23 +3665,23 @@ reachability_iterator(void *cls,
3659 * #GNUNET_NO if not. 3665 * #GNUNET_NO if not.
3660 */ 3666 */
3661static int 3667static int
3662iterate_reachables(void *cls, const struct GNUNET_HashCode *key, void *value) 3668iterate_reachables (void *cls, const struct GNUNET_HashCode *key, void *value)
3663{ 3669{
3664 struct client_iterator *ci = cls; 3670 struct client_iterator *ci = cls;
3665 struct temporal_state_store *state = value; 3671 struct temporal_state_store *state = value;
3666 3672
3667 if (GNUNET_YES == state->reachable) 3673 if (GNUNET_YES == state->reachable)
3668 { 3674 {
3669 ci->iterator(ci->iterator_cls, 3675 ci->iterator (ci->iterator_cls,
3670 key, 3676 key,
3671 state->proof, 3677 state->proof,
3672 state->accepting, 3678 state->accepting,
3673 state->num_edges, 3679 state->num_edges,
3674 state->edges); 3680 state->edges);
3675 } 3681 }
3676 GNUNET_free(state->edges); 3682 GNUNET_free (state->edges);
3677 GNUNET_free(state->proof); 3683 GNUNET_free (state->proof);
3678 GNUNET_free(state); 3684 GNUNET_free (state);
3679 return GNUNET_YES; 3685 return GNUNET_YES;
3680} 3686}
3681 3687
@@ -3690,22 +3696,22 @@ iterate_reachables(void *cls, const struct GNUNET_HashCode *key, void *value)
3690 * @param iterator_cls closure. 3696 * @param iterator_cls closure.
3691 */ 3697 */
3692void 3698void
3693REGEX_INTERNAL_iterate_reachable_edges(struct REGEX_INTERNAL_Automaton *a, 3699REGEX_INTERNAL_iterate_reachable_edges (struct REGEX_INTERNAL_Automaton *a,
3694 REGEX_INTERNAL_KeyIterator iterator, 3700 REGEX_INTERNAL_KeyIterator iterator,
3695 void *iterator_cls) 3701 void *iterator_cls)
3696{ 3702{
3697 struct GNUNET_CONTAINER_MultiHashMap *hm; 3703 struct GNUNET_CONTAINER_MultiHashMap *hm;
3698 struct client_iterator ci; 3704 struct client_iterator ci;
3699 3705
3700 hm = GNUNET_CONTAINER_multihashmap_create(a->state_count * 2, GNUNET_NO); 3706 hm = GNUNET_CONTAINER_multihashmap_create (a->state_count * 2, GNUNET_NO);
3701 ci.iterator = iterator; 3707 ci.iterator = iterator;
3702 ci.iterator_cls = iterator_cls; 3708 ci.iterator_cls = iterator_cls;
3703 3709
3704 REGEX_INTERNAL_iterate_all_edges(a, &store_all_states, hm); 3710 REGEX_INTERNAL_iterate_all_edges (a, &store_all_states, hm);
3705 GNUNET_CONTAINER_multihashmap_iterate(hm, &reachability_iterator, hm); 3711 GNUNET_CONTAINER_multihashmap_iterate (hm, &reachability_iterator, hm);
3706 GNUNET_CONTAINER_multihashmap_iterate(hm, &iterate_reachables, &ci); 3712 GNUNET_CONTAINER_multihashmap_iterate (hm, &iterate_reachables, &ci);
3707 3713
3708 GNUNET_CONTAINER_multihashmap_destroy(hm); 3714 GNUNET_CONTAINER_multihashmap_destroy (hm);
3709} 3715}
3710 3716
3711 3717
diff --git a/src/regex/regex_internal.h b/src/regex/regex_internal.h
index ab8b6f22d..1e0722136 100644
--- a/src/regex/regex_internal.h
+++ b/src/regex/regex_internal.h
@@ -39,7 +39,8 @@ extern "C"
39 * char array of literals that are allowed inside a regex (apart from the 39 * char array of literals that are allowed inside a regex (apart from the
40 * operators) 40 * operators)
41 */ 41 */
42#define ALLOWED_LITERALS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 42#define ALLOWED_LITERALS \
43 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
43 44
44 45
45/** 46/**
@@ -47,7 +48,8 @@ extern "C"
47 * which they origin ('from_state'). Each state can have 0-n transitions. 48 * which they origin ('from_state'). Each state can have 0-n transitions.
48 * If label is NULL, this is considered to be an epsilon transition. 49 * If label is NULL, this is considered to be an epsilon transition.
49 */ 50 */
50struct REGEX_INTERNAL_Transition { 51struct REGEX_INTERNAL_Transition
52{
51 /** 53 /**
52 * This is a linked list. 54 * This is a linked list.
53 */ 55 */
@@ -89,7 +91,8 @@ struct REGEX_INTERNAL_State;
89/** 91/**
90 * Set of states. 92 * Set of states.
91 */ 93 */
92struct REGEX_INTERNAL_StateSet { 94struct REGEX_INTERNAL_StateSet
95{
93 /** 96 /**
94 * Array of states. 97 * Array of states.
95 */ 98 */
@@ -110,7 +113,8 @@ struct REGEX_INTERNAL_StateSet {
110/** 113/**
111 * A state. Can be used in DFA and NFA automatons. 114 * A state. Can be used in DFA and NFA automatons.
112 */ 115 */
113struct REGEX_INTERNAL_State { 116struct REGEX_INTERNAL_State
117{
114 /** 118 /**
115 * This is a linked list to keep states in an automaton. 119 * This is a linked list to keep states in an automaton.
116 */ 120 */
@@ -242,7 +246,8 @@ struct REGEX_INTERNAL_State {
242/** 246/**
243 * Type of an automaton. 247 * Type of an automaton.
244 */ 248 */
245enum REGEX_INTERNAL_AutomatonType { 249enum REGEX_INTERNAL_AutomatonType
250{
246 NFA, 251 NFA,
247 DFA 252 DFA
248}; 253};
@@ -251,7 +256,8 @@ enum REGEX_INTERNAL_AutomatonType {
251/** 256/**
252 * Automaton representation. 257 * Automaton representation.
253 */ 258 */
254struct REGEX_INTERNAL_Automaton { 259struct REGEX_INTERNAL_Automaton
260{
255 /** 261 /**
256 * Linked list of NFAs used for partial NFA creation. 262 * Linked list of NFAs used for partial NFA creation.
257 */ 263 */
@@ -319,7 +325,7 @@ struct REGEX_INTERNAL_Automaton {
319 * @return NFA, needs to be freed using REGEX_INTERNAL_automaton_destroy. 325 * @return NFA, needs to be freed using REGEX_INTERNAL_automaton_destroy.
320 */ 326 */
321struct REGEX_INTERNAL_Automaton * 327struct REGEX_INTERNAL_Automaton *
322REGEX_INTERNAL_construct_nfa(const char *regex, const size_t len); 328REGEX_INTERNAL_construct_nfa (const char *regex, const size_t len);
323 329
324 330
325/** 331/**
@@ -335,8 +341,9 @@ REGEX_INTERNAL_construct_nfa(const char *regex, const size_t len);
335 * @return GNUNET_YES to proceed traversal, GNUNET_NO to stop. 341 * @return GNUNET_YES to proceed traversal, GNUNET_NO to stop.
336 */ 342 */
337typedef int (*REGEX_INTERNAL_traverse_check) (void *cls, 343typedef int (*REGEX_INTERNAL_traverse_check) (void *cls,
338 struct REGEX_INTERNAL_State * s, 344 struct REGEX_INTERNAL_State *s,
339 struct REGEX_INTERNAL_Transition * t); 345 struct REGEX_INTERNAL_Transition *
346 t);
340 347
341 348
342/** 349/**
@@ -348,7 +355,7 @@ typedef int (*REGEX_INTERNAL_traverse_check) (void *cls,
348 */ 355 */
349typedef void (*REGEX_INTERNAL_traverse_action) (void *cls, 356typedef void (*REGEX_INTERNAL_traverse_action) (void *cls,
350 const unsigned int count, 357 const unsigned int count,
351 struct REGEX_INTERNAL_State * s); 358 struct REGEX_INTERNAL_State *s);
352 359
353 360
354/** 361/**
@@ -365,12 +372,12 @@ typedef void (*REGEX_INTERNAL_traverse_action) (void *cls,
365 * @param action_cls closure for action 372 * @param action_cls closure for action
366 */ 373 */
367void 374void
368REGEX_INTERNAL_automaton_traverse(const struct REGEX_INTERNAL_Automaton *a, 375REGEX_INTERNAL_automaton_traverse (const struct REGEX_INTERNAL_Automaton *a,
369 struct REGEX_INTERNAL_State *start, 376 struct REGEX_INTERNAL_State *start,
370 REGEX_INTERNAL_traverse_check check, 377 REGEX_INTERNAL_traverse_check check,
371 void *check_cls, 378 void *check_cls,
372 REGEX_INTERNAL_traverse_action action, 379 REGEX_INTERNAL_traverse_action action,
373 void *action_cls); 380 void *action_cls);
374 381
375/** 382/**
376 * Get the canonical regex of the given automaton. 383 * Get the canonical regex of the given automaton.
@@ -384,7 +391,7 @@ REGEX_INTERNAL_automaton_traverse(const struct REGEX_INTERNAL_Automaton *a,
384 * @return canonical regex string. 391 * @return canonical regex string.
385 */ 392 */
386const char * 393const char *
387REGEX_INTERNAL_get_canonical_regex(struct REGEX_INTERNAL_Automaton *a); 394REGEX_INTERNAL_get_canonical_regex (struct REGEX_INTERNAL_Automaton *a);
388 395
389 396
390/** 397/**
@@ -395,14 +402,15 @@ REGEX_INTERNAL_get_canonical_regex(struct REGEX_INTERNAL_Automaton *a);
395 * @return number of transitions in the given automaton. 402 * @return number of transitions in the given automaton.
396 */ 403 */
397unsigned int 404unsigned int
398REGEX_INTERNAL_get_transition_count(struct REGEX_INTERNAL_Automaton *a); 405REGEX_INTERNAL_get_transition_count (struct REGEX_INTERNAL_Automaton *a);
399 406
400 407
401/** 408/**
402 * Context that contains an id counter for states and transitions as well as a 409 * Context that contains an id counter for states and transitions as well as a
403 * DLL of automatons used as a stack for NFA construction. 410 * DLL of automatons used as a stack for NFA construction.
404 */ 411 */
405struct REGEX_INTERNAL_Context { 412struct REGEX_INTERNAL_Context
413{
406 /** 414 /**
407 * Unique state id. 415 * Unique state id.
408 */ 416 */
@@ -433,9 +441,9 @@ struct REGEX_INTERNAL_Context {
433 * @param stride_len length of the strides. 441 * @param stride_len length of the strides.
434 */ 442 */
435void 443void
436REGEX_INTERNAL_dfa_add_multi_strides(struct REGEX_INTERNAL_Context *regex_ctx, 444REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx,
437 struct REGEX_INTERNAL_Automaton *dfa, 445 struct REGEX_INTERNAL_Automaton *dfa,
438 const unsigned int stride_len); 446 const unsigned int stride_len);
439 447
440 448
441 449
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c
index 611fb0a23..3cf48f3c2 100644
--- a/src/regex/regex_internal_dht.c
+++ b/src/regex/regex_internal_dht.c
@@ -32,7 +32,7 @@
32#include "gnunet_signatures.h" 32#include "gnunet_signatures.h"
33 33
34 34
35#define LOG(kind, ...) GNUNET_log_from(kind, "regex-dht", __VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from (kind, "regex-dht", __VA_ARGS__)
36 36
37/** 37/**
38 * DHT replication level to use. 38 * DHT replication level to use.
@@ -53,7 +53,8 @@
53/** 53/**
54 * Handle to store cached data about a regex announce. 54 * Handle to store cached data about a regex announce.
55 */ 55 */
56struct REGEX_INTERNAL_Announcement { 56struct REGEX_INTERNAL_Announcement
57{
57 /** 58 /**
58 * DHT handle to use, must be initialized externally. 59 * DHT handle to use, must be initialized externally.
59 */ 60 */
@@ -92,92 +93,93 @@ struct REGEX_INTERNAL_Announcement {
92 * @param edges edges leaving current state. 93 * @param edges edges leaving current state.
93 */ 94 */
94static void 95static void
95regex_iterator(void *cls, 96regex_iterator (void *cls,
96 const struct GNUNET_HashCode *key, 97 const struct GNUNET_HashCode *key,
97 const char *proof, 98 const char *proof,
98 int accepting, 99 int accepting,
99 unsigned int num_edges, 100 unsigned int num_edges,
100 const struct REGEX_BLOCK_Edge *edges) 101 const struct REGEX_BLOCK_Edge *edges)
101{ 102{
102 struct REGEX_INTERNAL_Announcement *h = cls; 103 struct REGEX_INTERNAL_Announcement *h = cls;
103 struct RegexBlock *block; 104 struct RegexBlock *block;
104 size_t size; 105 size_t size;
105 unsigned int i; 106 unsigned int i;
106 107
107 LOG(GNUNET_ERROR_TYPE_INFO, 108 LOG (GNUNET_ERROR_TYPE_INFO,
108 "DHT PUT for state %s with proof `%s' and %u edges:\n", 109 "DHT PUT for state %s with proof `%s' and %u edges:\n",
109 GNUNET_h2s(key), 110 GNUNET_h2s (key),
110 proof, 111 proof,
111 num_edges); 112 num_edges);
112 for (i = 0; i < num_edges; i++) 113 for (i = 0; i < num_edges; i++)
113 { 114 {
114 LOG(GNUNET_ERROR_TYPE_INFO, 115 LOG (GNUNET_ERROR_TYPE_INFO,
115 "Edge %u `%s' towards %s\n", 116 "Edge %u `%s' towards %s\n",
116 i, 117 i,
117 edges[i].label, 118 edges[i].label,
118 GNUNET_h2s(&edges[i].destination)); 119 GNUNET_h2s (&edges[i].destination));
119 } 120 }
120 if (GNUNET_YES == accepting) 121 if (GNUNET_YES == accepting)
121 { 122 {
122 struct RegexAcceptBlock ab; 123 struct RegexAcceptBlock ab;
123 124
124 LOG(GNUNET_ERROR_TYPE_INFO, 125 LOG (GNUNET_ERROR_TYPE_INFO,
125 "State %s is accepting, putting own id\n", 126 "State %s is accepting, putting own id\n",
126 GNUNET_h2s(key)); 127 GNUNET_h2s (key));
127 size = sizeof(struct RegexAcceptBlock); 128 size = sizeof(struct RegexAcceptBlock);
128 ab.purpose.size = ntohl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 129 ab.purpose.size = ntohl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
129 sizeof(struct GNUNET_TIME_AbsoluteNBO) + 130 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
130 sizeof(struct GNUNET_HashCode)); 131 + sizeof(struct GNUNET_HashCode));
131 ab.purpose.purpose = ntohl(GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); 132 ab.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT);
132 ab.expiration_time = GNUNET_TIME_absolute_hton(GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); 133 ab.expiration_time = GNUNET_TIME_absolute_hton (
133 ab.key = *key; 134 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION));
134 GNUNET_CRYPTO_eddsa_key_get_public(h->priv, 135 ab.key = *key;
135 &ab.peer.public_key); 136 GNUNET_CRYPTO_eddsa_key_get_public (h->priv,
136 GNUNET_assert(GNUNET_OK == 137 &ab.peer.public_key);
137 GNUNET_CRYPTO_eddsa_sign(h->priv, 138 GNUNET_assert (GNUNET_OK ==
139 GNUNET_CRYPTO_eddsa_sign (h->priv,
138 &ab.purpose, 140 &ab.purpose,
139 &ab.signature)); 141 &ab.signature));
140 142
141 GNUNET_STATISTICS_update(h->stats, "# regex accepting blocks stored", 143 GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored",
142 1, GNUNET_NO); 144 1, GNUNET_NO);
143 GNUNET_STATISTICS_update(h->stats, "# regex accepting block bytes stored", 145 GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored",
144 sizeof(struct RegexAcceptBlock), GNUNET_NO); 146 sizeof(struct RegexAcceptBlock), GNUNET_NO);
145 (void) 147 (void)
146 GNUNET_DHT_put(h->dht, key, 148 GNUNET_DHT_put (h->dht, key,
147 DHT_REPLICATION, 149 DHT_REPLICATION,
148 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, 150 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE,
149 GNUNET_BLOCK_TYPE_REGEX_ACCEPT, 151 GNUNET_BLOCK_TYPE_REGEX_ACCEPT,
150 size, 152 size,
151 &ab, 153 &ab,
152 GNUNET_TIME_relative_to_absolute(DHT_TTL), 154 GNUNET_TIME_relative_to_absolute (DHT_TTL),
153 NULL, NULL); 155 NULL, NULL);
154 } 156 }
155 block = REGEX_BLOCK_create(proof, 157 block = REGEX_BLOCK_create (proof,
156 num_edges, 158 num_edges,
157 edges, 159 edges,
158 accepting, 160 accepting,
159 &size); 161 &size);
160 if (NULL == block) 162 if (NULL == block)
161 return; 163 return;
162 (void)GNUNET_DHT_put(h->dht, 164 (void) GNUNET_DHT_put (h->dht,
163 key, 165 key,
164 DHT_REPLICATION, 166 DHT_REPLICATION,
165 DHT_OPT, 167 DHT_OPT,
166 GNUNET_BLOCK_TYPE_REGEX, 168 GNUNET_BLOCK_TYPE_REGEX,
167 size, 169 size,
168 block, 170 block,
169 GNUNET_TIME_relative_to_absolute(DHT_TTL), 171 GNUNET_TIME_relative_to_absolute (DHT_TTL),
170 NULL, 172 NULL,
171 NULL); 173 NULL);
172 GNUNET_STATISTICS_update(h->stats, 174 GNUNET_STATISTICS_update (h->stats,
173 "# regex blocks stored", 175 "# regex blocks stored",
174 1, 176 1,
175 GNUNET_NO); 177 GNUNET_NO);
176 GNUNET_STATISTICS_update(h->stats, 178 GNUNET_STATISTICS_update (h->stats,
177 "# regex block bytes stored", 179 "# regex block bytes stored",
178 size, 180 size,
179 GNUNET_NO); 181 GNUNET_NO);
180 GNUNET_free(block); 182 GNUNET_free (block);
181} 183}
182 184
183 185
@@ -194,22 +196,22 @@ regex_iterator(void *cls,
194 * Must be freed by calling #REGEX_INTERNAL_announce_cancel(). 196 * Must be freed by calling #REGEX_INTERNAL_announce_cancel().
195 */ 197 */
196struct REGEX_INTERNAL_Announcement * 198struct REGEX_INTERNAL_Announcement *
197REGEX_INTERNAL_announce(struct GNUNET_DHT_Handle *dht, 199REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
198 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 200 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
199 const char *regex, 201 const char *regex,
200 uint16_t compression, 202 uint16_t compression,
201 struct GNUNET_STATISTICS_Handle *stats) 203 struct GNUNET_STATISTICS_Handle *stats)
202{ 204{
203 struct REGEX_INTERNAL_Announcement *h; 205 struct REGEX_INTERNAL_Announcement *h;
204 206
205 GNUNET_assert(NULL != dht); 207 GNUNET_assert (NULL != dht);
206 h = GNUNET_new(struct REGEX_INTERNAL_Announcement); 208 h = GNUNET_new (struct REGEX_INTERNAL_Announcement);
207 h->regex = regex; 209 h->regex = regex;
208 h->dht = dht; 210 h->dht = dht;
209 h->stats = stats; 211 h->stats = stats;
210 h->priv = priv; 212 h->priv = priv;
211 h->dfa = REGEX_INTERNAL_construct_dfa(regex, strlen(regex), compression); 213 h->dfa = REGEX_INTERNAL_construct_dfa (regex, strlen (regex), compression);
212 REGEX_INTERNAL_reannounce(h); 214 REGEX_INTERNAL_reannounce (h);
213 return h; 215 return h;
214} 216}
215 217
@@ -221,15 +223,15 @@ REGEX_INTERNAL_announce(struct GNUNET_DHT_Handle *dht,
221 * @param h Handle returned by a previous #REGEX_INTERNAL_announce call(). 223 * @param h Handle returned by a previous #REGEX_INTERNAL_announce call().
222 */ 224 */
223void 225void
224REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h) 226REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
225{ 227{
226 GNUNET_assert(NULL != h->dfa); /* make sure to call announce first */ 228 GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
227 LOG(GNUNET_ERROR_TYPE_INFO, 229 LOG (GNUNET_ERROR_TYPE_INFO,
228 "REGEX_INTERNAL_reannounce: %s\n", 230 "REGEX_INTERNAL_reannounce: %s\n",
229 h->regex); 231 h->regex);
230 REGEX_INTERNAL_iterate_reachable_edges(h->dfa, 232 REGEX_INTERNAL_iterate_reachable_edges (h->dfa,
231 &regex_iterator, 233 &regex_iterator,
232 h); 234 h);
233} 235}
234 236
235 237
@@ -240,10 +242,10 @@ REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h)
240 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call. 242 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call.
241 */ 243 */
242void 244void
243REGEX_INTERNAL_announce_cancel(struct REGEX_INTERNAL_Announcement *h) 245REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h)
244{ 246{
245 REGEX_INTERNAL_automaton_destroy(h->dfa); 247 REGEX_INTERNAL_automaton_destroy (h->dfa);
246 GNUNET_free(h); 248 GNUNET_free (h);
247} 249}
248 250
249 251
@@ -254,7 +256,8 @@ REGEX_INTERNAL_announce_cancel(struct REGEX_INTERNAL_Announcement *h)
254 * Struct to keep state of running searches that have consumed a part of 256 * Struct to keep state of running searches that have consumed a part of
255 * the inital string. 257 * the inital string.
256 */ 258 */
257struct RegexSearchContext { 259struct RegexSearchContext
260{
258 /** 261 /**
259 * Part of the description already consumed by 262 * Part of the description already consumed by
260 * this particular search branch. 263 * this particular search branch.
@@ -282,7 +285,8 @@ struct RegexSearchContext {
282/** 285/**
283 * Type of values in `dht_get_results`. 286 * Type of values in `dht_get_results`.
284 */ 287 */
285struct Result { 288struct Result
289{
286 /** 290 /**
287 * Number of bytes in data. 291 * Number of bytes in data.
288 */ 292 */
@@ -299,7 +303,8 @@ struct Result {
299 * Struct to keep information of searches of services described by a regex 303 * Struct to keep information of searches of services described by a regex
300 * using a user-provided string service description. 304 * using a user-provided string service description.
301 */ 305 */
302struct REGEX_INTERNAL_Search { 306struct REGEX_INTERNAL_Search
307{
303 /** 308 /**
304 * DHT handle to use, must be initialized externally. 309 * DHT handle to use, must be initialized externally.
305 */ 310 */
@@ -356,9 +361,9 @@ struct REGEX_INTERNAL_Search {
356 * @param ctx Context of the search. 361 * @param ctx Context of the search.
357 */ 362 */
358static void 363static void
359regex_next_edge(const struct RegexBlock *block, 364regex_next_edge (const struct RegexBlock *block,
360 size_t size, 365 size_t size,
361 struct RegexSearchContext *ctx); 366 struct RegexSearchContext *ctx);
362 367
363 368
364/** 369/**
@@ -377,33 +382,33 @@ regex_next_edge(const struct RegexBlock *block,
377 * @param data Pointer to the result data. 382 * @param data Pointer to the result data.
378 */ 383 */
379static void 384static void
380dht_get_string_accept_handler(void *cls, struct GNUNET_TIME_Absolute exp, 385dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
381 const struct GNUNET_HashCode *key, 386 const struct GNUNET_HashCode *key,
382 const struct GNUNET_PeerIdentity *get_path, 387 const struct GNUNET_PeerIdentity *get_path,
383 unsigned int get_path_length, 388 unsigned int get_path_length,
384 const struct GNUNET_PeerIdentity *put_path, 389 const struct GNUNET_PeerIdentity *put_path,
385 unsigned int put_path_length, 390 unsigned int put_path_length,
386 enum GNUNET_BLOCK_Type type, 391 enum GNUNET_BLOCK_Type type,
387 size_t size, const void *data) 392 size_t size, const void *data)
388{ 393{
389 const struct RegexAcceptBlock *block = data; 394 const struct RegexAcceptBlock *block = data;
390 struct RegexSearchContext *ctx = cls; 395 struct RegexSearchContext *ctx = cls;
391 struct REGEX_INTERNAL_Search *info = ctx->info; 396 struct REGEX_INTERNAL_Search *info = ctx->info;
392 397
393 LOG(GNUNET_ERROR_TYPE_DEBUG, 398 LOG (GNUNET_ERROR_TYPE_DEBUG,
394 "Regex result accept for %s (key %s)\n", 399 "Regex result accept for %s (key %s)\n",
395 info->description, GNUNET_h2s(key)); 400 info->description, GNUNET_h2s (key));
396 401
397 GNUNET_STATISTICS_update(info->stats, 402 GNUNET_STATISTICS_update (info->stats,
398 "# regex accepting blocks found", 403 "# regex accepting blocks found",
399 1, GNUNET_NO); 404 1, GNUNET_NO);
400 GNUNET_STATISTICS_update(info->stats, 405 GNUNET_STATISTICS_update (info->stats,
401 "# regex accepting block bytes found", 406 "# regex accepting block bytes found",
402 size, GNUNET_NO); 407 size, GNUNET_NO);
403 info->callback(info->callback_cls, 408 info->callback (info->callback_cls,
404 &block->peer, 409 &block->peer,
405 get_path, get_path_length, 410 get_path, get_path_length,
406 put_path, put_path_length); 411 put_path, put_path_length);
407} 412}
408 413
409 414
@@ -415,28 +420,28 @@ dht_get_string_accept_handler(void *cls, struct GNUNET_TIME_Absolute exp,
415 * @param ctx Context containing info about the string, tunnel, etc. 420 * @param ctx Context containing info about the string, tunnel, etc.
416 */ 421 */
417static void 422static void
418regex_find_path(const struct GNUNET_HashCode *key, 423regex_find_path (const struct GNUNET_HashCode *key,
419 struct RegexSearchContext *ctx) 424 struct RegexSearchContext *ctx)
420{ 425{
421 struct GNUNET_DHT_GetHandle *get_h; 426 struct GNUNET_DHT_GetHandle *get_h;
422 427
423 LOG(GNUNET_ERROR_TYPE_DEBUG, 428 LOG (GNUNET_ERROR_TYPE_DEBUG,
424 "Accept state found, now searching for paths to %s\n", 429 "Accept state found, now searching for paths to %s\n",
425 GNUNET_h2s(key), 430 GNUNET_h2s (key),
426 (unsigned int)ctx->position); 431 (unsigned int) ctx->position);
427 get_h = GNUNET_DHT_get_start(ctx->info->dht, /* handle */ 432 get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */
428 GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ 433 GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */
429 key, /* key to search */ 434 key, /* key to search */
430 DHT_REPLICATION, /* replication level */ 435 DHT_REPLICATION, /* replication level */
431 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, 436 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE,
432 NULL, /* xquery */ // FIXME BLOOMFILTER 437 NULL, /* xquery */ // FIXME BLOOMFILTER
433 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE 438 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
434 &dht_get_string_accept_handler, ctx); 439 &dht_get_string_accept_handler, ctx);
435 GNUNET_break(GNUNET_OK == 440 GNUNET_break (GNUNET_OK ==
436 GNUNET_CONTAINER_multihashmap_put(ctx->info->dht_get_handles, 441 GNUNET_CONTAINER_multihashmap_put (ctx->info->dht_get_handles,
437 key, 442 key,
438 get_h, 443 get_h,
439 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 444 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
440} 445}
441 446
442 447
@@ -458,14 +463,14 @@ regex_find_path(const struct GNUNET_HashCode *key,
458 * TODO: re-issue the request after certain time? cancel after X results? 463 * TODO: re-issue the request after certain time? cancel after X results?
459 */ 464 */
460static void 465static void
461dht_get_string_handler(void *cls, struct GNUNET_TIME_Absolute exp, 466dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp,
462 const struct GNUNET_HashCode *key, 467 const struct GNUNET_HashCode *key,
463 const struct GNUNET_PeerIdentity *get_path, 468 const struct GNUNET_PeerIdentity *get_path,
464 unsigned int get_path_length, 469 unsigned int get_path_length,
465 const struct GNUNET_PeerIdentity *put_path, 470 const struct GNUNET_PeerIdentity *put_path,
466 unsigned int put_path_length, 471 unsigned int put_path_length,
467 enum GNUNET_BLOCK_Type type, 472 enum GNUNET_BLOCK_Type type,
468 size_t size, const void *data) 473 size_t size, const void *data)
469{ 474{
470 const struct RegexBlock *block = data; 475 const struct RegexBlock *block = data;
471 struct RegexSearchContext *ctx = cls; 476 struct RegexSearchContext *ctx = cls;
@@ -473,32 +478,32 @@ dht_get_string_handler(void *cls, struct GNUNET_TIME_Absolute exp,
473 size_t len; 478 size_t len;
474 struct Result *copy; 479 struct Result *copy;
475 480
476 LOG(GNUNET_ERROR_TYPE_INFO, 481 LOG (GNUNET_ERROR_TYPE_INFO,
477 "DHT GET result for %s (%s)\n", 482 "DHT GET result for %s (%s)\n",
478 GNUNET_h2s(key), ctx->info->description); 483 GNUNET_h2s (key), ctx->info->description);
479 copy = GNUNET_malloc(sizeof(struct Result) + size); 484 copy = GNUNET_malloc (sizeof(struct Result) + size);
480 copy->size = size; 485 copy->size = size;
481 copy->data = &copy[1]; 486 copy->data = &copy[1];
482 GNUNET_memcpy(&copy[1], block, size); 487 GNUNET_memcpy (&copy[1], block, size);
483 GNUNET_break(GNUNET_OK == 488 GNUNET_break (GNUNET_OK ==
484 GNUNET_CONTAINER_multihashmap_put(info->dht_get_results, 489 GNUNET_CONTAINER_multihashmap_put (info->dht_get_results,
485 key, copy, 490 key, copy,
486 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 491 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
487 len = strlen(info->description); 492 len = strlen (info->description);
488 if (len == ctx->position) // String processed 493 if (len == ctx->position) // String processed
494 {
495 if (GNUNET_YES == GNUNET_BLOCK_is_accepting (block, size))
489 { 496 {
490 if (GNUNET_YES == GNUNET_BLOCK_is_accepting(block, size)) 497 regex_find_path (key, ctx);
491 {
492 regex_find_path(key, ctx);
493 }
494 else
495 {
496 LOG(GNUNET_ERROR_TYPE_INFO, "block not accepting!\n");
497 /* FIXME REGEX this block not successful, wait for more? start timeout? */
498 }
499 return;
500 } 498 }
501 regex_next_edge(block, size, ctx); 499 else
500 {
501 LOG (GNUNET_ERROR_TYPE_INFO, "block not accepting!\n");
502 /* FIXME REGEX this block not successful, wait for more? start timeout? */
503 }
504 return;
505 }
506 regex_next_edge (block, size, ctx);
502} 507}
503 508
504 509
@@ -511,32 +516,32 @@ dht_get_string_handler(void *cls, struct GNUNET_TIME_Absolute exp,
511 * @return #GNUNET_YES: we should always continue to iterate. 516 * @return #GNUNET_YES: we should always continue to iterate.
512 */ 517 */
513static int 518static int
514regex_result_iterator(void *cls, 519regex_result_iterator (void *cls,
515 const struct GNUNET_HashCode * key, 520 const struct GNUNET_HashCode *key,
516 void *value) 521 void *value)
517{ 522{
518 struct Result *result = value; 523 struct Result *result = value;
519 const struct RegexBlock *block = result->data; 524 const struct RegexBlock *block = result->data;
520 struct RegexSearchContext *ctx = cls; 525 struct RegexSearchContext *ctx = cls;
521 526
522 if ((GNUNET_YES == 527 if ((GNUNET_YES ==
523 GNUNET_BLOCK_is_accepting(block, result->size)) && 528 GNUNET_BLOCK_is_accepting (block, result->size)) &&
524 (ctx->position == strlen(ctx->info->description))) 529 (ctx->position == strlen (ctx->info->description)))
525 { 530 {
526 LOG(GNUNET_ERROR_TYPE_INFO, 531 LOG (GNUNET_ERROR_TYPE_INFO,
527 "Found accepting known block\n"); 532 "Found accepting known block\n");
528 regex_find_path(key, ctx); 533 regex_find_path (key, ctx);
529 return GNUNET_YES; // We found an accept state! 534 return GNUNET_YES; // We found an accept state!
530 } 535 }
531 LOG(GNUNET_ERROR_TYPE_DEBUG, 536 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "* %u, %u, [%u]\n", 537 "* %u, %u, [%u]\n",
533 ctx->position, 538 ctx->position,
534 strlen(ctx->info->description), 539 strlen (ctx->info->description),
535 GNUNET_BLOCK_is_accepting(block, result->size)); 540 GNUNET_BLOCK_is_accepting (block, result->size));
536 regex_next_edge(block, result->size, ctx); 541 regex_next_edge (block, result->size, ctx);
537 542
538 GNUNET_STATISTICS_update(ctx->info->stats, "# regex cadet blocks iterated", 543 GNUNET_STATISTICS_update (ctx->info->stats, "# regex cadet blocks iterated",
539 1, GNUNET_NO); 544 1, GNUNET_NO);
540 545
541 return GNUNET_YES; 546 return GNUNET_YES;
542} 547}
@@ -552,43 +557,43 @@ regex_result_iterator(void *cls,
552 * @return #GNUNET_YES if should keep iterating, #GNUNET_NO otherwise. 557 * @return #GNUNET_YES if should keep iterating, #GNUNET_NO otherwise.
553 */ 558 */
554static int 559static int
555regex_edge_iterator(void *cls, 560regex_edge_iterator (void *cls,
556 const char *token, 561 const char *token,
557 size_t len, 562 size_t len,
558 const struct GNUNET_HashCode *key) 563 const struct GNUNET_HashCode *key)
559{ 564{
560 struct RegexSearchContext *ctx = cls; 565 struct RegexSearchContext *ctx = cls;
561 struct REGEX_INTERNAL_Search *info = ctx->info; 566 struct REGEX_INTERNAL_Search *info = ctx->info;
562 const char *current; 567 const char *current;
563 size_t current_len; 568 size_t current_len;
564 569
565 GNUNET_STATISTICS_update(info->stats, "# regex edges iterated", 570 GNUNET_STATISTICS_update (info->stats, "# regex edges iterated",
566 1, GNUNET_NO); 571 1, GNUNET_NO);
567 current = &info->description[ctx->position]; 572 current = &info->description[ctx->position];
568 current_len = strlen(info->description) - ctx->position; 573 current_len = strlen (info->description) - ctx->position;
569 if (len > current_len) 574 if (len > current_len)
570 { 575 {
571 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n"); 576 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n");
572 return GNUNET_YES; 577 return GNUNET_YES;
573 } 578 }
574 if (0 != strncmp(current, token, len)) 579 if (0 != strncmp (current, token, len))
575 { 580 {
576 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n"); 581 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n");
577 return GNUNET_YES; 582 return GNUNET_YES;
578 } 583 }
579 584
580 if (len > ctx->longest_match) 585 if (len > ctx->longest_match)
581 { 586 {
582 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n"); 587 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n");
583 ctx->longest_match = len; 588 ctx->longest_match = len;
584 ctx->hash = *key; 589 ctx->hash = *key;
585 } 590 }
586 else 591 else
587 { 592 {
588 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n"); 593 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n");
589 } 594 }
590 595
591 LOG(GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n"); 596 LOG (GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n");
592 return GNUNET_YES; 597 return GNUNET_YES;
593} 598}
594 599
@@ -601,9 +606,9 @@ regex_edge_iterator(void *cls,
601 * @param ctx Context of the search. 606 * @param ctx Context of the search.
602 */ 607 */
603static void 608static void
604regex_next_edge(const struct RegexBlock *block, 609regex_next_edge (const struct RegexBlock *block,
605 size_t size, 610 size_t size,
606 struct RegexSearchContext *ctx) 611 struct RegexSearchContext *ctx)
607{ 612{
608 struct RegexSearchContext *new_ctx; 613 struct RegexSearchContext *new_ctx;
609 struct REGEX_INTERNAL_Search *info = ctx->info; 614 struct REGEX_INTERNAL_Search *info = ctx->info;
@@ -612,69 +617,69 @@ regex_next_edge(const struct RegexBlock *block,
612 const char *rest; 617 const char *rest;
613 int result; 618 int result;
614 619
615 LOG(GNUNET_ERROR_TYPE_DEBUG, "Next edge\n"); 620 LOG (GNUNET_ERROR_TYPE_DEBUG, "Next edge\n");
616 /* Find the longest match for the current string position, 621 /* Find the longest match for the current string position,
617 * among tokens in the given block */ 622 * among tokens in the given block */
618 ctx->longest_match = 0; 623 ctx->longest_match = 0;
619 result = REGEX_BLOCK_iterate(block, size, 624 result = REGEX_BLOCK_iterate (block, size,
620 &regex_edge_iterator, ctx); 625 &regex_edge_iterator, ctx);
621 GNUNET_break(GNUNET_OK == result); 626 GNUNET_break (GNUNET_OK == result);
622 627
623 /* Did anything match? */ 628 /* Did anything match? */
624 if (0 == ctx->longest_match) 629 if (0 == ctx->longest_match)
625 { 630 {
626 LOG(GNUNET_ERROR_TYPE_DEBUG, 631 LOG (GNUNET_ERROR_TYPE_DEBUG,
627 "no match in block\n"); 632 "no match in block\n");
628 return; 633 return;
629 } 634 }
630 635
631 hash = &ctx->hash; 636 hash = &ctx->hash;
632 new_ctx = GNUNET_new(struct RegexSearchContext); 637 new_ctx = GNUNET_new (struct RegexSearchContext);
633 new_ctx->info = info; 638 new_ctx->info = info;
634 new_ctx->position = ctx->position + ctx->longest_match; 639 new_ctx->position = ctx->position + ctx->longest_match;
635 GNUNET_array_append(info->contexts, info->n_contexts, new_ctx); 640 GNUNET_array_append (info->contexts, info->n_contexts, new_ctx);
636 641
637 /* Check whether we already have a DHT GET running for it */ 642 /* Check whether we already have a DHT GET running for it */
638 if (GNUNET_YES == 643 if (GNUNET_YES ==
639 GNUNET_CONTAINER_multihashmap_contains(info->dht_get_handles, hash)) 644 GNUNET_CONTAINER_multihashmap_contains (info->dht_get_handles, hash))
640 { 645 {
641 LOG(GNUNET_ERROR_TYPE_DEBUG, 646 LOG (GNUNET_ERROR_TYPE_DEBUG,
642 "GET for %s running, END\n", 647 "GET for %s running, END\n",
643 GNUNET_h2s(hash)); 648 GNUNET_h2s (hash));
644 GNUNET_CONTAINER_multihashmap_get_multiple(info->dht_get_results, 649 GNUNET_CONTAINER_multihashmap_get_multiple (info->dht_get_results,
645 hash, 650 hash,
646 &regex_result_iterator, 651 &regex_result_iterator,
647 new_ctx); 652 new_ctx);
648 return; /* We are already looking for it */ 653 return; /* We are already looking for it */
649 } 654 }
650 655
651 GNUNET_STATISTICS_update(info->stats, "# regex nodes traversed", 656 GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed",
652 1, GNUNET_NO); 657 1, GNUNET_NO);
653 658
654 LOG(GNUNET_ERROR_TYPE_DEBUG, 659 LOG (GNUNET_ERROR_TYPE_DEBUG,
655 "Following edges at %s for offset %u in `%s'\n", 660 "Following edges at %s for offset %u in `%s'\n",
656 GNUNET_h2s(hash), 661 GNUNET_h2s (hash),
657 (unsigned int)ctx->position, 662 (unsigned int) ctx->position,
658 info->description); 663 info->description);
659 rest = &new_ctx->info->description[new_ctx->position]; 664 rest = &new_ctx->info->description[new_ctx->position];
660 get_h = 665 get_h =
661 GNUNET_DHT_get_start(info->dht, /* handle */ 666 GNUNET_DHT_get_start (info->dht, /* handle */
662 GNUNET_BLOCK_TYPE_REGEX, /* type */ 667 GNUNET_BLOCK_TYPE_REGEX, /* type */
663 hash, /* key to search */ 668 hash, /* key to search */
664 DHT_REPLICATION, /* replication level */ 669 DHT_REPLICATION, /* replication level */
665 DHT_OPT, 670 DHT_OPT,
666 rest, /* xquery */ 671 rest, /* xquery */
667 strlen(rest) + 1, /* xquery bits */ 672 strlen (rest) + 1, /* xquery bits */
668 &dht_get_string_handler, new_ctx); 673 &dht_get_string_handler, new_ctx);
669 if (GNUNET_OK != 674 if (GNUNET_OK !=
670 GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles, 675 GNUNET_CONTAINER_multihashmap_put (info->dht_get_handles,
671 hash, 676 hash,
672 get_h, 677 get_h,
673 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 678 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
674 { 679 {
675 GNUNET_break(0); 680 GNUNET_break (0);
676 return; 681 return;
677 } 682 }
678} 683}
679 684
680 685
@@ -692,11 +697,11 @@ regex_next_edge(const struct RegexBlock *block,
692 * Must be freed by calling #REGEX_INTERNAL_search_cancel(). 697 * Must be freed by calling #REGEX_INTERNAL_search_cancel().
693 */ 698 */
694struct REGEX_INTERNAL_Search * 699struct REGEX_INTERNAL_Search *
695REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht, 700REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht,
696 const char *string, 701 const char *string,
697 REGEX_INTERNAL_Found callback, 702 REGEX_INTERNAL_Found callback,
698 void *callback_cls, 703 void *callback_cls,
699 struct GNUNET_STATISTICS_Handle *stats) 704 struct GNUNET_STATISTICS_Handle *stats)
700{ 705{
701 struct REGEX_INTERNAL_Search *h; 706 struct REGEX_INTERNAL_Search *h;
702 struct GNUNET_DHT_GetHandle *get_h; 707 struct GNUNET_DHT_GetHandle *get_h;
@@ -706,49 +711,49 @@ REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht,
706 size_t len; 711 size_t len;
707 712
708 /* Initialize handle */ 713 /* Initialize handle */
709 GNUNET_assert(NULL != dht); 714 GNUNET_assert (NULL != dht);
710 GNUNET_assert(NULL != callback); 715 GNUNET_assert (NULL != callback);
711 h = GNUNET_new(struct REGEX_INTERNAL_Search); 716 h = GNUNET_new (struct REGEX_INTERNAL_Search);
712 h->dht = dht; 717 h->dht = dht;
713 h->description = GNUNET_strdup(string); 718 h->description = GNUNET_strdup (string);
714 h->callback = callback; 719 h->callback = callback;
715 h->callback_cls = callback_cls; 720 h->callback_cls = callback_cls;
716 h->stats = stats; 721 h->stats = stats;
717 h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO); 722 h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
718 h->dht_get_results = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO); 723 h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
719 724
720 /* Initialize context */ 725 /* Initialize context */
721 len = strlen(string); 726 len = strlen (string);
722 size = REGEX_INTERNAL_get_first_key(string, len, &key); 727 size = REGEX_INTERNAL_get_first_key (string, len, &key);
723 LOG(GNUNET_ERROR_TYPE_INFO, 728 LOG (GNUNET_ERROR_TYPE_INFO,
724 "Initial key for `%s' is %s (based on `%.*s')\n", 729 "Initial key for `%s' is %s (based on `%.*s')\n",
725 string, 730 string,
726 GNUNET_h2s(&key), 731 GNUNET_h2s (&key),
727 size, 732 size,
728 string); 733 string);
729 ctx = GNUNET_new(struct RegexSearchContext); 734 ctx = GNUNET_new (struct RegexSearchContext);
730 ctx->position = size; 735 ctx->position = size;
731 ctx->info = h; 736 ctx->info = h;
732 GNUNET_array_append(h->contexts, 737 GNUNET_array_append (h->contexts,
733 h->n_contexts, 738 h->n_contexts,
734 ctx); 739 ctx);
735 /* Start search in DHT */ 740 /* Start search in DHT */
736 get_h = GNUNET_DHT_get_start(h->dht, /* handle */ 741 get_h = GNUNET_DHT_get_start (h->dht, /* handle */
737 GNUNET_BLOCK_TYPE_REGEX, /* type */ 742 GNUNET_BLOCK_TYPE_REGEX, /* type */
738 &key, /* key to search */ 743 &key, /* key to search */
739 DHT_REPLICATION, /* replication level */ 744 DHT_REPLICATION, /* replication level */
740 DHT_OPT, 745 DHT_OPT,
741 &h->description[size], /* xquery */ 746 &h->description[size], /* xquery */
742 // FIXME add BLOOMFILTER to exclude filtered peers 747 // FIXME add BLOOMFILTER to exclude filtered peers
743 len + 1 - size, /* xquery bits */ 748 len + 1 - size, /* xquery bits */
744 // FIXME add BLOOMFILTER SIZE 749 // FIXME add BLOOMFILTER SIZE
745 &dht_get_string_handler, ctx); 750 &dht_get_string_handler, ctx);
746 GNUNET_break( 751 GNUNET_break (
747 GNUNET_OK == 752 GNUNET_OK ==
748 GNUNET_CONTAINER_multihashmap_put(h->dht_get_handles, 753 GNUNET_CONTAINER_multihashmap_put (h->dht_get_handles,
749 &key, 754 &key,
750 get_h, 755 get_h,
751 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST) 756 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)
752 ); 757 );
753 758
754 return h; 759 return h;
@@ -766,13 +771,13 @@ REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht,
766 * #GNUNET_NO if not. 771 * #GNUNET_NO if not.
767 */ 772 */
768static int 773static int
769regex_cancel_dht_get(void *cls, 774regex_cancel_dht_get (void *cls,
770 const struct GNUNET_HashCode * key, 775 const struct GNUNET_HashCode *key,
771 void *value) 776 void *value)
772{ 777{
773 struct GNUNET_DHT_GetHandle *h = value; 778 struct GNUNET_DHT_GetHandle *h = value;
774 779
775 GNUNET_DHT_get_stop(h); 780 GNUNET_DHT_get_stop (h);
776 return GNUNET_YES; 781 return GNUNET_YES;
777} 782}
778 783
@@ -788,11 +793,11 @@ regex_cancel_dht_get(void *cls,
788 * #GNUNET_NO if not. 793 * #GNUNET_NO if not.
789 */ 794 */
790static int 795static int
791regex_free_result(void *cls, 796regex_free_result (void *cls,
792 const struct GNUNET_HashCode * key, 797 const struct GNUNET_HashCode *key,
793 void *value) 798 void *value)
794{ 799{
795 GNUNET_free(value); 800 GNUNET_free (value);
796 return GNUNET_YES; 801 return GNUNET_YES;
797} 802}
798 803
@@ -803,24 +808,24 @@ regex_free_result(void *cls,
803 * @param h the search context. 808 * @param h the search context.
804 */ 809 */
805void 810void
806REGEX_INTERNAL_search_cancel(struct REGEX_INTERNAL_Search *h) 811REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h)
807{ 812{
808 unsigned int i; 813 unsigned int i;
809 814
810 GNUNET_free(h->description); 815 GNUNET_free (h->description);
811 GNUNET_CONTAINER_multihashmap_iterate(h->dht_get_handles, 816 GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_handles,
812 &regex_cancel_dht_get, NULL); 817 &regex_cancel_dht_get, NULL);
813 GNUNET_CONTAINER_multihashmap_iterate(h->dht_get_results, 818 GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_results,
814 &regex_free_result, NULL); 819 &regex_free_result, NULL);
815 GNUNET_CONTAINER_multihashmap_destroy(h->dht_get_results); 820 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_results);
816 GNUNET_CONTAINER_multihashmap_destroy(h->dht_get_handles); 821 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_handles);
817 if (0 < h->n_contexts) 822 if (0 < h->n_contexts)
818 { 823 {
819 for (i = 0; i < h->n_contexts; i++) 824 for (i = 0; i < h->n_contexts; i++)
820 GNUNET_free(h->contexts[i]); 825 GNUNET_free (h->contexts[i]);
821 GNUNET_free(h->contexts); 826 GNUNET_free (h->contexts);
822 } 827 }
823 GNUNET_free(h); 828 GNUNET_free (h);
824} 829}
825 830
826 831
diff --git a/src/regex/regex_internal_lib.h b/src/regex/regex_internal_lib.h
index 9cb925a17..531f998cc 100644
--- a/src/regex/regex_internal_lib.h
+++ b/src/regex/regex_internal_lib.h
@@ -64,9 +64,9 @@ struct REGEX_INTERNAL_Automaton;
64 * @return DFA, needs to be freed using #REGEX_INTERNAL_automaton_destroy(). 64 * @return DFA, needs to be freed using #REGEX_INTERNAL_automaton_destroy().
65 */ 65 */
66struct REGEX_INTERNAL_Automaton * 66struct REGEX_INTERNAL_Automaton *
67REGEX_INTERNAL_construct_dfa(const char *regex, 67REGEX_INTERNAL_construct_dfa (const char *regex,
68 const size_t len, 68 const size_t len,
69 unsigned int max_path_len); 69 unsigned int max_path_len);
70 70
71 71
72/** 72/**
@@ -76,7 +76,7 @@ REGEX_INTERNAL_construct_dfa(const char *regex,
76 * @param a automaton to be destroyed. 76 * @param a automaton to be destroyed.
77 */ 77 */
78void 78void
79REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a); 79REGEX_INTERNAL_automaton_destroy (struct REGEX_INTERNAL_Automaton *a);
80 80
81 81
82/** 82/**
@@ -88,8 +88,8 @@ REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a);
88 * @return 0 if string matches, non 0 otherwise. 88 * @return 0 if string matches, non 0 otherwise.
89 */ 89 */
90int 90int
91REGEX_INTERNAL_eval(struct REGEX_INTERNAL_Automaton *a, 91REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a,
92 const char *string); 92 const char *string);
93 93
94 94
95/** 95/**
@@ -103,9 +103,9 @@ REGEX_INTERNAL_eval(struct REGEX_INTERNAL_Automaton *a,
103 * to construct the key 103 * to construct the key
104 */ 104 */
105size_t 105size_t
106REGEX_INTERNAL_get_first_key(const char *input_string, 106REGEX_INTERNAL_get_first_key (const char *input_string,
107 size_t string_len, 107 size_t string_len,
108 struct GNUNET_HashCode * key); 108 struct GNUNET_HashCode *key);
109 109
110 110
111/** 111/**
@@ -136,9 +136,9 @@ typedef void
136 * @param iterator_cls closure. 136 * @param iterator_cls closure.
137 */ 137 */
138void 138void
139REGEX_INTERNAL_iterate_all_edges(struct REGEX_INTERNAL_Automaton *a, 139REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a,
140 REGEX_INTERNAL_KeyIterator iterator, 140 REGEX_INTERNAL_KeyIterator iterator,
141 void *iterator_cls); 141 void *iterator_cls);
142 142
143 143
144/** 144/**
@@ -152,9 +152,9 @@ REGEX_INTERNAL_iterate_all_edges(struct REGEX_INTERNAL_Automaton *a,
152 * @param iterator_cls closure. 152 * @param iterator_cls closure.
153 */ 153 */
154void 154void
155REGEX_INTERNAL_iterate_reachable_edges(struct REGEX_INTERNAL_Automaton *a, 155REGEX_INTERNAL_iterate_reachable_edges (struct REGEX_INTERNAL_Automaton *a,
156 REGEX_INTERNAL_KeyIterator iterator, 156 REGEX_INTERNAL_KeyIterator iterator,
157 void *iterator_cls); 157 void *iterator_cls);
158 158
159 159
160 160
@@ -182,11 +182,11 @@ struct REGEX_INTERNAL_Search;
182 * Must be freed by calling #REGEX_INTERNAL_announce_cancel(). 182 * Must be freed by calling #REGEX_INTERNAL_announce_cancel().
183 */ 183 */
184struct REGEX_INTERNAL_Announcement * 184struct REGEX_INTERNAL_Announcement *
185REGEX_INTERNAL_announce(struct GNUNET_DHT_Handle *dht, 185REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
186 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 186 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
187 const char *regex, 187 const char *regex,
188 uint16_t compression, 188 uint16_t compression,
189 struct GNUNET_STATISTICS_Handle *stats); 189 struct GNUNET_STATISTICS_Handle *stats);
190 190
191 191
192/** 192/**
@@ -196,7 +196,7 @@ REGEX_INTERNAL_announce(struct GNUNET_DHT_Handle *dht,
196 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call. 196 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call.
197 */ 197 */
198void 198void
199REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h); 199REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h);
200 200
201 201
202/** 202/**
@@ -206,7 +206,7 @@ REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h);
206 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call. 206 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call.
207 */ 207 */
208void 208void
209REGEX_INTERNAL_announce_cancel(struct REGEX_INTERNAL_Announcement *h); 209REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h);
210 210
211 211
212/** 212/**
@@ -242,11 +242,11 @@ typedef void
242 * Must be freed by calling #REGEX_INTERNAL_search_cancel(). 242 * Must be freed by calling #REGEX_INTERNAL_search_cancel().
243 */ 243 */
244struct REGEX_INTERNAL_Search * 244struct REGEX_INTERNAL_Search *
245REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht, 245REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht,
246 const char *string, 246 const char *string,
247 REGEX_INTERNAL_Found callback, 247 REGEX_INTERNAL_Found callback,
248 void *callback_cls, 248 void *callback_cls,
249 struct GNUNET_STATISTICS_Handle *stats); 249 struct GNUNET_STATISTICS_Handle *stats);
250 250
251/** 251/**
252 * Stop search and free all data used by a #REGEX_INTERNAL_search() call. 252 * Stop search and free all data used by a #REGEX_INTERNAL_search() call.
@@ -255,7 +255,7 @@ REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht,
255 * @param h Handle returned by a previous #REGEX_INTERNAL_search() call. 255 * @param h Handle returned by a previous #REGEX_INTERNAL_search() call.
256 */ 256 */
257void 257void
258REGEX_INTERNAL_search_cancel(struct REGEX_INTERNAL_Search *h); 258REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h);
259 259
260 260
261#if 0 /* keep Emacsens' auto-indent happy */ 261#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/regex/regex_ipc.h b/src/regex/regex_ipc.h
index 5106ead24..b5a474d56 100644
--- a/src/regex/regex_ipc.h
+++ b/src/regex/regex_ipc.h
@@ -31,7 +31,8 @@
31/** 31/**
32 * Request for regex service to announce capability. 32 * Request for regex service to announce capability.
33 */ 33 */
34struct AnnounceMessage { 34struct AnnounceMessage
35{
35 /** 36 /**
36 * Type is GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE 37 * Type is GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE
37 */ 38 */
@@ -59,7 +60,8 @@ struct AnnounceMessage {
59/** 60/**
60 * Message to initiate regex search. 61 * Message to initiate regex search.
61 */ 62 */
62struct RegexSearchMessage { 63struct RegexSearchMessage
64{
63 /** 65 /**
64 * Type is GNUNET_MESSAGE_TYPE_REGEX_SEARCH 66 * Type is GNUNET_MESSAGE_TYPE_REGEX_SEARCH
65 */ 67 */
@@ -72,7 +74,8 @@ struct RegexSearchMessage {
72/** 74/**
73 * Result from regex search. 75 * Result from regex search.
74 */ 76 */
75struct ResultMessage { 77struct ResultMessage
78{
76 /** 79 /**
77 * Type is GNUNET_MESSAGE_TYPE_REGEX_RESULT 80 * Type is GNUNET_MESSAGE_TYPE_REGEX_RESULT
78 */ 81 */
diff --git a/src/regex/regex_test_graph.c b/src/regex/regex_test_graph.c
index e809d578d..c988b5aae 100644
--- a/src/regex/regex_test_graph.c
+++ b/src/regex/regex_test_graph.c
@@ -31,7 +31,8 @@
31 * Context for graph creation. Passed as the cls to 31 * Context for graph creation. Passed as the cls to
32 * REGEX_TEST_automaton_save_graph_step. 32 * REGEX_TEST_automaton_save_graph_step.
33 */ 33 */
34struct REGEX_TEST_Graph_Context { 34struct REGEX_TEST_Graph_Context
35{
35 /** 36 /**
36 * File pointer to the dot file used for output. 37 * File pointer to the dot file used for output.
37 */ 38 */
@@ -62,10 +63,10 @@ struct REGEX_TEST_Graph_Context {
62 * @param stack_size current size of the stack 63 * @param stack_size current size of the stack
63 */ 64 */
64static void 65static void
65scc_tarjan_strongconnect(unsigned int *scc_counter, 66scc_tarjan_strongconnect (unsigned int *scc_counter,
66 struct REGEX_INTERNAL_State *v, unsigned int *index, 67 struct REGEX_INTERNAL_State *v, unsigned int *index,
67 struct REGEX_INTERNAL_State **stack, 68 struct REGEX_INTERNAL_State **stack,
68 unsigned int *stack_size) 69 unsigned int *stack_size)
69{ 70{
70 struct REGEX_INTERNAL_State *w; 71 struct REGEX_INTERNAL_State *w;
71 struct REGEX_INTERNAL_Transition *t; 72 struct REGEX_INTERNAL_Transition *t;
@@ -77,32 +78,32 @@ scc_tarjan_strongconnect(unsigned int *scc_counter,
77 v->contained = 1; 78 v->contained = 1;
78 79
79 for (t = v->transitions_head; NULL != t; t = t->next) 80 for (t = v->transitions_head; NULL != t; t = t->next)
81 {
82 w = t->to_state;
83
84 if (NULL == w)
85 continue;
86
87 if (w->index < 0)
80 { 88 {
81 w = t->to_state; 89 scc_tarjan_strongconnect (scc_counter, w, index, stack, stack_size);
82 90 v->lowlink = (v->lowlink > w->lowlink) ? w->lowlink : v->lowlink;
83 if (NULL == w)
84 continue;
85
86 if (w->index < 0)
87 {
88 scc_tarjan_strongconnect(scc_counter, w, index, stack, stack_size);
89 v->lowlink = (v->lowlink > w->lowlink) ? w->lowlink : v->lowlink;
90 }
91 else if (1 == w->contained)
92 v->lowlink = (v->lowlink > w->index) ? w->index : v->lowlink;
93 } 91 }
92 else if (1 == w->contained)
93 v->lowlink = (v->lowlink > w->index) ? w->index : v->lowlink;
94 }
94 95
95 if (v->lowlink == v->index) 96 if (v->lowlink == v->index)
97 {
98 (*scc_counter)++;
99 do
96 { 100 {
97 (*scc_counter)++; 101 w = stack[--(*stack_size)];
98 do 102 w->contained = 0;
99 { 103 w->scc_id = *scc_counter;
100 w = stack[--(*stack_size)];
101 w->contained = 0;
102 w->scc_id = *scc_counter;
103 }
104 while (w != v);
105 } 104 }
105 while (w != v);
106 }
106} 107}
107 108
108 109
@@ -113,7 +114,7 @@ scc_tarjan_strongconnect(unsigned int *scc_counter,
113 * @param a the automaton for which SCCs should be computed and assigned. 114 * @param a the automaton for which SCCs should be computed and assigned.
114 */ 115 */
115static void 116static void
116scc_tarjan(struct REGEX_INTERNAL_Automaton *a) 117scc_tarjan (struct REGEX_INTERNAL_Automaton *a)
117{ 118{
118 unsigned int index; 119 unsigned int index;
119 unsigned int scc_counter; 120 unsigned int scc_counter;
@@ -122,21 +123,21 @@ scc_tarjan(struct REGEX_INTERNAL_Automaton *a)
122 unsigned int stack_size; 123 unsigned int stack_size;
123 124
124 for (v = a->states_head; NULL != v; v = v->next) 125 for (v = a->states_head; NULL != v; v = v->next)
125 { 126 {
126 v->contained = 0; 127 v->contained = 0;
127 v->index = -1; 128 v->index = -1;
128 v->lowlink = -1; 129 v->lowlink = -1;
129 } 130 }
130 131
131 stack_size = 0; 132 stack_size = 0;
132 index = 0; 133 index = 0;
133 scc_counter = 0; 134 scc_counter = 0;
134 135
135 for (v = a->states_head; NULL != v; v = v->next) 136 for (v = a->states_head; NULL != v; v = v->next)
136 { 137 {
137 if (v->index < 0) 138 if (v->index < 0)
138 scc_tarjan_strongconnect(&scc_counter, v, &index, stack, &stack_size); 139 scc_tarjan_strongconnect (&scc_counter, v, &index, stack, &stack_size);
139 } 140 }
140} 141}
141 142
142 143
@@ -150,8 +151,8 @@ scc_tarjan(struct REGEX_INTERNAL_Automaton *a)
150 * @param s state. 151 * @param s state.
151 */ 152 */
152void 153void
153REGEX_TEST_automaton_save_graph_step(void *cls, unsigned int count, 154REGEX_TEST_automaton_save_graph_step (void *cls, unsigned int count,
154 struct REGEX_INTERNAL_State *s) 155 struct REGEX_INTERNAL_State *s)
155{ 156{
156 struct REGEX_TEST_Graph_Context *ctx = cls; 157 struct REGEX_TEST_Graph_Context *ctx = cls;
157 struct REGEX_INTERNAL_Transition *ctran; 158 struct REGEX_INTERNAL_Transition *ctran;
@@ -161,100 +162,100 @@ REGEX_TEST_automaton_save_graph_step(void *cls, unsigned int count,
161 char *to_name; 162 char *to_name;
162 163
163 if (GNUNET_YES == ctx->verbose) 164 if (GNUNET_YES == ctx->verbose)
164 GNUNET_asprintf(&name, "%i (%s) (%s) (%s)", s->dfs_id, s->name, s->proof, 165 GNUNET_asprintf (&name, "%i (%s) (%s) (%s)", s->dfs_id, s->name, s->proof,
165 GNUNET_h2s(&s->hash)); 166 GNUNET_h2s (&s->hash));
166 else 167 else
167 GNUNET_asprintf(&name, "%i", s->dfs_id); 168 GNUNET_asprintf (&name, "%i", s->dfs_id);
168 169
169 if (s->accepting) 170 if (s->accepting)
171 {
172 if (GNUNET_YES == ctx->coloring)
170 { 173 {
171 if (GNUNET_YES == ctx->coloring) 174 GNUNET_asprintf (&s_acc,
172 { 175 "\"%s\" [shape=doublecircle, color=\"0.%i 0.8 0.95\"];\n",
173 GNUNET_asprintf(&s_acc, 176 name, s->scc_id * s->scc_id);
174 "\"%s\" [shape=doublecircle, color=\"0.%i 0.8 0.95\"];\n",
175 name, s->scc_id * s->scc_id);
176 }
177 else
178 {
179 GNUNET_asprintf(&s_acc, "\"%s\" [shape=doublecircle];\n", name,
180 s->scc_id);
181 }
182 } 177 }
183 else if (GNUNET_YES == ctx->coloring) 178 else
184 { 179 {
185 GNUNET_asprintf(&s_acc, 180 GNUNET_asprintf (&s_acc, "\"%s\" [shape=doublecircle];\n", name,
186 "\"%s\" [shape=circle, color=\"0.%i 0.8 0.95\"];\n", name, 181 s->scc_id);
187 s->scc_id * s->scc_id);
188 } 182 }
183 }
184 else if (GNUNET_YES == ctx->coloring)
185 {
186 GNUNET_asprintf (&s_acc,
187 "\"%s\" [shape=circle, color=\"0.%i 0.8 0.95\"];\n", name,
188 s->scc_id * s->scc_id);
189 }
189 else 190 else
190 { 191 {
191 GNUNET_asprintf(&s_acc, "\"%s\" [shape=circle];\n", name, s->scc_id); 192 GNUNET_asprintf (&s_acc, "\"%s\" [shape=circle];\n", name, s->scc_id);
192 } 193 }
193 194
194 GNUNET_assert(NULL != s_acc); 195 GNUNET_assert (NULL != s_acc);
195 196
196 fwrite(s_acc, strlen(s_acc), 1, ctx->filep); 197 fwrite (s_acc, strlen (s_acc), 1, ctx->filep);
197 GNUNET_free(s_acc); 198 GNUNET_free (s_acc);
198 s_acc = NULL; 199 s_acc = NULL;
199 200
200 for (ctran = s->transitions_head; NULL != ctran; ctran = ctran->next) 201 for (ctran = s->transitions_head; NULL != ctran; ctran = ctran->next)
202 {
203 if (NULL == ctran->to_state)
204 {
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 "Transition from State %i has no state for transitioning\n",
207 s->id);
208 continue;
209 }
210
211 if (GNUNET_YES == ctx->verbose)
212 {
213 GNUNET_asprintf (&to_name, "%i (%s) (%s) (%s)", ctran->to_state->dfs_id,
214 ctran->to_state->name, ctran->to_state->proof,
215 GNUNET_h2s (&ctran->to_state->hash));
216 }
217 else
218 GNUNET_asprintf (&to_name, "%i", ctran->to_state->dfs_id);
219
220 if (NULL == ctran->label)
201 { 221 {
202 if (NULL == ctran->to_state) 222 if (GNUNET_YES == ctx->coloring)
203 { 223 {
204 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 224 GNUNET_asprintf (&s_tran,
205 "Transition from State %i has no state for transitioning\n", 225 "\"%s\" -> \"%s\" [label = \"ε\", color=\"0.%i 0.8 0.95\"];\n",
206 s->id); 226 name, to_name, s->scc_id * s->scc_id);
207 continue; 227 }
208 }
209
210 if (GNUNET_YES == ctx->verbose)
211 {
212 GNUNET_asprintf(&to_name, "%i (%s) (%s) (%s)", ctran->to_state->dfs_id,
213 ctran->to_state->name, ctran->to_state->proof,
214 GNUNET_h2s(&ctran->to_state->hash));
215 }
216 else 228 else
217 GNUNET_asprintf(&to_name, "%i", ctran->to_state->dfs_id); 229 {
218 230 GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"ε\"];\n", name,
219 if (NULL == ctran->label) 231 to_name, s->scc_id);
220 { 232 }
221 if (GNUNET_YES == ctx->coloring) 233 }
222 { 234 else
223 GNUNET_asprintf(&s_tran, 235 {
224 "\"%s\" -> \"%s\" [label = \"ε\", color=\"0.%i 0.8 0.95\"];\n", 236 if (GNUNET_YES == ctx->coloring)
225 name, to_name, s->scc_id * s->scc_id); 237 {
226 } 238 GNUNET_asprintf (&s_tran,
227 else 239 "\"%s\" -> \"%s\" [label = \"%s\", color=\"0.%i 0.8 0.95\"];\n",
228 { 240 name, to_name, ctran->label, s->scc_id * s->scc_id);
229 GNUNET_asprintf(&s_tran, "\"%s\" -> \"%s\" [label = \"ε\"];\n", name, 241 }
230 to_name, s->scc_id);
231 }
232 }
233 else 242 else
234 { 243 {
235 if (GNUNET_YES == ctx->coloring) 244 GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"%s\"];\n", name,
236 { 245 to_name, ctran->label, s->scc_id);
237 GNUNET_asprintf(&s_tran, 246 }
238 "\"%s\" -> \"%s\" [label = \"%s\", color=\"0.%i 0.8 0.95\"];\n",
239 name, to_name, ctran->label, s->scc_id * s->scc_id);
240 }
241 else
242 {
243 GNUNET_asprintf(&s_tran, "\"%s\" -> \"%s\" [label = \"%s\"];\n", name,
244 to_name, ctran->label, s->scc_id);
245 }
246 }
247
248 GNUNET_free(to_name);
249
250 GNUNET_assert(NULL != s_tran);
251
252 fwrite(s_tran, strlen(s_tran), 1, ctx->filep);
253 GNUNET_free(s_tran);
254 s_tran = NULL;
255 } 247 }
256 248
257 GNUNET_free(name); 249 GNUNET_free (to_name);
250
251 GNUNET_assert (NULL != s_tran);
252
253 fwrite (s_tran, strlen (s_tran), 1, ctx->filep);
254 GNUNET_free (s_tran);
255 s_tran = NULL;
256 }
257
258 GNUNET_free (name);
258} 259}
259 260
260 261
@@ -267,51 +268,51 @@ REGEX_TEST_automaton_save_graph_step(void *cls, unsigned int count,
267 * mode 268 * mode
268 */ 269 */
269void 270void
270REGEX_TEST_automaton_save_graph(struct REGEX_INTERNAL_Automaton *a, 271REGEX_TEST_automaton_save_graph (struct REGEX_INTERNAL_Automaton *a,
271 const char *filename, 272 const char *filename,
272 enum REGEX_TEST_GraphSavingOptions options) 273 enum REGEX_TEST_GraphSavingOptions options)
273{ 274{
274 char *start; 275 char *start;
275 char *end; 276 char *end;
276 struct REGEX_TEST_Graph_Context ctx; 277 struct REGEX_TEST_Graph_Context ctx;
277 278
278 if (NULL == a) 279 if (NULL == a)
279 { 280 {
280 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not print NFA, was NULL!"); 281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not print NFA, was NULL!");
281 return; 282 return;
282 } 283 }
283 284
284 if (NULL == filename || strlen(filename) < 1) 285 if ((NULL == filename)||(strlen (filename) < 1))
285 { 286 {
286 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No Filename given!"); 287 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No Filename given!");
287 return; 288 return;
288 } 289 }
289 290
290 ctx.filep = fopen(filename, "w"); 291 ctx.filep = fopen (filename, "w");
291 ctx.verbose = 292 ctx.verbose =
292 (0 == (options & REGEX_TEST_GRAPH_VERBOSE)) ? GNUNET_NO : GNUNET_YES; 293 (0 == (options & REGEX_TEST_GRAPH_VERBOSE)) ? GNUNET_NO : GNUNET_YES;
293 ctx.coloring = 294 ctx.coloring =
294 (0 == (options & REGEX_TEST_GRAPH_COLORING)) ? GNUNET_NO : GNUNET_YES; 295 (0 == (options & REGEX_TEST_GRAPH_COLORING)) ? GNUNET_NO : GNUNET_YES;
295 296
296 if (NULL == ctx.filep) 297 if (NULL == ctx.filep)
297 { 298 {
298 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not open file for writing: %s", 299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not open file for writing: %s",
299 filename); 300 filename);
300 return; 301 return;
301 } 302 }
302 303
303 /* First add the SCCs to the automaton, so we can color them nicely */ 304 /* First add the SCCs to the automaton, so we can color them nicely */
304 if (GNUNET_YES == ctx.coloring) 305 if (GNUNET_YES == ctx.coloring)
305 scc_tarjan(a); 306 scc_tarjan (a);
306 307
307 start = "digraph G {\nrankdir=LR\n"; 308 start = "digraph G {\nrankdir=LR\n";
308 fwrite(start, strlen(start), 1, ctx.filep); 309 fwrite (start, strlen (start), 1, ctx.filep);
309 310
310 REGEX_INTERNAL_automaton_traverse(a, a->start, NULL, NULL, 311 REGEX_INTERNAL_automaton_traverse (a, a->start, NULL, NULL,
311 &REGEX_TEST_automaton_save_graph_step, 312 &REGEX_TEST_automaton_save_graph_step,
312 &ctx); 313 &ctx);
313 314
314 end = "\n}\n"; 315 end = "\n}\n";
315 fwrite(end, strlen(end), 1, ctx.filep); 316 fwrite (end, strlen (end), 1, ctx.filep);
316 fclose(ctx.filep); 317 fclose (ctx.filep);
317} 318}
diff --git a/src/regex/regex_test_lib.c b/src/regex/regex_test_lib.c
index d8eb22370..15d6c653a 100644
--- a/src/regex/regex_test_lib.c
+++ b/src/regex/regex_test_lib.c
@@ -32,7 +32,8 @@
32/** 32/**
33 * Struct to hold the tree formed by prefix-combining the regexes. 33 * Struct to hold the tree formed by prefix-combining the regexes.
34 */ 34 */
35struct RegexCombineCtx { 35struct RegexCombineCtx
36{
36 /** 37 /**
37 * Child nodes with same prefix and token. 38 * Child nodes with same prefix and token.
38 */ 39 */
@@ -61,34 +62,34 @@ struct RegexCombineCtx {
61 * @return Int in range [0, (base-1)] 62 * @return Int in range [0, (base-1)]
62 */ 63 */
63static int 64static int
64c2i(char c, int size) 65c2i (char c, int size)
65{ 66{
66 switch (size) 67 switch (size)
67 { 68 {
68 case 2: 69 case 2:
69 case 8: 70 case 8:
71 return c - '0';
72 break;
73
74 case 16:
75 if ((c >= '0') &&(c <= '9') )
70 return c - '0'; 76 return c - '0';
71 break; 77 else if ((c >= 'A') &&(c <= 'F') )
72 78 return c - 'A' + 10;
73 case 16: 79 else if ((c >= 'a') &&(c <= 'f') )
74 if (c >= '0' && c <= '9') 80 return c - 'a' + 10;
75 return c - '0'; 81 else
76 else if (c >= 'A' && c <= 'F') 82 {
77 return c - 'A' + 10; 83 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
78 else if (c >= 'a' && c <= 'f') 84 "Cannot convert char %c in base %u\n",
79 return c - 'a' + 10; 85 c, size);
80 else 86 GNUNET_assert (0);
81 {
82 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
83 "Cannot convert char %c in base %u\n",
84 c, size);
85 GNUNET_assert(0);
86 }
87 break;
88
89 default:
90 GNUNET_assert(0);
91 } 87 }
88 break;
89
90 default:
91 GNUNET_assert (0);
92 }
92} 93}
93 94
94 95
@@ -98,10 +99,10 @@ c2i(char c, int size)
98 * @param n Indentation level 99 * @param n Indentation level
99 */ 100 */
100static void 101static void
101space(int n) 102space (int n)
102{ 103{
103 for (int i = 0; i < n; i++) 104 for (int i = 0; i < n; i++)
104 fprintf(stderr, "| "); 105 fprintf (stderr, "| ");
105} 106}
106 107
107 108
@@ -112,25 +113,25 @@ space(int n)
112 * @param level Indentation level to start with 113 * @param level Indentation level to start with
113 */ 114 */
114static void 115static void
115debugctx(struct RegexCombineCtx *ctx, int level) 116debugctx (struct RegexCombineCtx *ctx, int level)
116{ 117{
117#if DEBUG_REGEX 118#if DEBUG_REGEX
118 if (NULL != ctx->s) 119 if (NULL != ctx->s)
119 { 120 {
120 space(level - 1); 121 space (level - 1);
121 fprintf(stderr, "%u:'%s'\n", c2i(ctx->s[0], ctx->size), ctx->s); 122 fprintf (stderr, "%u:'%s'\n", c2i (ctx->s[0], ctx->size), ctx->s);
122 } 123 }
123 else 124 else
124 fprintf(stderr, "ROOT (base %u)\n", ctx->size); 125 fprintf (stderr, "ROOT (base %u)\n", ctx->size);
125 for (unsigned int i = 0; i < ctx->size; i++) 126 for (unsigned int i = 0; i < ctx->size; i++)
127 {
128 if (NULL != ctx->children[i])
126 { 129 {
127 if (NULL != ctx->children[i]) 130 space (level);
128 { 131 debugctx (ctx->children[i], level + 1);
129 space(level);
130 debugctx(ctx->children[i], level + 1);
131 }
132 } 132 }
133 fflush(stderr); 133 }
134 fflush (stderr);
134#endif 135#endif
135} 136}
136 137
@@ -142,8 +143,8 @@ debugctx(struct RegexCombineCtx *ctx, int level)
142 * @param regex Regex to add. 143 * @param regex Regex to add.
143 */ 144 */
144static void 145static void
145regex_add(struct RegexCombineCtx *ctx, 146regex_add (struct RegexCombineCtx *ctx,
146 const char *regex); 147 const char *regex);
147 148
148 149
149/** 150/**
@@ -152,14 +153,14 @@ regex_add(struct RegexCombineCtx *ctx,
152 * @param alphabet_size Size of the alphabet (and the Trie array) 153 * @param alphabet_size Size of the alphabet (and the Trie array)
153 */ 154 */
154static struct RegexCombineCtx * 155static struct RegexCombineCtx *
155new_regex_ctx(unsigned int alphabet_size) 156new_regex_ctx (unsigned int alphabet_size)
156{ 157{
157 struct RegexCombineCtx *ctx; 158 struct RegexCombineCtx *ctx;
158 size_t array_size; 159 size_t array_size;
159 160
160 array_size = sizeof(struct RegexCombineCtx *) * alphabet_size; 161 array_size = sizeof(struct RegexCombineCtx *) * alphabet_size;
161 ctx = GNUNET_new(struct RegexCombineCtx); 162 ctx = GNUNET_new (struct RegexCombineCtx);
162 ctx->children = GNUNET_malloc(array_size); 163 ctx->children = GNUNET_malloc (array_size);
163 ctx->size = alphabet_size; 164 ctx->size = alphabet_size;
164 165
165 return ctx; 166 return ctx;
@@ -167,19 +168,19 @@ new_regex_ctx(unsigned int alphabet_size)
167 168
168 169
169static void 170static void
170move_children(struct RegexCombineCtx *dst, 171move_children (struct RegexCombineCtx *dst,
171 const struct RegexCombineCtx *src) 172 const struct RegexCombineCtx *src)
172{ 173{
173 size_t array_size; 174 size_t array_size;
174 175
175 array_size = sizeof(struct RegexCombineCtx *) * src->size; 176 array_size = sizeof(struct RegexCombineCtx *) * src->size;
176 GNUNET_memcpy(dst->children, 177 GNUNET_memcpy (dst->children,
177 src->children, 178 src->children,
178 array_size); 179 array_size);
179 for (unsigned int i = 0; i < src->size; i++) 180 for (unsigned int i = 0; i < src->size; i++)
180 { 181 {
181 src->children[i] = NULL; 182 src->children[i] = NULL;
182 } 183 }
183} 184}
184 185
185 186
@@ -191,7 +192,7 @@ move_children(struct RegexCombineCtx *dst,
191 * @return Regex that matches any of the added regexes. 192 * @return Regex that matches any of the added regexes.
192 */ 193 */
193static char * 194static char *
194regex_combine(struct RegexCombineCtx *ctx) 195regex_combine (struct RegexCombineCtx *ctx)
195{ 196{
196 struct RegexCombineCtx *p; 197 struct RegexCombineCtx *p;
197 unsigned int i; 198 unsigned int i;
@@ -201,56 +202,57 @@ regex_combine(struct RegexCombineCtx *ctx)
201 char *s; 202 char *s;
202 int opt; 203 int opt;
203 204
204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "new combine %s\n", ctx->s); 205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new combine %s\n", ctx->s);
205 regex = GNUNET_strdup(""); 206 regex = GNUNET_strdup ("");
206 opt = GNUNET_NO; 207 opt = GNUNET_NO;
207 for (i = 0; i < ctx->size; i++) 208 for (i = 0; i < ctx->size; i++)
209 {
210 p = ctx->children[i];
211 if (NULL == p)
212 continue;
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "adding '%s' to innner %s\n",
215 p->s, ctx->s);
216 s = regex_combine (p);
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " total '%s'\n", s);
218 if (strlen (s) == 0)
208 { 219 {
209 p = ctx->children[i]; 220 opt = GNUNET_YES;
210 if (NULL == p)
211 continue;
212 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
213 "adding '%s' to innner %s\n",
214 p->s, ctx->s);
215 s = regex_combine(p);
216 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " total '%s'\n", s);
217 if (strlen(s) == 0)
218 {
219 opt = GNUNET_YES;
220 }
221 else
222 {
223 GNUNET_asprintf(&tmp, "%s%s|", regex, s);
224 GNUNET_free_non_null(regex);
225 regex = tmp;
226 }
227 GNUNET_free_non_null(s);
228 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " so far '%s' for inner %s\n", regex, ctx->s);
229 } 221 }
230 222 else
231 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "opt: %d, innner: '%s'\n", opt, regex);
232 len = strlen(regex);
233 if (0 == len)
234 { 223 {
235 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "empty, returning ''\n"); 224 GNUNET_asprintf (&tmp, "%s%s|", regex, s);
236 GNUNET_free(regex); 225 GNUNET_free_non_null (regex);
237 return NULL == ctx->s ? NULL : GNUNET_strdup(ctx->s); 226 regex = tmp;
238 } 227 }
228 GNUNET_free_non_null (s);
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " so far '%s' for inner %s\n", regex,
230 ctx->s);
231 }
232
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "opt: %d, innner: '%s'\n", opt, regex);
234 len = strlen (regex);
235 if (0 == len)
236 {
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "empty, returning ''\n");
238 GNUNET_free (regex);
239 return NULL == ctx->s ? NULL : GNUNET_strdup (ctx->s);
240 }
239 241
240 if ('|' == regex[len - 1]) 242 if ('|' == regex[len - 1])
241 regex[len - 1] = '\0'; 243 regex[len - 1] = '\0';
242 244
243 if (NULL != ctx->s) 245 if (NULL != ctx->s)
244 { 246 {
245 if (opt) 247 if (opt)
246 GNUNET_asprintf(&s, "%s(%s)?", ctx->s, regex); 248 GNUNET_asprintf (&s, "%s(%s)?", ctx->s, regex);
247 else 249 else
248 GNUNET_asprintf(&s, "%s(%s)", ctx->s, regex); 250 GNUNET_asprintf (&s, "%s(%s)", ctx->s, regex);
249 GNUNET_free(regex); 251 GNUNET_free (regex);
250 regex = s; 252 regex = s;
251 } 253 }
252 254
253 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "partial: %s\n", regex); 255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "partial: %s\n", regex);
254 return regex; 256 return regex;
255} 257}
256 258
@@ -264,22 +266,22 @@ regex_combine(struct RegexCombineCtx *ctx)
264 * @return Number of characters of matching prefix. 266 * @return Number of characters of matching prefix.
265 */ 267 */
266static unsigned int 268static unsigned int
267get_prefix_length(const char *s1, const char *s2) 269get_prefix_length (const char *s1, const char *s2)
268{ 270{
269 unsigned int l1; 271 unsigned int l1;
270 unsigned int l2; 272 unsigned int l2;
271 unsigned int limit; 273 unsigned int limit;
272 unsigned int i; 274 unsigned int i;
273 275
274 l1 = strlen(s1); 276 l1 = strlen (s1);
275 l2 = strlen(s2); 277 l2 = strlen (s2);
276 limit = l1 > l2 ? l2 : l1; 278 limit = l1 > l2 ? l2 : l1;
277 279
278 for (i = 0; i < limit; i++) 280 for (i = 0; i < limit; i++)
279 { 281 {
280 if (s1[i] != s2[i]) 282 if (s1[i] != s2[i])
281 return i; 283 return i;
282 } 284 }
283 return limit; 285 return limit;
284} 286}
285 287
@@ -294,7 +296,7 @@ get_prefix_length(const char *s1, const char *s2)
294 * @return Child with the longest prefix, NULL if no child matches. 296 * @return Child with the longest prefix, NULL if no child matches.
295 */ 297 */
296static struct RegexCombineCtx * 298static struct RegexCombineCtx *
297get_longest_prefix(struct RegexCombineCtx *ctx, const char *regex) 299get_longest_prefix (struct RegexCombineCtx *ctx, const char *regex)
298{ 300{
299 struct RegexCombineCtx *p; 301 struct RegexCombineCtx *p;
300 struct RegexCombineCtx *best; 302 struct RegexCombineCtx *best;
@@ -306,26 +308,26 @@ get_longest_prefix(struct RegexCombineCtx *ctx, const char *regex)
306 best = NULL; 308 best = NULL;
307 309
308 for (i = 0; i < ctx->size; i++) 310 for (i = 0; i < ctx->size; i++)
311 {
312 p = ctx->children[i];
313 if (NULL == p)
314 continue;
315
316 l = get_prefix_length (p->s, regex);
317 if (l > best_l)
309 { 318 {
310 p = ctx->children[i]; 319 GNUNET_break (0 == best_l);
311 if (NULL == p) 320 best = p;
312 continue; 321 best_l = l;
313
314 l = get_prefix_length(p->s, regex);
315 if (l > best_l)
316 {
317 GNUNET_break(0 == best_l);
318 best = p;
319 best_l = l;
320 }
321 } 322 }
323 }
322 return best; 324 return best;
323} 325}
324 326
325static void 327static void
326regex_add_multiple(struct RegexCombineCtx *ctx, 328regex_add_multiple (struct RegexCombineCtx *ctx,
327 const char *regex, 329 const char *regex,
328 struct RegexCombineCtx **children) 330 struct RegexCombineCtx **children)
329{ 331{
330 char tmp[2]; 332 char tmp[2];
331 long unsigned int i; 333 long unsigned int i;
@@ -334,43 +336,43 @@ regex_add_multiple(struct RegexCombineCtx *ctx,
334 unsigned int count; 336 unsigned int count;
335 337
336 if ('(' != regex[0]) 338 if ('(' != regex[0])
337 { 339 {
338 GNUNET_assert(0); 340 GNUNET_assert (0);
339 } 341 }
340 342
341 /* Does the regex cover *all* possible children? Then don't add any, 343 /* Does the regex cover *all* possible children? Then don't add any,
342 * as it will be covered by the post-regex "(a-z)*" 344 * as it will be covered by the post-regex "(a-z)*"
343 */ 345 */
344 l = strlen(regex); 346 l = strlen (regex);
345 count = 0; 347 count = 0;
346 for (i = 1UL; i < l; i++) 348 for (i = 1UL; i < l; i++)
349 {
350 if ((regex[i] != '|') &&(regex[i] != ')') )
347 { 351 {
348 if (regex[i] != '|' && regex[i] != ')') 352 count++;
349 {
350 count++;
351 }
352 } 353 }
354 }
353 if (count == ctx->size) 355 if (count == ctx->size)
354 { 356 {
355 return; 357 return;
356 } 358 }
357 359
358 /* Add every component as a child node */ 360 /* Add every component as a child node */
359 tmp[1] = '\0'; 361 tmp[1] = '\0';
360 for (i = 1UL; i < l; i++) 362 for (i = 1UL; i < l; i++)
363 {
364 if ((regex[i] != '|') &&(regex[i] != ')') )
361 { 365 {
362 if (regex[i] != '|' && regex[i] != ')') 366 tmp[0] = regex[i];
363 { 367 newctx = new_regex_ctx (ctx->size);
364 tmp[0] = regex[i]; 368 newctx->s = GNUNET_strdup (tmp);
365 newctx = new_regex_ctx(ctx->size); 369 if (children != NULL)
366 newctx->s = GNUNET_strdup(tmp); 370 GNUNET_memcpy (newctx->children,
367 if (children != NULL) 371 children,
368 GNUNET_memcpy(newctx->children, 372 sizeof(*children) * ctx->size);
369 children, 373 ctx->children[c2i (tmp[0], ctx->size)] = newctx;
370 sizeof(*children) * ctx->size);
371 ctx->children[c2i(tmp[0], ctx->size)] = newctx;
372 }
373 } 374 }
375 }
374} 376}
375 377
376/** 378/**
@@ -384,19 +386,19 @@ regex_add_multiple(struct RegexCombineCtx *ctx,
384 * @param prefix_l Lenght of common prefix of the new regex and @a ctx->s 386 * @param prefix_l Lenght of common prefix of the new regex and @a ctx->s
385 */ 387 */
386static void 388static void
387regex_split(struct RegexCombineCtx *ctx, 389regex_split (struct RegexCombineCtx *ctx,
388 unsigned int len, 390 unsigned int len,
389 unsigned int prefix_l) 391 unsigned int prefix_l)
390{ 392{
391 struct RegexCombineCtx *newctx; 393 struct RegexCombineCtx *newctx;
392 unsigned int idx; 394 unsigned int idx;
393 char *suffix; 395 char *suffix;
394 396
395 suffix = GNUNET_malloc(len - prefix_l + 1); 397 suffix = GNUNET_malloc (len - prefix_l + 1);
396 /* 398 /*
397 * We can use GNUNET_strlcpy because ctx->s is null-terminated 399 * We can use GNUNET_strlcpy because ctx->s is null-terminated
398 */ 400 */
399 GNUNET_strlcpy(suffix, &ctx->s[prefix_l], len - prefix_l + 1); 401 GNUNET_strlcpy (suffix, &ctx->s[prefix_l], len - prefix_l + 1);
400 402
401 /* Suffix saved, truncate current node so it only contains the prefix, 403 /* Suffix saved, truncate current node so it only contains the prefix,
402 * copy any children nodes to put as grandchildren and initialize new empty 404 * copy any children nodes to put as grandchildren and initialize new empty
@@ -406,22 +408,22 @@ regex_split(struct RegexCombineCtx *ctx,
406 408
407 /* If the suffix is an OR expression, add multiple children */ 409 /* If the suffix is an OR expression, add multiple children */
408 if ('(' == suffix[0]) 410 if ('(' == suffix[0])
409 { 411 {
410 struct RegexCombineCtx **tmp; 412 struct RegexCombineCtx **tmp;
411 413
412 tmp = ctx->children; 414 tmp = ctx->children;
413 ctx->children = GNUNET_malloc(sizeof(*tmp) * ctx->size); 415 ctx->children = GNUNET_malloc (sizeof(*tmp) * ctx->size);
414 regex_add_multiple(ctx, suffix, tmp); 416 regex_add_multiple (ctx, suffix, tmp);
415 GNUNET_free(suffix); 417 GNUNET_free (suffix);
416 GNUNET_free(tmp); 418 GNUNET_free (tmp);
417 return; 419 return;
418 } 420 }
419 421
420 /* The suffix is a normal string, add as one node */ 422 /* The suffix is a normal string, add as one node */
421 newctx = new_regex_ctx(ctx->size); 423 newctx = new_regex_ctx (ctx->size);
422 newctx->s = suffix; 424 newctx->s = suffix;
423 move_children(newctx, ctx); 425 move_children (newctx, ctx);
424 idx = c2i(suffix[0], ctx->size); 426 idx = c2i (suffix[0], ctx->size);
425 ctx->children[idx] = newctx; 427 ctx->children[idx] = newctx;
426} 428}
427 429
@@ -433,7 +435,7 @@ regex_split(struct RegexCombineCtx *ctx,
433 * @param regex Regex to add. 435 * @param regex Regex to add.
434 */ 436 */
435static void 437static void
436regex_add(struct RegexCombineCtx *ctx, const char *regex) 438regex_add (struct RegexCombineCtx *ctx, const char *regex)
437{ 439{
438 struct RegexCombineCtx *p; 440 struct RegexCombineCtx *p;
439 struct RegexCombineCtx *newctx; 441 struct RegexCombineCtx *newctx;
@@ -444,54 +446,54 @@ regex_add(struct RegexCombineCtx *ctx, const char *regex)
444 size_t len; 446 size_t len;
445 int idx; 447 int idx;
446 448
447 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "regex_add '%s' into '%s'\n", 450 "regex_add '%s' into '%s'\n",
449 regex, ctx->s); 451 regex, ctx->s);
450 l = strlen(regex); 452 l = strlen (regex);
451 if (0UL == l) 453 if (0UL == l)
452 return; 454 return;
453 455
454 /* If the regex is in the form of (a|b|c), add every character separately */ 456 /* If the regex is in the form of (a|b|c), add every character separately */
455 if ('(' == regex[0]) 457 if ('(' == regex[0])
456 { 458 {
457 regex_add_multiple(ctx, regex, NULL); 459 regex_add_multiple (ctx, regex, NULL);
458 return; 460 return;
459 } 461 }
460 462
461 p = get_longest_prefix(ctx, regex); 463 p = get_longest_prefix (ctx, regex);
462 if (NULL != p) 464 if (NULL != p)
465 {
466 /* There is some prefix match, reduce regex and try again */
467 prefix_l = get_prefix_length (p->s, regex);
468 rest_s = &p->s[prefix_l];
469 rest_r = &regex[prefix_l];
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "chosen '%s' [%u]\n", p->s, prefix_l);
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "prefix r '%.*s'\n", prefix_l, p->s);
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "rest r '%s'\n", rest_r);
473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "rest s '%s'\n", rest_s);
474 len = strlen (p->s);
475 if (prefix_l < len)
463 { 476 {
464 /* There is some prefix match, reduce regex and try again */ 477 regex_split (p, len, prefix_l);
465 prefix_l = get_prefix_length(p->s, regex);
466 rest_s = &p->s[prefix_l];
467 rest_r = &regex[prefix_l];
468 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "chosen '%s' [%u]\n", p->s, prefix_l);
469 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "prefix r '%.*s'\n", prefix_l, p->s);
470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "rest r '%s'\n", rest_r);
471 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "rest s '%s'\n", rest_s);
472 len = strlen(p->s);
473 if (prefix_l < len)
474 {
475 regex_split(p, len, prefix_l);
476 }
477 regex_add(p, rest_r);
478 return;
479 } 478 }
479 regex_add (p, rest_r);
480 return;
481 }
480 482
481 /* There is no prefix match, add new */ 483 /* There is no prefix match, add new */
482 idx = c2i(regex[0], ctx->size); 484 idx = c2i (regex[0], ctx->size);
483 if (NULL == ctx->children[idx] && NULL != ctx->s) 485 if ((NULL == ctx->children[idx])&&(NULL != ctx->s))
484 { 486 {
485 /* this was the end before, add empty string */ 487 /* this was the end before, add empty string */
486 newctx = new_regex_ctx(ctx->size); 488 newctx = new_regex_ctx (ctx->size);
487 newctx->s = GNUNET_strdup(""); 489 newctx->s = GNUNET_strdup ("");
488 ctx->children[idx] = newctx; 490 ctx->children[idx] = newctx;
489 } 491 }
490 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " no match\n"); 492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " no match\n");
491 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " new state %s\n", regex); 493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " new state %s\n", regex);
492 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " under %s\n", ctx->s); 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " under %s\n", ctx->s);
493 newctx = new_regex_ctx(ctx->size); 495 newctx = new_regex_ctx (ctx->size);
494 newctx->s = GNUNET_strdup(regex); 496 newctx->s = GNUNET_strdup (regex);
495 ctx->children[idx] = newctx; 497 ctx->children[idx] = newctx;
496} 498}
497 499
@@ -502,7 +504,7 @@ regex_add(struct RegexCombineCtx *ctx, const char *regex)
502 * @param ctx Context to free. 504 * @param ctx Context to free.
503 */ 505 */
504static void 506static void
505regex_ctx_destroy(struct RegexCombineCtx *ctx) 507regex_ctx_destroy (struct RegexCombineCtx *ctx)
506{ 508{
507 unsigned int i; 509 unsigned int i;
508 510
@@ -510,12 +512,12 @@ regex_ctx_destroy(struct RegexCombineCtx *ctx)
510 return; 512 return;
511 513
512 for (i = 0; i < ctx->size; i++) 514 for (i = 0; i < ctx->size; i++)
513 { 515 {
514 regex_ctx_destroy(ctx->children[i]); 516 regex_ctx_destroy (ctx->children[i]);
515 } 517 }
516 GNUNET_free_non_null(ctx->s); /* 's' on root node is null */ 518 GNUNET_free_non_null (ctx->s); /* 's' on root node is null */
517 GNUNET_free(ctx->children); 519 GNUNET_free (ctx->children);
518 GNUNET_free(ctx); 520 GNUNET_free (ctx);
519} 521}
520 522
521 523
@@ -534,27 +536,27 @@ regex_ctx_destroy(struct RegexCombineCtx *ctx)
534 * @return A string with a single regex that matches any of the original regexes 536 * @return A string with a single regex that matches any of the original regexes
535 */ 537 */
536char * 538char *
537REGEX_TEST_combine(char * const regexes[], unsigned int alphabet_size) 539REGEX_TEST_combine (char *const regexes[], unsigned int alphabet_size)
538{ 540{
539 unsigned int i; 541 unsigned int i;
540 char *combined; 542 char *combined;
541 const char *current; 543 const char *current;
542 struct RegexCombineCtx *ctx; 544 struct RegexCombineCtx *ctx;
543 545
544 ctx = new_regex_ctx(alphabet_size); 546 ctx = new_regex_ctx (alphabet_size);
545 for (i = 0; regexes[i]; i++) 547 for (i = 0; regexes[i]; i++)
546 { 548 {
547 current = regexes[i]; 549 current = regexes[i];
548 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Regex %u: %s\n", i, current); 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Regex %u: %s\n", i, current);
549 regex_add(ctx, current); 551 regex_add (ctx, current);
550 debugctx(ctx, 0); 552 debugctx (ctx, 0);
551 } 553 }
552 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\nCombining...\n"); 554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nCombining...\n");
553 debugctx(ctx, 0); 555 debugctx (ctx, 0);
554 556
555 combined = regex_combine(ctx); 557 combined = regex_combine (ctx);
556 558
557 regex_ctx_destroy(ctx); 559 regex_ctx_destroy (ctx);
558 560
559 return combined; 561 return combined;
560} 562}
@@ -570,7 +572,7 @@ REGEX_TEST_combine(char * const regexes[], unsigned int alphabet_size)
570 * @return A newly allocated, NULL terminated array of regexes. 572 * @return A newly allocated, NULL terminated array of regexes.
571 */ 573 */
572char ** 574char **
573REGEX_TEST_read_from_file(const char *filename) 575REGEX_TEST_read_from_file (const char *filename)
574{ 576{
575 struct GNUNET_DISK_FileHandle *f; 577 struct GNUNET_DISK_FileHandle *f;
576 unsigned int nr; 578 unsigned int nr;
@@ -581,55 +583,55 @@ REGEX_TEST_read_from_file(const char *filename)
581 char *regex; 583 char *regex;
582 char **regexes; 584 char **regexes;
583 585
584 f = GNUNET_DISK_file_open(filename, 586 f = GNUNET_DISK_file_open (filename,
585 GNUNET_DISK_OPEN_READ, 587 GNUNET_DISK_OPEN_READ,
586 GNUNET_DISK_PERM_NONE); 588 GNUNET_DISK_PERM_NONE);
587 if (NULL == f) 589 if (NULL == f)
588 { 590 {
589 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 591 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
590 "Can't open file %s for reading\n", filename); 592 "Can't open file %s for reading\n", filename);
591 return NULL; 593 return NULL;
592 } 594 }
593 if (GNUNET_OK != GNUNET_DISK_file_handle_size(f, &size)) 595 if (GNUNET_OK != GNUNET_DISK_file_handle_size (f, &size))
594 { 596 {
595 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
596 "Can't get size of file %s\n", filename); 598 "Can't get size of file %s\n", filename);
597 GNUNET_DISK_file_close(f); 599 GNUNET_DISK_file_close (f);
598 return NULL; 600 return NULL;
599 } 601 }
600 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
601 "using file %s, size %llu\n", 603 "using file %s, size %llu\n",
602 filename, (unsigned long long)size); 604 filename, (unsigned long long) size);
603 605
604 buffer = GNUNET_malloc(size + 1); 606 buffer = GNUNET_malloc (size + 1);
605 GNUNET_DISK_file_read(f, buffer, size); 607 GNUNET_DISK_file_read (f, buffer, size);
606 GNUNET_DISK_file_close(f); 608 GNUNET_DISK_file_close (f);
607 regexes = GNUNET_malloc(sizeof(char *)); 609 regexes = GNUNET_malloc (sizeof(char *));
608 nr = 1; 610 nr = 1;
609 offset = 0; 611 offset = 0;
610 regex = NULL; 612 regex = NULL;
611 do 613 do
612 { 614 {
613 if (NULL == regex) 615 if (NULL == regex)
614 regex = GNUNET_malloc(size + 1); 616 regex = GNUNET_malloc (size + 1);
615 len = (size_t)sscanf(&buffer[offset], "%s", regex); 617 len = (size_t) sscanf (&buffer[offset], "%s", regex);
616 if (0 == len) 618 if (0 == len)
617 break; 619 break;
618 len = strlen(regex); 620 len = strlen (regex);
619 offset += len + 1; 621 offset += len + 1;
620 if (len < 1) 622 if (len < 1)
621 continue; 623 continue;
622 regex[len] = '\0'; 624 regex[len] = '\0';
623 regex = GNUNET_realloc(regex, len + 1); 625 regex = GNUNET_realloc (regex, len + 1);
624 GNUNET_array_grow(regexes, nr, nr + 1); 626 GNUNET_array_grow (regexes, nr, nr + 1);
625 GNUNET_assert(NULL == regexes[nr - 2]); 627 GNUNET_assert (NULL == regexes[nr - 2]);
626 regexes[nr - 2] = regex; 628 regexes[nr - 2] = regex;
627 regexes[nr - 1] = NULL; 629 regexes[nr - 1] = NULL;
628 regex = NULL; 630 regex = NULL;
629 } 631 }
630 while (offset < size); 632 while (offset < size);
631 GNUNET_free_non_null(regex); 633 GNUNET_free_non_null (regex);
632 GNUNET_free(buffer); 634 GNUNET_free (buffer);
633 635
634 return regexes; 636 return regexes;
635} 637}
@@ -641,13 +643,13 @@ REGEX_TEST_read_from_file(const char *filename)
641 * @param regexes NULL-terminated array of regexes. 643 * @param regexes NULL-terminated array of regexes.
642 */ 644 */
643void 645void
644REGEX_TEST_free_from_file(char **regexes) 646REGEX_TEST_free_from_file (char **regexes)
645{ 647{
646 unsigned int i; 648 unsigned int i;
647 649
648 for (i = 0; regexes[i]; i++) 650 for (i = 0; regexes[i]; i++)
649 GNUNET_free(regexes[i]); 651 GNUNET_free (regexes[i]);
650 GNUNET_free(regexes); 652 GNUNET_free (regexes);
651} 653}
652 654
653/* end of regex_test_lib.c */ 655/* end of regex_test_lib.c */
diff --git a/src/regex/regex_test_lib.h b/src/regex/regex_test_lib.h
index fe4b30498..a0ad0723a 100644
--- a/src/regex/regex_test_lib.h
+++ b/src/regex/regex_test_lib.h
@@ -54,7 +54,7 @@ extern "C"
54 * @return A string with a single regex that matches any of the original regexes 54 * @return A string with a single regex that matches any of the original regexes
55 */ 55 */
56char * 56char *
57REGEX_TEST_combine(char * const regexes[], unsigned int alphabet_size); 57REGEX_TEST_combine (char *const regexes[], unsigned int alphabet_size);
58 58
59 59
60/** 60/**
@@ -67,7 +67,7 @@ REGEX_TEST_combine(char * const regexes[], unsigned int alphabet_size);
67 * @return A newly allocated, NULL terminated array of regexes. 67 * @return A newly allocated, NULL terminated array of regexes.
68 */ 68 */
69char ** 69char **
70REGEX_TEST_read_from_file(const char *filename); 70REGEX_TEST_read_from_file (const char *filename);
71 71
72 72
73/** 73/**
@@ -76,7 +76,7 @@ REGEX_TEST_read_from_file(const char *filename);
76 * @param regexes NULL-terminated array of regexes. 76 * @param regexes NULL-terminated array of regexes.
77 */ 77 */
78void 78void
79REGEX_TEST_free_from_file(char **regexes); 79REGEX_TEST_free_from_file (char **regexes);
80 80
81 81
82/** 82/**
@@ -93,7 +93,7 @@ REGEX_TEST_free_from_file(char **regexes);
93 * needs to be freed, otherwise. 93 * needs to be freed, otherwise.
94 */ 94 */
95char * 95char *
96REGEX_TEST_generate_random_regex(size_t rx_length, char *matching_str); 96REGEX_TEST_generate_random_regex (size_t rx_length, char *matching_str);
97 97
98 98
99/** 99/**
@@ -106,14 +106,15 @@ REGEX_TEST_generate_random_regex(size_t rx_length, char *matching_str);
106 * @return random string that needs to be freed. 106 * @return random string that needs to be freed.
107 */ 107 */
108char * 108char *
109REGEX_TEST_generate_random_string(size_t max_len); 109REGEX_TEST_generate_random_string (size_t max_len);
110 110
111 111
112/** 112/**
113 * Options for graph creation function 113 * Options for graph creation function
114 * REGEX_TEST_automaton_save_graph. 114 * REGEX_TEST_automaton_save_graph.
115 */ 115 */
116enum REGEX_TEST_GraphSavingOptions { 116enum REGEX_TEST_GraphSavingOptions
117{
117 /** 118 /**
118 * Default. Do nothing special. 119 * Default. Do nothing special.
119 */ 120 */
@@ -141,9 +142,9 @@ enum REGEX_TEST_GraphSavingOptions {
141 * mode 142 * mode
142 */ 143 */
143void 144void
144REGEX_TEST_automaton_save_graph(struct REGEX_INTERNAL_Automaton *a, 145REGEX_TEST_automaton_save_graph (struct REGEX_INTERNAL_Automaton *a,
145 const char *filename, 146 const char *filename,
146 enum REGEX_TEST_GraphSavingOptions options); 147 enum REGEX_TEST_GraphSavingOptions options);
147 148
148 149
149 150
diff --git a/src/regex/regex_test_random.c b/src/regex/regex_test_random.c
index 9a1e9665a..29b5315db 100644
--- a/src/regex/regex_test_random.c
+++ b/src/regex/regex_test_random.c
@@ -34,13 +34,13 @@
34 * @return random valid literal 34 * @return random valid literal
35 */ 35 */
36static char 36static char
37get_random_literal() 37get_random_literal ()
38{ 38{
39 uint32_t ridx; 39 uint32_t ridx;
40 40
41 ridx = 41 ridx =
42 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 42 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
43 (uint32_t)strlen(ALLOWED_LITERALS)); 43 (uint32_t) strlen (ALLOWED_LITERALS));
44 44
45 return ALLOWED_LITERALS[ridx]; 45 return ALLOWED_LITERALS[ridx];
46} 46}
@@ -61,7 +61,7 @@ get_random_literal()
61 * needs to be freed, otherwise. 61 * needs to be freed, otherwise.
62 */ 62 */
63char * 63char *
64REGEX_TEST_generate_random_regex(size_t rx_length, char *matching_str) 64REGEX_TEST_generate_random_regex (size_t rx_length, char *matching_str)
65{ 65{
66 char *rx; 66 char *rx;
67 char *rx_p; 67 char *rx_p;
@@ -80,59 +80,60 @@ REGEX_TEST_generate_random_regex(size_t rx_length, char *matching_str)
80 else 80 else
81 matching_strp = NULL; 81 matching_strp = NULL;
82 82
83 rx = GNUNET_malloc(rx_length + 1); 83 rx = GNUNET_malloc (rx_length + 1);
84 rx_p = rx; 84 rx_p = rx;
85 current_char = 0; 85 current_char = 0;
86 last_was_op = 1; 86 last_was_op = 1;
87 87
88 for (i = 0; i < rx_length; i++) 88 for (i = 0; i < rx_length; i++)
89 {
90 char_op_switch = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
91
92 if ((0 == char_op_switch) && ! last_was_op)
93 {
94 last_was_op = 1;
95 rx_op = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4);
96
97 switch (rx_op)
98 {
99 case 0:
100 current_char = '+';
101 break;
102
103 case 1:
104 current_char = '*';
105 break;
106
107 case 2:
108 current_char = '?';
109 break;
110
111 case 3:
112 if (i < rx_length - 1) /* '|' cannot be at the end */
113 current_char = '|';
114 else
115 current_char = get_random_literal ();
116 break;
117 }
118 }
119 else
89 { 120 {
90 char_op_switch = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2); 121 current_char = get_random_literal ();
91 122 last_was_op = 0;
92 if (0 == char_op_switch && !last_was_op)
93 {
94 last_was_op = 1;
95 rx_op = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 4);
96
97 switch (rx_op)
98 {
99 case 0:
100 current_char = '+';
101 break;
102
103 case 1:
104 current_char = '*';
105 break;
106
107 case 2:
108 current_char = '?';
109 break;
110
111 case 3:
112 if (i < rx_length - 1) /* '|' cannot be at the end */
113 current_char = '|';
114 else
115 current_char = get_random_literal();
116 break;
117 }
118 }
119 else
120 {
121 current_char = get_random_literal();
122 last_was_op = 0;
123 }
124
125 if (NULL != matching_strp &&
126 (current_char != '+' && current_char != '*' && current_char != '?' &&
127 current_char != '|'))
128 {
129 *matching_strp = current_char;
130 matching_strp++;
131 }
132
133 *rx_p = current_char;
134 rx_p++;
135 } 123 }
124
125 if ((NULL != matching_strp) &&
126 ((current_char != '+') &&(current_char != '*') &&(current_char !=
127 '?') &&
128 (current_char != '|') ))
129 {
130 *matching_strp = current_char;
131 matching_strp++;
132 }
133
134 *rx_p = current_char;
135 rx_p++;
136 }
136 *rx_p = '\0'; 137 *rx_p = '\0';
137 if (NULL != matching_strp) 138 if (NULL != matching_strp)
138 *matching_strp = '\0'; 139 *matching_strp = '\0';
@@ -151,22 +152,22 @@ REGEX_TEST_generate_random_regex(size_t rx_length, char *matching_str)
151 * @return random string that needs to be freed. 152 * @return random string that needs to be freed.
152 */ 153 */
153char * 154char *
154REGEX_TEST_generate_random_string(size_t max_len) 155REGEX_TEST_generate_random_string (size_t max_len)
155{ 156{
156 unsigned int i; 157 unsigned int i;
157 char *str; 158 char *str;
158 size_t len; 159 size_t len;
159 160
160 if (1 > max_len) 161 if (1 > max_len)
161 return GNUNET_strdup(""); 162 return GNUNET_strdup ("");
162 163
163 len = (size_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max_len); 164 len = (size_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max_len);
164 str = GNUNET_malloc(len + 1); 165 str = GNUNET_malloc (len + 1);
165 166
166 for (i = 0; i < len; i++) 167 for (i = 0; i < len; i++)
167 { 168 {
168 str[i] = get_random_literal(); 169 str[i] = get_random_literal ();
169 } 170 }
170 171
171 str[i] = '\0'; 172 str[i] = '\0';
172 173
diff --git a/src/regex/test_regex_api.c b/src/regex/test_regex_api.c
index 2ee24800a..eaae8c682 100644
--- a/src/regex/test_regex_api.c
+++ b/src/regex/test_regex_api.c
@@ -31,12 +31,13 @@
31/** 31/**
32 * How long until we really give up on a particular testcase portion? 32 * How long until we really give up on a particular testcase portion?
33 */ 33 */
34#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 600) 34#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
35 600)
35 36
36/** 37/**
37 * How long until we give up on any particular operation (and retry)? 38 * How long until we give up on any particular operation (and retry)?
38 */ 39 */
39#define BASE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) 40#define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
40 41
41 42
42static struct GNUNET_REGEX_Announcement *a; 43static struct GNUNET_REGEX_Announcement *a;
@@ -49,25 +50,25 @@ static struct GNUNET_SCHEDULER_Task *die_task;
49 50
50 51
51static void 52static void
52end(void *cls) 53end (void *cls)
53{ 54{
54 die_task = NULL; 55 die_task = NULL;
55 GNUNET_REGEX_announce_cancel(a); 56 GNUNET_REGEX_announce_cancel (a);
56 a = NULL; 57 a = NULL;
57 GNUNET_REGEX_search_cancel(s); 58 GNUNET_REGEX_search_cancel (s);
58 s = NULL; 59 s = NULL;
59 ok = 0; 60 ok = 0;
60} 61}
61 62
62 63
63static void 64static void
64end_badly() 65end_badly ()
65{ 66{
66 die_task = NULL; 67 die_task = NULL;
67 fprintf(stderr, "%s", "Testcase failed (timeout).\n"); 68 fprintf (stderr, "%s", "Testcase failed (timeout).\n");
68 GNUNET_REGEX_announce_cancel(a); 69 GNUNET_REGEX_announce_cancel (a);
69 a = NULL; 70 a = NULL;
70 GNUNET_REGEX_search_cancel(s); 71 GNUNET_REGEX_search_cancel (s);
71 s = NULL; 72 s = NULL;
72 ok = 1; 73 ok = 1;
73} 74}
@@ -84,44 +85,45 @@ end_badly()
84 * @param put_path_length Length of the put_path. 85 * @param put_path_length Length of the put_path.
85 */ 86 */
86static void 87static void
87found_cb(void *cls, 88found_cb (void *cls,
88 const struct GNUNET_PeerIdentity *id, 89 const struct GNUNET_PeerIdentity *id,
89 const struct GNUNET_PeerIdentity *get_path, 90 const struct GNUNET_PeerIdentity *get_path,
90 unsigned int get_path_length, 91 unsigned int get_path_length,
91 const struct GNUNET_PeerIdentity *put_path, 92 const struct GNUNET_PeerIdentity *put_path,
92 unsigned int put_path_length) 93 unsigned int put_path_length)
93{ 94{
94 GNUNET_SCHEDULER_cancel(die_task); 95 GNUNET_SCHEDULER_cancel (die_task);
95 die_task = 96 die_task =
96 GNUNET_SCHEDULER_add_now(&end, NULL); 97 GNUNET_SCHEDULER_add_now (&end, NULL);
97} 98}
98 99
99 100
100static void 101static void
101run(void *cls, 102run (void *cls,
102 const struct GNUNET_CONFIGURATION_Handle *cfg, 103 const struct GNUNET_CONFIGURATION_Handle *cfg,
103 struct GNUNET_TESTING_Peer *peer) 104 struct GNUNET_TESTING_Peer *peer)
104{ 105{
105 die_task = 106 die_task =
106 GNUNET_SCHEDULER_add_delayed(TOTAL_TIMEOUT, 107 GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
107 &end_badly, NULL); 108 &end_badly, NULL);
108 a = GNUNET_REGEX_announce(cfg, 109 a = GNUNET_REGEX_announce (cfg,
109 "my long prefix - hello world(0|1)*", 110 "my long prefix - hello world(0|1)*",
110 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 111 GNUNET_TIME_relative_multiply (
111 5), 112 GNUNET_TIME_UNIT_SECONDS,
112 1); 113 5),
113 s = GNUNET_REGEX_search(cfg, 114 1);
114 "my long prefix - hello world0101", 115 s = GNUNET_REGEX_search (cfg,
115 &found_cb, NULL); 116 "my long prefix - hello world0101",
117 &found_cb, NULL);
116} 118}
117 119
118 120
119int 121int
120main(int argc, char *argv[]) 122main (int argc, char *argv[])
121{ 123{
122 if (0 != GNUNET_TESTING_peer_run("test-regex-api", 124 if (0 != GNUNET_TESTING_peer_run ("test-regex-api",
123 "test_regex_api_data.conf", 125 "test_regex_api_data.conf",
124 &run, NULL)) 126 &run, NULL))
125 return 1; 127 return 1;
126 return ok; 128 return ok;
127} 129}
diff --git a/src/regex/test_regex_eval_api.c b/src/regex/test_regex_eval_api.c
index 88a05f912..f6078c7ef 100644
--- a/src/regex/test_regex_eval_api.c
+++ b/src/regex/test_regex_eval_api.c
@@ -29,12 +29,14 @@
29#include "regex_test_lib.h" 29#include "regex_test_lib.h"
30#include "regex_internal.h" 30#include "regex_internal.h"
31 31
32enum Match_Result { 32enum Match_Result
33{
33 match = 0, 34 match = 0,
34 nomatch = 1 35 nomatch = 1
35}; 36};
36 37
37struct Regex_String_Pair { 38struct Regex_String_Pair
39{
38 char *regex; 40 char *regex;
39 int string_count; 41 int string_count;
40 char *strings[20]; 42 char *strings[20];
@@ -55,8 +57,8 @@ struct Regex_String_Pair {
55 * @return 0 on success, non 0 otherwise. 57 * @return 0 on success, non 0 otherwise.
56 */ 58 */
57int 59int
58test_random(unsigned int rx_length, unsigned int max_str_len, 60test_random (unsigned int rx_length, unsigned int max_str_len,
59 unsigned int str_count) 61 unsigned int str_count)
60{ 62{
61 unsigned int i; 63 unsigned int i;
62 char *rand_rx; 64 char *rand_rx;
@@ -73,108 +75,112 @@ test_random(unsigned int rx_length, unsigned int max_str_len,
73 char *canonical_regex = NULL; 75 char *canonical_regex = NULL;
74 76
75 /* At least one string is needed for matching */ 77 /* At least one string is needed for matching */
76 GNUNET_assert(str_count > 0); 78 GNUNET_assert (str_count > 0);
77 /* The string should be at least as long as the regex itself */ 79 /* The string should be at least as long as the regex itself */
78 GNUNET_assert(max_str_len >= rx_length); 80 GNUNET_assert (max_str_len >= rx_length);
79 81
80 /* Generate random regex and a string that matches the regex */ 82 /* Generate random regex and a string that matches the regex */
81 matching_str = GNUNET_malloc(rx_length + 1); 83 matching_str = GNUNET_malloc (rx_length + 1);
82 rand_rx = REGEX_TEST_generate_random_regex(rx_length, matching_str); 84 rand_rx = REGEX_TEST_generate_random_regex (rx_length, matching_str);
83 85
84 /* Now match */ 86 /* Now match */
85 result = 0; 87 result = 0;
86 for (i = 0; i < str_count; i++) 88 for (i = 0; i < str_count; i++)
89 {
90 if (0 < i)
91 {
92 matching_str = REGEX_TEST_generate_random_string (max_str_len);
93 }
94
95 /* Match string using DFA */
96 dfa = REGEX_INTERNAL_construct_dfa (rand_rx, strlen (rand_rx), 0);
97 if (NULL == dfa)
87 { 98 {
88 if (0 < i) 99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
89 { 100 goto error;
90 matching_str = REGEX_TEST_generate_random_string(max_str_len); 101 }
91 } 102
92 103 eval = REGEX_INTERNAL_eval (dfa, matching_str);
93 /* Match string using DFA */ 104 /* save the canonical regex for later comparison */
94 dfa = REGEX_INTERNAL_construct_dfa(rand_rx, strlen(rand_rx), 0); 105 canonical_regex = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (dfa));
95 if (NULL == dfa) 106 REGEX_INTERNAL_automaton_destroy (dfa);
96 { 107
97 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n"); 108 /* Match string using glibc regex */
98 goto error; 109 if (0 != regcomp (&rx, rand_rx, REG_EXTENDED))
99 } 110 {
100 111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
101 eval = REGEX_INTERNAL_eval(dfa, matching_str); 112 "Could not compile regex using regcomp: %s\n", rand_rx);
102 /* save the canonical regex for later comparison */ 113 goto error;
103 canonical_regex = GNUNET_strdup(REGEX_INTERNAL_get_canonical_regex(dfa)); 114 }
104 REGEX_INTERNAL_automaton_destroy(dfa); 115
105 116 eval_check = regexec (&rx, matching_str, 1, matchptr, 0);
106 /* Match string using glibc regex */ 117 regfree (&rx);
107 if (0 != regcomp(&rx, rand_rx, REG_EXTENDED)) 118
108 { 119 /* We only want to match the whole string, because that's what our DFA does,
109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 120 * too. */
110 "Could not compile regex using regcomp: %s\n", rand_rx); 121 if ((eval_check == 0) &&
111 goto error; 122 ((matchptr[0].rm_so != 0) ||(matchptr[0].rm_eo != strlen (
112 } 123 matching_str)) ))
113 124 eval_check = 1;
114 eval_check = regexec(&rx, matching_str, 1, matchptr, 0); 125
115 regfree(&rx); 126 /* Match canonical regex */
116 127 dfa =
117 /* We only want to match the whole string, because that's what our DFA does, 128 REGEX_INTERNAL_construct_dfa (canonical_regex, strlen (canonical_regex),
118 * too. */ 129 0);
119 if (eval_check == 0 && 130 if (NULL == dfa)
120 (matchptr[0].rm_so != 0 || matchptr[0].rm_eo != strlen(matching_str))) 131 {
121 eval_check = 1; 132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
122 133 goto error;
123 /* Match canonical regex */ 134 }
124 dfa = 135
125 REGEX_INTERNAL_construct_dfa(canonical_regex, strlen(canonical_regex), 136 eval_canonical = REGEX_INTERNAL_eval (dfa, matching_str);
126 0); 137 REGEX_INTERNAL_automaton_destroy (dfa);
127 if (NULL == dfa) 138
128 { 139 if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED))
129 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n"); 140 {
130 goto error; 141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
131 } 142 "Could not compile regex using regcomp: %s\n",
132 143 canonical_regex);
133 eval_canonical = REGEX_INTERNAL_eval(dfa, matching_str); 144 goto error;
134 REGEX_INTERNAL_automaton_destroy(dfa); 145 }
135 146
136 if (0 != regcomp(&rx, canonical_regex, REG_EXTENDED)) 147 eval_canonical_check = regexec (&rx, matching_str, 1, matchptr, 0);
137 { 148 regfree (&rx);
138 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 149
139 "Could not compile regex using regcomp: %s\n", 150 /* We only want to match the whole string, because that's what our DFA does,
140 canonical_regex); 151 * too. */
141 goto error; 152 if ((eval_canonical_check == 0) &&
142 } 153 ((matchptr[0].rm_so != 0) ||(matchptr[0].rm_eo != strlen (
143 154 matching_str)) ))
144 eval_canonical_check = regexec(&rx, matching_str, 1, matchptr, 0); 155 eval_canonical_check = 1;
145 regfree(&rx); 156
146 157 /* compare results */
147 /* We only want to match the whole string, because that's what our DFA does, 158 if ((eval_check != eval) ||(eval_canonical != eval_canonical_check) )
148 * too. */ 159 {
149 if (eval_canonical_check == 0 && 160 regerror (eval_check, &rx, error, sizeof error);
150 (matchptr[0].rm_so != 0 || matchptr[0].rm_eo != strlen(matching_str))) 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
151 eval_canonical_check = 1; 162 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n\
152
153 /* compare results */
154 if (eval_check != eval || eval_canonical != eval_canonical_check)
155 {
156 regerror(eval_check, &rx, error, sizeof error);
157 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Unexpected result:\nregex: %s\ncanonical_regex: %s\n\
158 string: %s\ngnunet regex: %i\nglibc regex: %i\n\ 163 string: %s\ngnunet regex: %i\nglibc regex: %i\n\
159 canonical regex: %i\ncanonical regex glibc: %i\n\ 164 canonical regex: %i\ncanonical regex glibc: %i\n\
160 glibc error: %s\n\n", rand_rx, canonical_regex, matching_str, 165 glibc error: %s\n\n", rand_rx, canonical_regex, matching_str,
161 eval, eval_check, eval_canonical, eval_canonical_check, error); 166 eval, eval_check, eval_canonical, eval_canonical_check,
162 result += 1; 167 error);
163 } 168 result += 1;
164 GNUNET_free(canonical_regex);
165 GNUNET_free(matching_str);
166 canonical_regex = NULL;
167 matching_str = NULL;
168 } 169 }
170 GNUNET_free (canonical_regex);
171 GNUNET_free (matching_str);
172 canonical_regex = NULL;
173 matching_str = NULL;
174 }
169 175
170 GNUNET_free(rand_rx); 176 GNUNET_free (rand_rx);
171 177
172 return result; 178 return result;
173 179
174error: 180error:
175 GNUNET_free_non_null(matching_str); 181 GNUNET_free_non_null (matching_str);
176 GNUNET_free_non_null(rand_rx); 182 GNUNET_free_non_null (rand_rx);
177 GNUNET_free_non_null(canonical_regex); 183 GNUNET_free_non_null (canonical_regex);
178 return -1; 184 return -1;
179} 185}
180 186
@@ -191,8 +197,8 @@ error:
191 * @return 0 on successfull, non 0 otherwise 197 * @return 0 on successfull, non 0 otherwise
192 */ 198 */
193int 199int
194test_automaton(struct REGEX_INTERNAL_Automaton *a, regex_t * rx, 200test_automaton (struct REGEX_INTERNAL_Automaton *a, regex_t *rx,
195 struct Regex_String_Pair *rxstr) 201 struct Regex_String_Pair *rxstr)
196{ 202{
197 int result; 203 int result;
198 int eval; 204 int eval;
@@ -202,48 +208,49 @@ test_automaton(struct REGEX_INTERNAL_Automaton *a, regex_t * rx,
202 int i; 208 int i;
203 209
204 if (NULL == a) 210 if (NULL == a)
205 { 211 {
206 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Automaton was NULL\n"); 212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Automaton was NULL\n");
207 return 1; 213 return 1;
208 } 214 }
209 215
210 result = 0; 216 result = 0;
211 217
212 for (i = 0; i < rxstr->string_count; i++) 218 for (i = 0; i < rxstr->string_count; i++)
219 {
220 eval = REGEX_INTERNAL_eval (a, rxstr->strings[i]);
221 eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0);
222
223 /* We only want to match the whole string, because that's what our DFA does,
224 * too. */
225 if ((eval_check == 0) &&
226 ((matchptr[0].rm_so != 0) ||
227 (matchptr[0].rm_eo != strlen (rxstr->strings[i])) ))
228 eval_check = 1;
229
230 if (((rxstr->expected_results[i] == match) && ((0 != eval) ||(0 !=
231 eval_check) ))
232 || ((rxstr->expected_results[i] == nomatch) &&
233 ((0 == eval) ||(0 == eval_check) )))
213 { 234 {
214 eval = REGEX_INTERNAL_eval(a, rxstr->strings[i]); 235 result = 1;
215 eval_check = regexec(rx, rxstr->strings[i], 1, matchptr, 0); 236 regerror (eval_check, rx, error, sizeof error);
216 237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 /* We only want to match the whole string, because that's what our DFA does, 238 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n"
218 * too. */ 239 "string: %s\nexpected result: %i\n"
219 if (eval_check == 0 && 240 "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
220 (matchptr[0].rm_so != 0 || 241 "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
221 matchptr[0].rm_eo != strlen(rxstr->strings[i]))) 242 REGEX_INTERNAL_get_canonical_regex (a), rxstr->strings[i],
222 eval_check = 1; 243 rxstr->expected_results[i], eval, eval_check, error,
223 244 matchptr[0].rm_so, matchptr[0].rm_eo);
224 if ((rxstr->expected_results[i] == match && (0 != eval || 0 != eval_check))
225 || (rxstr->expected_results[i] == nomatch &&
226 (0 == eval || 0 == eval_check)))
227 {
228 result = 1;
229 regerror(eval_check, rx, error, sizeof error);
230 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
231 "Unexpected result:\nregex: %s\ncanonical_regex: %s\n"
232 "string: %s\nexpected result: %i\n"
233 "gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
234 "rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
235 REGEX_INTERNAL_get_canonical_regex(a), rxstr->strings[i],
236 rxstr->expected_results[i], eval, eval_check, error,
237 matchptr[0].rm_so, matchptr[0].rm_eo);
238 }
239 } 245 }
246 }
240 return result; 247 return result;
241} 248}
242 249
243int 250int
244main(int argc, char *argv[]) 251main (int argc, char *argv[])
245{ 252{
246 GNUNET_log_setup("test-regex", "WARNING", NULL); 253 GNUNET_log_setup ("test-regex", "WARNING", NULL);
247 254
248 struct REGEX_INTERNAL_Automaton *a; 255 struct REGEX_INTERNAL_Automaton *a;
249 regex_t rx; 256 regex_t rx;
@@ -270,15 +277,24 @@ main(int argc, char *argv[])
270 { "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", 1, 277 { "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", 1,
271 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" }, 278 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
272 { nomatch } }, 279 { nomatch } },
273 { "k|a+X*y+c|Q*e|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*g|N+V|t+L|P*j*3*9+X*h*J|J*6|b|E*i*f*R+S|Z|R|Y*Z|g*", 1, 280 {
281 "k|a+X*y+c|Q*e|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*g|N+V|t+L|P*j*3*9+X*h*J|J*6|b|E*i*f*R+S|Z|R|Y*Z|g*",
282 1,
274 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" }, 283 { "kaXycQepRZKyRwY6nhkwVFWBegNVtLPj39XhJJ6bEifRSZRYZg" },
275 { nomatch } }, 284 { nomatch }
276 { "F?W+m+2*6*c*s|P?U?a|B|y*i+t+A|V|6*C*7*e?Z*n*i|J?5+g?W*V?7*j?p?1|r?B?C+E+3+6*i+W*P?K?0|D+7?y*m+3?g?K?", 1, 285 },
286 {
287 "F?W+m+2*6*c*s|P?U?a|B|y*i+t+A|V|6*C*7*e?Z*n*i|J?5+g?W*V?7*j?p?1|r?B?C+E+3+6*i+W*P?K?0|D+7?y*m+3?g?K?",
288 1,
277 { "osfjsodfonONONOnosndfsdnfsd" }, 289 { "osfjsodfonONONOnosndfsdnfsd" },
278 { nomatch } }, 290 { nomatch }
279 { "V|M*o?x*p*d+h+b|E*m?h?Y*E*O?W*W*P+o?Z+H*M|I*q+C*a+5?5*9|b?z|G*y*k?R|p+u|8*h?B+l*H|e|L*O|1|F?v*0?5|C+", 1, 291 },
292 {
293 "V|M*o?x*p*d+h+b|E*m?h?Y*E*O?W*W*P+o?Z+H*M|I*q+C*a+5?5*9|b?z|G*y*k?R|p+u|8*h?B+l*H|e|L*O|1|F?v*0?5|C+",
294 1,
280 { "VMoxpdhbEmhYEOWWPoZHMIqCa559bzGykRpu8hBlHeLO1Fv05C" }, 295 { "VMoxpdhbEmhYEOWWPoZHMIqCa559bzGykRpu8hBlHeLO1Fv05C" },
281 { nomatch } }, 296 { nomatch }
297 },
282 { "(bla)*", 8, 298 { "(bla)*", 8,
283 { "", "bla", "blabla", "bl", "la", "b", "l", "a" }, 299 { "", "bla", "blabla", "bl", "la", "b", "l", "a" },
284 { match, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } }, 300 { match, match, match, nomatch, nomatch, nomatch, nomatch, nomatch } },
@@ -314,11 +330,13 @@ main(int argc, char *argv[])
314 { "a()b", 1, 330 { "a()b", 1,
315 { "ab" }, 331 { "ab" },
316 { match } }, 332 { match } },
317 { "GNVPN-0001-PAD(001110101001001010(0|1)*|001110101001001010000(0|1)*|001110101001001010001(0|1)*|001110101001001010010(0|1)*|001110101001001010011(0|1)*|001110101001001010100(0|1)*|001110101001001010101(0|1)*|001110101001001010110(0|1)*|001110101001001010111(0|1)*|0011101010110110(0|1)*|001110101011011000000(0|1)*|001110101011011000001(0|1)*|001110101011011000010(0|1)*|001110101011011000011(0|1)*|001110101011011000100(0|1)*|001110101011011000101(0|1)*|001110101011011000110(0|1)*|001110101011011000111(0|1)*|001110101011011001000(0|1)*|001110101011011001001(0|1)*|001110101011011001010(0|1)*|001110101011011001011(0|1)*|001110101011011001100(0|1)*|001110101011011001101(0|1)*|001110101011011001110(0|1)*|001110101011011001111(0|1)*|001110101011011010000(0|1)*|001110101011011010001(0|1)*|001110101011011010010(0|1)*|001110101011011010011(0|1)*|001110101011011010100(0|1)*|001110101011011010101(0|1)*|001110101011011010110(0|1)*|001110101011011010111(0|1)*|001110101011011011000(0|1)*|001110101011011011001(0|1)*|001110101011011011010(0|1)*|001110101011011011011(0|1)*|001110101011011011100(0|1)*|001110101011011011101(0|1)*|001110101011011011110(0|1)*|001110101011011011111(0|1)*|0011101110111101(0|1)*|001110111011110100000(0|1)*|001110111011110100001(0|1)*|001110111011110100010(0|1)*|001110111011110100011(0|1)*|001110111011110100100(0|1)*|001110111011110100101(0|1)*|001110111011110100110(0|1)*|001110111011110100111(0|1)*|001110111011110101000(0|1)*|001110111011110101001(0|1)*|001110111011110101010(0|1)*|001110111011110101011(0|1)*|001110111011110101100(0|1)*|001110111011110101101(0|1)*|001110111011110101110(0|1)*|001110111011110101111(0|1)*|001110111011110110000(0|1)*|001110111011110110001(0|1)*|001110111011110110010(0|1)*|001110111011110110011(0|1)*|001110111011110110100(0|1)*|001110111011110110101(0|1)*|001110111011110110110(0|1)*|001110111011110110111(0|1)*|001110111011110111000(0|1)*|001110111011110111001(0|1)*|001110111011110111010(0|1)*|001110111011110111011(0|1)*|001110111011110111100(0|1)*|001110111011110111101(0|1)*|001110111011110111110(0|1)*|0111010001010110(0|1)*|011101000101011000000(0|1)*|011101000101011000001(0|1)*|011101000101011000010(0|1)*|011101000101011000011(0|1)*|011101000101011000100(0|1)*|011101000101011000101(0|1)*|011101000101011000110(0|1)*|011101000101011000111(0|1)*|011101000101011001000(0|1)*|011101000101011001001(0|1)*|011101000101011001010(0|1)*|011101000101011001011(0|1)*|011101000101011001100(0|1)*|011101000101011001101(0|1)*|011101000101011001110(0|1)*|011101000101011001111(0|1)*|011101000101011010000(0|1)*|011101000101011010001(0|1)*|011101000101011010010(0|1)*|011101000101011010011(0|1)*|011101000101011010100(0|1)*|011101000101011010101(0|1)*|011101000101011010110(0|1)*|011101000101011010111(0|1)*|011101000101011011000(0|1)*|011101000101011011001(0|1)*|011101000101011011010(0|1)*|011101000101011011011(0|1)*|011101000101011011100(0|1)*|011101000101011011101(0|1)*|011101000101011011110(0|1)*|011101000101011011111(0|1)*|0111010001010111(0|1)*|011101000101011100000(0|1)*|011101000101011100001(0|1)*|011101000101011100010(0|1)*|011101000101011100011(0|1)*|011101000101011100100(0|1)*|011101000101011100101(0|1)*|011101000101011100110(0|1)*|011101000101011100111(0|1)*|011101000101011101000(0|1)*|011101000101011101001(0|1)*|011101000101011101010(0|1)*|011101000101011101011(0|1)*|011101000101011101100(0|1)*|011101000101011101101(0|1)*|011101000101011101110(0|1)*|011101000101011101111(0|1)*|011101000101011110000(0|1)*|011101000101011110001(0|1)*|011101000101011110010(0|1)*|011101000101011110011(0|1)*|011101000101011110100(0|1)*|011101000101011110101(0|1)*|011101000101011110110(0|1)*|011101000101011110111(0|1)*|011101000101011111000(0|1)*|011101000101011111001(0|1)*|011101000101011111010(0|1)*|011101000101011111011(0|1)*|011101000101011111100(0|1)*|011101000101011111101(0|1)*|011101000101011111110(0|1)*|011101000101011111111(0|1)*|0111010001011000(0|1)*|011101000101100000000(0|1)*|011101000101100000001(0|1)*|011101000101100000010(0|1)*|011101000101100000011(0|1)*|011101000101100000100(0|1)*|011101000101100000101(0|1)*|011101000101100000110(0|1)*|011101000101100000111(0|1)*|011101000101100001000(0|1)*|011101000101100001001(0|1)*|011101000101100001010(0|1)*|011101000101100001011(0|1)*|011101000101100001100(0|1)*|011101000101100001101(0|1)*|011101000101100001110(0|1)*|011101000101100001111(0|1)*|011101000101100010000(0|1)*|011101000101100010001(0|1)*|011101000101100010010(0|1)*|011101000101100010011(0|1)*|011101000101100010100(0|1)*|011101000101100010101(0|1)*|011101000101100010110(0|1)*|011101000101100010111(0|1)*|011101000101100011000(0|1)*|011101000101100011001(0|1)*|011101000101100011010(0|1)*|011101000101100011011(0|1)*|011101000101100011100(0|1)*|011101000101100011101(0|1)*|011101000101100011110(0|1)*|011101000101100011111(0|1)*|01110100010110010(0|1)*|011101000101100100000(0|1)*|011101000101100100001(0|1)*|011101000101100100010(0|1)*|011101000101100100011(0|1)*|011101000101100100100(0|1)*|011101000101100100101(0|1)*|011101000101100100110(0|1)*|011101000101100100111(0|1)*|011101000101100101000(0|1)*|011101000101100101001(0|1)*|011101000101100101010(0|1)*|011101000101100101011(0|1)*|011101000101100101100(0|1)*|011101000101100101101(0|1)*|011101000101100101110(0|1)*|011101000101100101111(0|1)*|011101000101100101111000(0|1)*|1100101010011100(0|1)*|110010101001110000000(0|1)*|110010101001110000000001(0|1)*|110010101001110000000010(0|1)*|110010101001110000000110(0|1)*|110010101001110000001(0|1)*|110010101001110000001000(0|1)*|110010101001110000001001(0|1)*|110010101001110000001010(0|1)*|110010101001110000001011(0|1)*|110010101001110000001101(0|1)*|110010101001110000001110(0|1)*|110010101001110000010(0|1)*|110010101001110000011(0|1)*|110010101001110000100(0|1)*|110010101001110000101(0|1)*|110010101001110000110(0|1)*|110010101001110000111(0|1)*|110010101001110001000(0|1)*|110010101001110001001(0|1)*|110010101001110001010(0|1)*|110010101001110001011(0|1)*|110010101001110001100(0|1)*|110010101001110001101(0|1)*|110010101001110001110(0|1)*|110010101001110001111(0|1)*|110010101001110010000(0|1)*|110010101001110010001(0|1)*|110010101001110010010(0|1)*|110010101001110010011(0|1)*|110010101001110010100(0|1)*|110010101001110010101(0|1)*|110010101001110010110(0|1)*|110010101001110010111(0|1)*|110010101001110011000(0|1)*|110010101001110011001(0|1)*|110010101001110011010(0|1)*|110010101001110011011(0|1)*|110010101001110011100(0|1)*|110010101001110011101(0|1)*|110010101001110011110(0|1)*|110010101001110011111(0|1)*|1101101010111010(0|1)*|110110101011101000000(0|1)*|110110101011101000000001(0|1)*|110110101011101000001000(0|1)*|110110101011101000001001(0|1)*|110110101011101000001010(0|1)*|110110101011101000001011(0|1)*|110110101011101000001100(0|1)*|110110101011101000001110(0|1)*|110110101011101000001111(0|1)*|110110101011101000010(0|1)*|110110101011101000010000(0|1)*|110110101011101000010001(0|1)*|110110101011101000010010(0|1)*|110110101011101000010011(0|1)*|110110101011101000011(0|1)*|110110101011101000100(0|1)*|110110101011101000101(0|1)*|110110101011101000110(0|1)*|110110101011101000111(0|1)*|110110101011101001000(0|1)*|110110101011101001001(0|1)*|110110101011101001010(0|1)*|110110101011101001011(0|1)*|110110101011101001100(0|1)*|110110101011101001101(0|1)*|110110101011101001110(0|1)*|110110101011101001111(0|1)*|110110101011101010000(0|1)*|110110101011101010001(0|1)*|110110101011101010010(0|1)*|110110101011101010011(0|1)*|110110101011101010100(0|1)*|110110101011101010101(0|1)*|110110101011101010110(0|1)*|110110101011101010111(0|1)*|110110101011101011000(0|1)*|110110101011101011001(0|1)*|110110101011101011010(0|1)*|110110101011101011011(0|1)*|110110101011101011100(0|1)*|110110101011101011101(0|1)*|110110101011101011110(0|1)*|110110101011101011111(0|1)*|1101101011010100(0|1)*|110110101101010000000(0|1)*|110110101101010000001(0|1)*|110110101101010000010(0|1)*|110110101101010000011(0|1)*|110110101101010000100(0|1)*|110110101101010000101(0|1)*|110110101101010000110(0|1)*|110110101101010000111(0|1)*|110110101101010001000(0|1)*|110110101101010001001(0|1)*|110110101101010001010(0|1)*|110110101101010001011(0|1)*|110110101101010001100(0|1)*|110110101101010001101(0|1)*|110110101101010001110(0|1)*|110110101101010001111(0|1)*|110110101101010010000(0|1)*|110110101101010010001(0|1)*|110110101101010010010(0|1)*|110110101101010010011(0|1)*|110110101101010010100(0|1)*|1101101011010100101000(0|1)*|110110101101010010101(0|1)*|110110101101010010110(0|1)*|110110101101010010111(0|1)*|110110101101010011000(0|1)*|110110101101010011010(0|1)*|110110101101010011011(0|1)*|110110101101010011100(0|1)*|110110101101010011101(0|1)*|110110101101010011110(0|1)*|110110101101010011111(0|1)*|1101111010100100(0|1)*|110111101010010000000(0|1)*|110111101010010000001(0|1)*|110111101010010000010(0|1)*|110111101010010000011(0|1)*|110111101010010000100(0|1)*|110111101010010000101(0|1)*|110111101010010000110(0|1)*|110111101010010000111(0|1)*|110111101010010001000(0|1)*|110111101010010001001(0|1)*|110111101010010001010(0|1)*|110111101010010001011(0|1)*|110111101010010001100(0|1)*|110111101010010001101(0|1)*|110111101010010001110(0|1)*|110111101010010001111(0|1)*|110111101010010010000(0|1)*|110111101010010010001(0|1)*|110111101010010010010(0|1)*|110111101010010010011(0|1)*|110111101010010010100(0|1)*|110111101010010010101(0|1)*|110111101010010010110(0|1)*|110111101010010010111(0|1)*|110111101010010011000(0|1)*|110111101010010011001(0|1)*|110111101010010011010(0|1)*|110111101010010011011(0|1)*|110111101010010011100(0|1)*|110111101010010011101(0|1)*|110111101010010011110(0|1)*|110111101010010011111(0|1)*|11011110101001010(0|1)*|110111101010010100000(0|1)*|110111101010010100001(0|1)*|110111101010010100010(0|1)*|110111101010010100011(0|1)*|110111101010010100100(0|1)*|110111101010010100101(0|1)*|110111101010010100110(0|1)*|110111101010010100111(0|1)*|110111101010010101000(0|1)*|110111101010010101001(0|1)*|110111101010010101010(0|1)*|110111101010010101011(0|1)*|110111101010010101100(0|1)*|110111101010010101101(0|1)*|110111101010010101110(0|1)*|110111101010010101111(0|1)*)", 333 {
334 "GNVPN-0001-PAD(001110101001001010(0|1)*|001110101001001010000(0|1)*|001110101001001010001(0|1)*|001110101001001010010(0|1)*|001110101001001010011(0|1)*|001110101001001010100(0|1)*|001110101001001010101(0|1)*|001110101001001010110(0|1)*|001110101001001010111(0|1)*|0011101010110110(0|1)*|001110101011011000000(0|1)*|001110101011011000001(0|1)*|001110101011011000010(0|1)*|001110101011011000011(0|1)*|001110101011011000100(0|1)*|001110101011011000101(0|1)*|001110101011011000110(0|1)*|001110101011011000111(0|1)*|001110101011011001000(0|1)*|001110101011011001001(0|1)*|001110101011011001010(0|1)*|001110101011011001011(0|1)*|001110101011011001100(0|1)*|001110101011011001101(0|1)*|001110101011011001110(0|1)*|001110101011011001111(0|1)*|001110101011011010000(0|1)*|001110101011011010001(0|1)*|001110101011011010010(0|1)*|001110101011011010011(0|1)*|001110101011011010100(0|1)*|001110101011011010101(0|1)*|001110101011011010110(0|1)*|001110101011011010111(0|1)*|001110101011011011000(0|1)*|001110101011011011001(0|1)*|001110101011011011010(0|1)*|001110101011011011011(0|1)*|001110101011011011100(0|1)*|001110101011011011101(0|1)*|001110101011011011110(0|1)*|001110101011011011111(0|1)*|0011101110111101(0|1)*|001110111011110100000(0|1)*|001110111011110100001(0|1)*|001110111011110100010(0|1)*|001110111011110100011(0|1)*|001110111011110100100(0|1)*|001110111011110100101(0|1)*|001110111011110100110(0|1)*|001110111011110100111(0|1)*|001110111011110101000(0|1)*|001110111011110101001(0|1)*|001110111011110101010(0|1)*|001110111011110101011(0|1)*|001110111011110101100(0|1)*|001110111011110101101(0|1)*|001110111011110101110(0|1)*|001110111011110101111(0|1)*|001110111011110110000(0|1)*|001110111011110110001(0|1)*|001110111011110110010(0|1)*|001110111011110110011(0|1)*|001110111011110110100(0|1)*|001110111011110110101(0|1)*|001110111011110110110(0|1)*|001110111011110110111(0|1)*|001110111011110111000(0|1)*|001110111011110111001(0|1)*|001110111011110111010(0|1)*|001110111011110111011(0|1)*|001110111011110111100(0|1)*|001110111011110111101(0|1)*|001110111011110111110(0|1)*|0111010001010110(0|1)*|011101000101011000000(0|1)*|011101000101011000001(0|1)*|011101000101011000010(0|1)*|011101000101011000011(0|1)*|011101000101011000100(0|1)*|011101000101011000101(0|1)*|011101000101011000110(0|1)*|011101000101011000111(0|1)*|011101000101011001000(0|1)*|011101000101011001001(0|1)*|011101000101011001010(0|1)*|011101000101011001011(0|1)*|011101000101011001100(0|1)*|011101000101011001101(0|1)*|011101000101011001110(0|1)*|011101000101011001111(0|1)*|011101000101011010000(0|1)*|011101000101011010001(0|1)*|011101000101011010010(0|1)*|011101000101011010011(0|1)*|011101000101011010100(0|1)*|011101000101011010101(0|1)*|011101000101011010110(0|1)*|011101000101011010111(0|1)*|011101000101011011000(0|1)*|011101000101011011001(0|1)*|011101000101011011010(0|1)*|011101000101011011011(0|1)*|011101000101011011100(0|1)*|011101000101011011101(0|1)*|011101000101011011110(0|1)*|011101000101011011111(0|1)*|0111010001010111(0|1)*|011101000101011100000(0|1)*|011101000101011100001(0|1)*|011101000101011100010(0|1)*|011101000101011100011(0|1)*|011101000101011100100(0|1)*|011101000101011100101(0|1)*|011101000101011100110(0|1)*|011101000101011100111(0|1)*|011101000101011101000(0|1)*|011101000101011101001(0|1)*|011101000101011101010(0|1)*|011101000101011101011(0|1)*|011101000101011101100(0|1)*|011101000101011101101(0|1)*|011101000101011101110(0|1)*|011101000101011101111(0|1)*|011101000101011110000(0|1)*|011101000101011110001(0|1)*|011101000101011110010(0|1)*|011101000101011110011(0|1)*|011101000101011110100(0|1)*|011101000101011110101(0|1)*|011101000101011110110(0|1)*|011101000101011110111(0|1)*|011101000101011111000(0|1)*|011101000101011111001(0|1)*|011101000101011111010(0|1)*|011101000101011111011(0|1)*|011101000101011111100(0|1)*|011101000101011111101(0|1)*|011101000101011111110(0|1)*|011101000101011111111(0|1)*|0111010001011000(0|1)*|011101000101100000000(0|1)*|011101000101100000001(0|1)*|011101000101100000010(0|1)*|011101000101100000011(0|1)*|011101000101100000100(0|1)*|011101000101100000101(0|1)*|011101000101100000110(0|1)*|011101000101100000111(0|1)*|011101000101100001000(0|1)*|011101000101100001001(0|1)*|011101000101100001010(0|1)*|011101000101100001011(0|1)*|011101000101100001100(0|1)*|011101000101100001101(0|1)*|011101000101100001110(0|1)*|011101000101100001111(0|1)*|011101000101100010000(0|1)*|011101000101100010001(0|1)*|011101000101100010010(0|1)*|011101000101100010011(0|1)*|011101000101100010100(0|1)*|011101000101100010101(0|1)*|011101000101100010110(0|1)*|011101000101100010111(0|1)*|011101000101100011000(0|1)*|011101000101100011001(0|1)*|011101000101100011010(0|1)*|011101000101100011011(0|1)*|011101000101100011100(0|1)*|011101000101100011101(0|1)*|011101000101100011110(0|1)*|011101000101100011111(0|1)*|01110100010110010(0|1)*|011101000101100100000(0|1)*|011101000101100100001(0|1)*|011101000101100100010(0|1)*|011101000101100100011(0|1)*|011101000101100100100(0|1)*|011101000101100100101(0|1)*|011101000101100100110(0|1)*|011101000101100100111(0|1)*|011101000101100101000(0|1)*|011101000101100101001(0|1)*|011101000101100101010(0|1)*|011101000101100101011(0|1)*|011101000101100101100(0|1)*|011101000101100101101(0|1)*|011101000101100101110(0|1)*|011101000101100101111(0|1)*|011101000101100101111000(0|1)*|1100101010011100(0|1)*|110010101001110000000(0|1)*|110010101001110000000001(0|1)*|110010101001110000000010(0|1)*|110010101001110000000110(0|1)*|110010101001110000001(0|1)*|110010101001110000001000(0|1)*|110010101001110000001001(0|1)*|110010101001110000001010(0|1)*|110010101001110000001011(0|1)*|110010101001110000001101(0|1)*|110010101001110000001110(0|1)*|110010101001110000010(0|1)*|110010101001110000011(0|1)*|110010101001110000100(0|1)*|110010101001110000101(0|1)*|110010101001110000110(0|1)*|110010101001110000111(0|1)*|110010101001110001000(0|1)*|110010101001110001001(0|1)*|110010101001110001010(0|1)*|110010101001110001011(0|1)*|110010101001110001100(0|1)*|110010101001110001101(0|1)*|110010101001110001110(0|1)*|110010101001110001111(0|1)*|110010101001110010000(0|1)*|110010101001110010001(0|1)*|110010101001110010010(0|1)*|110010101001110010011(0|1)*|110010101001110010100(0|1)*|110010101001110010101(0|1)*|110010101001110010110(0|1)*|110010101001110010111(0|1)*|110010101001110011000(0|1)*|110010101001110011001(0|1)*|110010101001110011010(0|1)*|110010101001110011011(0|1)*|110010101001110011100(0|1)*|110010101001110011101(0|1)*|110010101001110011110(0|1)*|110010101001110011111(0|1)*|1101101010111010(0|1)*|110110101011101000000(0|1)*|110110101011101000000001(0|1)*|110110101011101000001000(0|1)*|110110101011101000001001(0|1)*|110110101011101000001010(0|1)*|110110101011101000001011(0|1)*|110110101011101000001100(0|1)*|110110101011101000001110(0|1)*|110110101011101000001111(0|1)*|110110101011101000010(0|1)*|110110101011101000010000(0|1)*|110110101011101000010001(0|1)*|110110101011101000010010(0|1)*|110110101011101000010011(0|1)*|110110101011101000011(0|1)*|110110101011101000100(0|1)*|110110101011101000101(0|1)*|110110101011101000110(0|1)*|110110101011101000111(0|1)*|110110101011101001000(0|1)*|110110101011101001001(0|1)*|110110101011101001010(0|1)*|110110101011101001011(0|1)*|110110101011101001100(0|1)*|110110101011101001101(0|1)*|110110101011101001110(0|1)*|110110101011101001111(0|1)*|110110101011101010000(0|1)*|110110101011101010001(0|1)*|110110101011101010010(0|1)*|110110101011101010011(0|1)*|110110101011101010100(0|1)*|110110101011101010101(0|1)*|110110101011101010110(0|1)*|110110101011101010111(0|1)*|110110101011101011000(0|1)*|110110101011101011001(0|1)*|110110101011101011010(0|1)*|110110101011101011011(0|1)*|110110101011101011100(0|1)*|110110101011101011101(0|1)*|110110101011101011110(0|1)*|110110101011101011111(0|1)*|1101101011010100(0|1)*|110110101101010000000(0|1)*|110110101101010000001(0|1)*|110110101101010000010(0|1)*|110110101101010000011(0|1)*|110110101101010000100(0|1)*|110110101101010000101(0|1)*|110110101101010000110(0|1)*|110110101101010000111(0|1)*|110110101101010001000(0|1)*|110110101101010001001(0|1)*|110110101101010001010(0|1)*|110110101101010001011(0|1)*|110110101101010001100(0|1)*|110110101101010001101(0|1)*|110110101101010001110(0|1)*|110110101101010001111(0|1)*|110110101101010010000(0|1)*|110110101101010010001(0|1)*|110110101101010010010(0|1)*|110110101101010010011(0|1)*|110110101101010010100(0|1)*|1101101011010100101000(0|1)*|110110101101010010101(0|1)*|110110101101010010110(0|1)*|110110101101010010111(0|1)*|110110101101010011000(0|1)*|110110101101010011010(0|1)*|110110101101010011011(0|1)*|110110101101010011100(0|1)*|110110101101010011101(0|1)*|110110101101010011110(0|1)*|110110101101010011111(0|1)*|1101111010100100(0|1)*|110111101010010000000(0|1)*|110111101010010000001(0|1)*|110111101010010000010(0|1)*|110111101010010000011(0|1)*|110111101010010000100(0|1)*|110111101010010000101(0|1)*|110111101010010000110(0|1)*|110111101010010000111(0|1)*|110111101010010001000(0|1)*|110111101010010001001(0|1)*|110111101010010001010(0|1)*|110111101010010001011(0|1)*|110111101010010001100(0|1)*|110111101010010001101(0|1)*|110111101010010001110(0|1)*|110111101010010001111(0|1)*|110111101010010010000(0|1)*|110111101010010010001(0|1)*|110111101010010010010(0|1)*|110111101010010010011(0|1)*|110111101010010010100(0|1)*|110111101010010010101(0|1)*|110111101010010010110(0|1)*|110111101010010010111(0|1)*|110111101010010011000(0|1)*|110111101010010011001(0|1)*|110111101010010011010(0|1)*|110111101010010011011(0|1)*|110111101010010011100(0|1)*|110111101010010011101(0|1)*|110111101010010011110(0|1)*|110111101010010011111(0|1)*|11011110101001010(0|1)*|110111101010010100000(0|1)*|110111101010010100001(0|1)*|110111101010010100010(0|1)*|110111101010010100011(0|1)*|110111101010010100100(0|1)*|110111101010010100101(0|1)*|110111101010010100110(0|1)*|110111101010010100111(0|1)*|110111101010010101000(0|1)*|110111101010010101001(0|1)*|110111101010010101010(0|1)*|110111101010010101011(0|1)*|110111101010010101100(0|1)*|110111101010010101101(0|1)*|110111101010010101110(0|1)*|110111101010010101111(0|1)*)",
318 2, 335 2,
319 { "GNVPN-0001-PAD1101111010100101011101010101010101", 336 { "GNVPN-0001-PAD1101111010100101011101010101010101",
320 "GNVPN-0001-PAD11001010100111000101101010101" }, 337 "GNVPN-0001-PAD11001010100111000101101010101" },
321 { match, match } } 338 { match, match }
339 }
322 }; 340 };
323 341
324 check_nfa = 0; 342 check_nfa = 0;
@@ -326,39 +344,40 @@ main(int argc, char *argv[])
326 check_rand = 0; 344 check_rand = 0;
327 345
328 for (i = 0; i < 19; i++) 346 for (i = 0; i < 19; i++)
347 {
348 if (0 != regcomp (&rx, rxstr[i].regex, REG_EXTENDED))
329 { 349 {
330 if (0 != regcomp(&rx, rxstr[i].regex, REG_EXTENDED)) 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
331 { 351 "Could not compile regex using regcomp()\n");
332 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 352 return 1;
333 "Could not compile regex using regcomp()\n");
334 return 1;
335 }
336
337 /* NFA test */
338 a = REGEX_INTERNAL_construct_nfa(rxstr[i].regex, strlen(rxstr[i].regex));
339 check_nfa += test_automaton(a, &rx, &rxstr[i]);
340 REGEX_INTERNAL_automaton_destroy(a);
341
342 /* DFA test */
343 a = REGEX_INTERNAL_construct_dfa(rxstr[i].regex, strlen(rxstr[i].regex), 0);
344 check_dfa += test_automaton(a, &rx, &rxstr[i]);
345 check_proof = GNUNET_strdup(REGEX_INTERNAL_get_canonical_regex(a));
346 REGEX_INTERNAL_automaton_destroy(a);
347
348 a = REGEX_INTERNAL_construct_dfa(check_proof, strlen(check_proof), 0);
349 check_dfa += test_automaton(a, &rx, &rxstr[i]);
350 REGEX_INTERNAL_automaton_destroy(a);
351 if (0 != check_dfa)
352 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
353 GNUNET_free_non_null(check_proof);
354
355 regfree(&rx);
356 } 353 }
357 354
355 /* NFA test */
356 a = REGEX_INTERNAL_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
357 check_nfa += test_automaton (a, &rx, &rxstr[i]);
358 REGEX_INTERNAL_automaton_destroy (a);
359
360 /* DFA test */
361 a = REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex),
362 0);
363 check_dfa += test_automaton (a, &rx, &rxstr[i]);
364 check_proof = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (a));
365 REGEX_INTERNAL_automaton_destroy (a);
366
367 a = REGEX_INTERNAL_construct_dfa (check_proof, strlen (check_proof), 0);
368 check_dfa += test_automaton (a, &rx, &rxstr[i]);
369 REGEX_INTERNAL_automaton_destroy (a);
370 if (0 != check_dfa)
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
372 GNUNET_free_non_null (check_proof);
373
374 regfree (&rx);
375 }
376
358 /* Random tests */ 377 /* Random tests */
359 srand(time(NULL)); 378 srand (time (NULL));
360 for (i = 0; i < 20; i++) 379 for (i = 0; i < 20; i++)
361 check_rand += test_random(50, 60, 10); 380 check_rand += test_random (50, 60, 10);
362 381
363 return check_nfa + check_dfa + check_rand; 382 return check_nfa + check_dfa + check_rand;
364} 383}
diff --git a/src/regex/test_regex_graph_api.c b/src/regex/test_regex_graph_api.c
index 356782dec..923bb9f42 100644
--- a/src/regex/test_regex_graph_api.c
+++ b/src/regex/test_regex_graph_api.c
@@ -39,39 +39,39 @@
39 * @return 0 if ok, non 0 on error. 39 * @return 0 if ok, non 0 on error.
40 */ 40 */
41static int 41static int
42filecheck(const char *filename) 42filecheck (const char *filename)
43{ 43{
44 int error = 0; 44 int error = 0;
45 FILE *fp; 45 FILE *fp;
46 46
47 /* Check if file was created and delete it again */ 47 /* Check if file was created and delete it again */
48 if (NULL == (fp = fopen(filename, "r"))) 48 if (NULL == (fp = fopen (filename, "r")))
49 { 49 {
50 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not find graph %s\n", filename); 50 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not find graph %s\n", filename);
51 return 1; 51 return 1;
52 } 52 }
53 53
54 GNUNET_break(0 == fseek(fp, 0L, SEEK_END)); 54 GNUNET_break (0 == fseek (fp, 0L, SEEK_END));
55 if (1 > ftell(fp)) 55 if (1 > ftell (fp))
56 { 56 {
57 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 57 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
58 "Graph writing failed, got empty file (%s)!\n", filename); 58 "Graph writing failed, got empty file (%s)!\n", filename);
59 error = 2; 59 error = 2;
60 } 60 }
61 61
62 GNUNET_assert(0 == fclose(fp)); 62 GNUNET_assert (0 == fclose (fp));
63 63
64 if (!KEEP_FILES) 64 if (! KEEP_FILES)
65 { 65 {
66 if (0 != unlink(filename)) 66 if (0 != unlink (filename))
67 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "unlink", filename); 67 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", filename);
68 } 68 }
69 return error; 69 return error;
70} 70}
71 71
72 72
73int 73int
74main(int argc, char *argv[]) 74main (int argc, char *argv[])
75{ 75{
76 int error; 76 int error;
77 struct REGEX_INTERNAL_Automaton *a; 77 struct REGEX_INTERNAL_Automaton *a;
@@ -93,65 +93,65 @@ main(int argc, char *argv[])
93 "PADPADPADPADPADPabcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd" 93 "PADPADPADPADPADPabcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd"
94 }; 94 };
95 95
96 GNUNET_log_setup("test-regex", "WARNING", NULL); 96 GNUNET_log_setup ("test-regex", "WARNING", NULL);
97 error = 0; 97 error = 0;
98 for (i = 0; i < 12; i++) 98 for (i = 0; i < 12; i++)
99 { 99 {
100 /* Check NFA graph creation */ 100 /* Check NFA graph creation */
101 a = REGEX_INTERNAL_construct_nfa(regex[i], strlen(regex[i])); 101 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
102 REGEX_TEST_automaton_save_graph(a, filename, REGEX_TEST_GRAPH_DEFAULT); 102 REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
103 REGEX_INTERNAL_automaton_destroy(a); 103 REGEX_INTERNAL_automaton_destroy (a);
104 error += filecheck(filename); 104 error += filecheck (filename);
105 105
106 a = REGEX_INTERNAL_construct_nfa(regex[i], strlen(regex[i])); 106 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
107 REGEX_TEST_automaton_save_graph(a, filename, 107 REGEX_TEST_automaton_save_graph (a, filename,
108 REGEX_TEST_GRAPH_DEFAULT | 108 REGEX_TEST_GRAPH_DEFAULT
109 REGEX_TEST_GRAPH_VERBOSE); 109 | REGEX_TEST_GRAPH_VERBOSE);
110 REGEX_INTERNAL_automaton_destroy(a); 110 REGEX_INTERNAL_automaton_destroy (a);
111 error += filecheck(filename); 111 error += filecheck (filename);
112 112
113 a = REGEX_INTERNAL_construct_nfa(regex[i], strlen(regex[i])); 113 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
114 REGEX_TEST_automaton_save_graph(a, filename, 114 REGEX_TEST_automaton_save_graph (a, filename,
115 REGEX_TEST_GRAPH_DEFAULT | 115 REGEX_TEST_GRAPH_DEFAULT
116 REGEX_TEST_GRAPH_COLORING); 116 | REGEX_TEST_GRAPH_COLORING);
117 REGEX_INTERNAL_automaton_destroy(a); 117 REGEX_INTERNAL_automaton_destroy (a);
118 error += filecheck(filename); 118 error += filecheck (filename);
119 119
120 a = REGEX_INTERNAL_construct_nfa(regex[i], strlen(regex[i])); 120 a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
121 REGEX_TEST_automaton_save_graph(a, filename, 121 REGEX_TEST_automaton_save_graph (a, filename,
122 REGEX_TEST_GRAPH_DEFAULT | 122 REGEX_TEST_GRAPH_DEFAULT
123 REGEX_TEST_GRAPH_VERBOSE | 123 | REGEX_TEST_GRAPH_VERBOSE
124 REGEX_TEST_GRAPH_COLORING); 124 | REGEX_TEST_GRAPH_COLORING);
125 REGEX_INTERNAL_automaton_destroy(a); 125 REGEX_INTERNAL_automaton_destroy (a);
126 error += filecheck(filename); 126 error += filecheck (filename);
127 127
128 128
129 /* Check DFA graph creation */ 129 /* Check DFA graph creation */
130 a = REGEX_INTERNAL_construct_dfa(regex[i], strlen(regex[i]), 0); 130 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
131 REGEX_TEST_automaton_save_graph(a, filename, REGEX_TEST_GRAPH_DEFAULT); 131 REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
132 REGEX_INTERNAL_automaton_destroy(a); 132 REGEX_INTERNAL_automaton_destroy (a);
133 error += filecheck(filename); 133 error += filecheck (filename);
134 134
135 a = REGEX_INTERNAL_construct_dfa(regex[i], strlen(regex[i]), 0); 135 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
136 REGEX_TEST_automaton_save_graph(a, filename, 136 REGEX_TEST_automaton_save_graph (a, filename,
137 REGEX_TEST_GRAPH_DEFAULT | 137 REGEX_TEST_GRAPH_DEFAULT
138 REGEX_TEST_GRAPH_VERBOSE); 138 | REGEX_TEST_GRAPH_VERBOSE);
139 REGEX_INTERNAL_automaton_destroy(a); 139 REGEX_INTERNAL_automaton_destroy (a);
140 error += filecheck(filename); 140 error += filecheck (filename);
141 141
142 a = REGEX_INTERNAL_construct_dfa(regex[i], strlen(regex[i]), 0); 142 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
143 REGEX_TEST_automaton_save_graph(a, filename, 143 REGEX_TEST_automaton_save_graph (a, filename,
144 REGEX_TEST_GRAPH_DEFAULT | 144 REGEX_TEST_GRAPH_DEFAULT
145 REGEX_TEST_GRAPH_COLORING); 145 | REGEX_TEST_GRAPH_COLORING);
146 REGEX_INTERNAL_automaton_destroy(a); 146 REGEX_INTERNAL_automaton_destroy (a);
147 error += filecheck(filename); 147 error += filecheck (filename);
148 148
149 149
150 a = REGEX_INTERNAL_construct_dfa(regex[i], strlen(regex[i]), 4); 150 a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 4);
151 REGEX_TEST_automaton_save_graph(a, filename, REGEX_TEST_GRAPH_DEFAULT); 151 REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
152 REGEX_INTERNAL_automaton_destroy(a); 152 REGEX_INTERNAL_automaton_destroy (a);
153 error += filecheck(filename); 153 error += filecheck (filename);
154 } 154 }
155 155
156 return error; 156 return error;
157} 157}
diff --git a/src/regex/test_regex_integration.c b/src/regex/test_regex_integration.c
index b107c6d09..c7a7e38b5 100644
--- a/src/regex/test_regex_integration.c
+++ b/src/regex/test_regex_integration.c
@@ -35,12 +35,13 @@
35/** 35/**
36 * How long until we really give up on a particular testcase portion? 36 * How long until we really give up on a particular testcase portion?
37 */ 37 */
38#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 600) 38#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
39 600)
39 40
40/** 41/**
41 * How long until we give up on any particular operation (and retry)? 42 * How long until we give up on any particular operation (and retry)?
42 */ 43 */
43#define BASE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) 44#define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
44 45
45 46
46static struct GNUNET_REGEX_Announcement *a4; 47static struct GNUNET_REGEX_Announcement *a4;
@@ -57,26 +58,26 @@ static struct GNUNET_SCHEDULER_Task *die_task;
57 58
58 59
59static void 60static void
60end(void *cls) 61end (void *cls)
61{ 62{
62 die_task = NULL; 63 die_task = NULL;
63 GNUNET_REGEX_announce_cancel(a4); 64 GNUNET_REGEX_announce_cancel (a4);
64 a4 = NULL; 65 a4 = NULL;
65 GNUNET_REGEX_search_cancel(s4); 66 GNUNET_REGEX_search_cancel (s4);
66 s4 = NULL; 67 s4 = NULL;
67 GNUNET_REGEX_announce_cancel(a6); 68 GNUNET_REGEX_announce_cancel (a6);
68 a6 = NULL; 69 a6 = NULL;
69 GNUNET_REGEX_search_cancel(s6); 70 GNUNET_REGEX_search_cancel (s6);
70 s6 = NULL; 71 s6 = NULL;
71 ok = 0; 72 ok = 0;
72} 73}
73 74
74 75
75static void 76static void
76end_badly() 77end_badly ()
77{ 78{
78 fprintf(stderr, "%s", "Testcase failed (timeout).\n"); 79 fprintf (stderr, "%s", "Testcase failed (timeout).\n");
79 end(NULL); 80 end (NULL);
80 ok = 1; 81 ok = 1;
81} 82}
82 83
@@ -92,36 +93,36 @@ end_badly()
92 * @param put_path_length Length of the @a put_path. 93 * @param put_path_length Length of the @a put_path.
93 */ 94 */
94static void 95static void
95found_cb(void *cls, 96found_cb (void *cls,
96 const struct GNUNET_PeerIdentity *id, 97 const struct GNUNET_PeerIdentity *id,
97 const struct GNUNET_PeerIdentity *get_path, 98 const struct GNUNET_PeerIdentity *get_path,
98 unsigned int get_path_length, 99 unsigned int get_path_length,
99 const struct GNUNET_PeerIdentity *put_path, 100 const struct GNUNET_PeerIdentity *put_path,
100 unsigned int put_path_length) 101 unsigned int put_path_length)
101{ 102{
102 const char *str = cls; 103 const char *str = cls;
103 static int found; 104 static int found;
104 105
105 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
106 "IPv%s-exit found\n", 107 "IPv%s-exit found\n",
107 str); 108 str);
108 if (0 == strcmp(str, "4")) 109 if (0 == strcmp (str, "4"))
109 found |= 4; 110 found |= 4;
110 if (0 == strcmp(str, "6")) 111 if (0 == strcmp (str, "6"))
111 found |= 2; 112 found |= 2;
112 if ((4 | 2) == found) 113 if ((4 | 2) == found)
113 { 114 {
114 GNUNET_SCHEDULER_cancel(die_task); 115 GNUNET_SCHEDULER_cancel (die_task);
115 die_task = 116 die_task =
116 GNUNET_SCHEDULER_add_now(&end, NULL); 117 GNUNET_SCHEDULER_add_now (&end, NULL);
117 } 118 }
118} 119}
119 120
120 121
121static void 122static void
122run(void *cls, 123run (void *cls,
123 const struct GNUNET_CONFIGURATION_Handle *cfg, 124 const struct GNUNET_CONFIGURATION_Handle *cfg,
124 struct GNUNET_TESTING_Peer *peer) 125 struct GNUNET_TESTING_Peer *peer)
125{ 126{
126 char rxstr4[GNUNET_TUN_IPV4_REGEXLEN]; 127 char rxstr4[GNUNET_TUN_IPV4_REGEXLEN];
127 char rxstr6[GNUNET_TUN_IPV6_REGEXLEN]; 128 char rxstr6[GNUNET_TUN_IPV6_REGEXLEN];
@@ -135,72 +136,74 @@ run(void *cls,
135 struct in6_addr i6; 136 struct in6_addr i6;
136 137
137 die_task = 138 die_task =
138 GNUNET_SCHEDULER_add_delayed(TOTAL_TIMEOUT, 139 GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
139 &end_badly, NULL); 140 &end_badly, NULL);
140 GNUNET_assert(1 == 141 GNUNET_assert (1 ==
141 inet_pton(AF_INET, 142 inet_pton (AF_INET,
142 "127.0.0.1", 143 "127.0.0.1",
143 &i4)); 144 &i4));
144 GNUNET_assert(1 == 145 GNUNET_assert (1 ==
145 inet_pton(AF_INET6, 146 inet_pton (AF_INET6,
146 "::1:5", 147 "::1:5",
147 &i6)); 148 &i6));
148 GNUNET_TUN_ipv4toregexsearch(&i4, 149 GNUNET_TUN_ipv4toregexsearch (&i4,
149 8080, 150 8080,
150 rxstr4); 151 rxstr4);
151 GNUNET_TUN_ipv6toregexsearch(&i6, 152 GNUNET_TUN_ipv6toregexsearch (&i6,
152 8686, 153 8686,
153 rxstr6); 154 rxstr6);
154 GNUNET_asprintf(&ss4, 155 GNUNET_asprintf (&ss4,
155 "%s%s", 156 "%s%s",
156 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 157 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
157 rxstr4); 158 rxstr4);
158 GNUNET_asprintf(&ss6, 159 GNUNET_asprintf (&ss6,
159 "%s%s", 160 "%s%s",
160 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 161 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
161 rxstr6); 162 rxstr6);
162 p4r = GNUNET_TUN_ipv4policy2regex("0.0.0.0/0:!25;"); 163 p4r = GNUNET_TUN_ipv4policy2regex ("0.0.0.0/0:!25;");
163 p6r = GNUNET_TUN_ipv6policy2regex("::/0:!25;"); 164 p6r = GNUNET_TUN_ipv6policy2regex ("::/0:!25;");
164 GNUNET_asprintf(&p4, 165 GNUNET_asprintf (&p4,
165 "%s%s", 166 "%s%s",
166 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 167 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
167 p4r); 168 p4r);
168 GNUNET_asprintf(&p6, 169 GNUNET_asprintf (&p6,
169 "%s%s", 170 "%s%s",
170 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 171 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
171 p6r); 172 p6r);
172 GNUNET_free(p4r); 173 GNUNET_free (p4r);
173 GNUNET_free(p6r); 174 GNUNET_free (p6r);
174 a4 = GNUNET_REGEX_announce(cfg, 175 a4 = GNUNET_REGEX_announce (cfg,
175 p4, 176 p4,
176 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 177 GNUNET_TIME_relative_multiply (
177 5), 178 GNUNET_TIME_UNIT_SECONDS,
178 1); 179 5),
179 a6 = GNUNET_REGEX_announce(cfg, 180 1);
180 p6, 181 a6 = GNUNET_REGEX_announce (cfg,
181 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 182 p6,
182 5), 183 GNUNET_TIME_relative_multiply (
183 1); 184 GNUNET_TIME_UNIT_SECONDS,
184 GNUNET_free(p4); 185 5),
185 GNUNET_free(p6); 186 1);
186 187 GNUNET_free (p4);
187 s4 = GNUNET_REGEX_search(cfg, 188 GNUNET_free (p6);
188 ss4, 189
189 &found_cb, "4"); 190 s4 = GNUNET_REGEX_search (cfg,
190 s6 = GNUNET_REGEX_search(cfg, 191 ss4,
191 ss6, 192 &found_cb, "4");
192 &found_cb, "6"); 193 s6 = GNUNET_REGEX_search (cfg,
193 GNUNET_free(ss4); 194 ss6,
194 GNUNET_free(ss6); 195 &found_cb, "6");
196 GNUNET_free (ss4);
197 GNUNET_free (ss6);
195} 198}
196 199
197 200
198int 201int
199main(int argc, char *argv[]) 202main (int argc, char *argv[])
200{ 203{
201 if (0 != GNUNET_TESTING_peer_run("test-regex-integration", 204 if (0 != GNUNET_TESTING_peer_run ("test-regex-integration",
202 "test_regex_api_data.conf", 205 "test_regex_api_data.conf",
203 &run, NULL)) 206 &run, NULL))
204 return 1; 207 return 1;
205 return ok; 208 return ok;
206} 209}
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c
index 7711a1154..e7ef72b58 100644
--- a/src/regex/test_regex_iterate_api.c
+++ b/src/regex/test_regex_iterate_api.c
@@ -41,7 +41,8 @@
41 41
42static unsigned int transition_counter; 42static unsigned int transition_counter;
43 43
44struct IteratorContext { 44struct IteratorContext
45{
45 int error; 46 int error;
46 int should_save_graph; 47 int should_save_graph;
47 FILE *graph_filep; 48 FILE *graph_filep;
@@ -50,7 +51,8 @@ struct IteratorContext {
50 unsigned int match_count; 51 unsigned int match_count;
51}; 52};
52 53
53struct RegexStringPair { 54struct RegexStringPair
55{
54 char *regex; 56 char *regex;
55 unsigned int string_count; 57 unsigned int string_count;
56 char *strings[20]; 58 char *strings[20];
@@ -58,63 +60,63 @@ struct RegexStringPair {
58 60
59 61
60static void 62static void
61key_iterator(void *cls, const struct GNUNET_HashCode *key, 63key_iterator (void *cls, const struct GNUNET_HashCode *key,
62 const char *proof, 64 const char *proof,
63 int accepting, unsigned int num_edges, 65 int accepting, unsigned int num_edges,
64 const struct REGEX_BLOCK_Edge *edges) 66 const struct REGEX_BLOCK_Edge *edges)
65{ 67{
66 unsigned int i; 68 unsigned int i;
67 struct IteratorContext *ctx = cls; 69 struct IteratorContext *ctx = cls;
68 char *out_str; 70 char *out_str;
69 char *state_id = GNUNET_strdup(GNUNET_h2s(key)); 71 char *state_id = GNUNET_strdup (GNUNET_h2s (key));
70 72
71 GNUNET_assert(NULL != proof); 73 GNUNET_assert (NULL != proof);
72 if (GNUNET_YES == ctx->should_save_graph) 74 if (GNUNET_YES == ctx->should_save_graph)
75 {
76 if (GNUNET_YES == accepting)
77 GNUNET_asprintf (&out_str, "\"%s\" [shape=doublecircle]\n", state_id);
78 else
79 GNUNET_asprintf (&out_str, "\"%s\" [shape=circle]\n", state_id);
80 fwrite (out_str, strlen (out_str), 1, ctx->graph_filep);
81 GNUNET_free (out_str);
82
83 for (i = 0; i < num_edges; i++)
73 { 84 {
74 if (GNUNET_YES == accepting) 85 transition_counter++;
75 GNUNET_asprintf(&out_str, "\"%s\" [shape=doublecircle]\n", state_id); 86 GNUNET_asprintf (&out_str, "\"%s\" -> \"%s\" [label = \"%s (%s)\"]\n",
76 else 87 state_id, GNUNET_h2s (&edges[i].destination),
77 GNUNET_asprintf(&out_str, "\"%s\" [shape=circle]\n", state_id); 88 edges[i].label, proof);
78 fwrite(out_str, strlen(out_str), 1, ctx->graph_filep); 89 fwrite (out_str, strlen (out_str), 1, ctx->graph_filep);
79 GNUNET_free(out_str); 90
80 91 GNUNET_free (out_str);
81 for (i = 0; i < num_edges; i++)
82 {
83 transition_counter++;
84 GNUNET_asprintf(&out_str, "\"%s\" -> \"%s\" [label = \"%s (%s)\"]\n",
85 state_id, GNUNET_h2s(&edges[i].destination),
86 edges[i].label, proof);
87 fwrite(out_str, strlen(out_str), 1, ctx->graph_filep);
88
89 GNUNET_free(out_str);
90 }
91 } 92 }
93 }
92 else 94 else
93 { 95 {
94 for (i = 0; i < num_edges; i++) 96 for (i = 0; i < num_edges; i++)
95 transition_counter++; 97 transition_counter++;
96 } 98 }
97 99
98 for (i = 0; i < ctx->string_count; i++) 100 for (i = 0; i < ctx->string_count; i++)
99 { 101 {
100 if (0 == strcmp(proof, ctx->strings[i])) 102 if (0 == strcmp (proof, ctx->strings[i]))
101 ctx->match_count++; 103 ctx->match_count++;
102 } 104 }
103 105
104 if (GNUNET_OK != REGEX_BLOCK_check_proof(proof, strlen(proof), key)) 106 if (GNUNET_OK != REGEX_BLOCK_check_proof (proof, strlen (proof), key))
105 { 107 {
106 ctx->error++; 108 ctx->error++;
107 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
108 "Proof check failed: proof: %s key: %s\n", proof, state_id); 110 "Proof check failed: proof: %s key: %s\n", proof, state_id);
109 } 111 }
110 GNUNET_free(state_id); 112 GNUNET_free (state_id);
111} 113}
112 114
113 115
114int 116int
115main(int argc, char *argv[]) 117main (int argc, char *argv[])
116{ 118{
117 GNUNET_log_setup("test-regex", "WARNING", NULL); 119 GNUNET_log_setup ("test-regex", "WARNING", NULL);
118 120
119 int error; 121 int error;
120 struct REGEX_INTERNAL_Automaton *dfa; 122 struct REGEX_INTERNAL_Automaton *dfa;
@@ -143,115 +145,117 @@ main(int argc, char *argv[])
143 2, { INITIAL_PADDING "abcd:000", INITIAL_PADDING "abcd:101" } }, 145 2, { INITIAL_PADDING "abcd:000", INITIAL_PADDING "abcd:101" } },
144 { INITIAL_PADDING "(x*|(0|1|2)(a|b|c|d)+)", 2, 146 { INITIAL_PADDING "(x*|(0|1|2)(a|b|c|d)+)", 2,
145 { INITIAL_PADDING "xxxxxxxx", INITIAL_PADDING "0abcdbad" } }, 147 { INITIAL_PADDING "xxxxxxxx", INITIAL_PADDING "0abcdbad" } },
146 { INITIAL_PADDING "(0|1)(0|1)23456789ABC", 1, { INITIAL_PADDING "11234567" } }, 148 { INITIAL_PADDING "(0|1)(0|1)23456789ABC", 1,
149 { INITIAL_PADDING "11234567" } },
147 { INITIAL_PADDING "0*123456789ABC*", 3, 150 { INITIAL_PADDING "0*123456789ABC*", 3,
148 { INITIAL_PADDING "00123456", INITIAL_PADDING "00000000", 151 { INITIAL_PADDING "00123456", INITIAL_PADDING "00000000",
149 INITIAL_PADDING "12345678" } }, 152 INITIAL_PADDING "12345678" } },
150 { INITIAL_PADDING "0123456789A*BC", 1, { INITIAL_PADDING "01234567" } }, 153 { INITIAL_PADDING "0123456789A*BC", 1, { INITIAL_PADDING "01234567" } },
151 { "GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, { "GNUNETVPN000100000IPEX6-" } } 154 { "GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1,
155 { "GNUNETVPN000100000IPEX6-" } }
152 }; 156 };
153 157
154 const char *graph_start_str = "digraph G {\nrankdir=LR\n"; 158 const char *graph_start_str = "digraph G {\nrankdir=LR\n";
155 const char *graph_end_str = "\n}\n"; 159 const char *graph_end_str = "\n}\n";
156 160
157 for (i = 0; i < 13; i++) 161 for (i = 0; i < 13; i++)
162 {
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating DFA for regex %s\n",
164 rxstr[i].regex);
165
166
167 /* Create graph */
168 if (GNUNET_YES == REGEX_INTERNAL_ITERATE_SAVE_DEBUG_GRAPH)
158 { 169 {
159 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iterating DFA for regex %s\n", 170 GNUNET_asprintf (&filename, "iteration_graph_%u.dot", i);
160 rxstr[i].regex); 171 ctx.graph_filep = fopen (filename, "w");
161 172 if (NULL == ctx.graph_filep)
162 173 {
163 /* Create graph */ 174 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
164 if (GNUNET_YES == REGEX_INTERNAL_ITERATE_SAVE_DEBUG_GRAPH) 175 "Could not open file %s for saving iteration graph.\n",
165 { 176 filename);
166 GNUNET_asprintf(&filename, "iteration_graph_%u.dot", i); 177 ctx.should_save_graph = GNUNET_NO;
167 ctx.graph_filep = fopen(filename, "w"); 178 }
168 if (NULL == ctx.graph_filep)
169 {
170 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
171 "Could not open file %s for saving iteration graph.\n",
172 filename);
173 ctx.should_save_graph = GNUNET_NO;
174 }
175 else
176 {
177 ctx.should_save_graph = GNUNET_YES;
178 fwrite(graph_start_str, strlen(graph_start_str), 1, ctx.graph_filep);
179 }
180 GNUNET_free(filename);
181 }
182 else 179 else
183 { 180 {
184 ctx.should_save_graph = GNUNET_NO; 181 ctx.should_save_graph = GNUNET_YES;
185 ctx.graph_filep = NULL; 182 fwrite (graph_start_str, strlen (graph_start_str), 1, ctx.graph_filep);
186 } 183 }
187 184 GNUNET_free (filename);
188 /* Iterate over DFA edges */ 185 }
189 transition_counter = 0; 186 else
190 ctx.string_count = rxstr[i].string_count; 187 {
191 ctx.strings = rxstr[i].strings; 188 ctx.should_save_graph = GNUNET_NO;
192 ctx.match_count = 0; 189 ctx.graph_filep = NULL;
193 dfa =
194 REGEX_INTERNAL_construct_dfa(rxstr[i].regex, strlen(rxstr[i].regex), 0);
195 REGEX_INTERNAL_iterate_all_edges(dfa, key_iterator, &ctx);
196 num_transitions =
197 REGEX_INTERNAL_get_transition_count(dfa) - dfa->start->transition_count;
198
199 if (transition_counter < num_transitions)
200 {
201 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
202 "Automaton has %d transitions, iterated over %d transitions\n",
203 num_transitions, transition_counter);
204 error += 1;
205 }
206
207 if (ctx.match_count < ctx.string_count)
208 {
209 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
210 "Missing initial states for regex %s\n", rxstr[i].regex);
211 error += (ctx.string_count - ctx.match_count);
212 }
213 else if (ctx.match_count > ctx.string_count)
214 {
215 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
216 "Duplicate initial transitions for regex %s\n",
217 rxstr[i].regex);
218 error += (ctx.string_count - ctx.match_count);
219 }
220
221 REGEX_INTERNAL_automaton_destroy(dfa);
222
223 /* Finish graph */
224 if (GNUNET_YES == ctx.should_save_graph)
225 {
226 fwrite(graph_end_str, strlen(graph_end_str), 1, ctx.graph_filep);
227 fclose(ctx.graph_filep);
228 ctx.graph_filep = NULL;
229 ctx.should_save_graph = GNUNET_NO;
230 }
231 } 190 }
232 191
192 /* Iterate over DFA edges */
193 transition_counter = 0;
194 ctx.string_count = rxstr[i].string_count;
195 ctx.strings = rxstr[i].strings;
196 ctx.match_count = 0;
197 dfa =
198 REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
199 REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx);
200 num_transitions =
201 REGEX_INTERNAL_get_transition_count (dfa) - dfa->start->transition_count;
202
203 if (transition_counter < num_transitions)
204 {
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 "Automaton has %d transitions, iterated over %d transitions\n",
207 num_transitions, transition_counter);
208 error += 1;
209 }
210
211 if (ctx.match_count < ctx.string_count)
212 {
213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
214 "Missing initial states for regex %s\n", rxstr[i].regex);
215 error += (ctx.string_count - ctx.match_count);
216 }
217 else if (ctx.match_count > ctx.string_count)
218 {
219 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
220 "Duplicate initial transitions for regex %s\n",
221 rxstr[i].regex);
222 error += (ctx.string_count - ctx.match_count);
223 }
224
225 REGEX_INTERNAL_automaton_destroy (dfa);
226
227 /* Finish graph */
228 if (GNUNET_YES == ctx.should_save_graph)
229 {
230 fwrite (graph_end_str, strlen (graph_end_str), 1, ctx.graph_filep);
231 fclose (ctx.graph_filep);
232 ctx.graph_filep = NULL;
233 ctx.should_save_graph = GNUNET_NO;
234 }
235 }
236
233 237
234 for (i = 0; i < 13; i++) 238 for (i = 0; i < 13; i++)
239 {
240 ctx.string_count = rxstr[i].string_count;
241 ctx.strings = rxstr[i].strings;
242 ctx.match_count = 0;
243
244 dfa =
245 REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
246 REGEX_INTERNAL_dfa_add_multi_strides (NULL, dfa, 2);
247 REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx);
248
249 if (ctx.match_count < ctx.string_count)
235 { 250 {
236 ctx.string_count = rxstr[i].string_count; 251 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
237 ctx.strings = rxstr[i].strings; 252 "Missing initial states for regex %s\n", rxstr[i].regex);
238 ctx.match_count = 0; 253 error += (ctx.string_count - ctx.match_count);
239
240 dfa =
241 REGEX_INTERNAL_construct_dfa(rxstr[i].regex, strlen(rxstr[i].regex), 0);
242 REGEX_INTERNAL_dfa_add_multi_strides(NULL, dfa, 2);
243 REGEX_INTERNAL_iterate_all_edges(dfa, key_iterator, &ctx);
244
245 if (ctx.match_count < ctx.string_count)
246 {
247 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
248 "Missing initial states for regex %s\n", rxstr[i].regex);
249 error += (ctx.string_count - ctx.match_count);
250 }
251
252 REGEX_INTERNAL_automaton_destroy(dfa);
253 } 254 }
254 255
256 REGEX_INTERNAL_automaton_destroy (dfa);
257 }
258
255 error += ctx.error; 259 error += ctx.error;
256 260
257 return error; 261 return error;
diff --git a/src/regex/test_regex_proofs.c b/src/regex/test_regex_proofs.c
index 3649ac8aa..8908084b0 100644
--- a/src/regex/test_regex_proofs.c
+++ b/src/regex/test_regex_proofs.c
@@ -40,32 +40,32 @@
40 * @return 0 on success, 1 on failure 40 * @return 0 on success, 1 on failure
41 */ 41 */
42static unsigned int 42static unsigned int
43test_proof(const char *regex) 43test_proof (const char *regex)
44{ 44{
45 unsigned int error; 45 unsigned int error;
46 struct REGEX_INTERNAL_Automaton *dfa; 46 struct REGEX_INTERNAL_Automaton *dfa;
47 char *c_rx1; 47 char *c_rx1;
48 const char *c_rx2; 48 const char *c_rx2;
49 49
50 dfa = REGEX_INTERNAL_construct_dfa(regex, strlen(regex), 1); 50 dfa = REGEX_INTERNAL_construct_dfa (regex, strlen (regex), 1);
51 GNUNET_assert(NULL != dfa); 51 GNUNET_assert (NULL != dfa);
52 c_rx1 = GNUNET_strdup(REGEX_INTERNAL_get_canonical_regex(dfa)); 52 c_rx1 = GNUNET_strdup (REGEX_INTERNAL_get_canonical_regex (dfa));
53 REGEX_INTERNAL_automaton_destroy(dfa); 53 REGEX_INTERNAL_automaton_destroy (dfa);
54 dfa = REGEX_INTERNAL_construct_dfa(c_rx1, strlen(c_rx1), 1); 54 dfa = REGEX_INTERNAL_construct_dfa (c_rx1, strlen (c_rx1), 1);
55 GNUNET_assert(NULL != dfa); 55 GNUNET_assert (NULL != dfa);
56 c_rx2 = REGEX_INTERNAL_get_canonical_regex(dfa); 56 c_rx2 = REGEX_INTERNAL_get_canonical_regex (dfa);
57 57
58 error = (0 == strcmp(c_rx1, c_rx2)) ? 0 : 1; 58 error = (0 == strcmp (c_rx1, c_rx2)) ? 0 : 1;
59 59
60 if (error > 0) 60 if (error > 0)
61 { 61 {
62 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 62 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
63 "Comparing canonical regex of\n%s\nfailed:\n%s\nvs.\n%s\n", 63 "Comparing canonical regex of\n%s\nfailed:\n%s\nvs.\n%s\n",
64 regex, c_rx1, c_rx2); 64 regex, c_rx1, c_rx2);
65 } 65 }
66 66
67 GNUNET_free(c_rx1); 67 GNUNET_free (c_rx1);
68 REGEX_INTERNAL_automaton_destroy(dfa); 68 REGEX_INTERNAL_automaton_destroy (dfa);
69 69
70 return error; 70 return error;
71} 71}
@@ -81,7 +81,7 @@ test_proof(const char *regex)
81 * @return 0 on succes, number of failures otherwise. 81 * @return 0 on succes, number of failures otherwise.
82 */ 82 */
83static unsigned int 83static unsigned int
84test_proofs_random(unsigned int count, size_t rx_length) 84test_proofs_random (unsigned int count, size_t rx_length)
85{ 85{
86 unsigned int i; 86 unsigned int i;
87 char *rand_rx; 87 char *rand_rx;
@@ -90,11 +90,11 @@ test_proofs_random(unsigned int count, size_t rx_length)
90 failures = 0; 90 failures = 0;
91 91
92 for (i = 0; i < count; i++) 92 for (i = 0; i < count; i++)
93 { 93 {
94 rand_rx = REGEX_TEST_generate_random_regex(rx_length, NULL); 94 rand_rx = REGEX_TEST_generate_random_regex (rx_length, NULL);
95 failures += test_proof(rand_rx); 95 failures += test_proof (rand_rx);
96 GNUNET_free(rand_rx); 96 GNUNET_free (rand_rx);
97 } 97 }
98 98
99 return failures; 99 return failures;
100} 100}
@@ -106,7 +106,7 @@ test_proofs_random(unsigned int count, size_t rx_length)
106 * @return 0 on success, number of failures otherwise. 106 * @return 0 on success, number of failures otherwise.
107 */ 107 */
108static unsigned int 108static unsigned int
109test_proofs_static() 109test_proofs_static ()
110{ 110{
111 unsigned int i; 111 unsigned int i;
112 unsigned int error; 112 unsigned int error;
@@ -130,43 +130,44 @@ test_proofs_static()
130 error = 0; 130 error = 0;
131 131
132 for (i = 0; i < 8; i += 2) 132 for (i = 0; i < 8; i += 2)
133 { 133 {
134 dfa1 = REGEX_INTERNAL_construct_dfa(regex[i], strlen(regex[i]), 1); 134 dfa1 = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 1);
135 dfa2 = REGEX_INTERNAL_construct_dfa(regex[i + 1], strlen(regex[i + 1]), 1); 135 dfa2 = REGEX_INTERNAL_construct_dfa (regex[i + 1], strlen (regex[i + 1]),
136 GNUNET_assert(NULL != dfa1); 136 1);
137 GNUNET_assert(NULL != dfa2); 137 GNUNET_assert (NULL != dfa1);
138 138 GNUNET_assert (NULL != dfa2);
139 canon_rx1 = REGEX_INTERNAL_get_canonical_regex(dfa1);
140 canon_rx2 = REGEX_INTERNAL_get_canonical_regex(dfa2);
141 139
142 error += (0 == strcmp(canon_rx1, canon_rx2)) ? 0 : 1; 140 canon_rx1 = REGEX_INTERNAL_get_canonical_regex (dfa1);
141 canon_rx2 = REGEX_INTERNAL_get_canonical_regex (dfa2);
143 142
144 if (error > 0) 143 error += (0 == strcmp (canon_rx1, canon_rx2)) ? 0 : 1;
145 {
146 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
147 "Comparing canonical regex failed:\nrx1:\t%s\ncrx1:\t%s\nrx2:\t%s\ncrx2:\t%s\n",
148 regex[i], canon_rx1, regex[i + 1], canon_rx2);
149 }
150 144
151 REGEX_INTERNAL_automaton_destroy(dfa1); 145 if (error > 0)
152 REGEX_INTERNAL_automaton_destroy(dfa2); 146 {
147 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
148 "Comparing canonical regex failed:\nrx1:\t%s\ncrx1:\t%s\nrx2:\t%s\ncrx2:\t%s\n",
149 regex[i], canon_rx1, regex[i + 1], canon_rx2);
153 } 150 }
154 151
152 REGEX_INTERNAL_automaton_destroy (dfa1);
153 REGEX_INTERNAL_automaton_destroy (dfa2);
154 }
155
155 return error; 156 return error;
156} 157}
157 158
158 159
159int 160int
160main(int argc, char *argv[]) 161main (int argc, char *argv[])
161{ 162{
162 GNUNET_log_setup("test-regex", "WARNING", NULL); 163 GNUNET_log_setup ("test-regex", "WARNING", NULL);
163 164
164 int error; 165 int error;
165 166
166 error = 0; 167 error = 0;
167 168
168 error += test_proofs_static(); 169 error += test_proofs_static ();
169 error += test_proofs_random(100, 30); 170 error += test_proofs_random (100, 30);
170 171
171 return error; 172 return error;
172} 173}