regex \
mesh \
lockmanager \
- stream \
+ stream \
fs \
$(LINUX_DIR) \
$(MINGW_DIR) \
gnunet_program_lib.h \
gnunet_protocols.h \
gnunet_resolver_service.h \
- gnunet_regex_lib.h \
gnunet_regex_service.h \
gnunet_scheduler_lib.h \
gnunet_server_lib.h \
+++ /dev/null
-/*
- This file is part of GNUnet
- (C) 2012 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/**
- * @file include/gnunet_regex_lib.h
- * @brief library to parse regular expressions into dfa
- * @author Maximilian Szengel
- *
- */
-
-#ifndef GNUNET_REGEX_LIB_H
-#define GNUNET_REGEX_LIB_H
-
-#include "gnunet_util_lib.h"
-#include "gnunet_dht_service.h"
-#include "gnunet_statistics_service.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
-}
-#endif
-#endif
-
-
-/**
- * Constant for how many bytes the initial string regex should have.
- */
-#define GNUNET_REGEX_INITIAL_BYTES 24
-
-
-/**
- * Maximum regex string length for use with GNUNET_REGEX_ipv4toregex
- */
-#define GNUNET_REGEX_IPV4_REGEXLEN 32 + 6
-
-
-/**
- * Maximum regex string length for use with GNUNET_REGEX_ipv6toregex
- */
-#define GNUNET_REGEX_IPV6_REGEXLEN 128 + 6
-
-
-/**
- * Automaton (NFA/DFA) representation.
- */
-struct GNUNET_REGEX_Automaton;
-
-
-/**
- * Edge representation.
- */
-struct GNUNET_REGEX_Edge
-{
- /**
- * Label of the edge. FIXME: might want to not consume exactly multiples of 8 bits, need length?
- */
- const char *label;
-
- /**
- * Destionation of the edge.
- */
- struct GNUNET_HashCode destination;
-};
-
-
-/**
- * Construct DFA for the given 'regex' of length 'len'.
- *
- * Path compression means, that for example a DFA o -> a -> b -> c -> o will be
- * compressed to o -> abc -> o. Note that this parameter influences the
- * non-determinism of states of the resulting NFA in the DHT (number of outgoing
- * edges with the same label). For example for an application that stores IPv4
- * addresses as bitstrings it could make sense to limit the path compression to
- * 4 or 8.
- *
- * @param regex regular expression string.
- * @param len length of the regular expression.
- * @param max_path_len limit the path compression length to the
- * given value. If set to 1, no path compression is applied. Set to 0 for
- * maximal possible path compression (generally not desireable).
- * @return DFA, needs to be freed using GNUNET_REGEX_automaton_destroy.
- */
-struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_dfa (const char *regex, const size_t len,
- unsigned int max_path_len);
-
-
-/**
- * Free the memory allocated by constructing the GNUNET_REGEX_Automaton.
- * data structure.
- *
- * @param a automaton to be destroyed.
- */
-void
-GNUNET_REGEX_automaton_destroy (struct GNUNET_REGEX_Automaton *a);
-
-
-/**
- * Options for graph creation function
- * GNUNET_REGEX_automaton_save_graph.
- */
-enum GNUNET_REGEX_GraphSavingOptions
-{
- /**
- * Default. Do nothing special.
- */
- GNUNET_REGEX_GRAPH_DEFAULT = 0,
-
- /**
- * The generated graph will include extra information such as the NFA states
- * that were used to generate the DFA state.
- */
- GNUNET_REGEX_GRAPH_VERBOSE = 1,
-
- /**
- * Enable graph coloring. Will color each SCC in a different color.
- */
- GNUNET_REGEX_GRAPH_COLORING = 2
-};
-
-
-/**
- * Save the given automaton as a GraphViz dot file.
- *
- * @param a the automaton to be saved.
- * @param filename where to save the file.
- * @param options options for graph generation that include coloring or verbose
- * mode
- */
-void
-GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
- const char *filename,
- enum GNUNET_REGEX_GraphSavingOptions options);
-
-
-/**
- * Evaluates the given 'string' against the given compiled regex.
- *
- * @param a automaton.
- * @param string string to check.
- *
- * @return 0 if string matches, non 0 otherwise.
- */
-int
-GNUNET_REGEX_eval (struct GNUNET_REGEX_Automaton *a,
- const char *string);
-
-
-/**
- * Get the first key for the given 'input_string'. This hashes
- * the first x bits of the 'input_string'.
- *
- * @param input_string string.
- * @param string_len length of the 'input_string'.
- * @param key pointer to where to write the hash code.
- *
- * @return number of bits of 'input_string' that have been consumed
- * to construct the key
- */
-size_t
-GNUNET_REGEX_get_first_key (const char *input_string, size_t string_len,
- struct GNUNET_HashCode * key);
-
-
-/**
- * Check if the given 'proof' matches the given 'key'.
- *
- * @param proof partial regex of a state.
- * @param key hash of a state.
- *
- * @return GNUNET_OK if the proof is valid for the given key.
- */
-int
-GNUNET_REGEX_check_proof (const char *proof,
- const struct GNUNET_HashCode *key);
-
-
-/**
- * Iterator callback function.
- *
- * @param cls closure.
- * @param key hash for current state.
- * @param proof proof for current state.
- * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
- * @param num_edges number of edges leaving current state.
- * @param edges edges leaving current state.
- */
-typedef void (*GNUNET_REGEX_KeyIterator)(void *cls,
- const struct GNUNET_HashCode *key,
- const char *proof,
- int accepting,
- unsigned int num_edges,
- const struct GNUNET_REGEX_Edge *edges);
-
-
-/**
- * Iterate over all edges starting from start state of automaton 'a'. Calling
- * iterator for each edge.
- *
- * @param a automaton.
- * @param iterator iterator called for each edge.
- * @param iterator_cls closure.
- */
-void
-GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a,
- GNUNET_REGEX_KeyIterator iterator,
- void *iterator_cls);
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ip' and 'netmask'.
- *
- * @param ip IPv4 representation.
- * @param netmask netmask for the ip.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN
- * bytes long.
- */
-void
-GNUNET_REGEX_ipv4toregex (const struct in_addr *ip, const char *netmask,
- char *rxstr);
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'.
- *
- * @param ipv6 IPv6 representation.
- * @param prefixlen length of the ipv6 prefix.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN
- * bytes long.
- */
-void
-GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6,
- unsigned int prefixlen, char *rxstr);
-
-
-
-/**
- * Handle to store cached data about a regex announce.
- */
-struct GNUNET_REGEX_announce_handle;
-
-/**
- * Handle to store data about a regex search.
- */
-struct GNUNET_REGEX_search_handle;
-
-/**
- * Announce a regular expression: put all states of the automaton in the DHT.
- * Does not free resources, must call GNUNET_REGEX_announce_cancel for that.
- *
- * @param dht An existing and valid DHT service handle. CANNOT be NULL.
- * @param id ID to announce as provider of regex. Own ID in most cases.
- * @param regex Regular expression to announce.
- * @param compression How many characters per edge can we squeeze?
- * @param stats Optional statistics handle to report usage. Can be NULL.
- *
- * @return Handle to reuse o free cached resources.
- * Must be freed by calling GNUNET_REGEX_announce_cancel.
- */
-struct GNUNET_REGEX_announce_handle *
-GNUNET_REGEX_announce (struct GNUNET_DHT_Handle *dht,
- const struct GNUNET_PeerIdentity *id,
- const char *regex,
- uint16_t compression,
- struct GNUNET_STATISTICS_Handle *stats);
-
-/**
- * Announce again a regular expression previously announced.
- * Does use caching to speed up process.
- *
- * @param h Handle returned by a previous GNUNET_REGEX_announce call.
- */
-void
-GNUNET_REGEX_reannounce (struct GNUNET_REGEX_announce_handle *h);
-
-
-/**
- * Clear all cached data used by a regex announce.
- * Does not close DHT connection.
- *
- * @param h Handle returned by a previous GNUNET_REGEX_announce call.
- */
-void
-GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_announce_handle *h);
-
-
-/**
- * Search callback function.
- *
- * @param cls Closure provided in GNUNET_REGEX_search.
- * @param id Peer providing a regex that matches the string.
- * @param get_path Path of the get request.
- * @param get_path_length Lenght of get_path.
- * @param put_path Path of the put request.
- * @param put_path_length Length of the put_path.
- */
-typedef void (*GNUNET_REGEX_Found)(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length);
-
-
-/**
- * Search for a peer offering a regex matching certain string in the DHT.
- * The search runs until GNUNET_REGEX_search_cancel is called, even if results
- * are returned.
- *
- * @param dht An existing and valid DHT service handle.
- * @param string String to match against the regexes in the DHT.
- * @param callback Callback for found peers.
- * @param callback_cls Closure for @c callback.
- * @param stats Optional statistics handle to report usage. Can be NULL.
- *
- * @return Handle to stop search and free resources.
- * Must be freed by calling GNUNET_REGEX_search_cancel.
- */
-struct GNUNET_REGEX_search_handle *
-GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht,
- const char *string,
- GNUNET_REGEX_Found callback,
- void *callback_cls,
- struct GNUNET_STATISTICS_Handle *stats);
-
-/**
- * Stop search and free all data used by a GNUNET_REGEX_search call.
- * Does not close DHT connection.
- *
- * @param h Handle returned by a previous GNUNET_REGEX_search call.
- */
-void
-GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_search_handle *h);
-
-
-#if 0 /* keep Emacsens' auto-indent happy */
-{
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-/* end of gnunet_regex_lib.h */
-#endif
#endif
+/**
+ * Maximum regex string length for use with GNUNET_TUN_ipv4toregex
+ */
+#define GNUNET_TUN_IPV4_REGEXLEN 32 + 6
+
+
+/**
+ * Maximum regex string length for use with GNUNET_TUN_ipv6toregex
+ */
+#define GNUNET_TUN_IPV6_REGEXLEN 128 + 6
+
+
GNUNET_NETWORK_STRUCT_BEGIN
/**
uint16_t payload_length);
+/**
+ * Create a regex in 'rxstr' from the given 'ip' and 'netmask'.
+ *
+ * @param ip IPv4 representation.
+ * @param netmask netmask for the ip.
+ * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN
+ * bytes long.
+ */
+void
+GNUNET_TUN_ipv4toregex (const struct in_addr *ip, const char *netmask,
+ char *rxstr);
+
+
+/**
+ * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'.
+ *
+ * @param ipv6 IPv6 representation.
+ * @param prefixlen length of the ipv6 prefix.
+ * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN
+ * bytes long.
+ */
+void
+GNUNET_TUN_ipv6toregex (const struct in6_addr *ipv6,
+ unsigned int prefixlen, char *rxstr);
+
+
+
#endif
mesh_common.c
gnunet_service_mesh_CFLAGS = $(AM_CFLAGS)
gnunet_service_mesh_LDADD = \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/regex/libgnunetregexnew.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/core/libgnunetcore.la \
$(top_builddir)/src/dht/libgnunetdht.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(top_builddir)/src/block/libgnunetblock.la \
- $(top_builddir)/src/regex/libgnunetregex.la
+ $(top_builddir)/src/block/libgnunetblock.la
gnunet_service_mesh_DEPENDENCIES = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/core/libgnunetcore.la \
$(top_builddir)/src/dht/libgnunetdht.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
$(top_builddir)/src/block/libgnunetblock.la \
- $(top_builddir)/src/regex/libgnunetregex.la
+ $(top_builddir)/src/regex/libgnunetregexnew.la
if LINUX
gnunet_service_mesh_LDFLAGS = -lrt
endif
#include "block_mesh.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
-#include "gnunet_regex_lib.h"
+#include "gnunet_regex_service.h"
#define MESH_BLOOM_SIZE 128
GNUNET_TIME_UNIT_MINUTES,\
10)
+
#if MESH_DEBUG_CONNECTION
#define DEBUG_CONN(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
#else
/**
* Handle to announce the regex.
*/
- struct GNUNET_REGEX_announce_handle *h;
+ struct GNUNET_REGEX_Announcement *h;
};
/**
* Regex search handle.
*/
- struct GNUNET_REGEX_search_handle *search_handle;
+ struct GNUNET_REGEX_Search *search_handle;
/**
* Peer that is connecting via connect_by_string. When connected, free ctx.
*/
static struct GNUNET_CONTAINER_MultiHashMap *peers;
-/*
- * Handle to communicate with transport
+/**
+ * Configuration handle
*/
-// static struct GNUNET_TRANSPORT_Handle *transport_handle;
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Handle to communicate with core.
if (NULL == regex->h)
{
DEBUG_REGEX (" first put, creating DFA\n");
- regex->h = GNUNET_REGEX_announce (dht_handle,
+ regex->h = GNUNET_REGEX_announce (cfg,
&my_full_id,
regex->regex,
- regex->compression,
- stats);
- }
- else
- {
- DEBUG_REGEX (" not first put, using cached data\n");
- GNUNET_REGEX_reannounce (regex->h);
+ app_announce_time,
+ regex->compression);
}
DEBUG_REGEX (" regex_put (%s) end\n", regex->regex);
}
c = next;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " done!\n");
- return;
}
t->regex_search = info;
- info->search_handle = GNUNET_REGEX_search (dht_handle,
+ info->search_handle = GNUNET_REGEX_search (cfg,
info->description,
- ®ex_found_handler, info,
- stats);
+ ®ex_found_handler, info);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connect by string processed\n");
{
char *keyfile;
+ cfg = c;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
server_handle = server;
gnunet_service_regex_SOURCES = \
gnunet-service-regex.c
-gnunet_service_regex_LDADD = \
- $(top_builddir)/src/regex/libgnunetregex.la \
+gnunet_service_regex_LDADD = -lm \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
$(top_builddir)/src/dht/libgnunetdht.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
gnunet_service_regex_DEPENDENCIES = \
- libgnunetregex.la
+ libgnunetregex_internal.a
# todo: link files from libgnunetregex statically into gnunet_service_regex,
# rename API prefix to avoid collision with 'libgnunetregexnew'...
+noinst_LIBRARIES = \
+ libgnunetregex_internal.a \
+ libgnunetregextest.a
lib_LTLIBRARIES = \
libgnunetregexblock.la \
- libgnunetregex.la \
libgnunetregexnew.la
$(GN_LIB_LDFLAGS) $(WINFLAGS) \
-version-info 1:0:0
-libgnunetregex_la_SOURCES = \
+
+libgnunetregex_internal_a_SOURCES = \
regex_internal.h regex.c \
regex_graph.c regex_random.c \
regex_dht.c
-libgnunetregex_la_LIBADD = -lm \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/dht/libgnunetdht.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(top_builddir)/src/regex/libgnunetregexblock.la
-libgnunetregex_la_DEPENDENCIES = \
+libgnunetregex_internal_a_DEPENDENCIES = \
libgnunetregexblock.la
-libgnunetregex_la_LDFLAGS = \
- $(GN_LIB_LDFLAGS) \
- -version-info 2:0:1
libgnunetregexnew_la_SOURCES = \
-version-info 3:0:0
-plugindir = $(libdir)/gnunet
-
plugin_LTLIBRARIES = \
libgnunet_plugin_block_regex.la
gnunet-regex-simulation-profiler.c
gnunet_regex_simulation_profiler_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/regex/libgnunetregex.la \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
$(top_builddir)/src/mysql/libgnunetmysql.la
gnunet_regex_simulation_profiler_DEPENDENCIES = \
- libgnunetregex.la
+ libgnunetregex_internal.a
endif
-noinst_LTLIBRARIES = libgnunetregextest.la
-
-libgnunetregextest_la_SOURCES = \
+libgnunetregextest_a_SOURCES = \
regex_test_lib.c regex_test_lib.h
-libgnunetregextest_la_LIBADD = \
+libgnunetregextest_a_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/regex/libgnunetregex.la
-libgnunetregextest_la_DEPENDENCIES = \
- libgnunetregex.la
+ $(top_builddir)/src/regex/libgnunetregex_internal.a
+libgnunetregextest_a_DEPENDENCIES = \
+ libgnunetregex_internal.a
noinst_PROGRAMS = $(noinst_mysql_progs) \
perf_regex_SOURCES = \
perf-regex.c
-perf_regex_LDADD = \
+perf_regex_LDADD = -lm \
$(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/regex/libgnunetregex.la \
- $(top_builddir)/src/regex/libgnunetregextest.la
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
+ $(top_builddir)/src/regex/libgnunetregextest.a
perf_regex_DEPENDENCIES = \
- libgnunetregex.la \
- libgnunetregextest.la
+ libgnunetregex_internal.a \
+ libgnunetregextest.a
gnunet_regex_profiler_SOURCES = \
gnunet-regex-profiler.c
-gnunet_regex_profiler_LDADD = \
+gnunet_regex_profiler_LDADD = -lm \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/dht/libgnunetdht.la \
$(top_builddir)/src/testbed/libgnunettestbed.la \
- $(top_builddir)/src/regex/libgnunetregex.la \
- $(top_builddir)/src/regex/libgnunetregextest.la \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
+ $(top_builddir)/src/regex/libgnunetregextest.a \
$(top_builddir)/src/statistics/libgnunetstatistics.la
gnunet_regex_profiler_DEPENDENCIES = \
$(top_builddir)/src/arm/libgnunetarm.la \
$(top_builddir)/src/dht/libgnunetdht.la \
- libgnunetregex.la \
- libgnunetregextest.la
+ libgnunetregex_internal.a \
+ libgnunetregextest.a
gnunet_daemon_regexprofiler_SOURCES = \
gnunet-daemon-regexprofiler.c
-gnunet_daemon_regexprofiler_LDADD = \
+gnunet_daemon_regexprofiler_LDADD = -lm \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/dht/libgnunetdht.la \
- $(top_builddir)/src/regex/libgnunetregex.la \
- $(top_builddir)/src/regex/libgnunetregextest.la \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
+ $(top_builddir)/src/regex/libgnunetregextest.a \
$(top_builddir)/src/statistics/libgnunetstatistics.la
gnunet_daemon_regexprofiler_DEPENDENCIES = \
$(top_builddir)/src/dht/libgnunetdht.la \
- libgnunetregextest.la \
- libgnunetregex.la
+ libgnunetregextest.a \
+ libgnunetregex_internal.a
test_regex_eval_api \
test_regex_iterate_api \
test_regex_proofs \
- test_regex_graph_api \
- test_regex_iptoregex
+ test_regex_graph_api
if ENABLE_TEST_RUN
TESTS = $(check_PROGRAMS)
test_regex_eval_api_SOURCES = \
test_regex_eval_api.c
-test_regex_eval_api_LDADD = \
- $(top_builddir)/src/regex/libgnunetregex.la \
+test_regex_eval_api_LDADD = -lm \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
$(top_builddir)/src/util/libgnunetutil.la
test_regex_iterate_api_SOURCES = \
test_regex_iterate_api.c
-test_regex_iterate_api_LDADD = \
- $(top_builddir)/src/regex/libgnunetregex.la \
+test_regex_iterate_api_LDADD = -lm \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
$(top_builddir)/src/util/libgnunetutil.la
test_regex_proofs_SOURCES = \
test_regex_proofs.c
-test_regex_proofs_LDADD = \
- $(top_builddir)/src/regex/libgnunetregex.la \
+test_regex_proofs_LDADD = -lm \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
$(top_builddir)/src/util/libgnunetutil.la
test_regex_graph_api_SOURCES = \
test_regex_graph_api.c
-test_regex_graph_api_LDADD = \
- $(top_builddir)/src/regex/libgnunetregex.la \
+test_regex_graph_api_LDADD = -lm \
+ $(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
$(top_builddir)/src/util/libgnunetutil.la
-test_regex_iptoregex_SOURCES = \
- test_regex_iptoregex.c
-test_regex_iptoregex_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/regex/libgnunetregex.la
-
EXTRA_DIST = \
regex_simulation_profiler_test.conf
*/
#include "platform.h"
#include "gnunet_util_lib.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_test_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
/**
* Peer's regex announce handle.
*/
-static struct GNUNET_REGEX_announce_handle *announce_handle;
+static struct REGEX_ITERNAL_Announcement *announce_handle;
/**
* Periodically reannounce regex.
if (NULL != announce_handle)
{
- GNUNET_REGEX_announce_cancel (announce_handle);
+ REGEX_ITERNAL_announce_cancel (announce_handle);
announce_handle = NULL;
}
"First time, creating regex: %s\n",
regex);
memset (&id, 0, sizeof (struct GNUNET_PeerIdentity));
- announce_handle = GNUNET_REGEX_announce (dht_handle,
+ announce_handle = REGEX_ITERNAL_announce (dht_handle,
&id,
regex,
(unsigned int) max_path_compression,
else
{
GNUNET_assert (NULL != announce_handle);
- GNUNET_REGEX_reannounce (announce_handle);
+ REGEX_ITERNAL_reannounce (announce_handle);
}
random_delay =
/* Read regexes from policy files */
GNUNET_assert (-1 != GNUNET_DISK_directory_scan (policy_dir, &scan,
(void *) (long) peer_id));
- if (NULL == (components = GNUNET_REGEX_read_from_file (policy_filename)))
+ if (NULL == (components = REGEX_ITERNAL_read_from_file (policy_filename)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Policy file %s contains no policies. Exiting.\n",
GNUNET_SCHEDULER_shutdown ();
return;
}
- regex = GNUNET_REGEX_combine (components);
- GNUNET_REGEX_free_from_file (components);
+ regex = REGEX_ITERNAL_combine (components);
+ REGEX_ITERNAL_free_from_file (components);
/* Announcing regexes from policy_filename */
GNUNET_asprintf (&rx_with_pfx, "%s(%s)(0|1)*", regex_prefix, regex);
#include "platform.h"
#include "gnunet_applications.h"
#include "gnunet_util_lib.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_dht_service.h"
#include "gnunet_testbed_service.h"
/**
* Handle to a running regex search.
*/
- struct GNUNET_REGEX_search_handle *search_handle;
+ struct REGEX_ITERNAL_Search *search_handle;
/**
* Testbed operation handle for DHT.
* Method called when we've found a peer that announced a regex
* that matches our search string. Now get the statistics.
*
- * @param cls Closure provided in GNUNET_REGEX_search.
+ * @param cls Closure provided in REGEX_ITERNAL_search.
* @param id Peer providing a regex that matches the string.
* @param get_path Path of the get request.
* @param get_path_length Lenght of get_path.
GNUNET_assert (peer->dht_handle == ca_result);
peer->search_str_matched = GNUNET_NO;
- peer->search_handle = GNUNET_REGEX_search (peer->dht_handle,
+ peer->search_handle = REGEX_ITERNAL_search (peer->dht_handle,
peer->search_str,
®ex_found_handler, peer,
NULL);
if (NULL != peer->search_handle)
{
- GNUNET_REGEX_search_cancel (peer->search_handle);
+ REGEX_ITERNAL_search_cancel (peer->search_handle);
peer->search_handle = NULL;
}
#include "platform.h"
#include "gnunet_util_lib.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "gnunet_mysql_lib.h"
#include <mysql/mysql.h>
static void
regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
int accepting, unsigned int num_edges,
- const struct GNUNET_REGEX_Edge *edges)
+ const struct REGEX_ITERNAL_Edge *edges)
{
unsigned int i;
int result;
static int
announce_regex (const char *regex)
{
- struct GNUNET_REGEX_Automaton *dfa;
+ struct REGEX_ITERNAL_Automaton *dfa;
dfa =
- GNUNET_REGEX_construct_dfa (regex, strlen (regex), max_path_compression);
+ REGEX_ITERNAL_construct_dfa (regex, strlen (regex), max_path_compression);
if (NULL == dfa)
{
return GNUNET_SYSERR;
}
- GNUNET_REGEX_iterate_all_edges (dfa, ®ex_iterator, NULL);
+ REGEX_ITERNAL_iterate_all_edges (dfa, ®ex_iterator, NULL);
- GNUNET_REGEX_automaton_destroy (dfa);
+ REGEX_ITERNAL_automaton_destroy (dfa);
return GNUNET_OK;
}
*/
#include "platform.h"
#include "gnunet_util_lib.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_ipc.h"
/**
* Search handle (if this client is searching).
*/
- struct GNUNET_REGEX_search_handle *sh;
+ struct REGEX_ITERNAL_Search *sh;
/**
* Announcement handle (if this client is announcing).
*/
- struct GNUNET_REGEX_announce_handle *ah;
+ struct REGEX_ITERNAL_Announcement *ah;
/**
* Refresh frequency for announcements.
}
if (NULL != ce->ah)
{
- GNUNET_REGEX_announce_cancel (ce->ah);
+ REGEX_ITERNAL_announce_cancel (ce->ah);
ce->ah = NULL;
}
if (NULL != ce->sh)
{
- GNUNET_REGEX_search_cancel (ce->sh);
+ REGEX_ITERNAL_search_cancel (ce->sh);
ce->sh = NULL;
}
GNUNET_CONTAINER_DLL_remove (client_head, client_tail, ce);
{
struct ClientEntry *ce = cls;
- GNUNET_REGEX_reannounce (ce->ah);
+ REGEX_ITERNAL_reannounce (ce->ah);
ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency,
&reannounce,
ce);
}
ce = GNUNET_new (struct ClientEntry);
ce->client = client;
- ce->ah = GNUNET_REGEX_announce (dht,
+ ce->ah = REGEX_ITERNAL_announce (dht,
&am->pid,
regex,
ntohs (am->compression),
}
ce = GNUNET_new (struct ClientEntry);
ce->client = client;
- ce->sh = GNUNET_REGEX_search (dht,
+ ce->sh = REGEX_ITERNAL_search (dht,
string,
&handle_search_result,
ce,
#include <regex.h>
#include <time.h>
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_test_lib.h"
static const char *exe;
const char *proof,
int accepting,
unsigned int num_edges,
- const struct GNUNET_REGEX_Edge *edges)
+ const struct REGEX_ITERNAL_Edge *edges)
{
unsigned int i;
}
static void
-print_dfa (struct GNUNET_REGEX_Automaton* dfa)
+print_dfa (struct REGEX_ITERNAL_Automaton* dfa)
{
- GNUNET_REGEX_iterate_all_edges (dfa, iter, NULL);
+ REGEX_ITERNAL_iterate_all_edges (dfa, iter, NULL);
}
/**
int
main (int argc, char *const *argv)
{
- struct GNUNET_REGEX_Automaton* dfa;
+ struct REGEX_ITERNAL_Automaton* dfa;
char **regexes;
char *buffer;
char *regex;
usage();
return 1;
}
- regexes = GNUNET_REGEX_read_from_file (argv[1]);
+ regexes = REGEX_ITERNAL_read_from_file (argv[1]);
if (NULL == regexes)
{
usage();
return 2;
}
- buffer = GNUNET_REGEX_combine (regexes);
+ buffer = REGEX_ITERNAL_combine (regexes);
GNUNET_asprintf (®ex, "GNVPN-0001-PAD(%s)(0|1)*", buffer);
size = strlen (regex);
// return 0;
compression = atoi (argv[2]);
- dfa = GNUNET_REGEX_construct_dfa (regex, size, compression);
+ dfa = REGEX_ITERNAL_construct_dfa (regex, size, compression);
print_dfa (dfa);
- GNUNET_REGEX_automaton_destroy (dfa);
+ REGEX_ITERNAL_automaton_destroy (dfa);
GNUNET_free (buffer);
- GNUNET_REGEX_free_from_file (regexes);
+ REGEX_ITERNAL_free_from_file (regexes);
GNUNET_free (regex);
return 0;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Block with no xquery\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " key: %s, %u edges\n",
GNUNET_h2s (&rblock->key), ntohl (rblock->n_edges));
- GNUNET_REGEX_block_iterate (rblock, reply_block_size, &rdebug, NULL);
+ REGEX_ITERNAL_block_iterate (rblock, reply_block_size, &rdebug, NULL);
return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
}
- switch (GNUNET_REGEX_block_check (reply_block,
+ switch (REGEX_ITERNAL_block_check (reply_block,
reply_block_size,
xquery))
{
* @author Maximilian Szengel
*/
#include "platform.h"
-#include "gnunet_container_lib.h"
-#include "gnunet_crypto_lib.h"
-#include "gnunet_regex_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_regex_service.h"
+#include "regex_internal_lib.h"
#include "regex_internal.h"
+
/**
* Set this to GNUNET_YES to enable state naming. Used to debug NFA->DFA
* creation. Disabled by default for better performance.
/**
* Set of states using MDLL API.
*/
-struct GNUNET_REGEX_StateSet_MDLL
+struct REGEX_ITERNAL_StateSet_MDLL
{
/**
* MDLL of states.
*/
- struct GNUNET_REGEX_State *head;
+ struct REGEX_ITERNAL_State *head;
/**
* MDLL of states.
*/
- struct GNUNET_REGEX_State *tail;
+ struct REGEX_ITERNAL_State *tail;
/**
* Length of the MDLL.
* @param state state to be appended
*/
static void
-state_set_append (struct GNUNET_REGEX_StateSet *set,
- struct GNUNET_REGEX_State *state)
+state_set_append (struct REGEX_ITERNAL_StateSet *set,
+ struct REGEX_ITERNAL_State *state)
{
if (set->off == set->size)
GNUNET_array_grow (set->states, set->size, set->size * 2 + 4);
* @param to_state state to where the transition should point to
*/
static void
-state_add_transition (struct GNUNET_REGEX_Context *ctx,
- struct GNUNET_REGEX_State *from_state, const char *label,
- struct GNUNET_REGEX_State *to_state)
+state_add_transition (struct REGEX_ITERNAL_Context *ctx,
+ struct REGEX_ITERNAL_State *from_state, const char *label,
+ struct REGEX_ITERNAL_State *to_state)
{
- struct GNUNET_REGEX_Transition *t;
- struct GNUNET_REGEX_Transition *oth;
+ struct REGEX_ITERNAL_Transition *t;
+ struct REGEX_ITERNAL_Transition *oth;
if (NULL == from_state)
{
break;
}
- t = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Transition));
+ t = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_Transition));
if (NULL != ctx)
t->id = ctx->transition_id++;
if (NULL != label)
* @param transition transition that should be removed from state 'state'.
*/
static void
-state_remove_transition (struct GNUNET_REGEX_State *state,
- struct GNUNET_REGEX_Transition *transition)
+state_remove_transition (struct REGEX_ITERNAL_State *state,
+ struct REGEX_ITERNAL_Transition *transition)
{
if (NULL == state || NULL == transition)
return;
static int
state_compare (const void *a, const void *b)
{
- struct GNUNET_REGEX_State **s1 = (struct GNUNET_REGEX_State **) a;
- struct GNUNET_REGEX_State **s2 = (struct GNUNET_REGEX_State **) b;
+ struct REGEX_ITERNAL_State **s1 = (struct REGEX_ITERNAL_State **) a;
+ struct REGEX_ITERNAL_State **s2 = (struct REGEX_ITERNAL_State **) b;
return (*s1)->id - (*s2)->id;
}
* @return number of edges.
*/
static unsigned int
-state_get_edges (struct GNUNET_REGEX_State *s, struct GNUNET_REGEX_Edge *edges)
+state_get_edges (struct REGEX_ITERNAL_State *s, struct REGEX_ITERNAL_Edge *edges)
{
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_Transition *t;
unsigned int count;
if (NULL == s)
* @return 0 if the sets are equal, otherwise non-zero
*/
static int
-state_set_compare (struct GNUNET_REGEX_StateSet *sset1,
- struct GNUNET_REGEX_StateSet *sset2)
+state_set_compare (struct REGEX_ITERNAL_StateSet *sset1,
+ struct REGEX_ITERNAL_StateSet *sset2)
{
int result;
unsigned int i;
* @param set set to be cleared
*/
static void
-state_set_clear (struct GNUNET_REGEX_StateSet *set)
+state_set_clear (struct REGEX_ITERNAL_StateSet *set)
{
GNUNET_array_grow (set->states, set->size, 0);
set->off = 0;
* @param a automaton to be cleared
*/
static void
-automaton_fragment_clear (struct GNUNET_REGEX_Automaton *a)
+automaton_fragment_clear (struct REGEX_ITERNAL_Automaton *a)
{
if (NULL == a)
return;
* @param s state that should be destroyed
*/
static void
-automaton_destroy_state (struct GNUNET_REGEX_State *s)
+automaton_destroy_state (struct REGEX_ITERNAL_State *s)
{
- struct GNUNET_REGEX_Transition *t;
- struct GNUNET_REGEX_Transition *next_t;
+ struct REGEX_ITERNAL_Transition *t;
+ struct REGEX_ITERNAL_Transition *next_t;
if (NULL == s)
return;
* @param s state to remove
*/
static void
-automaton_remove_state (struct GNUNET_REGEX_Automaton *a,
- struct GNUNET_REGEX_State *s)
+automaton_remove_state (struct REGEX_ITERNAL_Automaton *a,
+ struct REGEX_ITERNAL_State *s)
{
- struct GNUNET_REGEX_State *s_check;
- struct GNUNET_REGEX_Transition *t_check;
- struct GNUNET_REGEX_Transition *t_check_next;
+ struct REGEX_ITERNAL_State *s_check;
+ struct REGEX_ITERNAL_Transition *t_check;
+ struct REGEX_ITERNAL_Transition *t_check_next;
if (NULL == a || NULL == s)
return;
* @param s2 second state, will be destroyed
*/
static void
-automaton_merge_states (struct GNUNET_REGEX_Context *ctx,
- struct GNUNET_REGEX_Automaton *a,
- struct GNUNET_REGEX_State *s1,
- struct GNUNET_REGEX_State *s2)
-{
- struct GNUNET_REGEX_State *s_check;
- struct GNUNET_REGEX_Transition *t_check;
- struct GNUNET_REGEX_Transition *t;
- struct GNUNET_REGEX_Transition *t_next;
+automaton_merge_states (struct REGEX_ITERNAL_Context *ctx,
+ struct REGEX_ITERNAL_Automaton *a,
+ struct REGEX_ITERNAL_State *s1,
+ struct REGEX_ITERNAL_State *s2)
+{
+ struct REGEX_ITERNAL_State *s_check;
+ struct REGEX_ITERNAL_Transition *t_check;
+ struct REGEX_ITERNAL_Transition *t;
+ struct REGEX_ITERNAL_Transition *t_next;
int is_dup;
if (s1 == s2)
* @param s state that should be added
*/
static void
-automaton_add_state (struct GNUNET_REGEX_Automaton *a,
- struct GNUNET_REGEX_State *s)
+automaton_add_state (struct REGEX_ITERNAL_Automaton *a,
+ struct REGEX_ITERNAL_State *s)
{
GNUNET_CONTAINER_DLL_insert (a->states_head, a->states_tail, s);
a->state_count++;
* @param action_cls closure for action.
*/
static void
-automaton_state_traverse (struct GNUNET_REGEX_State *s, int *marks,
+automaton_state_traverse (struct REGEX_ITERNAL_State *s, int *marks,
unsigned int *count,
- GNUNET_REGEX_traverse_check check, void *check_cls,
- GNUNET_REGEX_traverse_action action, void *action_cls)
+ REGEX_ITERNAL_traverse_check check, void *check_cls,
+ REGEX_ITERNAL_traverse_action action, void *action_cls)
{
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_Transition *t;
if (GNUNET_YES == marks[s->traversal_id])
return;
* @param action_cls closure for action
*/
void
-GNUNET_REGEX_automaton_traverse (const struct GNUNET_REGEX_Automaton *a,
- struct GNUNET_REGEX_State *start,
- GNUNET_REGEX_traverse_check check,
+REGEX_ITERNAL_automaton_traverse (const struct REGEX_ITERNAL_Automaton *a,
+ struct REGEX_ITERNAL_State *start,
+ REGEX_ITERNAL_traverse_check check,
void *check_cls,
- GNUNET_REGEX_traverse_action action,
+ REGEX_ITERNAL_traverse_action action,
void *action_cls)
{
unsigned int count;
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
if (NULL == a || 0 == a->state_count)
return;
/**
- * Helper function used as 'action' in 'GNUNET_REGEX_automaton_traverse'
+ * Helper function used as 'action' in 'REGEX_ITERNAL_automaton_traverse'
* function to create the depth-first numbering of the states.
*
* @param cls states array.
*/
static void
number_states (void *cls, const unsigned int count,
- struct GNUNET_REGEX_State *s)
+ struct REGEX_ITERNAL_State *s)
{
- struct GNUNET_REGEX_State **states = cls;
+ struct REGEX_ITERNAL_State **states = cls;
s->dfs_id = count;
if (NULL != states)
* @param a automaton for which to assign proofs and hashes, must not be NULL
*/
static int
-automaton_create_proofs (struct GNUNET_REGEX_Automaton *a)
+automaton_create_proofs (struct REGEX_ITERNAL_Automaton *a)
{
unsigned int n = a->state_count;
- struct GNUNET_REGEX_State *states[n];
+ struct REGEX_ITERNAL_State *states[n];
struct StringBuffer *R_last;
struct StringBuffer *R_cur;
struct StringBuffer R_cur_r;
struct StringBuffer R_cur_l;
struct StringBuffer *R_swap;
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_Transition *t;
struct StringBuffer complete_regex;
unsigned int i;
unsigned int j;
}
/* create depth-first numbering of the states, initializes 'state' */
- GNUNET_REGEX_automaton_traverse (a, a->start, NULL, NULL, &number_states,
+ REGEX_ITERNAL_automaton_traverse (a, a->start, NULL, NULL, &number_states,
states);
for (i = 0; i < n; i++)
*
* @return new DFA state
*/
-static struct GNUNET_REGEX_State *
-dfa_state_create (struct GNUNET_REGEX_Context *ctx,
- struct GNUNET_REGEX_StateSet *nfa_states)
+static struct REGEX_ITERNAL_State *
+dfa_state_create (struct REGEX_ITERNAL_Context *ctx,
+ struct REGEX_ITERNAL_StateSet *nfa_states)
{
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
char *pos;
size_t len;
- struct GNUNET_REGEX_State *cstate;
- struct GNUNET_REGEX_Transition *ctran;
+ struct REGEX_ITERNAL_State *cstate;
+ struct REGEX_ITERNAL_Transition *ctran;
unsigned int i;
- s = GNUNET_malloc (sizeof (struct GNUNET_REGEX_State));
+ s = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_State));
s->id = ctx->state_id++;
s->index = -1;
s->lowlink = -1;
pos[-1] = '}';
s->name = GNUNET_realloc (s->name, strlen (s->name) + 1);
- memset (nfa_states, 0, sizeof (struct GNUNET_REGEX_StateSet));
+ memset (nfa_states, 0, sizeof (struct REGEX_ITERNAL_StateSet));
return s;
}
* @return length of the substring comsumed from 'str'
*/
static unsigned int
-dfa_move (struct GNUNET_REGEX_State **s, const char *str)
+dfa_move (struct REGEX_ITERNAL_State **s, const char *str)
{
- struct GNUNET_REGEX_Transition *t;
- struct GNUNET_REGEX_State *new_s;
+ struct REGEX_ITERNAL_Transition *t;
+ struct REGEX_ITERNAL_State *new_s;
unsigned int len;
unsigned int max_len;
* @param s state where the marked attribute will be set to GNUNET_YES.
*/
static void
-mark_states (void *cls, const unsigned int count, struct GNUNET_REGEX_State *s)
+mark_states (void *cls, const unsigned int count, struct REGEX_ITERNAL_State *s)
{
s->marked = GNUNET_YES;
}
* @param a DFA automaton
*/
static void
-dfa_remove_unreachable_states (struct GNUNET_REGEX_Automaton *a)
+dfa_remove_unreachable_states (struct REGEX_ITERNAL_Automaton *a)
{
- struct GNUNET_REGEX_State *s;
- struct GNUNET_REGEX_State *s_next;
+ struct REGEX_ITERNAL_State *s;
+ struct REGEX_ITERNAL_State *s_next;
/* 1. unmark all states */
for (s = a->states_head; NULL != s; s = s->next)
s->marked = GNUNET_NO;
/* 2. traverse dfa from start state and mark all visited states */
- GNUNET_REGEX_automaton_traverse (a, a->start, NULL, NULL, &mark_states, NULL);
+ REGEX_ITERNAL_automaton_traverse (a, a->start, NULL, NULL, &mark_states, NULL);
/* 3. delete all states that were not visited */
for (s = a->states_head; NULL != s; s = s_next)
* @param a DFA automaton
*/
static void
-dfa_remove_dead_states (struct GNUNET_REGEX_Automaton *a)
+dfa_remove_dead_states (struct REGEX_ITERNAL_Automaton *a)
{
- struct GNUNET_REGEX_State *s;
- struct GNUNET_REGEX_State *s_next;
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_State *s;
+ struct REGEX_ITERNAL_State *s_next;
+ struct REGEX_ITERNAL_Transition *t;
int dead;
GNUNET_assert (DFA == a->type);
* @return GNUNET_OK on success
*/
static int
-dfa_merge_nondistinguishable_states (struct GNUNET_REGEX_Context *ctx,
- struct GNUNET_REGEX_Automaton *a)
+dfa_merge_nondistinguishable_states (struct REGEX_ITERNAL_Context *ctx,
+ struct REGEX_ITERNAL_Automaton *a)
{
uint32_t *table;
- struct GNUNET_REGEX_State *s1;
- struct GNUNET_REGEX_State *s2;
- struct GNUNET_REGEX_Transition *t1;
- struct GNUNET_REGEX_Transition *t2;
- struct GNUNET_REGEX_State *s1_next;
- struct GNUNET_REGEX_State *s2_next;
+ struct REGEX_ITERNAL_State *s1;
+ struct REGEX_ITERNAL_State *s2;
+ struct REGEX_ITERNAL_Transition *t1;
+ struct REGEX_ITERNAL_Transition *t2;
+ struct REGEX_ITERNAL_State *s1_next;
+ struct REGEX_ITERNAL_State *s2_next;
int change;
unsigned int num_equal_edges;
unsigned int i;
* @return GNUNET_OK on success
*/
static int
-dfa_minimize (struct GNUNET_REGEX_Context *ctx,
- struct GNUNET_REGEX_Automaton *a)
+dfa_minimize (struct REGEX_ITERNAL_Context *ctx,
+ struct REGEX_ITERNAL_Automaton *a)
{
if (NULL == a)
return GNUNET_SYSERR;
/**
* Context for adding strided transitions to a DFA.
*/
-struct GNUNET_REGEX_Strided_Context
+struct REGEX_ITERNAL_Strided_Context
{
/**
* Length of the strides.
* Strided transitions DLL. New strided transitions will be stored in this DLL
* and afterwards added to the DFA.
*/
- struct GNUNET_REGEX_Transition *transitions_head;
+ struct REGEX_ITERNAL_Transition *transitions_head;
/**
* Strided transitions DLL.
*/
- struct GNUNET_REGEX_Transition *transitions_tail;
+ struct REGEX_ITERNAL_Transition *transitions_tail;
};
*/
void
dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label,
- struct GNUNET_REGEX_State *start,
- struct GNUNET_REGEX_State *s)
+ struct REGEX_ITERNAL_State *start,
+ struct REGEX_ITERNAL_State *s)
{
- struct GNUNET_REGEX_Strided_Context *ctx = cls;
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_Strided_Context *ctx = cls;
+ struct REGEX_ITERNAL_Transition *t;
char *new_label;
if (depth == ctx->stride)
{
- t = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Transition));
+ t = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_Transition));
t->label = GNUNET_strdup (label);
t->to_state = s;
t->from_state = start;
*/
void
dfa_add_multi_strides (void *cls, const unsigned int count,
- struct GNUNET_REGEX_State *s)
+ struct REGEX_ITERNAL_State *s)
{
dfa_add_multi_strides_helper (cls, 0, NULL, s, s);
}
* @param stride_len length of the strides.
*/
void
-GNUNET_REGEX_dfa_add_multi_strides (struct GNUNET_REGEX_Context *regex_ctx,
- struct GNUNET_REGEX_Automaton *dfa,
+REGEX_ITERNAL_dfa_add_multi_strides (struct REGEX_ITERNAL_Context *regex_ctx,
+ struct REGEX_ITERNAL_Automaton *dfa,
const unsigned int stride_len)
{
- struct GNUNET_REGEX_Strided_Context ctx = { stride_len, NULL, NULL };
- struct GNUNET_REGEX_Transition *t;
- struct GNUNET_REGEX_Transition *t_next;
+ struct REGEX_ITERNAL_Strided_Context ctx = { stride_len, NULL, NULL };
+ struct REGEX_ITERNAL_Transition *t;
+ struct REGEX_ITERNAL_Transition *t_next;
if (1 > stride_len || GNUNET_YES == dfa->is_multistrided)
return;
/* Compute the new transitions of given stride_len */
- GNUNET_REGEX_automaton_traverse (dfa, dfa->start, NULL, NULL,
+ REGEX_ITERNAL_automaton_traverse (dfa, dfa->start, NULL, NULL,
&dfa_add_multi_strides, &ctx);
/* Add all the new transitions to the automaton. */
* @param transitions_tail transitions DLL.
*/
void
-dfa_compress_paths_helper (struct GNUNET_REGEX_Automaton *dfa,
- struct GNUNET_REGEX_State *start,
- struct GNUNET_REGEX_State *cur, char *label,
+dfa_compress_paths_helper (struct REGEX_ITERNAL_Automaton *dfa,
+ struct REGEX_ITERNAL_State *start,
+ struct REGEX_ITERNAL_State *cur, char *label,
unsigned int max_len,
- struct GNUNET_REGEX_Transition **transitions_head,
- struct GNUNET_REGEX_Transition **transitions_tail)
+ struct REGEX_ITERNAL_Transition **transitions_head,
+ struct REGEX_ITERNAL_Transition **transitions_tail)
{
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_Transition *t;
char *new_label;
max_len == strlen (label)) ||
(start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen (label))))
{
- t = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Transition));
+ t = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_Transition));
t->label = GNUNET_strdup (label);
t->to_state = cur;
t->from_state = start;
* @param max_len maximal length of the compressed paths.
*/
static void
-dfa_compress_paths (struct GNUNET_REGEX_Context *regex_ctx,
- struct GNUNET_REGEX_Automaton *dfa, unsigned int max_len)
+dfa_compress_paths (struct REGEX_ITERNAL_Context *regex_ctx,
+ struct REGEX_ITERNAL_Automaton *dfa, unsigned int max_len)
{
- struct GNUNET_REGEX_State *s;
- struct GNUNET_REGEX_State *s_next;
- struct GNUNET_REGEX_Transition *t;
- struct GNUNET_REGEX_Transition *t_next;
- struct GNUNET_REGEX_Transition *transitions_head = NULL;
- struct GNUNET_REGEX_Transition *transitions_tail = NULL;
+ struct REGEX_ITERNAL_State *s;
+ struct REGEX_ITERNAL_State *s_next;
+ struct REGEX_ITERNAL_Transition *t;
+ struct REGEX_ITERNAL_Transition *t_next;
+ struct REGEX_ITERNAL_Transition *transitions_head = NULL;
+ struct REGEX_ITERNAL_Transition *transitions_tail = NULL;
if (NULL == dfa)
return;
*
* @return new NFA fragment
*/
-static struct GNUNET_REGEX_Automaton *
-nfa_fragment_create (struct GNUNET_REGEX_State *start,
- struct GNUNET_REGEX_State *end)
+static struct REGEX_ITERNAL_Automaton *
+nfa_fragment_create (struct REGEX_ITERNAL_State *start,
+ struct REGEX_ITERNAL_State *end)
{
- struct GNUNET_REGEX_Automaton *n;
+ struct REGEX_ITERNAL_Automaton *n;
- n = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Automaton));
+ n = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_Automaton));
n->type = NFA;
n->start = NULL;
* @param states_tail tail of the DLL of states
*/
static void
-nfa_add_states (struct GNUNET_REGEX_Automaton *n,
- struct GNUNET_REGEX_State *states_head,
- struct GNUNET_REGEX_State *states_tail)
+nfa_add_states (struct REGEX_ITERNAL_Automaton *n,
+ struct REGEX_ITERNAL_State *states_head,
+ struct REGEX_ITERNAL_State *states_tail)
{
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
if (NULL == n || NULL == states_head)
{
*
* @return new NFA state
*/
-static struct GNUNET_REGEX_State *
-nfa_state_create (struct GNUNET_REGEX_Context *ctx, int accepting)
+static struct REGEX_ITERNAL_State *
+nfa_state_create (struct REGEX_ITERNAL_Context *ctx, int accepting)
{
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
- s = GNUNET_malloc (sizeof (struct GNUNET_REGEX_State));
+ s = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_State));
s->id = ctx->state_id++;
s->accepting = accepting;
s->marked = GNUNET_NO;
* pass NULL for epsilon transition
*/
static void
-nfa_closure_set_create (struct GNUNET_REGEX_StateSet *ret,
- struct GNUNET_REGEX_Automaton *nfa,
- struct GNUNET_REGEX_StateSet *states, const char *label)
+nfa_closure_set_create (struct REGEX_ITERNAL_StateSet *ret,
+ struct REGEX_ITERNAL_Automaton *nfa,
+ struct REGEX_ITERNAL_StateSet *states, const char *label)
{
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
unsigned int i;
- struct GNUNET_REGEX_StateSet_MDLL cls_stack;
- struct GNUNET_REGEX_State *clsstate;
- struct GNUNET_REGEX_State *currentstate;
- struct GNUNET_REGEX_Transition *ctran;
+ struct REGEX_ITERNAL_StateSet_MDLL cls_stack;
+ struct REGEX_ITERNAL_State *clsstate;
+ struct REGEX_ITERNAL_State *currentstate;
+ struct REGEX_ITERNAL_Transition *ctran;
- memset (ret, 0, sizeof (struct GNUNET_REGEX_StateSet));
+ memset (ret, 0, sizeof (struct REGEX_ITERNAL_StateSet));
if (NULL == states)
return;
ret->states[i]->contained = 0;
if (ret->off > 1)
- qsort (ret->states, ret->off, sizeof (struct GNUNET_REGEX_State *),
+ qsort (ret->states, ret->off, sizeof (struct REGEX_ITERNAL_State *),
&state_compare);
}
* @param ctx context
*/
static void
-nfa_add_concatenation (struct GNUNET_REGEX_Context *ctx)
+nfa_add_concatenation (struct REGEX_ITERNAL_Context *ctx)
{
- struct GNUNET_REGEX_Automaton *a;
- struct GNUNET_REGEX_Automaton *b;
- struct GNUNET_REGEX_Automaton *new_nfa;
+ struct REGEX_ITERNAL_Automaton *a;
+ struct REGEX_ITERNAL_Automaton *b;
+ struct REGEX_ITERNAL_Automaton *new_nfa;
b = ctx->stack_tail;
GNUNET_assert (NULL != b);
* @param ctx context
*/
static void
-nfa_add_star_op (struct GNUNET_REGEX_Context *ctx)
+nfa_add_star_op (struct REGEX_ITERNAL_Context *ctx)
{
- struct GNUNET_REGEX_Automaton *a;
- struct GNUNET_REGEX_Automaton *new_nfa;
- struct GNUNET_REGEX_State *start;
- struct GNUNET_REGEX_State *end;
+ struct REGEX_ITERNAL_Automaton *a;
+ struct REGEX_ITERNAL_Automaton *new_nfa;
+ struct REGEX_ITERNAL_State *start;
+ struct REGEX_ITERNAL_State *end;
a = ctx->stack_tail;
* @param ctx context
*/
static void
-nfa_add_plus_op (struct GNUNET_REGEX_Context *ctx)
+nfa_add_plus_op (struct REGEX_ITERNAL_Context *ctx)
{
- struct GNUNET_REGEX_Automaton *a;
+ struct REGEX_ITERNAL_Automaton *a;
a = ctx->stack_tail;
* @param ctx context
*/
static void
-nfa_add_question_op (struct GNUNET_REGEX_Context *ctx)
+nfa_add_question_op (struct REGEX_ITERNAL_Context *ctx)
{
- struct GNUNET_REGEX_Automaton *a;
- struct GNUNET_REGEX_Automaton *new_nfa;
- struct GNUNET_REGEX_State *start;
- struct GNUNET_REGEX_State *end;
+ struct REGEX_ITERNAL_Automaton *a;
+ struct REGEX_ITERNAL_Automaton *new_nfa;
+ struct REGEX_ITERNAL_State *start;
+ struct REGEX_ITERNAL_State *end;
a = ctx->stack_tail;
* @param ctx context
*/
static void
-nfa_add_alternation (struct GNUNET_REGEX_Context *ctx)
+nfa_add_alternation (struct REGEX_ITERNAL_Context *ctx)
{
- struct GNUNET_REGEX_Automaton *a;
- struct GNUNET_REGEX_Automaton *b;
- struct GNUNET_REGEX_Automaton *new_nfa;
- struct GNUNET_REGEX_State *start;
- struct GNUNET_REGEX_State *end;
+ struct REGEX_ITERNAL_Automaton *a;
+ struct REGEX_ITERNAL_Automaton *b;
+ struct REGEX_ITERNAL_Automaton *new_nfa;
+ struct REGEX_ITERNAL_State *start;
+ struct REGEX_ITERNAL_State *end;
b = ctx->stack_tail;
GNUNET_assert (NULL != b);
* @param label label for nfa transition
*/
static void
-nfa_add_label (struct GNUNET_REGEX_Context *ctx, const char *label)
+nfa_add_label (struct REGEX_ITERNAL_Context *ctx, const char *label)
{
- struct GNUNET_REGEX_Automaton *n;
- struct GNUNET_REGEX_State *start;
- struct GNUNET_REGEX_State *end;
+ struct REGEX_ITERNAL_Automaton *n;
+ struct REGEX_ITERNAL_State *start;
+ struct REGEX_ITERNAL_State *end;
GNUNET_assert (NULL != ctx);
* @param ctx context
*/
static void
-GNUNET_REGEX_context_init (struct GNUNET_REGEX_Context *ctx)
+REGEX_ITERNAL_context_init (struct REGEX_ITERNAL_Context *ctx)
{
if (NULL == ctx)
{
* @param regex regular expression string
* @param len length of the string
*
- * @return NFA, needs to be freed using GNUNET_REGEX_destroy_automaton
+ * @return NFA, needs to be freed using REGEX_ITERNAL_destroy_automaton
*/
-struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_nfa (const char *regex, const size_t len)
+struct REGEX_ITERNAL_Automaton *
+REGEX_ITERNAL_construct_nfa (const char *regex, const size_t len)
{
- struct GNUNET_REGEX_Context ctx;
- struct GNUNET_REGEX_Automaton *nfa;
+ struct REGEX_ITERNAL_Context ctx;
+ struct REGEX_ITERNAL_Automaton *nfa;
const char *regexp;
char curlabel[2];
char *error_msg;
return NULL;
}
- GNUNET_REGEX_context_init (&ctx);
+ REGEX_ITERNAL_context_init (&ctx);
regexp = regex;
curlabel[1] = '\0';
nfa->regex = GNUNET_strdup (regex);
/* create depth-first numbering of the states for pretty printing */
- GNUNET_REGEX_automaton_traverse (nfa, NULL, NULL, NULL, &number_states, NULL);
+ REGEX_ITERNAL_automaton_traverse (nfa, NULL, NULL, NULL, &number_states, NULL);
/* No multistriding added so far */
nfa->is_multistrided = GNUNET_NO;
while (NULL != (nfa = ctx.stack_head))
{
GNUNET_CONTAINER_DLL_remove (ctx.stack_head, ctx.stack_tail, nfa);
- GNUNET_REGEX_automaton_destroy (nfa);
+ REGEX_ITERNAL_automaton_destroy (nfa);
}
return NULL;
* for starting.
*/
static void
-construct_dfa_states (struct GNUNET_REGEX_Context *ctx,
- struct GNUNET_REGEX_Automaton *nfa,
- struct GNUNET_REGEX_Automaton *dfa,
- struct GNUNET_REGEX_State *dfa_state)
-{
- struct GNUNET_REGEX_Transition *ctran;
- struct GNUNET_REGEX_State *new_dfa_state;
- struct GNUNET_REGEX_State *state_contains;
- struct GNUNET_REGEX_State *state_iter;
- struct GNUNET_REGEX_StateSet tmp;
- struct GNUNET_REGEX_StateSet nfa_set;
+construct_dfa_states (struct REGEX_ITERNAL_Context *ctx,
+ struct REGEX_ITERNAL_Automaton *nfa,
+ struct REGEX_ITERNAL_Automaton *dfa,
+ struct REGEX_ITERNAL_State *dfa_state)
+{
+ struct REGEX_ITERNAL_Transition *ctran;
+ struct REGEX_ITERNAL_State *new_dfa_state;
+ struct REGEX_ITERNAL_State *state_contains;
+ struct REGEX_ITERNAL_State *state_iter;
+ struct REGEX_ITERNAL_StateSet tmp;
+ struct REGEX_ITERNAL_StateSet nfa_set;
for (ctran = dfa_state->transitions_head; NULL != ctran; ctran = ctran->next)
{
* @param max_path_len limit the path compression length to the
* given value. If set to 1, no path compression is applied. Set to 0 for
* maximal possible path compression (generally not desireable).
- * @return DFA, needs to be freed using GNUNET_REGEX_automaton_destroy.
+ * @return DFA, needs to be freed using REGEX_ITERNAL_automaton_destroy.
*/
-struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_dfa (const char *regex, const size_t len,
+struct REGEX_ITERNAL_Automaton *
+REGEX_ITERNAL_construct_dfa (const char *regex, const size_t len,
unsigned int max_path_len)
{
- struct GNUNET_REGEX_Context ctx;
- struct GNUNET_REGEX_Automaton *dfa;
- struct GNUNET_REGEX_Automaton *nfa;
- struct GNUNET_REGEX_StateSet nfa_start_eps_cls;
- struct GNUNET_REGEX_StateSet singleton_set;
+ struct REGEX_ITERNAL_Context ctx;
+ struct REGEX_ITERNAL_Automaton *dfa;
+ struct REGEX_ITERNAL_Automaton *nfa;
+ struct REGEX_ITERNAL_StateSet nfa_start_eps_cls;
+ struct REGEX_ITERNAL_StateSet singleton_set;
- GNUNET_REGEX_context_init (&ctx);
+ REGEX_ITERNAL_context_init (&ctx);
/* Create NFA */
// fprintf (stderr, "N");
- nfa = GNUNET_REGEX_construct_nfa (regex, len);
+ nfa = REGEX_ITERNAL_construct_nfa (regex, len);
if (NULL == nfa)
{
return NULL;
}
- dfa = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Automaton));
+ dfa = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_Automaton));
dfa->type = DFA;
dfa->regex = GNUNET_strdup (regex);
/* Create DFA start state from epsilon closure */
- memset (&singleton_set, 0, sizeof (struct GNUNET_REGEX_StateSet));
+ memset (&singleton_set, 0, sizeof (struct REGEX_ITERNAL_StateSet));
state_set_append (&singleton_set, nfa->start);
nfa_closure_set_create (&nfa_start_eps_cls, nfa, &singleton_set, NULL);
state_set_clear (&singleton_set);
// fprintf (stderr, "D");
construct_dfa_states (&ctx, nfa, dfa, dfa->start);
- GNUNET_REGEX_automaton_destroy (nfa);
+ REGEX_ITERNAL_automaton_destroy (nfa);
/* Minimize DFA */
// fprintf (stderr, "M");
if (GNUNET_OK != dfa_minimize (&ctx, dfa))
{
- GNUNET_REGEX_automaton_destroy (dfa);
+ REGEX_ITERNAL_automaton_destroy (dfa);
return NULL;
}
/* Create proofs and hashes for all states */
if (GNUNET_OK != automaton_create_proofs (dfa))
{
- GNUNET_REGEX_automaton_destroy (dfa);
+ REGEX_ITERNAL_automaton_destroy (dfa);
return NULL;
}
/**
- * Free the memory allocated by constructing the GNUNET_REGEX_Automaton data
+ * Free the memory allocated by constructing the REGEX_ITERNAL_Automaton data
* structure.
*
* @param a automaton to be destroyed
*/
void
-GNUNET_REGEX_automaton_destroy (struct GNUNET_REGEX_Automaton *a)
+REGEX_ITERNAL_automaton_destroy (struct REGEX_ITERNAL_Automaton *a)
{
- struct GNUNET_REGEX_State *s;
- struct GNUNET_REGEX_State *next_state;
+ struct REGEX_ITERNAL_State *s;
+ struct REGEX_ITERNAL_State *next_state;
if (NULL == a)
return;
* @return 0 if string matches, non 0 otherwise
*/
static int
-evaluate_dfa (struct GNUNET_REGEX_Automaton *a, const char *string)
+evaluate_dfa (struct REGEX_ITERNAL_Automaton *a, const char *string)
{
const char *strp;
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
unsigned int step_len;
if (DFA != a->type)
* @return 0 if string matches, non 0 otherwise
*/
static int
-evaluate_nfa (struct GNUNET_REGEX_Automaton *a, const char *string)
+evaluate_nfa (struct REGEX_ITERNAL_Automaton *a, const char *string)
{
const char *strp;
char str[2];
- struct GNUNET_REGEX_State *s;
- struct GNUNET_REGEX_StateSet sset;
- struct GNUNET_REGEX_StateSet new_sset;
- struct GNUNET_REGEX_StateSet singleton_set;
+ struct REGEX_ITERNAL_State *s;
+ struct REGEX_ITERNAL_StateSet sset;
+ struct REGEX_ITERNAL_StateSet new_sset;
+ struct REGEX_ITERNAL_StateSet singleton_set;
unsigned int i;
int result;
return 0;
result = 1;
- memset (&singleton_set, 0, sizeof (struct GNUNET_REGEX_StateSet));
+ memset (&singleton_set, 0, sizeof (struct REGEX_ITERNAL_StateSet));
state_set_append (&singleton_set, a->start);
nfa_closure_set_create (&sset, a, &singleton_set, NULL);
state_set_clear (&singleton_set);
* @return 0 if string matches, non 0 otherwise
*/
int
-GNUNET_REGEX_eval (struct GNUNET_REGEX_Automaton *a, const char *string)
+REGEX_ITERNAL_eval (struct REGEX_ITERNAL_Automaton *a, const char *string)
{
int result;
* @return
*/
const char *
-GNUNET_REGEX_get_canonical_regex (struct GNUNET_REGEX_Automaton *a)
+REGEX_ITERNAL_get_canonical_regex (struct REGEX_ITERNAL_Automaton *a)
{
if (NULL == a)
return NULL;
* @return number of transitions in the given automaton.
*/
unsigned int
-GNUNET_REGEX_get_transition_count (struct GNUNET_REGEX_Automaton *a)
+REGEX_ITERNAL_get_transition_count (struct REGEX_ITERNAL_Automaton *a)
{
unsigned int t_count;
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
if (NULL == a)
return 0;
* to construct the key
*/
size_t
-GNUNET_REGEX_get_first_key (const char *input_string, size_t string_len,
+REGEX_ITERNAL_get_first_key (const char *input_string, size_t string_len,
struct GNUNET_HashCode * key)
{
unsigned int size;
* @return GNUNET_OK if the proof is valid for the given key.
*/
int
-GNUNET_REGEX_check_proof (const char *proof, const struct GNUNET_HashCode *key)
+REGEX_ITERNAL_check_proof (const char *proof, const struct GNUNET_HashCode *key)
{
struct GNUNET_HashCode key_check;
*/
static void
iterate_initial_edge (const unsigned int min_len, const unsigned int max_len,
- char *consumed_string, struct GNUNET_REGEX_State *state,
- GNUNET_REGEX_KeyIterator iterator, void *iterator_cls)
+ char *consumed_string, struct REGEX_ITERNAL_State *state,
+ REGEX_ITERNAL_KeyIterator iterator, void *iterator_cls)
{
unsigned int i;
char *temp;
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_Transition *t;
unsigned int num_edges = state->transition_count;
- struct GNUNET_REGEX_Edge edges[num_edges];
- struct GNUNET_REGEX_Edge edge[1];
+ struct REGEX_ITERNAL_Edge edges[num_edges];
+ struct REGEX_ITERNAL_Edge edge[1];
struct GNUNET_HashCode hash;
struct GNUNET_HashCode hash_new;
* @param iterator_cls closure.
*/
void
-GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a,
- GNUNET_REGEX_KeyIterator iterator,
+REGEX_ITERNAL_iterate_all_edges (struct REGEX_ITERNAL_Automaton *a,
+ REGEX_ITERNAL_KeyIterator iterator,
void *iterator_cls)
{
- struct GNUNET_REGEX_State *s;
+ struct REGEX_ITERNAL_State *s;
for (s = a->states_head; NULL != s; s = s->next)
{
- struct GNUNET_REGEX_Edge edges[s->transition_count];
+ struct REGEX_ITERNAL_Edge edges[s->transition_count];
unsigned int num_edges;
num_edges = state_get_edges (s, edges);
}
-/**
- * Create a string with binary IP notation for the given 'addr' in 'str'.
- *
- * @param af address family of the given 'addr'.
- * @param addr address that should be converted to a string.
- * struct in_addr * for IPv4 and struct in6_addr * for IPv6.
- * @param str string that will contain binary notation of 'addr'. Expected
- * to be at least 33 bytes long for IPv4 and 129 bytes long for IPv6.
- */
-static void
-iptobinstr (const int af, const void *addr, char *str)
-{
- int i;
-
- switch (af)
- {
- case AF_INET:
- {
- uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
-
- str[32] = '\0';
- str += 31;
- for (i = 31; i >= 0; i--)
- {
- *str = (b & 1) + '0';
- str--;
- b >>= 1;
- }
- break;
- }
- case AF_INET6:
- {
- struct in6_addr b = *(const struct in6_addr *) addr;
-
- str[128] = '\0';
- str += 127;
- for (i = 127; i >= 0; i--)
- {
- *str = (b.s6_addr[i / 8] & 1) + '0';
- str--;
- b.s6_addr[i / 8] >>= 1;
- }
- break;
- }
- }
-}
-
-
-/**
- * Get the ipv4 network prefix from the given 'netmask'.
- *
- * @param netmask netmask for which to get the prefix len.
- *
- * @return length of ipv4 prefix for 'netmask'.
- */
-static unsigned int
-ipv4netmasktoprefixlen (const char *netmask)
-{
- struct in_addr a;
- unsigned int len;
- uint32_t t;
-
- if (1 != inet_pton (AF_INET, netmask, &a))
- return 0;
- len = 32;
- for (t = htonl (~a.s_addr); 0 != t; t >>= 1)
- len--;
- return len;
-}
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ip' and 'netmask'.
- *
- * @param ip IPv4 representation.
- * @param netmask netmask for the ip.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN
- * bytes long.
- */
-void
-GNUNET_REGEX_ipv4toregex (const struct in_addr *ip, const char *netmask,
- char *rxstr)
-{
- unsigned int pfxlen;
-
- pfxlen = ipv4netmasktoprefixlen (netmask);
- iptobinstr (AF_INET, ip, rxstr);
- rxstr[pfxlen] = '\0';
- if (pfxlen < 32)
- strcat (rxstr, "(0|1)+");
-}
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'.
- *
- * @param ipv6 IPv6 representation.
- * @param prefixlen length of the ipv6 prefix.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN
- * bytes long.
- */
-void
-GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
- char *rxstr)
-{
- iptobinstr (AF_INET6, ipv6, rxstr);
- rxstr[prefixlen] = '\0';
- if (prefixlen < 128)
- strcat (rxstr, "(0|1)+");
-}
/* end of regex.c */
int
-GNUNET_REGEX_block_check (const struct RegexBlock *block,
+REGEX_ITERNAL_block_check (const struct RegexBlock *block,
size_t size,
const char *xquery)
{
ctx.xquery = xquery;
ctx.found = GNUNET_NO;
ctx.key = GNUNET_strdup (GNUNET_h2s (&block->key));
- res = GNUNET_REGEX_block_iterate (block, size, &check_edge, &ctx);
+ res = REGEX_ITERNAL_block_iterate (block, size, &check_edge, &ctx);
GNUNET_free (ctx.key);
if (GNUNET_SYSERR == res)
return GNUNET_SYSERR;
int
-GNUNET_REGEX_block_iterate (const struct RegexBlock *block,
+REGEX_ITERNAL_block_iterate (const struct RegexBlock *block,
size_t size,
- GNUNET_REGEX_EgdeIterator iterator,
+ REGEX_ITERNAL_EgdeIterator iterator,
void *iter_cls)
{
struct RegexEdge *edge;
* GNUNET_SYSERR if the block is invalid.
*/
int
-GNUNET_REGEX_block_check (const struct RegexBlock *block,
+REGEX_ITERNAL_block_check (const struct RegexBlock *block,
size_t size,
const char *xquery);
*
* @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
*/
-typedef int (*GNUNET_REGEX_EgdeIterator)(void *cls,
+typedef int (*REGEX_ITERNAL_EgdeIterator)(void *cls,
const char *token,
size_t len,
const struct GNUNET_HashCode *key);
* be errors in further edges.
*/
int
-GNUNET_REGEX_block_iterate (const struct RegexBlock *block,
+REGEX_ITERNAL_block_iterate (const struct RegexBlock *block,
size_t size,
- GNUNET_REGEX_EgdeIterator iterator,
+ REGEX_ITERNAL_EgdeIterator iterator,
void *iter_cls);
#if 0 /* keep Emacsens' auto-indent happy */
* @author Bartlomiej Polot
*/
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_block_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
#endif
-struct GNUNET_REGEX_announce_handle
+struct REGEX_ITERNAL_Announcement
{
/**
* DHT handle to use, must be initialized externally.
/**
* Automaton representation of the regex (expensive to build).
*/
- struct GNUNET_REGEX_Automaton* dfa;
+ struct REGEX_ITERNAL_Automaton* dfa;
/**
* Identity under which to announce the regex.
const char *proof,
int accepting,
unsigned int num_edges,
- const struct GNUNET_REGEX_Edge *edges)
+ const struct REGEX_ITERNAL_Edge *edges)
{
- struct GNUNET_REGEX_announce_handle *h = cls;
+ struct REGEX_ITERNAL_Announcement *h = cls;
struct RegexBlock *block;
struct RegexEdge *block_edge;
size_t size;
}
-struct GNUNET_REGEX_announce_handle *
-GNUNET_REGEX_announce (struct GNUNET_DHT_Handle *dht,
+struct REGEX_ITERNAL_Announcement *
+REGEX_ITERNAL_announce (struct GNUNET_DHT_Handle *dht,
const struct GNUNET_PeerIdentity *id,
const char *regex,
uint16_t compression,
struct GNUNET_STATISTICS_Handle *stats)
{
- struct GNUNET_REGEX_announce_handle *h;
+ struct REGEX_ITERNAL_Announcement *h;
GNUNET_assert (NULL != dht);
- h = GNUNET_malloc (sizeof (struct GNUNET_REGEX_announce_handle));
+ h = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_Announcement));
h->regex = regex;
h->dht = dht;
h->stats = stats;
h->id = *id;
- h->dfa = GNUNET_REGEX_construct_dfa (regex,
+ h->dfa = REGEX_ITERNAL_construct_dfa (regex,
strlen (regex),
compression);
- GNUNET_REGEX_reannounce (h);
+ REGEX_ITERNAL_reannounce (h);
return h;
}
void
-GNUNET_REGEX_reannounce (struct GNUNET_REGEX_announce_handle *h)
+REGEX_ITERNAL_reannounce (struct REGEX_ITERNAL_Announcement *h)
{
GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
- LOG (GNUNET_ERROR_TYPE_INFO, "GNUNET_REGEX_reannounce: %.60s\n", h->regex);
+ LOG (GNUNET_ERROR_TYPE_INFO, "REGEX_ITERNAL_reannounce: %.60s\n", h->regex);
LOG (GNUNET_ERROR_TYPE_DEBUG, " full: %s\n", h->regex);
- GNUNET_REGEX_iterate_all_edges (h->dfa, ®ex_iterator, h);
+ REGEX_ITERNAL_iterate_all_edges (h->dfa, ®ex_iterator, h);
}
void
-GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_announce_handle *h)
+REGEX_ITERNAL_announce_cancel (struct REGEX_ITERNAL_Announcement *h)
{
- GNUNET_REGEX_automaton_destroy (h->dfa);
+ REGEX_ITERNAL_automaton_destroy (h->dfa);
GNUNET_free (h);
}
/**
* Information about the search.
*/
- struct GNUNET_REGEX_search_handle *info;
+ struct REGEX_ITERNAL_Search *info;
/**
* We just want to look for one edge, the longer the better.
* Struct to keep information of searches of services described by a regex
* using a user-provided string service description.
*/
-struct GNUNET_REGEX_search_handle
+struct REGEX_ITERNAL_Search
{
/**
* DHT handle to use, must be initialized externally.
/**
* @param callback Callback for found peers.
*/
- GNUNET_REGEX_Found callback;
+ REGEX_ITERNAL_Found callback;
/**
* @param callback_cls Closure for @c callback.
{
const struct RegexAccept *block = data;
struct RegexSearchContext *ctx = cls;
- struct GNUNET_REGEX_search_handle *info = ctx->info;
+ struct REGEX_ITERNAL_Search *info = ctx->info;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n");
LOG (GNUNET_ERROR_TYPE_INFO, " accept for %s (key %s)\n",
{
const struct RegexBlock *block = data;
struct RegexSearchContext *ctx = cls;
- struct GNUNET_REGEX_search_handle *info = ctx->info;
+ struct REGEX_ITERNAL_Search *info = ctx->info;
void *copy;
size_t len;
char *datastore;
memcpy (proof, &block[1], len);
proof[len] = '\0';
- if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key))
+ if (GNUNET_OK != REGEX_ITERNAL_check_proof (proof, key))
{
GNUNET_break_op (0);
return;
const struct GNUNET_HashCode *key)
{
struct RegexSearchContext *ctx = cls;
- struct GNUNET_REGEX_search_handle *info = ctx->info;
+ struct REGEX_ITERNAL_Search *info = ctx->info;
const char *current;
size_t current_len;
struct RegexSearchContext *ctx)
{
struct RegexSearchContext *new_ctx;
- struct GNUNET_REGEX_search_handle *info = ctx->info;
+ struct REGEX_ITERNAL_Search *info = ctx->info;
struct GNUNET_DHT_GetHandle *get_h;
struct GNUNET_HashCode *hash;
const char *rest;
/* Find the longest match for the current string position,
* among tokens in the given block */
ctx->longest_match = 0;
- result = GNUNET_REGEX_block_iterate (block, size,
+ result = REGEX_ITERNAL_block_iterate (block, size,
®ex_edge_iterator, ctx);
GNUNET_break (GNUNET_OK == result);
}
-struct GNUNET_REGEX_search_handle *
-GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht,
+struct REGEX_ITERNAL_Search *
+REGEX_ITERNAL_search (struct GNUNET_DHT_Handle *dht,
const char *string,
- GNUNET_REGEX_Found callback,
+ REGEX_ITERNAL_Found callback,
void *callback_cls,
struct GNUNET_STATISTICS_Handle *stats)
{
- struct GNUNET_REGEX_search_handle *h;
+ struct REGEX_ITERNAL_Search *h;
struct GNUNET_DHT_GetHandle *get_h;
struct RegexSearchContext *ctx;
struct GNUNET_HashCode key;
size_t len;
/* Initialize handle */
- LOG (GNUNET_ERROR_TYPE_INFO, "GNUNET_REGEX_search: %s\n", string);
+ LOG (GNUNET_ERROR_TYPE_INFO, "REGEX_ITERNAL_search: %s\n", string);
GNUNET_assert (NULL != dht);
GNUNET_assert (NULL != callback);
- h = GNUNET_malloc (sizeof (struct GNUNET_REGEX_search_handle));
+ h = GNUNET_malloc (sizeof (struct REGEX_ITERNAL_Search));
h->dht = dht;
h->description = GNUNET_strdup (string);
h->callback = callback;
/* Initialize context */
len = strlen (string);
- size = GNUNET_REGEX_get_first_key (string, len, &key);
+ size = REGEX_ITERNAL_get_first_key (string, len, &key);
ctx = GNUNET_malloc (sizeof (struct RegexSearchContext));
ctx->position = size;
ctx->info = h;
* @param ctx The search context.
*/
static void
-regex_cancel_search (struct GNUNET_REGEX_search_handle *ctx)
+regex_cancel_search (struct REGEX_ITERNAL_Search *ctx)
{
GNUNET_free (ctx->description);
GNUNET_CONTAINER_multihashmap_iterate (ctx->dht_get_handles,
}
void
-GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_search_handle *h)
+REGEX_ITERNAL_search_cancel (struct REGEX_ITERNAL_Search *h)
{
regex_cancel_search (h);
GNUNET_free (h);
* @author Maximilian Szengel
*/
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_internal.h"
/**
* Context for graph creation. Passed as the cls to
- * GNUNET_REGEX_automaton_save_graph_step.
+ * REGEX_ITERNAL_automaton_save_graph_step.
*/
-struct GNUNET_REGEX_Graph_Context
+struct REGEX_ITERNAL_Graph_Context
{
/**
* File pointer to the dot file used for output.
*/
static void
scc_tarjan_strongconnect (unsigned int *scc_counter,
- struct GNUNET_REGEX_State *v, unsigned int *index,
- struct GNUNET_REGEX_State **stack,
+ struct REGEX_ITERNAL_State *v, unsigned int *index,
+ struct REGEX_ITERNAL_State **stack,
unsigned int *stack_size)
{
- struct GNUNET_REGEX_State *w;
- struct GNUNET_REGEX_Transition *t;
+ struct REGEX_ITERNAL_State *w;
+ struct REGEX_ITERNAL_Transition *t;
v->index = *index;
v->lowlink = *index;
* @param a the automaton for which SCCs should be computed and assigned.
*/
static void
-scc_tarjan (struct GNUNET_REGEX_Automaton *a)
+scc_tarjan (struct REGEX_ITERNAL_Automaton *a)
{
unsigned int index;
unsigned int scc_counter;
- struct GNUNET_REGEX_State *v;
- struct GNUNET_REGEX_State *stack[a->state_count];
+ struct REGEX_ITERNAL_State *v;
+ struct REGEX_ITERNAL_State *stack[a->state_count];
unsigned int stack_size;
for (v = a->states_head; NULL != v; v = v->next)
/**
* Save a state to an open file pointer. cls is expected to be a file pointer to
* an open file. Used only in conjunction with
- * GNUNET_REGEX_automaton_save_graph.
+ * REGEX_ITERNAL_automaton_save_graph.
*
* @param cls file pointer.
* @param count current count of the state, not used.
* @param s state.
*/
void
-GNUNET_REGEX_automaton_save_graph_step (void *cls, unsigned int count,
- struct GNUNET_REGEX_State *s)
+REGEX_ITERNAL_automaton_save_graph_step (void *cls, unsigned int count,
+ struct REGEX_ITERNAL_State *s)
{
- struct GNUNET_REGEX_Graph_Context *ctx = cls;
- struct GNUNET_REGEX_Transition *ctran;
+ struct REGEX_ITERNAL_Graph_Context *ctx = cls;
+ struct REGEX_ITERNAL_Transition *ctran;
char *s_acc = NULL;
char *s_tran = NULL;
char *name;
* mode
*/
void
-GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a,
+REGEX_ITERNAL_automaton_save_graph (struct REGEX_ITERNAL_Automaton *a,
const char *filename,
- enum GNUNET_REGEX_GraphSavingOptions options)
+ enum REGEX_ITERNAL_GraphSavingOptions options)
{
char *start;
char *end;
- struct GNUNET_REGEX_Graph_Context ctx;
+ struct REGEX_ITERNAL_Graph_Context ctx;
if (NULL == a)
{
ctx.filep = fopen (filename, "w");
ctx.verbose =
- (0 == (options & GNUNET_REGEX_GRAPH_VERBOSE)) ? GNUNET_NO : GNUNET_YES;
+ (0 == (options & REGEX_ITERNAL_GRAPH_VERBOSE)) ? GNUNET_NO : GNUNET_YES;
ctx.coloring =
- (0 == (options & GNUNET_REGEX_GRAPH_COLORING)) ? GNUNET_NO : GNUNET_YES;
+ (0 == (options & REGEX_ITERNAL_GRAPH_COLORING)) ? GNUNET_NO : GNUNET_YES;
if (NULL == ctx.filep)
{
start = "digraph G {\nrankdir=LR\n";
fwrite (start, strlen (start), 1, ctx.filep);
- GNUNET_REGEX_automaton_traverse (a, a->start, NULL, NULL,
- &GNUNET_REGEX_automaton_save_graph_step,
+ REGEX_ITERNAL_automaton_traverse (a, a->start, NULL, NULL,
+ ®EX_ITERNAL_automaton_save_graph_step,
&ctx);
end = "\n}\n";
#ifndef REGEX_INTERNAL_H
#define REGEX_INTERNAL_H
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#ifdef __cplusplus
extern "C"
* which they origin ('from_state'). Each state can have 0-n transitions.
* If label is NULL, this is considered to be an epsilon transition.
*/
-struct GNUNET_REGEX_Transition
+struct REGEX_ITERNAL_Transition
{
/**
* This is a linked list.
*/
- struct GNUNET_REGEX_Transition *prev;
+ struct REGEX_ITERNAL_Transition *prev;
/**
* This is a linked list.
*/
- struct GNUNET_REGEX_Transition *next;
+ struct REGEX_ITERNAL_Transition *next;
/**
* Unique id of this transition.
/**
* State to which this transition leads.
*/
- struct GNUNET_REGEX_State *to_state;
+ struct REGEX_ITERNAL_State *to_state;
/**
* State from which this transition origins.
*/
- struct GNUNET_REGEX_State *from_state;
+ struct REGEX_ITERNAL_State *from_state;
};
/**
* A state. Can be used in DFA and NFA automatons.
*/
-struct GNUNET_REGEX_State;
+struct REGEX_ITERNAL_State;
/**
* Set of states.
*/
-struct GNUNET_REGEX_StateSet
+struct REGEX_ITERNAL_StateSet
{
/**
* Array of states.
*/
- struct GNUNET_REGEX_State **states;
+ struct REGEX_ITERNAL_State **states;
/**
* Number of entries in *use* in the 'states' array.
/**
* A state. Can be used in DFA and NFA automatons.
*/
-struct GNUNET_REGEX_State
+struct REGEX_ITERNAL_State
{
/**
* This is a linked list to keep states in an automaton.
*/
- struct GNUNET_REGEX_State *prev;
+ struct REGEX_ITERNAL_State *prev;
/**
* This is a linked list to keep states in an automaton.
*/
- struct GNUNET_REGEX_State *next;
+ struct REGEX_ITERNAL_State *next;
/**
* This is a multi DLL for StateSet_MDLL.
*/
- struct GNUNET_REGEX_State *prev_SS;
+ struct REGEX_ITERNAL_State *prev_SS;
/**
* This is a multi DLL for StateSet_MDLL.
*/
- struct GNUNET_REGEX_State *next_SS;
+ struct REGEX_ITERNAL_State *next_SS;
/**
* This is a multi DLL for StateSet_MDLL Stack.
*/
- struct GNUNET_REGEX_State *prev_ST;
+ struct REGEX_ITERNAL_State *prev_ST;
/**
* This is a multi DLL for StateSet_MDLL Stack.
*/
- struct GNUNET_REGEX_State *next_ST;
+ struct REGEX_ITERNAL_State *next_ST;
/**
* Unique state id.
/**
* DLL of transitions.
*/
- struct GNUNET_REGEX_Transition *transitions_head;
+ struct REGEX_ITERNAL_Transition *transitions_head;
/**
* DLL of transitions.
*/
- struct GNUNET_REGEX_Transition *transitions_tail;
+ struct REGEX_ITERNAL_Transition *transitions_tail;
/**
* Number of incoming transitions. Used for compressing DFA paths.
* Set of states on which this state is based on. Used when creating a DFA out
* of several NFA states.
*/
- struct GNUNET_REGEX_StateSet nfa_set;
+ struct REGEX_ITERNAL_StateSet nfa_set;
};
/**
* Type of an automaton.
*/
-enum GNUNET_REGEX_AutomatonType
+enum REGEX_ITERNAL_AutomatonType
{
NFA,
DFA
/**
* Automaton representation.
*/
-struct GNUNET_REGEX_Automaton
+struct REGEX_ITERNAL_Automaton
{
/**
* Linked list of NFAs used for partial NFA creation.
*/
- struct GNUNET_REGEX_Automaton *prev;
+ struct REGEX_ITERNAL_Automaton *prev;
/**
* Linked list of NFAs used for partial NFA creation.
*/
- struct GNUNET_REGEX_Automaton *next;
+ struct REGEX_ITERNAL_Automaton *next;
/**
* First state of the automaton. This is mainly used for constructing an NFA,
* where each NFA itself consists of one or more NFAs linked together.
*/
- struct GNUNET_REGEX_State *start;
+ struct REGEX_ITERNAL_State *start;
/**
* End state of the partial NFA. This is undefined for DFAs
*/
- struct GNUNET_REGEX_State *end;
+ struct REGEX_ITERNAL_State *end;
/**
* Number of states in the automaton.
/**
* DLL of states.
*/
- struct GNUNET_REGEX_State *states_head;
+ struct REGEX_ITERNAL_State *states_head;
/**
* DLL of states
*/
- struct GNUNET_REGEX_State *states_tail;
+ struct REGEX_ITERNAL_State *states_tail;
/**
* Type of the automaton.
*/
- enum GNUNET_REGEX_AutomatonType type;
+ enum REGEX_ITERNAL_AutomatonType type;
/**
* Regex
* @param regex regular expression string.
* @param len length of the string.
*
- * @return NFA, needs to be freed using GNUNET_REGEX_automaton_destroy.
+ * @return NFA, needs to be freed using REGEX_ITERNAL_automaton_destroy.
*/
-struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_nfa (const char *regex, const size_t len);
+struct REGEX_ITERNAL_Automaton *
+REGEX_ITERNAL_construct_nfa (const char *regex, const size_t len);
/**
*
* @return GNUNET_YES to proceed traversal, GNUNET_NO to stop.
*/
-typedef int (*GNUNET_REGEX_traverse_check) (void *cls,
- struct GNUNET_REGEX_State * s,
- struct GNUNET_REGEX_Transition * t);
+typedef int (*REGEX_ITERNAL_traverse_check) (void *cls,
+ struct REGEX_ITERNAL_State * s,
+ struct REGEX_ITERNAL_Transition * t);
/**
* @param count current count of the state, from 0 to a->state_count -1.
* @param s state.
*/
-typedef void (*GNUNET_REGEX_traverse_action) (void *cls,
+typedef void (*REGEX_ITERNAL_traverse_action) (void *cls,
const unsigned int count,
- struct GNUNET_REGEX_State * s);
+ struct REGEX_ITERNAL_State * s);
/**
* @param action_cls closure for action
*/
void
-GNUNET_REGEX_automaton_traverse (const struct GNUNET_REGEX_Automaton *a,
- struct GNUNET_REGEX_State *start,
- GNUNET_REGEX_traverse_check check,
+REGEX_ITERNAL_automaton_traverse (const struct REGEX_ITERNAL_Automaton *a,
+ struct REGEX_ITERNAL_State *start,
+ REGEX_ITERNAL_traverse_check check,
void *check_cls,
- GNUNET_REGEX_traverse_action action,
+ REGEX_ITERNAL_traverse_action action,
void *action_cls);
/**
* @return canonical regex string.
*/
const char *
-GNUNET_REGEX_get_canonical_regex (struct GNUNET_REGEX_Automaton *a);
+REGEX_ITERNAL_get_canonical_regex (struct REGEX_ITERNAL_Automaton *a);
/**
* @return number of transitions in the given automaton.
*/
unsigned int
-GNUNET_REGEX_get_transition_count (struct GNUNET_REGEX_Automaton *a);
+REGEX_ITERNAL_get_transition_count (struct REGEX_ITERNAL_Automaton *a);
/**
* Context that contains an id counter for states and transitions as well as a
* DLL of automatons used as a stack for NFA construction.
*/
-struct GNUNET_REGEX_Context
+struct REGEX_ITERNAL_Context
{
/**
* Unique state id.
unsigned int transition_id;
/**
- * DLL of GNUNET_REGEX_Automaton's used as a stack.
+ * DLL of REGEX_ITERNAL_Automaton's used as a stack.
*/
- struct GNUNET_REGEX_Automaton *stack_head;
+ struct REGEX_ITERNAL_Automaton *stack_head;
/**
- * DLL of GNUNET_REGEX_Automaton's used as a stack.
+ * DLL of REGEX_ITERNAL_Automaton's used as a stack.
*/
- struct GNUNET_REGEX_Automaton *stack_tail;
+ struct REGEX_ITERNAL_Automaton *stack_tail;
};
* @param stride_len length of the strides.
*/
void
-GNUNET_REGEX_dfa_add_multi_strides (struct GNUNET_REGEX_Context *regex_ctx,
- struct GNUNET_REGEX_Automaton *dfa,
+REGEX_ITERNAL_dfa_add_multi_strides (struct REGEX_ITERNAL_Context *regex_ctx,
+ struct REGEX_ITERNAL_Automaton *dfa,
const unsigned int stride_len);
* needs to be freed, otherwise.
*/
char *
-GNUNET_REGEX_generate_random_regex (size_t rx_length, char *matching_str);
+REGEX_ITERNAL_generate_random_regex (size_t rx_length, char *matching_str);
/**
* @return random string that needs to be freed.
*/
char *
-GNUNET_REGEX_generate_random_string (size_t max_len);
+REGEX_ITERNAL_generate_random_string (size_t max_len);
#if 0 /* keep Emacsens' auto-indent happy */
--- /dev/null
+/*
+ This file is part of GNUnet
+ (C) 2012, 2013 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file regex/regex_internal_lib.h
+ * @brief library to parse regular expressions into dfa
+ * @author Maximilian Szengel
+ *
+ */
+
+#ifndef REGEX_INTERNAL_LIB_H
+#define REGEX_INTERNAL_LIB_H
+
+#include "gnunet_util_lib.h"
+#include "gnunet_dht_service.h"
+#include "gnunet_statistics_service.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0 /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+
+
+
+/**
+ * Automaton (NFA/DFA) representation.
+- */
+struct REGEX_ITERNAL_Automaton;
+
+
+/**
+ * Edge representation.
+ */
+struct REGEX_ITERNAL_Edge
+{
+ /**
+ * Label of the edge. FIXME: might want to not consume exactly multiples of 8 bits, need length?
+ */
+ const char *label;
+
+ /**
+ * Destionation of the edge.
+ */
+ struct GNUNET_HashCode destination;
+};
+
+
+/**
+ * Construct DFA for the given 'regex' of length 'len'.
+ *
+ * Path compression means, that for example a DFA o -> a -> b -> c -> o will be
+ * compressed to o -> abc -> o. Note that this parameter influences the
+ * non-determinism of states of the resulting NFA in the DHT (number of outgoing
+ * edges with the same label). For example for an application that stores IPv4
+ * addresses as bitstrings it could make sense to limit the path compression to
+ * 4 or 8.
+ *
+ * @param regex regular expression string.
+ * @param len length of the regular expression.
+ * @param max_path_len limit the path compression length to the
+ * given value. If set to 1, no path compression is applied. Set to 0 for
+ * maximal possible path compression (generally not desireable).
+ * @return DFA, needs to be freed using REGEX_ITERNAL_automaton_destroy.
+ */
+struct REGEX_ITERNAL_Automaton *
+REGEX_ITERNAL_construct_dfa (const char *regex, const size_t len,
+ unsigned int max_path_len);
+
+
+/**
+ * Free the memory allocated by constructing the REGEX_ITERNAL_Automaton.
+ * data structure.
+ *
+ * @param a automaton to be destroyed.
+ */
+void
+REGEX_ITERNAL_automaton_destroy (struct REGEX_ITERNAL_Automaton *a);
+
+
+/**
+ * Options for graph creation function
+ * REGEX_ITERNAL_automaton_save_graph.
+ */
+enum REGEX_ITERNAL_GraphSavingOptions
+{
+ /**
+ * Default. Do nothing special.
+ */
+ REGEX_ITERNAL_GRAPH_DEFAULT = 0,
+
+ /**
+ * The generated graph will include extra information such as the NFA states
+ * that were used to generate the DFA state.
+ */
+ REGEX_ITERNAL_GRAPH_VERBOSE = 1,
+
+ /**
+ * Enable graph coloring. Will color each SCC in a different color.
+ */
+ REGEX_ITERNAL_GRAPH_COLORING = 2
+};
+
+
+/**
+ * Save the given automaton as a GraphViz dot file.
+ *
+ * @param a the automaton to be saved.
+ * @param filename where to save the file.
+ * @param options options for graph generation that include coloring or verbose
+ * mode
+ */
+void
+REGEX_ITERNAL_automaton_save_graph (struct REGEX_ITERNAL_Automaton *a,
+ const char *filename,
+ enum REGEX_ITERNAL_GraphSavingOptions options);
+
+
+/**
+ * Evaluates the given 'string' against the given compiled regex.
+ *
+ * @param a automaton.
+ * @param string string to check.
+ *
+ * @return 0 if string matches, non 0 otherwise.
+ */
+int
+REGEX_ITERNAL_eval (struct REGEX_ITERNAL_Automaton *a,
+ const char *string);
+
+
+/**
+ * Get the first key for the given 'input_string'. This hashes
+ * the first x bits of the 'input_string'.
+ *
+ * @param input_string string.
+ * @param string_len length of the 'input_string'.
+ * @param key pointer to where to write the hash code.
+ *
+ * @return number of bits of 'input_string' that have been consumed
+ * to construct the key
+ */
+size_t
+REGEX_ITERNAL_get_first_key (const char *input_string, size_t string_len,
+ struct GNUNET_HashCode * key);
+
+
+/**
+ * Check if the given 'proof' matches the given 'key'.
+ *
+ * @param proof partial regex of a state.
+ * @param key hash of a state.
+ *
+ * @return GNUNET_OK if the proof is valid for the given key.
+ */
+int
+REGEX_ITERNAL_check_proof (const char *proof,
+ const struct GNUNET_HashCode *key);
+
+
+/**
+ * Iterator callback function.
+ *
+ * @param cls closure.
+ * @param key hash for current state.
+ * @param proof proof for current state.
+ * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
+ * @param num_edges number of edges leaving current state.
+ * @param edges edges leaving current state.
+ */
+typedef void (*REGEX_ITERNAL_KeyIterator)(void *cls,
+ const struct GNUNET_HashCode *key,
+ const char *proof,
+ int accepting,
+ unsigned int num_edges,
+ const struct REGEX_ITERNAL_Edge *edges);
+
+
+/**
+ * Iterate over all edges starting from start state of automaton 'a'. Calling
+ * iterator for each edge.
+ *
+ * @param a automaton.
+ * @param iterator iterator called for each edge.
+ * @param iterator_cls closure.
+ */
+void
+REGEX_ITERNAL_iterate_all_edges (struct REGEX_ITERNAL_Automaton *a,
+ REGEX_ITERNAL_KeyIterator iterator,
+ void *iterator_cls);
+
+
+
+/**
+ * Handle to store cached data about a regex announce.
+ */
+struct REGEX_ITERNAL_Announcement;
+
+/**
+ * Handle to store data about a regex search.
+ */
+struct REGEX_ITERNAL_Search;
+
+/**
+ * Announce a regular expression: put all states of the automaton in the DHT.
+ * Does not free resources, must call REGEX_ITERNAL_announce_cancel for that.
+ *
+ * @param dht An existing and valid DHT service handle. CANNOT be NULL.
+ * @param id ID to announce as provider of regex. Own ID in most cases.
+ * @param regex Regular expression to announce.
+ * @param compression How many characters per edge can we squeeze?
+ * @param stats Optional statistics handle to report usage. Can be NULL.
+ *
+ * @return Handle to reuse o free cached resources.
+ * Must be freed by calling REGEX_ITERNAL_announce_cancel.
+ */
+struct REGEX_ITERNAL_Announcement *
+REGEX_ITERNAL_announce (struct GNUNET_DHT_Handle *dht,
+ const struct GNUNET_PeerIdentity *id,
+ const char *regex,
+ uint16_t compression,
+ struct GNUNET_STATISTICS_Handle *stats);
+
+/**
+ * Announce again a regular expression previously announced.
+ * Does use caching to speed up process.
+ *
+ * @param h Handle returned by a previous REGEX_ITERNAL_announce call.
+ */
+void
+REGEX_ITERNAL_reannounce (struct REGEX_ITERNAL_Announcement *h);
+
+
+/**
+ * Clear all cached data used by a regex announce.
+ * Does not close DHT connection.
+ *
+ * @param h Handle returned by a previous REGEX_ITERNAL_announce call.
+ */
+void
+REGEX_ITERNAL_announce_cancel (struct REGEX_ITERNAL_Announcement *h);
+
+
+/**
+ * Search callback function.
+ *
+ * @param cls Closure provided in REGEX_ITERNAL_search.
+ * @param id Peer providing a regex that matches the string.
+ * @param get_path Path of the get request.
+ * @param get_path_length Lenght of get_path.
+ * @param put_path Path of the put request.
+ * @param put_path_length Length of the put_path.
+ */
+typedef void (*REGEX_ITERNAL_Found)(void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length);
+
+
+/**
+ * Search for a peer offering a regex matching certain string in the DHT.
+ * The search runs until REGEX_ITERNAL_search_cancel is called, even if results
+ * are returned.
+ *
+ * @param dht An existing and valid DHT service handle.
+ * @param string String to match against the regexes in the DHT.
+ * @param callback Callback for found peers.
+ * @param callback_cls Closure for @c callback.
+ * @param stats Optional statistics handle to report usage. Can be NULL.
+ *
+ * @return Handle to stop search and free resources.
+ * Must be freed by calling REGEX_ITERNAL_search_cancel.
+ */
+struct REGEX_ITERNAL_Search *
+REGEX_ITERNAL_search (struct GNUNET_DHT_Handle *dht,
+ const char *string,
+ REGEX_ITERNAL_Found callback,
+ void *callback_cls,
+ struct GNUNET_STATISTICS_Handle *stats);
+
+/**
+ * Stop search and free all data used by a REGEX_ITERNAL_search call.
+ * Does not close DHT connection.
+ *
+ * @param h Handle returned by a previous REGEX_ITERNAL_search call.
+ */
+void
+REGEX_ITERNAL_search_cancel (struct REGEX_ITERNAL_Search *h);
+
+
+#if 0 /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+/* end of regex_internal_lib.h */
+#endif
* @author Maximilian Szengel
*/
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "gnunet_crypto_lib.h"
#include "regex_internal.h"
* needs to be freed, otherwise.
*/
char *
-GNUNET_REGEX_generate_random_regex (size_t rx_length, char *matching_str)
+REGEX_ITERNAL_generate_random_regex (size_t rx_length, char *matching_str)
{
char *rx;
char *rx_p;
* @return random string that needs to be freed.
*/
char *
-GNUNET_REGEX_generate_random_string (size_t max_len)
+REGEX_ITERNAL_generate_random_string (size_t max_len)
{
unsigned int i;
char *str;
* This function DOES NOT support arbitrary regex combining.
*/
char *
-GNUNET_REGEX_combine (char * const regexes[])
+REGEX_ITERNAL_combine (char * const regexes[])
{
unsigned int i;
char *combined;
/**
* Read a set of regexes from a file, one per line and return them in an array
- * suitable for GNUNET_REGEX_combine.
- * The array must be free'd using GNUNET_REGEX_free_from_file.
+ * suitable for REGEX_ITERNAL_combine.
+ * The array must be free'd using REGEX_ITERNAL_free_from_file.
*
* @param filename Name of the file containing the regexes.
*
* @return A newly allocated, NULL terminated array of regexes.
*/
char **
-GNUNET_REGEX_read_from_file (const char *filename)
+REGEX_ITERNAL_read_from_file (const char *filename)
{
struct GNUNET_DISK_FileHandle *f;
unsigned int nr;
* @param regexes NULL-terminated array of regexes.
*/
void
-GNUNET_REGEX_free_from_file (char **regexes)
+REGEX_ITERNAL_free_from_file (char **regexes)
{
unsigned int i;
*
*/
-#ifndef GNUNET_REGEX_TEST_LIB_H
-#define GNUNET_REGEX_TEST_LIB_H
+#ifndef REGEX_ITERNAL_TEST_LIB_H
+#define REGEX_ITERNAL_TEST_LIB_H
#ifdef __cplusplus
* @return A string with a single regex that matches any of the original regexes
*/
char *
-GNUNET_REGEX_combine(char * const regexes[]);
+REGEX_ITERNAL_combine(char * const regexes[]);
/**
* Read a set of regexes from a file, one per line and return them in an array
- * suitable for GNUNET_REGEX_combine.
- * The array must be free'd using GNUNET_REGEX_free_from_file.
+ * suitable for REGEX_ITERNAL_combine.
+ * The array must be free'd using REGEX_ITERNAL_free_from_file.
*
* @param filename Name of the file containing the regexes.
*
* @return A newly allocated, NULL terminated array of regexes.
*/
char **
-GNUNET_REGEX_read_from_file (const char *filename);
+REGEX_ITERNAL_read_from_file (const char *filename);
/**
* @param regexes NULL-terminated array of regexes.
*/
void
-GNUNET_REGEX_free_from_file (char **regexes);
+REGEX_ITERNAL_free_from_file (char **regexes);
#if 0 /* keep Emacsens' auto-indent happy */
{
}
#endif
-/* end of gnunet_regex_lib.h */
+/* end of regex_internal_lib.h */
#endif
\ No newline at end of file
#include <regex.h>
#include <time.h>
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_internal.h"
enum Match_Result
int eval_check;
int eval_canonical;
int eval_canonical_check;
- struct GNUNET_REGEX_Automaton *dfa;
+ struct REGEX_ITERNAL_Automaton *dfa;
regex_t rx;
regmatch_t matchptr[1];
char error[200];
/* Generate random regex and a string that matches the regex */
matching_str = GNUNET_malloc (rx_length + 1);
- rand_rx = GNUNET_REGEX_generate_random_regex (rx_length, matching_str);
+ rand_rx = REGEX_ITERNAL_generate_random_regex (rx_length, matching_str);
/* Now match */
result = 0;
{
if (0 < i)
{
- matching_str = GNUNET_REGEX_generate_random_string (max_str_len);
+ matching_str = REGEX_ITERNAL_generate_random_string (max_str_len);
}
/* Match string using DFA */
- dfa = GNUNET_REGEX_construct_dfa (rand_rx, strlen (rand_rx), 0);
+ dfa = REGEX_ITERNAL_construct_dfa (rand_rx, strlen (rand_rx), 0);
if (NULL == dfa)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constructing DFA failed\n");
goto error;
}
- eval = GNUNET_REGEX_eval (dfa, matching_str);
+ eval = REGEX_ITERNAL_eval (dfa, matching_str);
/* save the canonical regex for later comparison */
- canonical_regex = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (dfa));
- GNUNET_REGEX_automaton_destroy (dfa);
+ canonical_regex = GNUNET_strdup (REGEX_ITERNAL_get_canonical_regex (dfa));
+ REGEX_ITERNAL_automaton_destroy (dfa);
/* Match string using glibc regex */
if (0 != regcomp (&rx, rand_rx, REG_EXTENDED))
/* Match canonical regex */
dfa =
- GNUNET_REGEX_construct_dfa (canonical_regex, strlen (canonical_regex),
+ REGEX_ITERNAL_construct_dfa (canonical_regex, strlen (canonical_regex),
0);
if (NULL == dfa)
{
goto error;
}
- eval_canonical = GNUNET_REGEX_eval (dfa, matching_str);
- GNUNET_REGEX_automaton_destroy (dfa);
+ eval_canonical = REGEX_ITERNAL_eval (dfa, matching_str);
+ REGEX_ITERNAL_automaton_destroy (dfa);
if (0 != regcomp (&rx, canonical_regex, REG_EXTENDED))
{
* @return 0 on successfull, non 0 otherwise
*/
int
-test_automaton (struct GNUNET_REGEX_Automaton *a, regex_t * rx,
+test_automaton (struct REGEX_ITERNAL_Automaton *a, regex_t * rx,
struct Regex_String_Pair *rxstr)
{
int result;
for (i = 0; i < rxstr->string_count; i++)
{
- eval = GNUNET_REGEX_eval (a, rxstr->strings[i]);
+ eval = REGEX_ITERNAL_eval (a, rxstr->strings[i]);
eval_check = regexec (rx, rxstr->strings[i], 1, matchptr, 0);
/* We only want to match the whole string, because that's what our DFA does,
"string: %s\nexpected result: %i\n"
"gnunet regex: %i\nglibc regex: %i\nglibc error: %s\n"
"rm_so: %i\nrm_eo: %i\n\n", rxstr->regex,
- GNUNET_REGEX_get_canonical_regex (a), rxstr->strings[i],
+ REGEX_ITERNAL_get_canonical_regex (a), rxstr->strings[i],
rxstr->expected_results[i], eval, eval_check, error,
matchptr[0].rm_so, matchptr[0].rm_eo);
}
{
GNUNET_log_setup ("test-regex", "WARNING", NULL);
- struct GNUNET_REGEX_Automaton *a;
+ struct REGEX_ITERNAL_Automaton *a;
regex_t rx;
int i;
int check_nfa;
}
/* NFA test */
- a = GNUNET_REGEX_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
+ a = REGEX_ITERNAL_construct_nfa (rxstr[i].regex, strlen (rxstr[i].regex));
check_nfa += test_automaton (a, &rx, &rxstr[i]);
- GNUNET_REGEX_automaton_destroy (a);
+ REGEX_ITERNAL_automaton_destroy (a);
/* DFA test */
- a = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
+ a = REGEX_ITERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
check_dfa += test_automaton (a, &rx, &rxstr[i]);
- check_proof = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (a));
- GNUNET_REGEX_automaton_destroy (a);
+ check_proof = GNUNET_strdup (REGEX_ITERNAL_get_canonical_regex (a));
+ REGEX_ITERNAL_automaton_destroy (a);
- a = GNUNET_REGEX_construct_dfa (check_proof, strlen (check_proof), 0);
+ a = REGEX_ITERNAL_construct_dfa (check_proof, strlen (check_proof), 0);
check_dfa += test_automaton (a, &rx, &rxstr[i]);
- GNUNET_REGEX_automaton_destroy (a);
+ REGEX_ITERNAL_automaton_destroy (a);
if (0 != check_dfa)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "check_proof: %s\n", check_proof);
GNUNET_free_non_null (check_proof);
#include <regex.h>
#include <time.h>
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_internal.h"
#define KEEP_FILES 1
main (int argc, char *argv[])
{
int error;
- struct GNUNET_REGEX_Automaton *a;
+ struct REGEX_ITERNAL_Automaton *a;
unsigned int i;
const char *filename = "test_graph.dot";
for (i = 0; i < 12; i++)
{
/* Check NFA graph creation */
- a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
- GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_nfa (regex[i], strlen (regex[i]));
+ REGEX_ITERNAL_automaton_save_graph (a, filename, REGEX_ITERNAL_GRAPH_DEFAULT);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
- a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
- GNUNET_REGEX_automaton_save_graph (a, filename,
- GNUNET_REGEX_GRAPH_DEFAULT |
- GNUNET_REGEX_GRAPH_VERBOSE);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_nfa (regex[i], strlen (regex[i]));
+ REGEX_ITERNAL_automaton_save_graph (a, filename,
+ REGEX_ITERNAL_GRAPH_DEFAULT |
+ REGEX_ITERNAL_GRAPH_VERBOSE);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
- a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
- GNUNET_REGEX_automaton_save_graph (a, filename,
- GNUNET_REGEX_GRAPH_DEFAULT |
- GNUNET_REGEX_GRAPH_COLORING);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_nfa (regex[i], strlen (regex[i]));
+ REGEX_ITERNAL_automaton_save_graph (a, filename,
+ REGEX_ITERNAL_GRAPH_DEFAULT |
+ REGEX_ITERNAL_GRAPH_COLORING);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
- a = GNUNET_REGEX_construct_nfa (regex[i], strlen (regex[i]));
- GNUNET_REGEX_automaton_save_graph (a, filename,
- GNUNET_REGEX_GRAPH_DEFAULT |
- GNUNET_REGEX_GRAPH_VERBOSE |
- GNUNET_REGEX_GRAPH_COLORING);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_nfa (regex[i], strlen (regex[i]));
+ REGEX_ITERNAL_automaton_save_graph (a, filename,
+ REGEX_ITERNAL_GRAPH_DEFAULT |
+ REGEX_ITERNAL_GRAPH_VERBOSE |
+ REGEX_ITERNAL_GRAPH_COLORING);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
/* Check DFA graph creation */
- a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 0);
- GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
+ REGEX_ITERNAL_automaton_save_graph (a, filename, REGEX_ITERNAL_GRAPH_DEFAULT);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
- a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 0);
- GNUNET_REGEX_automaton_save_graph (a, filename,
- GNUNET_REGEX_GRAPH_DEFAULT |
- GNUNET_REGEX_GRAPH_VERBOSE);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
+ REGEX_ITERNAL_automaton_save_graph (a, filename,
+ REGEX_ITERNAL_GRAPH_DEFAULT |
+ REGEX_ITERNAL_GRAPH_VERBOSE);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
- a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 0);
- GNUNET_REGEX_automaton_save_graph (a, filename,
- GNUNET_REGEX_GRAPH_DEFAULT |
- GNUNET_REGEX_GRAPH_COLORING);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
+ REGEX_ITERNAL_automaton_save_graph (a, filename,
+ REGEX_ITERNAL_GRAPH_DEFAULT |
+ REGEX_ITERNAL_GRAPH_COLORING);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
- a = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 4);
- GNUNET_REGEX_automaton_save_graph (a, filename, GNUNET_REGEX_GRAPH_DEFAULT);
- GNUNET_REGEX_automaton_destroy (a);
+ a = REGEX_ITERNAL_construct_dfa (regex[i], strlen (regex[i]), 4);
+ REGEX_ITERNAL_automaton_save_graph (a, filename, REGEX_ITERNAL_GRAPH_DEFAULT);
+ REGEX_ITERNAL_automaton_destroy (a);
error += filecheck (filename);
}
+++ /dev/null
-/*
- This file is part of GNUnet
- (C) 2012 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/**
- * @file regex/test_regex_iptoregex.c
- * @brief simple test for regex.c iptoregex functions
- * @author Maximilian Szengel
- */
-#include "platform.h"
-#include "gnunet_regex_lib.h"
-
-
-static int
-test_iptoregex (const char *ipv4, const char *netmask, const char *expectedv4,
- const char *ipv6, unsigned int prefixlen,
- const char *expectedv6)
-{
- int error = 0;
-
- struct in_addr a;
- struct in6_addr b;
- char rxv4[GNUNET_REGEX_IPV4_REGEXLEN];
- char rxv6[GNUNET_REGEX_IPV6_REGEXLEN];
-
- GNUNET_assert (1 == inet_pton (AF_INET, ipv4, &a));
- GNUNET_REGEX_ipv4toregex (&a, netmask, rxv4);
-
-
- if (0 != strcmp (rxv4, expectedv4))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected: %s but got: %s\n",
- expectedv4, rxv4);
- error++;
- }
-
- GNUNET_assert (1 == inet_pton (AF_INET6, ipv6, &b));
- GNUNET_REGEX_ipv6toregex (&b, prefixlen, rxv6);
-
- if (0 != strcmp (rxv6, expectedv6))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected: %s but got: %s\n",
- expectedv6, rxv6);
- error++;
- }
-
- return error;
-}
-
-int
-main (int argc, char *argv[])
-{
- GNUNET_log_setup ("test-regex", "WARNING", NULL);
-
- int error;
-
- error = 0;
-
- error +=
- test_iptoregex ("192.0.0.0", "255.255.255.0",
- "110000000000000000000000(0|1)+", "FFFF::0", 16,
- "1111111111111111(0|1)+");
-
- error +=
- test_iptoregex ("187.238.225.0", "255.255.255.128",
- "1011101111101110111000010(0|1)+", "E1E1:73F9:51BE::0",
- 49,
- "1110000111100001011100111111100101010001101111100(0|1)+");
-
- error +=
- test_iptoregex ("255.255.255.255", "255.255.255.255",
- "11111111111111111111111111111111",
- "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 128,
- "11111111111111111111111111111111"
- "11111111111111111111111111111111"
- "11111111111111111111111111111111"
- "11111111111111111111111111111111");
-
- error +=
- test_iptoregex ("0.0.0.0", "255.255.255.255",
- "00000000000000000000000000000000", "0::0", 128,
- "00000000000000000000000000000000"
- "00000000000000000000000000000000"
- "00000000000000000000000000000000"
- "00000000000000000000000000000000");
-
- return error;
-}
#include <regex.h>
#include <time.h>
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_internal.h"
/**
/**
* Set to GNUNET_YES to save a debug graph.
*/
-#define GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH GNUNET_NO
+#define REGEX_ITERNAL_ITERATE_SAVE_DEBUG_GRAPH GNUNET_NO
static unsigned int transition_counter;
static void
key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
int accepting, unsigned int num_edges,
- const struct GNUNET_REGEX_Edge *edges)
+ const struct REGEX_ITERNAL_Edge *edges)
{
unsigned int i;
struct IteratorContext *ctx = cls;
ctx->match_count++;
}
- if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key))
+ if (GNUNET_OK != REGEX_ITERNAL_check_proof (proof, key))
{
ctx->error++;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_log_setup ("test-regex", "WARNING", NULL);
int error;
- struct GNUNET_REGEX_Automaton *dfa;
+ struct REGEX_ITERNAL_Automaton *dfa;
unsigned int i;
unsigned int num_transitions;
char *filename = NULL;
/* Create graph */
- if (GNUNET_YES == GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH)
+ if (GNUNET_YES == REGEX_ITERNAL_ITERATE_SAVE_DEBUG_GRAPH)
{
GNUNET_asprintf (&filename, "iteration_graph_%u.dot", i);
ctx.graph_filep = fopen (filename, "w");
ctx.strings = rxstr[i].strings;
ctx.match_count = 0;
dfa =
- GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
- GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx);
+ REGEX_ITERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
+ REGEX_ITERNAL_iterate_all_edges (dfa, key_iterator, &ctx);
num_transitions =
- GNUNET_REGEX_get_transition_count (dfa) - dfa->start->transition_count;
+ REGEX_ITERNAL_get_transition_count (dfa) - dfa->start->transition_count;
if (transition_counter < num_transitions)
{
error += (ctx.string_count - ctx.match_count);
}
- GNUNET_REGEX_automaton_destroy (dfa);
+ REGEX_ITERNAL_automaton_destroy (dfa);
/* Finish graph */
if (GNUNET_YES == ctx.should_save_graph)
ctx.match_count = 0;
dfa =
- GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
- GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2);
- GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx);
+ REGEX_ITERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
+ REGEX_ITERNAL_dfa_add_multi_strides (NULL, dfa, 2);
+ REGEX_ITERNAL_iterate_all_edges (dfa, key_iterator, &ctx);
if (ctx.match_count < ctx.string_count)
{
error += (ctx.string_count - ctx.match_count);
}
- GNUNET_REGEX_automaton_destroy (dfa);
+ REGEX_ITERNAL_automaton_destroy (dfa);
}
error += ctx.error;
* @author Maximilian Szengel
*/
#include "platform.h"
-#include "gnunet_regex_lib.h"
+#include "regex_internal_lib.h"
#include "regex_internal.h"
test_proof (const char *regex)
{
unsigned int error;
- struct GNUNET_REGEX_Automaton *dfa;
+ struct REGEX_ITERNAL_Automaton *dfa;
char *c_rx1;
const char *c_rx2;
- dfa = GNUNET_REGEX_construct_dfa (regex, strlen (regex), 1);
+ dfa = REGEX_ITERNAL_construct_dfa (regex, strlen (regex), 1);
GNUNET_assert (NULL != dfa);
- c_rx1 = GNUNET_strdup (GNUNET_REGEX_get_canonical_regex (dfa));
- GNUNET_REGEX_automaton_destroy (dfa);
- dfa = GNUNET_REGEX_construct_dfa (c_rx1, strlen (c_rx1), 1);
+ c_rx1 = GNUNET_strdup (REGEX_ITERNAL_get_canonical_regex (dfa));
+ REGEX_ITERNAL_automaton_destroy (dfa);
+ dfa = REGEX_ITERNAL_construct_dfa (c_rx1, strlen (c_rx1), 1);
GNUNET_assert (NULL != dfa);
- c_rx2 = GNUNET_REGEX_get_canonical_regex (dfa);
+ c_rx2 = REGEX_ITERNAL_get_canonical_regex (dfa);
error = (0 == strcmp (c_rx1, c_rx2)) ? 0 : 1;
}
GNUNET_free (c_rx1);
- GNUNET_REGEX_automaton_destroy (dfa);
+ REGEX_ITERNAL_automaton_destroy (dfa);
return error;
}
for (i = 0; i < count; i++)
{
- rand_rx = GNUNET_REGEX_generate_random_regex (rx_length, NULL);
+ rand_rx = REGEX_ITERNAL_generate_random_regex (rx_length, NULL);
failures += test_proof (rand_rx);
GNUNET_free (rand_rx);
}
const char *canon_rx1;
const char *canon_rx2;
- struct GNUNET_REGEX_Automaton *dfa1;
- struct GNUNET_REGEX_Automaton *dfa2;
+ struct REGEX_ITERNAL_Automaton *dfa1;
+ struct REGEX_ITERNAL_Automaton *dfa2;
error = 0;
for (i = 0; i < 8; i += 2)
{
- dfa1 = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]), 1);
- dfa2 = GNUNET_REGEX_construct_dfa (regex[i + 1], strlen (regex[i + 1]), 1);
+ dfa1 = REGEX_ITERNAL_construct_dfa (regex[i], strlen (regex[i]), 1);
+ dfa2 = REGEX_ITERNAL_construct_dfa (regex[i + 1], strlen (regex[i + 1]), 1);
GNUNET_assert (NULL != dfa1);
GNUNET_assert (NULL != dfa2);
- canon_rx1 = GNUNET_REGEX_get_canonical_regex (dfa1);
- canon_rx2 = GNUNET_REGEX_get_canonical_regex (dfa2);
+ canon_rx1 = REGEX_ITERNAL_get_canonical_regex (dfa1);
+ canon_rx2 = REGEX_ITERNAL_get_canonical_regex (dfa2);
error += (0 == strcmp (canon_rx1, canon_rx2)) ? 0 : 1;
regex[i], canon_rx1, regex[i + 1], canon_rx2);
}
- GNUNET_REGEX_automaton_destroy (dfa1);
- GNUNET_REGEX_automaton_destroy (dfa2);
+ REGEX_ITERNAL_automaton_destroy (dfa1);
+ REGEX_ITERNAL_automaton_destroy (dfa2);
}
return error;
lib_LTLIBRARIES = libgnunettun.la
libgnunettun_la_SOURCES = \
- tun.c
+ tun.c \
+ regex.c
libgnunettun_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la $(XLIB) \
$(LTLIBINTL)
libgnunettun_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) \
- -version-info 0:0:0
+ -version-info 1:0:1
check_PROGRAMS = \
- test_tun
-
+ test_tun \
+ test_regex
if ENABLE_TEST_RUN
TESTS = $(check_PROGRAMS)
test_tun_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/tun/libgnunettun.la
+
+
+test_regex_SOURCES = \
+ test_regex.c
+test_regex_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/tun/libgnunettun.la
--- /dev/null
+/*
+ This file is part of GNUnet
+ (C) 2012, 2013 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file tun/test_regex.c
+ * @brief simple test for regex.c iptoregex functions
+ * @author Maximilian Szengel
+ */
+#include "platform.h"
+#include "gnunet_tun_lib.h"
+
+
+static int
+test_iptoregex (const char *ipv4, const char *netmask, const char *expectedv4,
+ const char *ipv6, unsigned int prefixlen,
+ const char *expectedv6)
+{
+ int error = 0;
+
+ struct in_addr a;
+ struct in6_addr b;
+ char rxv4[GNUNET_REGEX_IPV4_REGEXLEN];
+ char rxv6[GNUNET_REGEX_IPV6_REGEXLEN];
+
+ GNUNET_assert (1 == inet_pton (AF_INET, ipv4, &a));
+ GNUNET_TUN_ipv4toregex (&a, netmask, rxv4);
+
+
+ if (0 != strcmp (rxv4, expectedv4))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected: %s but got: %s\n",
+ expectedv4, rxv4);
+ error++;
+ }
+
+ GNUNET_assert (1 == inet_pton (AF_INET6, ipv6, &b));
+ GNUNET_TUN_ipv6toregex (&b, prefixlen, rxv6);
+
+ if (0 != strcmp (rxv6, expectedv6))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected: %s but got: %s\n",
+ expectedv6, rxv6);
+ error++;
+ }
+
+ return error;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GNUNET_log_setup ("test-regex", "WARNING", NULL);
+
+ int error;
+
+ error = 0;
+
+ error +=
+ test_iptoregex ("192.0.0.0", "255.255.255.0",
+ "110000000000000000000000(0|1)+", "FFFF::0", 16,
+ "1111111111111111(0|1)+");
+
+ error +=
+ test_iptoregex ("187.238.225.0", "255.255.255.128",
+ "1011101111101110111000010(0|1)+", "E1E1:73F9:51BE::0",
+ 49,
+ "1110000111100001011100111111100101010001101111100(0|1)+");
+
+ error +=
+ test_iptoregex ("255.255.255.255", "255.255.255.255",
+ "11111111111111111111111111111111",
+ "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 128,
+ "11111111111111111111111111111111"
+ "11111111111111111111111111111111"
+ "11111111111111111111111111111111"
+ "11111111111111111111111111111111");
+
+ error +=
+ test_iptoregex ("0.0.0.0", "255.255.255.255",
+ "00000000000000000000000000000000", "0::0", 128,
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000");
+
+ return error;
+}
*/
#define MAX_MESSAGE_QUEUE_SIZE 4
-/**
- * Maximum regex string length for use with GNUNET_REGEX_ipv4toregex
- */
-#define GNUNET_REGEX_IPV4_REGEXLEN 32 + 6
-
-/**
- * Maximum regex string length for use with GNUNET_REGEX_ipv6toregex
- */
-#define GNUNET_REGEX_IPV6_REGEXLEN 128 + 6
-
/**
* State we keep for each of our tunnels.
}
-/**
- * Create a string with binary IP notation for the given 'addr' in 'str'.
- *
- * @param af address family of the given 'addr'.
- * @param addr address that should be converted to a string.
- * struct in_addr * for IPv4 and struct in6_addr * for IPv6.
- * @param str string that will contain binary notation of 'addr'. Expected
- * to be at least 33 bytes long for IPv4 and 129 bytes long for IPv6.
- */
-static void
-iptobinstr (const int af, const void *addr, char *str)
-{
- int i;
-
- switch (af)
- {
- case AF_INET:
- {
- uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
-
- str[32] = '\0';
- str += 31;
- for (i = 31; i >= 0; i--)
- {
- *str = (b & 1) + '0';
- str--;
- b >>= 1;
- }
- break;
- }
- case AF_INET6:
- {
- struct in6_addr b = *(const struct in6_addr *) addr;
-
- str[128] = '\0';
- str += 127;
- for (i = 127; i >= 0; i--)
- {
- *str = (b.s6_addr[i / 8] & 1) + '0';
- str--;
- b.s6_addr[i / 8] >>= 1;
- }
- break;
- }
- }
-}
-
-
-/**
- * Get the ipv4 network prefix from the given 'netmask'.
- *
- * @param netmask netmask for which to get the prefix len.
- *
- * @return length of ipv4 prefix for 'netmask'.
- */
-static unsigned int
-ipv4netmasktoprefixlen (const char *netmask)
-{
- struct in_addr a;
- unsigned int len;
- uint32_t t;
-
- if (1 != inet_pton (AF_INET, netmask, &a))
- return 0;
- len = 32;
- for (t = htonl (~a.s_addr); 0 != t; t >>= 1)
- len--;
- return len;
-}
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ip' and 'netmask'.
- *
- * @param ip IPv4 representation.
- * @param netmask netmask for the ip.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN
- * bytes long.
- */
-static void
-ipv4toregex (const struct in_addr *ip, const char *netmask,
- char *rxstr)
-{
- unsigned int pfxlen;
-
- pfxlen = ipv4netmasktoprefixlen (netmask);
- iptobinstr (AF_INET, ip, rxstr);
- rxstr[pfxlen] = '\0';
- if (pfxlen < 32)
- strcat (rxstr, "(0|1)+");
-}
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'.
- *
- * @param ipv6 IPv6 representation.
- * @param prefixlen length of the ipv6 prefix.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN
- * bytes long.
- */
-static void
-ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
- char *rxstr)
-{
- iptobinstr (AF_INET6, ipv6, rxstr);
- rxstr[prefixlen] = '\0';
- if (prefixlen < 128)
- strcat (rxstr, "(0|1)+");
-}
-
-
/**
* Regex has found a potential exit peer for us; consider using it.
*
{
case AF_INET:
{
- char address[GNUNET_REGEX_IPV4_REGEXLEN];
+ char address[GNUNET_TUN_IPV4_REGEXLEN];
- ipv4toregex (&de->details.exit_destination.ip.v4,
+ GNUNET_TUN_ipv4toregex (&de->details.exit_destination.ip.v4,
"255.255.255.255", address);
GNUNET_asprintf (&policy, "%s%s%s",
GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
}
case AF_INET6:
{
- char address[GNUNET_REGEX_IPV6_REGEXLEN];
+ char address[GNUNET_TUN_IPV6_REGEXLEN];
- ipv6toregex (&de->details.exit_destination.ip.v6,
+ GNUNET_TUN_ipv6toregex (&de->details.exit_destination.ip.v6,
128, address);
GNUNET_asprintf (&policy, "%s%s%s",
GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,