sip/call/mncc: Move source/dest into the call structure

In preparation of a better show calls VTY command it is of interest
to know which number has been dialed by whom. For that store the
source/dest in there.

MNCC: Change the talloc root context to the call and don't try to
free the strings after calling the routing code

SIP: Use talloc_strdup to duplicate them.

Call: Add null check because the talloc_strdup of the SIP layer
could have failed.
changes/26/126/1
Holger Hans Peter Freyther 7 years ago
parent 32162fe7c8
commit 211ad859de
  1. 24
      src/app.c
  2. 3
      src/call.h
  3. 19
      src/mncc.c
  4. 3
      src/mncc.h
  5. 9
      src/sip.c
  6. 2
      src/sip.h

@ -59,25 +59,35 @@ void app_setup(struct app_config *cfg)
cfg->mncc.conn.on_disconnect = app_mncc_disconnected;
}
static void route_to_sip(struct call *call, const char *source, const char *dest)
static void route_to_sip(struct call *call)
{
if (sip_create_remote_leg(&g_app.sip.agent, call, source, dest) != 0)
if (sip_create_remote_leg(&g_app.sip.agent, call) != 0)
call->initial->release_call(call->initial);
}
static void route_to_mncc(struct call *call, const char *source,
const char *dest)
static void route_to_mncc(struct call *call)
{
if (mncc_create_remote_leg(&g_app.mncc.conn, call, source, dest) != 0)
if (mncc_create_remote_leg(&g_app.mncc.conn, call) != 0)
call->initial->release_call(call->initial);
}
void app_route_call(struct call *call, const char *source, const char *dest)
{
if (!source || !dest) {
LOGP(DAPP, LOGL_ERROR, "call(%u) missing source(%p)/dest(%p)\n",
call->id, source, dest);
call->initial->release_call(call->initial);
return;
}
call->source = source;
call->dest = dest;
if (call->initial->type == CALL_TYPE_MNCC)
route_to_sip(call, source, dest);
route_to_sip(call);
else
route_to_mncc(call, source, dest);
route_to_mncc(call);
}
const char *app_media_name(int ptmsg)

@ -27,6 +27,9 @@ struct call {
unsigned int id;
struct call_leg *initial;
struct call_leg *remote;
const char *source;
const char *dest;
};
enum {

@ -254,18 +254,16 @@ static void continue_mo_call(struct mncc_call_leg *leg)
leg->state = MNCC_CC_PROCEEDING;
if (leg->called.type == GSM340_TYPE_INTERNATIONAL)
dest = talloc_asprintf(tall_mncc_ctx, "+%.32s", leg->called.number);
dest = talloc_asprintf(leg, "+%.32s", leg->called.number);
else
dest = talloc_asprintf(tall_mncc_ctx, "%.32s", leg->called.number);
dest = talloc_asprintf(leg, "%.32s", leg->called.number);
if (leg->conn->app->use_imsi_as_id)
source = talloc_asprintf(tall_mncc_ctx, "%.16s", leg->imsi);
source = talloc_asprintf(leg, "%.16s", leg->imsi);
else
source = talloc_asprintf(tall_mncc_ctx, "%.32s", leg->calling.number);
source = talloc_asprintf(leg, "%.32s", leg->calling.number);
app_route_call(leg->base.call, source, dest);
talloc_free(source);
talloc_free(dest);
}
static void continue_mt_call(struct mncc_call_leg *leg)
@ -641,8 +639,7 @@ static void check_hello(struct mncc_connection *conn, char *buf, int rc)
conn->state = MNCC_READY;
}
int mncc_create_remote_leg(struct mncc_connection *conn, struct call *call,
const char *calling, const char *called)
int mncc_create_remote_leg(struct mncc_connection *conn, struct call *call)
{
struct mncc_call_leg *leg;
struct gsm_mncc mncc = { 0, };
@ -673,15 +670,15 @@ int mncc_create_remote_leg(struct mncc_connection *conn, struct call *call,
mncc.fields |= MNCC_F_CALLING;
mncc.calling.plan = 1;
mncc.calling.type = 0x0;
memcpy(&mncc.calling.number, calling, sizeof(mncc.calling.number));
memcpy(&mncc.calling.number, call->source, sizeof(mncc.calling.number));
if (conn->app->use_imsi_as_id) {
snprintf(mncc.imsi, 15, "%s", called);
snprintf(mncc.imsi, 15, "%s", call->dest);
} else {
mncc.fields |= MNCC_F_CALLED;
mncc.called.plan = 1;
mncc.called.type = 0x0;
memcpy(&mncc.called.number, called, sizeof(mncc.called.number));
memcpy(&mncc.called.number, call->dest, sizeof(mncc.called.number));
}
/*

@ -30,5 +30,4 @@ struct mncc_connection {
void mncc_connection_init(struct mncc_connection *conn, struct app_config *cfg);
void mncc_connection_start(struct mncc_connection *conn);
int mncc_create_remote_leg(struct mncc_connection *conn, struct call *call,
const char *calling, const char *called);
int mncc_create_remote_leg(struct mncc_connection *conn, struct call *call);

@ -136,7 +136,9 @@ static void new_call(struct sip_agent *agent, nua_handle_t *nh,
nua_handle_bind(nh, leg);
leg->sdp_payload = talloc_strdup(leg, sip->sip_payload->pl_data);
app_route_call(call, from, to);
app_route_call(call,
talloc_strdup(leg, from),
talloc_strdup(leg, to));
}
void nua_callback(nua_event_t event, int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tags[])
@ -316,8 +318,7 @@ static int send_invite(struct sip_agent *agent, struct sip_call_leg *leg,
return 0;
}
int sip_create_remote_leg(struct sip_agent *agent, struct call *call,
const char *source, const char *dest)
int sip_create_remote_leg(struct sip_agent *agent, struct call *call)
{
struct sip_call_leg *leg;
@ -341,7 +342,7 @@ int sip_create_remote_leg(struct sip_agent *agent, struct call *call,
return -2;
}
return send_invite(agent, leg, source, dest);
return send_invite(agent, leg, call->source, call->dest);
}
char *make_sip_uri(struct sip_agent *agent)

@ -21,4 +21,4 @@ struct sip_agent {
void sip_agent_init(struct sip_agent *agent, struct app_config *app);
int sip_agent_start(struct sip_agent *agent);
int sip_create_remote_leg(struct sip_agent *agent, struct call *call, const char *local, const char *remote);
int sip_create_remote_leg(struct sip_agent *agent, struct call *call);

Loading…
Cancel
Save