diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-06-09 21:48:49 +0200 |
---|---|---|
committer | Daniel Willmann <daniel@totalueberwachung.de> | 2011-11-04 12:27:06 +0100 |
commit | 5aba19e8886abe3c84f0e0f62b825874e4192b4b (patch) | |
tree | 953b9cbb1418896ade7ab00f2edc453941154781 /openbsc/src | |
parent | 1754842be6daec57106eeb480047e9204fc20eca (diff) |
misc: Move the bsc_parse_reg to libcommom and name it gsm_parse_reg
Move the regexp parsing code from the NAT to libcommon as it will
be used by the NAT and BSC code. This also adds the #include <regex.h>
include to gsm_data. This header should be split up.
Diffstat (limited to 'openbsc/src')
-rw-r--r-- | openbsc/src/libcommon/gsm_data.c | 25 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat_utils.c | 25 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat_vty.c | 9 |
3 files changed, 30 insertions, 29 deletions
diff --git a/openbsc/src/libcommon/gsm_data.c b/openbsc/src/libcommon/gsm_data.c index 3df69d69c..a794d224b 100644 --- a/openbsc/src/libcommon/gsm_data.c +++ b/openbsc/src/libcommon/gsm_data.c @@ -420,3 +420,28 @@ int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts) return gsm48_construct_ra(buf, &raid); } + +int gsm_parse_reg(void *ctx, regex_t *reg, char **str, int argc, const char **argv) +{ + int ret; + + ret = 0; + if (*str) { + talloc_free(*str); + *str = NULL; + } + regfree(reg); + + if (argc > 0) { + *str = talloc_strdup(ctx, argv[0]); + ret = regcomp(reg, argv[0], 0); + + /* handle compilation failures */ + if (ret != 0) { + talloc_free(*str); + *str = NULL; + } + } + + return ret; +} diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c index 8658c3d9b..b8d6dbaac 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c @@ -672,31 +672,6 @@ int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg, } } -int bsc_parse_reg(void *ctx, regex_t *reg, char **imsi, int argc, const char **argv) -{ - int ret; - - ret = 0; - if (*imsi) { - talloc_free(*imsi); - *imsi = NULL; - } - regfree(reg); - - if (argc > 0) { - *imsi = talloc_strdup(ctx, argv[0]); - ret = regcomp(reg, argv[0], 0); - - /* handle compilation failures */ - if (ret != 0) { - talloc_free(*imsi); - *imsi = NULL; - } - } - - return ret; -} - static const char *con_types [] = { [NAT_CON_TYPE_NONE] = "n/a", [NAT_CON_TYPE_LU] = "Location Update", diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c index b5c1cf287..55b3958c0 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c @@ -19,6 +19,7 @@ */ #include <openbsc/vty.h> +#include <openbsc/gsm_data.h> #include <openbsc/bsc_nat.h> #include <openbsc/bsc_nat_sccp.h> #include <openbsc/bsc_msc.h> @@ -527,7 +528,7 @@ DEFUN(cfg_nat_ussd_query, "Set the USSD query to match with the ussd-list-name\n" "The query to match") { - if (bsc_parse_reg(_nat, &_nat->ussd_query_re, &_nat->ussd_query, argc, argv) != 0) + if (gsm_parse_reg(_nat, &_nat->ussd_query_re, &_nat->ussd_query, argc, argv) != 0) return CMD_WARNING; return CMD_SUCCESS; } @@ -641,7 +642,7 @@ DEFUN(cfg_lst_imsi_allow, if (!entry) return CMD_WARNING; - if (bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]) != 0) + if (gsm_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]) != 0) return CMD_WARNING; return CMD_SUCCESS; } @@ -664,7 +665,7 @@ DEFUN(cfg_lst_imsi_deny, if (!entry) return CMD_WARNING; - if (bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]) != 0) + if (gsm_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]) != 0) return CMD_WARNING; return CMD_SUCCESS; } @@ -797,7 +798,7 @@ DEFUN(test_regex, test_regex_cmd, char *str = NULL; memset(®, 0, sizeof(reg)); - if (bsc_parse_reg(_nat, ®, &str, 1, argv) != 0) + if (gsm_parse_reg(_nat, ®, &str, 1, argv) != 0) return CMD_WARNING; vty_out(vty, "String matches allow pattern: %d%s", |