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-06-15 20:24:18 +0800 |
commit | 12dc89ad37c3ced7538d228e432587036ad52189 (patch) | |
tree | 4ab2787f072721334d3e519a888c6e1e25318388 | |
parent | 290ed9a98c4c64bc2466ca7fd86e7d1fb1da3e11 (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 6baa952e6..275ecb472 100644 --- a/openbsc/src/nat/bsc_nat_utils.c +++ b/openbsc/src/nat/bsc_nat_utils.c @@ -272,3 +272,17 @@ int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg, struct return 0; } } + +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; } |