diff options
author | szengel <szengel@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-09-26 14:46:32 +0000 |
---|---|---|
committer | szengel <szengel@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-09-26 14:46:32 +0000 |
commit | 2b23b2a341c934d70ca3c87dda2a0670f51f0050 (patch) | |
tree | 61cc7ba0eeb91164544c9fbcdd0a22001e9373f5 /src | |
parent | 3c280f7174883cae2682f39a26d5b120645a0dbc (diff) |
fixes
git-svn-id: https://gnunet.org/svn/gnunet@24019 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src')
-rw-r--r-- | src/regex/regex.c | 26 | ||||
-rw-r--r-- | src/regex/test_regex_iterate_api.c | 30 |
2 files changed, 36 insertions, 20 deletions
diff --git a/src/regex/regex.c b/src/regex/regex.c index a4126e02dd..26ad38d349 100644 --- a/src/regex/regex.c +++ b/src/regex/regex.c @@ -2816,7 +2816,9 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len, struct GNUNET_REGEX_Transition *t; unsigned int num_edges = state->transition_count; struct GNUNET_REGEX_Edge edges[num_edges]; + struct GNUNET_REGEX_Edge edge[1]; struct GNUNET_HashCode hash; + struct GNUNET_HashCode hash_new; unsigned int cur_len; @@ -2825,9 +2827,8 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len, else cur_len = 0; - if (cur_len > min_len && NULL != consumed_string) + if (cur_len >= min_len && cur_len > 0 && NULL != consumed_string) { - if (cur_len <= max_len) { for (i = 0, t = state->transitions_head; NULL != t && i < num_edges; @@ -2841,27 +2842,28 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len, iterator (iterator_cls, &hash, consumed_string, state->accepting, num_edges, edges); - // Special case for regex consisting of just a string that is shorter than max_len + // Special case for regex consisting of just a string that is shorter than + // max_len if (GNUNET_YES == state->accepting && cur_len > 1 && - state->transition_count < 1) + state->transition_count < 1 && cur_len < max_len) { - edges[0].label = &consumed_string[cur_len - 1]; - edges[0].destination = state->hash; + edge[0].label = &consumed_string[cur_len - 1]; + edge[0].destination = state->hash; temp = GNUNET_strdup (consumed_string); temp[cur_len - 1] = '\0'; - GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash); - iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edges); + GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new); + iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge); GNUNET_free (temp); } } - else + else if (max_len < cur_len) { - edges[0].label = &consumed_string[max_len]; - edges[0].destination = state->hash; + edge[0].label = &consumed_string[max_len]; + edge[0].destination = state->hash; temp = GNUNET_strdup (consumed_string); temp[max_len] = '\0'; GNUNET_CRYPTO_hash (temp, max_len, &hash); - iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edges); + iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge); GNUNET_free (temp); } } diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c index 84bb6e9fbf..37475ee91e 100644 --- a/src/regex/test_regex_iterate_api.c +++ b/src/regex/test_regex_iterate_api.c @@ -85,15 +85,20 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, transition_counter++; } - GNUNET_free (state_id); - for (i = 0; i < ctx->string_count; i++) { if (0 == strcmp (proof, ctx->strings[i])) ctx->match_count++; } - ctx->error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1; + if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key)) + { + ctx->error++; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Proof check failed: proof: %s key: %s\n", proof, state_id); + } + + GNUNET_free (state_id); } int @@ -111,12 +116,12 @@ main (int argc, char *argv[]) struct GNUNET_REGEX_Automaton *dfa; unsigned int i; unsigned int num_transitions; - struct IteratorContext ctx = { 0, 0, NULL }; char *filename = NULL; + struct IteratorContext ctx = { 0, 0, NULL, 0, NULL, 0 }; error = 0; - const struct RegexStringPair rxstr[10] = { + const struct RegexStringPair rxstr[14] = { {"ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, {"abcdcdca", "abcabdbl"}}, {"abcdefghijklmnop*qst", 1, {"abcdefgh"}}, {"VPN-4-1(0|1)*", 2, {"VPN-4-10", "VPN-4-11"}}, @@ -128,13 +133,17 @@ main (int argc, char *argv[]) {"xyz*", 2, {"xy", "xyz"}}, {"ab", 1, {"a"}}, {"abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)", 2, {"abcd:000", "abcd:101"}}, - {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}} + {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}}, + {"(0|1)(0|1)23456789ABC", 1, {"11234567"}}, + {"0*123456789ABC*", 3, {"00123456", "00000000", "12345678"}}, + {"0123456789A*BC", 1, {"01234567"}}, + {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVP"}} }; const char *graph_start_str = "digraph G {\nrankdir=LR\n"; const char *graph_end_str = "\n}\n"; - for (i = 0; i < 10; i++) + for (i = 0; i < 14; i++) { // Create graph if (GNUNET_YES == GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH) @@ -158,6 +167,7 @@ main (int argc, char *argv[]) else { ctx.should_save_graph = GNUNET_NO; + ctx.graph_filep = NULL; } // Iterate over DFA edges @@ -187,7 +197,7 @@ main (int argc, char *argv[]) else if (ctx.match_count > ctx.string_count) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Doublicate initial transitions for regex %s\n", + "Duplicate initial transitions for regex %s\n", rxstr[i].regex); error += (ctx.string_count - ctx.match_count); } @@ -207,6 +217,10 @@ main (int argc, char *argv[]) for (i = 0; i < 10; i++) { + ctx.string_count = rxstr[i].string_count; + ctx.strings = rxstr[i].strings; + ctx.match_count = 0; + dfa = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex)); GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2); GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx); |