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.
zecke/mt-mncc-call
Holger Hans Peter Freyther 7 years ago
parent 49a4a643da
commit ad6eabd4b5
  1. 72
      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);

Loading…
Cancel
Save