summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-03-24 21:37:10 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-03-26 06:22:06 +0100
commitad6eabd4b50cfe184b99578b91cf8aa5572b94b1 (patch)
tree26add47d04ddd6103532f3387ab547c602286f37
parent49a4a643da0da08fe73b7ce7b4b37d550dc81bc2 (diff)
mncc: Refactor and reduce some code clones for sanity checks
Not every message might have the size of gsm_mncc and the size check is done inside each routine. Routines that relate to calls now share the code to check the size and the look-up to find the leg.
-rw-r--r--src/mncc.c72
1 files changed, 28 insertions, 44 deletions
diff --git a/src/mncc.c b/src/mncc.c
index eaf6add..4436a3f 100644
--- a/src/mncc.c
+++ b/src/mncc.c
@@ -322,24 +322,37 @@ static void check_setup(struct mncc_connection *conn, char *buf, int rc)
mncc_rtp_send(conn, MNCC_RTP_CREATE, data->callref);
}
-static void check_disc_ind(struct mncc_connection *conn, char *buf, int rc)
+static struct mncc_call_leg *find_leg(struct mncc_connection *conn,
+ char *buf, int rc, struct gsm_mncc **mncc)
{
- struct gsm_mncc *data;
struct mncc_call_leg *leg;
- if (rc != sizeof(*data)) {
+ if (rc != sizeof(**mncc)) {
LOGP(DMNCC, LOGL_ERROR, "gsm_mncc of wrong size %d vs. %zu\n",
- rc, sizeof(*data));
- return close_connection(conn);
+ rc, sizeof(**mncc));
+ close_connection(conn);
+ return NULL;
}
- data = (struct gsm_mncc *) buf;
- leg = mncc_find_leg(data->callref);
+ *mncc = (struct gsm_mncc *) buf;
+ leg = mncc_find_leg((*mncc)->callref);
if (!leg) {
- LOGP(DMNCC, LOGL_ERROR, "disc call(%u) can not be found\n", data->callref);
- return;
+ LOGP(DMNCC, LOGL_ERROR, "call(%u) can not be found\n", (*mncc)->callref);
+ return NULL;
}
+ return leg;
+}
+
+static void check_disc_ind(struct mncc_connection *conn, char *buf, int rc)
+{
+ struct gsm_mncc *data;
+ struct mncc_call_leg *leg;
+
+ leg = find_leg(conn, buf, rc, &data);
+ if (!leg)
+ return;
+
LOGP(DMNCC,
LOGL_DEBUG, "leg(%u) was disconnected. Releasing\n", data->callref);
leg->base.in_release = true;
@@ -352,18 +365,9 @@ static void check_rel_ind(struct mncc_connection *conn, char *buf, int rc)
struct gsm_mncc *data;
struct mncc_call_leg *leg;
- if (rc != sizeof(*data)) {
- LOGP(DMNCC, LOGL_ERROR, "gsm_mncc of wrong size %d vs. %zu\n",
- rc, sizeof(*data));
- return close_connection(conn);
- }
-
- data = (struct gsm_mncc *) buf;
- leg = mncc_find_leg(data->callref);
- if (!leg) {
- LOGP(DMNCC, LOGL_ERROR, "rel call(%u) can not be found\n", data->callref);
+ leg = find_leg(conn, buf, rc, &data);
+ if (!leg)
return;
- }
if (leg->base.in_release)
stop_cmd_timer(leg, MNCC_REL_IND);
@@ -382,19 +386,9 @@ static void check_rel_cnf(struct mncc_connection *conn, char *buf, int rc)
struct gsm_mncc *data;
struct mncc_call_leg *leg;
- if (rc != sizeof(*data)) {
- LOGP(DMNCC, LOGL_ERROR, "gsm_mncc of wrong size %d vs. %zu\n",
- rc, sizeof(*data));
- return close_connection(conn);
- }
-
- data = (struct gsm_mncc *) buf;
- leg = mncc_find_leg(data->callref);
- if (!leg) {
- LOGP(DMNCC, LOGL_ERROR, "rel.cnf call(%u) can not be found\n",
- data->callref);
+ leg = find_leg(conn, buf, rc, &data);
+ if (!leg)
return;
- }
stop_cmd_timer(leg, MNCC_REL_CNF);
LOGP(DMNCC, LOGL_DEBUG, "leg(%u) was cnf released.\n", data->callref);
@@ -406,19 +400,9 @@ static void check_stp_cmpl_ind(struct mncc_connection *conn, char *buf, int rc)
struct gsm_mncc *data;
struct mncc_call_leg *leg;
- if (rc != sizeof(*data)) {
- LOGP(DMNCC, LOGL_ERROR, "gsm_mncc of wrong size %d vs. %zu\n",
- rc, sizeof(*data));
- return close_connection(conn);
- }
-
- data = (struct gsm_mncc *) buf;
- leg = mncc_find_leg(data->callref);
- if (!leg) {
- LOGP(DMNCC, LOGL_ERROR, "stp.cmpl call(%u) can not be found\n",
- data->callref);
+ leg = find_leg(conn, buf, rc, &data);
+ if (!leg)
return;
- }
LOGP(DMNCC, LOGL_NOTICE, "leg(%u) is now connected.\n", leg->callref);
stop_cmd_timer(leg, MNCC_SETUP_COMPL_IND);