Skip to content

Commit

Permalink
siprec: add group support and caller/callee info
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Sep 28, 2017
1 parent b6f2f84 commit f2c42e3
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 40 deletions.
101 changes: 75 additions & 26 deletions modules/siprec/siprec.c
Expand Up @@ -36,7 +36,8 @@ static int mod_init(void);
static int child_init(int);
static void mod_destroy(void);

static int srec_engage(struct sip_msg *msg, char *_srs, char *_rtp, char *_sid);
static int srec_engage(struct sip_msg *msg, char *_srs, char *_cA, char *_cB,
char *_rtp, char *_grp);
static int fixup_srec_engage(void **param, int param_no);
static int free_fixup_srec_engage(void **param, int param_no);
static struct mi_root* mi_example(struct mi_root* cmd_tree, void* param);
Expand All @@ -56,8 +57,18 @@ static dep_export_t deps = {

/* exported commands */
static cmd_export_t cmds[] = {
{"siprec_engage",(cmd_function)srec_engage, 1, fixup_srec_engage,
free_fixup_srec_engage, REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE },
{"siprec_engage",(cmd_function)srec_engage, 2, fixup_srec_engage,
free_fixup_srec_engage, REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE },
{"siprec_engage",(cmd_function)srec_engage, 3, fixup_srec_engage,
free_fixup_srec_engage, REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE },
{"siprec_engage",(cmd_function)srec_engage, 4, fixup_srec_engage,
free_fixup_srec_engage, REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE },
{"siprec_engage",(cmd_function)srec_engage, 5, fixup_srec_engage,
free_fixup_srec_engage, REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE },
{"siprec_engage",(cmd_function)srec_engage, 6, fixup_srec_engage,
free_fixup_srec_engage, REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE },
{0, 0, 0, 0, 0, 0}
};

Expand Down Expand Up @@ -150,7 +161,7 @@ static void mod_destroy(void)
*/
static int fixup_srec_engage(void **param, int param_no)
{
if (param_no > 0 && param_no < 3)
if (param_no > 0 && param_no < 7)
return fixup_spve(param);
LM_ERR("Unsupported parameter %d\n", param_no);
return E_CFG;
Expand All @@ -167,12 +178,14 @@ static int free_fixup_srec_engage(void **param, int param_no)
/*
* function that simply prints the parameters passed
*/
static int srec_engage(struct sip_msg *msg, char *_srs, char *_rtp, char *_sid)
static int srec_engage(struct sip_msg *msg, char *_srs, char *_cA, char *_cB,
char *_rtp, char *_grp)
{
int ret;
str srs, rtp;
str srs, rtp, group, tmp_str, *aor, *display;
struct src_sess *ss;
struct dlg_cell *dlg;
struct to_body tmp_body;

if (!_srs) {
LM_ERR("No siprec SRS uri specified!\n");
Expand All @@ -187,16 +200,11 @@ static int srec_engage(struct sip_msg *msg, char *_srs, char *_rtp, char *_sid)
LM_ERR("cannot fetch set!\n");
return -1;
}

if (parse_from_header(msg) < 0) {
LM_ERR("cannot parse from header!\n");
return -2;
if (_grp && fixup_get_svalue(msg, (gparam_p)_grp, &group) < 0) {
LM_ERR("cannot fetch group for this session!\n");
return -1;
}

if ((!msg->to && parse_headers(msg, HDR_TO_F, 0) < 0) || !msg->to) {
LM_ERR("inexisting or invalid to header!\n");
return -2;
}
/*
* TODO: check where it was called: request or reply: depending on that we
* can use different logics for caller/callee;
Expand All @@ -213,29 +221,68 @@ static int srec_engage(struct sip_msg *msg, char *_srs, char *_rtp, char *_sid)
}

/* check if the current dialog has a siprec session ongoing */
if (!_sid) {
if (!(ss = src_create_session(&srs, (_rtp ? &rtp : NULL)))) {
LM_ERR("cannot create siprec session!\n");
return -2;
}
/* TODO: link the dlg here, but do we need to ref it ? */
ss->dlg = dlg;
} else {
/* TODO: lookup session */
ss = NULL;
if (!(ss = src_create_session(&srs, (_rtp ? &rtp : NULL),
(_grp ? &group : NULL)))) {
LM_ERR("cannot create siprec session!\n");
return -2;
}

/* TODO: link the dlg here, but do we need to ref it ? */
ss->dlg = dlg;

ret = -2;

if (src_add_participant(ss, &get_from(msg)->uri) < 0) {
/* caller info */
if (_cA) {
if (fixup_get_svalue(msg, (gparam_p)_cA, &tmp_str) < 0) {
LM_ERR("cannot fetch caller information!\n");
goto session_cleanup;
}
if (parse_to(tmp_str.s, tmp_str.s + tmp_str.len, &tmp_body) < 0) {
LM_ERR("invalid caller information: [%.*s]!\n", tmp_str.len, tmp_str.s);
goto session_cleanup;
}
aor = &tmp_body.uri;
display = (tmp_body.display.s ? &tmp_body.display : NULL);
} else {
if (parse_from_header(msg) < 0) {
LM_ERR("cannot parse from header!\n");
goto session_cleanup;
}
aor = &get_from(msg)->uri;
display = (get_from(msg)->display.s ? &get_from(msg)->display : NULL);
}

if (src_add_participant(ss, aor, display) < 0) {
LM_ERR("cannot add caller participant!\n");
goto session_cleanup;
}
if (srs_add_sdp_streams(msg, ss, &ss->participants[0]) < 0) {
LM_ERR("cannot add SDP for caller!\n");
return -1;
goto session_cleanup;
}
/* caller info */
if (_cB) {
if (fixup_get_svalue(msg, (gparam_p)_cB, &tmp_str) < 0) {
LM_ERR("cannot fetch callee information!\n");
goto session_cleanup;
}
if (parse_to(tmp_str.s, tmp_str.s + tmp_str.len, &tmp_body) < 0) {
LM_ERR("invalid callee information: [%.*s]!\n", tmp_str.len, tmp_str.s);
goto session_cleanup;
}
aor = &tmp_body.uri;
display = (tmp_body.display.s ? &tmp_body.display : NULL);
} else {
if ((!msg->to && parse_headers(msg, HDR_TO_F, 0) < 0) || !msg->to) {
LM_ERR("inexisting or invalid to header!\n");
goto session_cleanup;
}
aor = &get_to(msg)->uri;
display = (get_to(msg)->display.s ? &get_to(msg)->display : NULL);
}

if (src_add_participant(ss, &get_to(msg)->uri) < 0) {
if (src_add_participant(ss, aor, display) < 0) {
LM_ERR("cannot add callee pariticipant!\n");
goto session_cleanup;
}
Expand All @@ -246,8 +293,10 @@ static int srec_engage(struct sip_msg *msg, char *_srs, char *_rtp, char *_sid)
LM_ERR("cannot register tm callbacks\n");
goto session_cleanup;
}
ret = 1;
return 1;

session_cleanup:
/* TODO: session destroy! */
return ret;
}

Expand Down
1 change: 0 additions & 1 deletion modules/siprec/src_logic.c
Expand Up @@ -146,7 +146,6 @@ int src_start_recording(struct sip_msg *msg, struct src_sess *sess)
ci.to_uri = ci.req_uri;
ci.from_uri = ci.to_uri;
ci.extra_headers = &extra_headers;
LM_INFO("XXX: started seesion with uri %.*s\n", ci.to_uri.len, ci.to_uri.s);

if (!send_sock) {
send_sock = uri2sock(msg, &ci.req_uri, &tmp, PROTO_NONE);
Expand Down
20 changes: 16 additions & 4 deletions modules/siprec/src_sess.c
Expand Up @@ -43,9 +43,10 @@ struct src_sess *src_get_session(struct dlg_cell *dlg)
return (struct src_sess *)val.s;
}

struct src_sess *src_create_session(str *srs, str *rtp)
struct src_sess *src_create_session(str *srs, str *rtp, str *grp)
{
struct src_sess *ss = shm_malloc(sizeof *ss + (rtp ? rtp->len : 0));
struct src_sess *ss = shm_malloc(sizeof *ss +
(rtp ? rtp->len : 0) + (grp ? grp->len : 0));
if (!ss) {
LM_ERR("not enough memory for creating siprec session!\n");
return NULL;
Expand All @@ -63,6 +64,12 @@ struct src_sess *src_create_session(str *srs, str *rtp)
memcpy(ss->rtpproxy.s, rtp->s, rtp->len);
ss->rtpproxy.len = rtp->len;
}

if (grp) {
ss->group.s = (char *)(ss + 1) + ss->rtpproxy.len;
memcpy(ss->group.s, grp->s, grp->len);
ss->group.len = grp->len;
}
siprec_build_uuid(ss->uuid);
ss->participants_no = 0;
ss->ts = time(NULL);
Expand Down Expand Up @@ -108,7 +115,7 @@ void src_free_session(struct src_sess *sess)
shm_free(sess);
}

int src_add_participant(struct src_sess *sess, str *aor)
int src_add_participant(struct src_sess *sess, str *aor, str *name)
{
struct src_part *part;
if (sess->participants_no >= SRC_MAX_PARTICIPANTS) {
Expand All @@ -120,14 +127,19 @@ int src_add_participant(struct src_sess *sess, str *aor)
INIT_LIST_HEAD(&part->streams);
siprec_build_uuid(part->uuid);

part->aor.s = shm_malloc(aor->len);
part->aor.s = shm_malloc(aor->len + (name ? name->len: 0));
if (!part->aor.s) {
LM_ERR("out of shared memory!\n");
return -1;
}

part->aor.len = aor->len;
memcpy(part->aor.s, aor->s, aor->len);
if (name) {
part->name.len = name->len;
part->name.s = part->aor.s + part->aor.len;
memcpy(part->name.s, name->s, name->len);
}
sess->participants_no++;

return 1;
Expand Down
6 changes: 4 additions & 2 deletions modules/siprec/src_sess.h
Expand Up @@ -36,6 +36,7 @@

struct src_part {
str aor;
str name;
siprec_uuid uuid;
struct list_head streams;
};
Expand All @@ -48,6 +49,7 @@ struct src_sess {
int streams_no;
str rtpproxy;
str srs_uri;
str group;

/* siprec */
siprec_uuid uuid;
Expand All @@ -63,8 +65,8 @@ struct src_sess {
};

struct src_sess *src_get_session(struct dlg_cell *dlg);
struct src_sess *src_create_session(str *srs, str *rtp);
int src_add_participant(struct src_sess *sess, str *aor);
struct src_sess *src_create_session(str *srs, str *rtp, str *group);
int src_add_participant(struct src_sess *sess, str *aor, str *name);

extern struct tm_binds srec_tm;
extern struct dlg_binds srec_dlg;
Expand Down
37 changes: 30 additions & 7 deletions modules/siprec/srs_body.c
Expand Up @@ -391,17 +391,45 @@ static int srs_build_xml(struct src_sess *sess, struct srec_buffer *buf)
SIPREC_COPY_OPEN_TAG("datamode", buf);
SIPREC_COPY("complete", buf);
SIPREC_COPY_CLOSE_TAG("datamode", buf);
if (sess->group.s) {
SIPREC_COPY("\r\n\t<group group_id=\"", buf);
SIPREC_COPY_STR(sess->group, buf);
SIPREC_COPY("\"/>", buf);
}
SIPREC_COPY("\r\n\t<session session_id=\"", buf);
SIPREC_COPY_UUID(sess->uuid, buf);
SIPREC_COPY("\"/>\r\n", buf);
if (!sess->group.s && !sess->dlg)
SIPREC_COPY("\"/>\r\n", buf);
else {
SIPREC_COPY("\">", buf);
if (sess->dlg) {
SIPREC_COPY("\r\n\t\t", buf);
SIPREC_COPY_OPEN_TAG("sipSessionID", buf);
SIPREC_COPY_STR(sess->dlg->callid, buf);
SIPREC_COPY_CLOSE_TAG("sipSessionID", buf);
}
if (sess->group.s) {
SIPREC_COPY("\r\n\t\t", buf);
SIPREC_COPY_OPEN_TAG("group-ref", buf);
SIPREC_COPY_STR(sess->group, buf);
SIPREC_COPY_CLOSE_TAG("group-ref", buf);
}
SIPREC_COPY("\r\n\t</session>\r\n", buf);
}
for (p = 0; p < sess->participants_no; p++) {
if (!sess->participants[p].aor.s)
continue;
SIPREC_COPY("\t<participant participant_id=\"", buf);
SIPREC_COPY_UUID(sess->participants[p].uuid, buf);
SIPREC_COPY("\">\r\n\t\t<nameID aor=\"", buf);
SIPREC_COPY_STR(sess->participants[p].aor, buf);
SIPREC_COPY("\"/>\r\n\t</participant>\r\n", buf);
if (sess->participants[p].name.s) {
SIPREC_COPY("\">\r\n\t\t\t<name>", buf);
SIPREC_COPY_STR(sess->participants[p].name, buf);
SIPREC_COPY("</name>\r\n\t\t</nameID>", buf);
} else
SIPREC_COPY("\"/>", buf);
SIPREC_COPY("\r\n\t</participant>\r\n", buf);
}

for (p = 0; p < sess->participants_no; p++) {
Expand Down Expand Up @@ -589,8 +617,3 @@ int srs_handle_media(struct sip_msg *msg, struct src_sess *sess)
}


int srs_get_default_name(struct to_body *body)
{
/* uri */
return -1;
}

0 comments on commit f2c42e3

Please sign in to comment.