aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-06-09 21:48:49 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-05-02 19:24:21 +0200
commit2c7f7e6bf50e797715591e3a4d0991c1b821aa80 (patch)
treef9b795a3974a193dfbb1c8c4165cfdd84873e37c
parent1754842be6daec57106eeb480047e9204fc20eca (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.
-rw-r--r--openbsc/include/openbsc/bsc_nat.h1
-rw-r--r--openbsc/include/openbsc/gsm_data_shared.h9
-rw-r--r--openbsc/src/libcommon/gsm_data.c26
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_utils.c25
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_vty.c9
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c6
6 files changed, 43 insertions, 33 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 5423ed278..6680614a9 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -396,7 +396,6 @@ int bsc_write_msg(struct osmo_wqueue *queue, struct msgb *msg);
int bsc_write_cb(struct osmo_fd *bfd, struct msgb *msg);
/* IMSI allow/deny handling */
-int bsc_parse_reg(void *ctx, regex_t *reg, char **imsi, int argc, const char **argv) __attribute__ ((warn_unused_result));
struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct bsc_nat *nat, const char *name);
struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(struct bsc_nat *nat, const char *name);
void bsc_nat_acc_lst_delete(struct bsc_nat_acc_lst *lst);
diff --git a/openbsc/include/openbsc/gsm_data_shared.h b/openbsc/include/openbsc/gsm_data_shared.h
index d76862877..80e953ff0 100644
--- a/openbsc/include/openbsc/gsm_data_shared.h
+++ b/openbsc/include/openbsc/gsm_data_shared.h
@@ -1,6 +1,7 @@
#ifndef _GSM_DATA_SHAREDH
#define _GSM_DATA_SHAREDH
+#include <regex.h>
#include <stdbool.h>
#include <stdint.h>
@@ -605,4 +606,12 @@ void gsm_bts_mo_reset(struct gsm_bts *bts);
uint8_t gsm_ts2chan_nr(const struct gsm_bts_trx_ts *ts, uint8_t lchan_nr);
uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
+/*
+ * help with parsing regexps
+ */
+int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
+ int argc, const char **argv) __attribute__ ((warn_unused_result));
+
+
+
#endif
diff --git a/openbsc/src/libcommon/gsm_data.c b/openbsc/src/libcommon/gsm_data.c
index 3df69d69c..3cc0c13bc 100644
--- a/openbsc/src/libcommon/gsm_data.c
+++ b/openbsc/src/libcommon/gsm_data.c
@@ -420,3 +420,29 @@ 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(&reg, 0, sizeof(reg));
- if (bsc_parse_reg(_nat, &reg, &str, 1, argv) != 0)
+ if (gsm_parse_reg(_nat, &reg, &str, 1, argv) != 0)
return CMD_WARNING;
vty_out(vty, "String matches allow pattern: %d%s",
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index d198424a4..d6105adb8 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -745,15 +745,15 @@ static void test_cr_filter()
nat_lst = bsc_nat_acc_lst_get(nat, "nat");
bsc_lst = bsc_nat_acc_lst_get(nat, "bsc");
- if (bsc_parse_reg(nat_entry, &nat_entry->imsi_deny_re, &nat_entry->imsi_deny,
+ if (gsm_parse_reg(nat_entry, &nat_entry->imsi_deny_re, &nat_entry->imsi_deny,
cr_filter[i].nat_imsi_deny ? 1 : 0,
&cr_filter[i].nat_imsi_deny) != 0)
abort();
- if (bsc_parse_reg(bsc_entry, &bsc_entry->imsi_allow_re, &bsc_entry->imsi_allow,
+ if (gsm_parse_reg(bsc_entry, &bsc_entry->imsi_allow_re, &bsc_entry->imsi_allow,
cr_filter[i].bsc_imsi_allow ? 1 : 0,
&cr_filter[i].bsc_imsi_allow) != 0)
abort();
- if (bsc_parse_reg(bsc_entry, &bsc_entry->imsi_deny_re, &bsc_entry->imsi_deny,
+ if (gsm_parse_reg(bsc_entry, &bsc_entry->imsi_deny_re, &bsc_entry->imsi_deny,
cr_filter[i].bsc_imsi_deny ? 1 : 0,
&cr_filter[i].bsc_imsi_deny) != 0)
abort();