diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-05-21 11:51:29 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-05-21 11:51:29 +0000 |
commit | 43b524dbd4acad61c41adb9c4e1a5c0394596992 (patch) | |
tree | 18a99b29377d91af252b8a3fd762a3e29101667b /src | |
parent | 49b629963d40bbb0c0ee09f9415aaa821393f2fe (diff) | |
download | gnunet-43b524dbd4acad61c41adb9c4e1a5c0394596992.tar.gz gnunet-43b524dbd4acad61c41adb9c4e1a5c0394596992.zip |
- use lib
Diffstat (limited to 'src')
-rw-r--r-- | src/regex/Makefile.am | 7 | ||||
-rw-r--r-- | src/regex/gnunet-daemon-regexprofiler.c | 68 |
2 files changed, 12 insertions, 63 deletions
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am index e526b9977..4900e5e91 100644 --- a/src/regex/Makefile.am +++ b/src/regex/Makefile.am | |||
@@ -102,11 +102,14 @@ gnunet_regex_profiler_LDADD = \ | |||
102 | $(top_builddir)/src/dht/libgnunetdht.la \ | 102 | $(top_builddir)/src/dht/libgnunetdht.la \ |
103 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 103 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
104 | $(top_builddir)/src/regex/libgnunetregex.la \ | 104 | $(top_builddir)/src/regex/libgnunetregex.la \ |
105 | $(top_builddir)/src/regex/libgnunetregextest.la \ | ||
105 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 106 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
106 | gnunet_regex_profiler_DEPENDENCIES = \ | 107 | gnunet_regex_profiler_DEPENDENCIES = \ |
107 | $(top_builddir)/src/arm/libgnunetarm.la \ | 108 | $(top_builddir)/src/arm/libgnunetarm.la \ |
108 | $(top_builddir)/src/dht/libgnunetdht.la \ | 109 | $(top_builddir)/src/dht/libgnunetdht.la \ |
109 | libgnunetregex.la | 110 | libgnunetregex.la \ |
111 | libgnunetregextest.la | ||
112 | |||
110 | 113 | ||
111 | gnunet_daemon_regexprofiler_SOURCES = \ | 114 | gnunet_daemon_regexprofiler_SOURCES = \ |
112 | gnunet-daemon-regexprofiler.c | 115 | gnunet-daemon-regexprofiler.c |
@@ -114,9 +117,11 @@ gnunet_daemon_regexprofiler_LDADD = \ | |||
114 | $(top_builddir)/src/util/libgnunetutil.la \ | 117 | $(top_builddir)/src/util/libgnunetutil.la \ |
115 | $(top_builddir)/src/dht/libgnunetdht.la \ | 118 | $(top_builddir)/src/dht/libgnunetdht.la \ |
116 | $(top_builddir)/src/regex/libgnunetregex.la \ | 119 | $(top_builddir)/src/regex/libgnunetregex.la \ |
120 | $(top_builddir)/src/regex/libgnunetregextest.la \ | ||
117 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 121 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
118 | gnunet_daemon_regexprofiler_DEPENDENCIES = \ | 122 | gnunet_daemon_regexprofiler_DEPENDENCIES = \ |
119 | $(top_builddir)/src/dht/libgnunetdht.la \ | 123 | $(top_builddir)/src/dht/libgnunetdht.la \ |
124 | libgnunetregextest.la \ | ||
120 | libgnunetregex.la | 125 | libgnunetregex.la |
121 | 126 | ||
122 | 127 | ||
diff --git a/src/regex/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c index 17610992a..88621d882 100644 --- a/src/regex/gnunet-daemon-regexprofiler.c +++ b/src/regex/gnunet-daemon-regexprofiler.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "platform.h" | 30 | #include "platform.h" |
31 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
32 | #include "gnunet_regex_lib.h" | 32 | #include "gnunet_regex_lib.h" |
33 | #include "regex_test_lib.h" | ||
33 | #include "gnunet_dht_service.h" | 34 | #include "gnunet_dht_service.h" |
34 | #include "gnunet_statistics_service.h" | 35 | #include "gnunet_statistics_service.h" |
35 | 36 | ||
@@ -208,66 +209,6 @@ announce_regex (const char * regex) | |||
208 | 209 | ||
209 | 210 | ||
210 | /** | 211 | /** |
211 | * Load regular expressions from filename into 'rxes' array. Array needs to be freed. | ||
212 | * | ||
213 | * @param filename filename of the file containing the regexes, one per line. | ||
214 | * @param rx string with the union of all regular expressions. | ||
215 | * | ||
216 | * @return number of regular expressions read from filename and in rxes array. | ||
217 | * FIXME use load regex lib function | ||
218 | */ | ||
219 | static unsigned int | ||
220 | load_regexes (const char *filename, char **rx) | ||
221 | { | ||
222 | char *data; | ||
223 | char *buf; | ||
224 | uint64_t filesize; | ||
225 | unsigned int offset; | ||
226 | unsigned int rx_cnt; | ||
227 | |||
228 | if (GNUNET_YES != GNUNET_DISK_file_test (policy_filename)) | ||
229 | { | ||
230 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
231 | "Could not find policy file %s\n", policy_filename); | ||
232 | return 0; | ||
233 | } | ||
234 | if (GNUNET_OK != GNUNET_DISK_file_size (policy_filename, &filesize, GNUNET_YES, GNUNET_YES)) | ||
235 | filesize = 0; | ||
236 | if (0 == filesize) | ||
237 | { | ||
238 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Policy file %s is empty.\n", policy_filename); | ||
239 | return 0; | ||
240 | } | ||
241 | data = GNUNET_malloc (filesize); | ||
242 | if (filesize != GNUNET_DISK_fn_read (policy_filename, data, filesize)) | ||
243 | { | ||
244 | GNUNET_free (data); | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not read policy file %s.\n", | ||
246 | policy_filename); | ||
247 | return 0; | ||
248 | } | ||
249 | buf = data; | ||
250 | offset = 0; | ||
251 | rx_cnt = 0; | ||
252 | while (offset < (filesize - 1)) | ||
253 | { | ||
254 | offset++; | ||
255 | if ((data[offset] == '\n') && (buf != &data[offset])) | ||
256 | { | ||
257 | data[offset] = '|'; | ||
258 | buf = &data[offset + 1]; | ||
259 | rx_cnt++; | ||
260 | } | ||
261 | else if ((data[offset] == '\n') || (data[offset] == '\0')) | ||
262 | buf = &data[offset + 1]; | ||
263 | } | ||
264 | data[offset] = '\0'; | ||
265 | *rx = data; | ||
266 | |||
267 | return rx_cnt; | ||
268 | } | ||
269 | |||
270 | /** | ||
271 | * Scan through the policy_dir looking for the n-th filename. | 212 | * Scan through the policy_dir looking for the n-th filename. |
272 | * | 213 | * |
273 | * @param cls Closure (target number n). | 214 | * @param cls Closure (target number n). |
@@ -305,6 +246,7 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
305 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 246 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
306 | { | 247 | { |
307 | char *regex = NULL; | 248 | char *regex = NULL; |
249 | char **components; | ||
308 | char *policy_dir; | 250 | char *policy_dir; |
309 | long long unsigned int peer_id; | 251 | long long unsigned int peer_id; |
310 | 252 | ||
@@ -388,7 +330,7 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
388 | /* Read regexes from policy files */ | 330 | /* Read regexes from policy files */ |
389 | GNUNET_assert (-1 != GNUNET_DISK_directory_scan (policy_dir, &scan, | 331 | GNUNET_assert (-1 != GNUNET_DISK_directory_scan (policy_dir, &scan, |
390 | (void *) (long) peer_id)); | 332 | (void *) (long) peer_id)); |
391 | if (0 == load_regexes (policy_filename, ®ex)) | 333 | if (NULL == (components = GNUNET_REGEX_read_from_file (policy_filename))) |
392 | { | 334 | { |
393 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
394 | "Policy file %s contains no policies. Exiting.\n", | 336 | "Policy file %s contains no policies. Exiting.\n", |
@@ -397,9 +339,11 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
397 | GNUNET_SCHEDULER_shutdown (); | 339 | GNUNET_SCHEDULER_shutdown (); |
398 | return; | 340 | return; |
399 | } | 341 | } |
342 | regex = GNUNET_REGEX_combine (components); | ||
343 | GNUNET_REGEX_free_from_file (components); | ||
400 | 344 | ||
401 | /* Announcing regexes from policy_filename */ | 345 | /* Announcing regexes from policy_filename */ |
402 | GNUNET_asprintf (&rx_with_pfx, "%s(%s)", regex_prefix, regex); | 346 | GNUNET_asprintf (&rx_with_pfx, "%s(%s)(0|1)*", regex_prefix, regex); |
403 | announce_regex (rx_with_pfx); | 347 | announce_regex (rx_with_pfx); |
404 | GNUNET_free (regex); | 348 | GNUNET_free (regex); |
405 | GNUNET_free (rx_with_pfx); | 349 | GNUNET_free (rx_with_pfx); |