aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/regex/regex.c26
-rw-r--r--src/regex/test_regex_iterate_api.c30
2 files changed, 36 insertions, 20 deletions
diff --git a/src/regex/regex.c b/src/regex/regex.c
index a4126e02d..26ad38d34 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,
2816 struct GNUNET_REGEX_Transition *t; 2816 struct GNUNET_REGEX_Transition *t;
2817 unsigned int num_edges = state->transition_count; 2817 unsigned int num_edges = state->transition_count;
2818 struct GNUNET_REGEX_Edge edges[num_edges]; 2818 struct GNUNET_REGEX_Edge edges[num_edges];
2819 struct GNUNET_REGEX_Edge edge[1];
2819 struct GNUNET_HashCode hash; 2820 struct GNUNET_HashCode hash;
2821 struct GNUNET_HashCode hash_new;
2820 2822
2821 unsigned int cur_len; 2823 unsigned int cur_len;
2822 2824
@@ -2825,9 +2827,8 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len,
2825 else 2827 else
2826 cur_len = 0; 2828 cur_len = 0;
2827 2829
2828 if (cur_len > min_len && NULL != consumed_string) 2830 if (cur_len >= min_len && cur_len > 0 && NULL != consumed_string)
2829 { 2831 {
2830
2831 if (cur_len <= max_len) 2832 if (cur_len <= max_len)
2832 { 2833 {
2833 for (i = 0, t = state->transitions_head; NULL != t && i < num_edges; 2834 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,
2841 iterator (iterator_cls, &hash, consumed_string, state->accepting, 2842 iterator (iterator_cls, &hash, consumed_string, state->accepting,
2842 num_edges, edges); 2843 num_edges, edges);
2843 2844
2844 // Special case for regex consisting of just a string that is shorter than max_len 2845 // Special case for regex consisting of just a string that is shorter than
2846 // max_len
2845 if (GNUNET_YES == state->accepting && cur_len > 1 && 2847 if (GNUNET_YES == state->accepting && cur_len > 1 &&
2846 state->transition_count < 1) 2848 state->transition_count < 1 && cur_len < max_len)
2847 { 2849 {
2848 edges[0].label = &consumed_string[cur_len - 1]; 2850 edge[0].label = &consumed_string[cur_len - 1];
2849 edges[0].destination = state->hash; 2851 edge[0].destination = state->hash;
2850 temp = GNUNET_strdup (consumed_string); 2852 temp = GNUNET_strdup (consumed_string);
2851 temp[cur_len - 1] = '\0'; 2853 temp[cur_len - 1] = '\0';
2852 GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash); 2854 GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new);
2853 iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edges); 2855 iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge);
2854 GNUNET_free (temp); 2856 GNUNET_free (temp);
2855 } 2857 }
2856 } 2858 }
2857 else 2859 else if (max_len < cur_len)
2858 { 2860 {
2859 edges[0].label = &consumed_string[max_len]; 2861 edge[0].label = &consumed_string[max_len];
2860 edges[0].destination = state->hash; 2862 edge[0].destination = state->hash;
2861 temp = GNUNET_strdup (consumed_string); 2863 temp = GNUNET_strdup (consumed_string);
2862 temp[max_len] = '\0'; 2864 temp[max_len] = '\0';
2863 GNUNET_CRYPTO_hash (temp, max_len, &hash); 2865 GNUNET_CRYPTO_hash (temp, max_len, &hash);
2864 iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edges); 2866 iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge);
2865 GNUNET_free (temp); 2867 GNUNET_free (temp);
2866 } 2868 }
2867 } 2869 }
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c
index 84bb6e9fb..37475ee91 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,
85 transition_counter++; 85 transition_counter++;
86 } 86 }
87 87
88 GNUNET_free (state_id);
89
90 for (i = 0; i < ctx->string_count; i++) 88 for (i = 0; i < ctx->string_count; i++)
91 { 89 {
92 if (0 == strcmp (proof, ctx->strings[i])) 90 if (0 == strcmp (proof, ctx->strings[i]))
93 ctx->match_count++; 91 ctx->match_count++;
94 } 92 }
95 93
96 ctx->error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1; 94 if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key))
95 {
96 ctx->error++;
97 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
98 "Proof check failed: proof: %s key: %s\n", proof, state_id);
99 }
100
101 GNUNET_free (state_id);
97} 102}
98 103
99int 104int
@@ -111,12 +116,12 @@ main (int argc, char *argv[])
111 struct GNUNET_REGEX_Automaton *dfa; 116 struct GNUNET_REGEX_Automaton *dfa;
112 unsigned int i; 117 unsigned int i;
113 unsigned int num_transitions; 118 unsigned int num_transitions;
114 struct IteratorContext ctx = { 0, 0, NULL };
115 char *filename = NULL; 119 char *filename = NULL;
120 struct IteratorContext ctx = { 0, 0, NULL, 0, NULL, 0 };
116 121
117 error = 0; 122 error = 0;
118 123
119 const struct RegexStringPair rxstr[10] = { 124 const struct RegexStringPair rxstr[14] = {
120 {"ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, {"abcdcdca", "abcabdbl"}}, 125 {"ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, {"abcdcdca", "abcabdbl"}},
121 {"abcdefghijklmnop*qst", 1, {"abcdefgh"}}, 126 {"abcdefghijklmnop*qst", 1, {"abcdefgh"}},
122 {"VPN-4-1(0|1)*", 2, {"VPN-4-10", "VPN-4-11"}}, 127 {"VPN-4-1(0|1)*", 2, {"VPN-4-10", "VPN-4-11"}},
@@ -128,13 +133,17 @@ main (int argc, char *argv[])
128 {"xyz*", 2, {"xy", "xyz"}}, 133 {"xyz*", 2, {"xy", "xyz"}},
129 {"ab", 1, {"a"}}, 134 {"ab", 1, {"a"}},
130 {"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"}}, 135 {"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"}},
131 {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}} 136 {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}},
137 {"(0|1)(0|1)23456789ABC", 1, {"11234567"}},
138 {"0*123456789ABC*", 3, {"00123456", "00000000", "12345678"}},
139 {"0123456789A*BC", 1, {"01234567"}},
140 {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVP"}}
132 }; 141 };
133 142
134 const char *graph_start_str = "digraph G {\nrankdir=LR\n"; 143 const char *graph_start_str = "digraph G {\nrankdir=LR\n";
135 const char *graph_end_str = "\n}\n"; 144 const char *graph_end_str = "\n}\n";
136 145
137 for (i = 0; i < 10; i++) 146 for (i = 0; i < 14; i++)
138 { 147 {
139 // Create graph 148 // Create graph
140 if (GNUNET_YES == GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH) 149 if (GNUNET_YES == GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH)
@@ -158,6 +167,7 @@ main (int argc, char *argv[])
158 else 167 else
159 { 168 {
160 ctx.should_save_graph = GNUNET_NO; 169 ctx.should_save_graph = GNUNET_NO;
170 ctx.graph_filep = NULL;
161 } 171 }
162 172
163 // Iterate over DFA edges 173 // Iterate over DFA edges
@@ -187,7 +197,7 @@ main (int argc, char *argv[])
187 else if (ctx.match_count > ctx.string_count) 197 else if (ctx.match_count > ctx.string_count)
188 { 198 {
189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
190 "Doublicate initial transitions for regex %s\n", 200 "Duplicate initial transitions for regex %s\n",
191 rxstr[i].regex); 201 rxstr[i].regex);
192 error += (ctx.string_count - ctx.match_count); 202 error += (ctx.string_count - ctx.match_count);
193 } 203 }
@@ -207,6 +217,10 @@ main (int argc, char *argv[])
207 217
208 for (i = 0; i < 10; i++) 218 for (i = 0; i < 10; i++)
209 { 219 {
220 ctx.string_count = rxstr[i].string_count;
221 ctx.strings = rxstr[i].strings;
222 ctx.match_count = 0;
223
210 dfa = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex)); 224 dfa = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex));
211 GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2); 225 GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2);
212 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx); 226 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx);