Skip to content

Commit

Permalink
siprec: if available, use a non-received part
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Nov 3, 2021
1 parent 86eabcf commit c9d034c
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions modules/siprec/siprec_body.c
Expand Up @@ -179,6 +179,50 @@ int srs_add_raw_sdp_stream(int label, int medianum, str *body,
return 0;
}

static sdp_info_t *siprec_parse_sdp(struct sip_msg *_m, int *release_sdp)
{
struct body_part *part;
static sdp_info_t sdp;
unsigned int mime;

if ( parse_sip_body(_m)<0 || _m->body==NULL) {
LM_DBG("message body has length zero\n");
return NULL;
}
*release_sdp = 0;

/* first, check if there is any body added */
for( part=&_m->body->first ; part ; part=part->next) {
if (is_body_part_received(part) || is_body_part_deleted(part))
continue;

if (!part->mime) {
if (!decode_mime_type(part->mime_s.s,
part->mime_s.s + part->mime_s.len, &mime, NULL)) {
LM_ERR("cannot parse mime [%.*s]\n",
part->mime_s.len, part->mime_s.s);
continue;
}
} else {
mime = part->mime;
}
if (mime != ((TYPE_APPLICATION<<16)+SUBTYPE_SDP))
continue;

if (!part->parsed) {
*release_sdp = 1;
memset(&sdp, 0, sizeof(sdp));
if (parse_sdp_session(&part->body, 0, NULL, &sdp)<0)
LM_ERR("failed to parse SDP for body part, skipping\n");
else
return &sdp;
} else {
return part->parsed;
}
}
return parse_sdp(_m);
}

int srs_fill_sdp_stream(struct sip_msg *msg, struct src_sess *sess,
struct src_part *part, int update)
{
Expand All @@ -196,10 +240,11 @@ int srs_fill_sdp_stream(struct sip_msg *msg, struct src_sess *sess,
int label;
int stream_port;
int inactive_streams = 0;
int free_sdp = 0;

struct srs_sdp_stream *stream = NULL;

msg_sdp = parse_sdp(msg);
msg_sdp = siprec_parse_sdp(msg, &free_sdp);
if (!msg_sdp)
return 0;
allocated_buf = NULL;
Expand All @@ -218,7 +263,7 @@ int srs_fill_sdp_stream(struct sip_msg *msg, struct src_sess *sess,
allocated_buf = pkg_malloc(msg_session->body.len);
if (!allocated_buf) {
LM_ERR("no more pkg memory to build body stream!\n");
return -1;
goto error;
}
tmp_buf.s = allocated_buf;
tmp_buf.len = 0;
Expand Down Expand Up @@ -404,10 +449,15 @@ int srs_fill_sdp_stream(struct sip_msg *msg, struct src_sess *sess,
pkg_free(allocated_buf);
}
/* update inactive streams */
if (free_sdp)
free_sdp_content(msg_sdp);
sess->streams_inactive = inactive_streams;
return streams_no;
stream_error:
pkg_free(allocated_buf);
error:
if (free_sdp)
free_sdp_content(msg_sdp);
return -1;
}

Expand Down

0 comments on commit c9d034c

Please sign in to comment.