diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-05-14 18:38:29 +0800 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-05-14 18:38:29 +0800 |
commit | fa53aba62c4c56ec45aa98029744b74971ac9cdd (patch) | |
tree | 134081a34d25c39c6d935f74ed21e65e735878f8 | |
parent | 34c0b245fb337c64dc4ced37e3dab19ddcb8fa35 (diff) |
[nat] Make the string -> regexp parsing public
This way it can be used from within a test case to test
the regexps..
-rw-r--r-- | openbsc/include/openbsc/bsc_nat.h | 3 | ||||
-rw-r--r-- | openbsc/src/nat/bsc_nat_utils.c | 14 | ||||
-rw-r--r-- | openbsc/src/nat/bsc_nat_vty.c | 22 |
3 files changed, 21 insertions, 18 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index b3a12f5c1..ed1e5cd9e 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -292,4 +292,7 @@ int bsc_mgcp_extract_ci(const char *resp); int bsc_write(struct bsc_connection *bsc, struct msgb *msg, int id); +/* regexp handling */ +void bsc_parse_reg(void *ctx, regex_t *reg, char **imsi, int argc, const char **argv); + #endif diff --git a/openbsc/src/nat/bsc_nat_utils.c b/openbsc/src/nat/bsc_nat_utils.c index 050d25e28..dbff1ab3e 100644 --- a/openbsc/src/nat/bsc_nat_utils.c +++ b/openbsc/src/nat/bsc_nat_utils.c @@ -273,3 +273,17 @@ int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg, struct } } +void bsc_parse_reg(void *ctx, regex_t *reg, char **imsi, int argc, const char **argv) +{ + if (*imsi) { + talloc_free(*imsi); + *imsi = NULL; + } + regfree(reg); + + if (argc > 0) { + *imsi = talloc_strdup(ctx, argv[0]); + regcomp(reg, argv[0], 0); + } +} + diff --git a/openbsc/src/nat/bsc_nat_vty.c b/openbsc/src/nat/bsc_nat_vty.c index c24f7e511..9688de3f8 100644 --- a/openbsc/src/nat/bsc_nat_vty.c +++ b/openbsc/src/nat/bsc_nat_vty.c @@ -224,27 +224,13 @@ DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT") return CMD_SUCCESS; } -static void parse_reg(void *ctx, regex_t *reg, char **imsi, int argc, const char **argv) -{ - if (*imsi) { - talloc_free(*imsi); - *imsi = NULL; - } - regfree(reg); - - if (argc > 0) { - *imsi = talloc_strdup(ctx, argv[0]); - regcomp(reg, argv[0], 0); - } -} - DEFUN(cfg_nat_imsi_allow, cfg_nat_imsi_allow_cmd, "imsi allow [REGEXP]", "Allow matching IMSIs to talk to the MSC. " "The defualt is to allow everyone.") { - parse_reg(_nat, &_nat->imsi_allow_re, &_nat->imsi_allow, argc, argv); + bsc_parse_reg(_nat, &_nat->imsi_allow_re, &_nat->imsi_allow, argc, argv); return CMD_SUCCESS; } @@ -254,7 +240,7 @@ DEFUN(cfg_nat_imsi_deny, "Deny matching IMSIs to talk to the MSC. " "The defualt is to not deny.") { - parse_reg(_nat, &_nat->imsi_deny_re, &_nat->imsi_deny, argc, argv); + bsc_parse_reg(_nat, &_nat->imsi_deny_re, &_nat->imsi_deny, argc, argv); return CMD_SUCCESS; } @@ -373,7 +359,7 @@ DEFUN(cfg_bsc_imsi_allow, { struct bsc_config *conf = vty->index; - parse_reg(conf, &conf->imsi_allow_re, &conf->imsi_allow, argc, argv); + bsc_parse_reg(conf, &conf->imsi_allow_re, &conf->imsi_allow, argc, argv); return CMD_SUCCESS; } @@ -385,7 +371,7 @@ DEFUN(cfg_bsc_imsi_deny, { struct bsc_config *conf = vty->index; - parse_reg(conf, &conf->imsi_deny_re, &conf->imsi_deny, argc, argv); + bsc_parse_reg(conf, &conf->imsi_deny_re, &conf->imsi_deny, argc, argv); return CMD_SUCCESS; } |