Module: sip-router
Branch: master
Commit: d6ac6a12e171fe5cff766ef187a0a0be945de758
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d6ac6a1…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Tue Mar 24 20:36:57 2009 +0100
Update the SDP parser for the sip-router core.
This patch makes the SDP parser work with the sip-router core. The
sr core sip_msg structure does not contain the pointer to sdp_info_t,
instead it contains an element called body which points to a generic
structure msg_body_t.
To make the SDP parser work with the sr core we need to cast msg_body_t
to sdp_info_t and add 'type' and 'free' elements at the beginning of
the sdp_info structure.
Function new_sdp then stores the type of the document being parsed in
msg->body->type and a pointer to free_sdp function in msg->body->free.
Furthemore, testing just if (msg->body != 0) is not enough anymore,
because the variable could also contain a pointer to a different body
document type. So we need to change all such tests to something like:
if ((msg->body != 0) && (msg->body->type == MSG_BODY_SDP))
---
parser/sdp/sdp.c | 38 ++++++++++++++++++++++++--------------
parser/sdp/sdp.h | 2 ++
2 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/parser/sdp/sdp.c b/parser/sdp/sdp.c
index ec43cf3..4a6697f 100644
--- a/parser/sdp/sdp.c
+++ b/parser/sdp/sdp.c
@@ -51,8 +51,9 @@ static inline int new_sdp(struct sip_msg* _m)
return -1;
}
memset( sdp, 0, sizeof(sdp_info_t));
-
- _m->sdp = sdp;
+ sdp->type = MSG_BODY_SDP;
+ sdp->free = (free_msg_body_f)free_sdp;
+ _m->body = (msg_body_t*)sdp;
return 0;
}
@@ -279,8 +280,9 @@ sdp_session_cell_t* get_sdp_session_sdp(struct sdp_info* sdp, int
session_num)
sdp_session_cell_t* get_sdp_session(struct sip_msg* _m, int session_num)
{
- if (_m->sdp == NULL) return NULL;
- return get_sdp_session_sdp(_m->sdp, session_num);
+ if (_m->body == NULL) return NULL;
+ if (_m->body->type != MSG_BODY_SDP) return NULL;
+ return get_sdp_session_sdp((sdp_info_t*)_m->body, session_num);
}
@@ -311,15 +313,18 @@ sdp_stream_cell_t* get_sdp_stream_sdp(struct sdp_info* sdp, int
session_num, int
sdp_stream_cell_t* get_sdp_stream(struct sip_msg* _m, int session_num, int stream_num)
{
+ sdp_info_t* sdp;
sdp_session_cell_t *session;
sdp_stream_cell_t *stream;
- return get_sdp_stream_sdp(_m->sdp, session_num, stream_num);
+ return get_sdp_stream_sdp((sdp_info_t*)_m->body, session_num, stream_num);
- if (_m->sdp == NULL) return NULL;
- if (session_num > _m->sdp->sessions_num) return NULL;
+ sdp = (sdp_info_t*)_m->body;
+ if (sdp == NULL) return NULL;
+ if (sdp->type != MSG_BODY_SDP) return NULL;
+ if (session_num > sdp->sessions_num) return NULL;
- session = _m->sdp->sessions;
+ session = sdp->sessions;
while (session) {
if (session->session_num == session_num) {
stream = session->streams;
@@ -666,7 +671,7 @@ int parse_sdp(struct sip_msg* _m)
str body, mp_delimiter;
int mime;
- if (_m->sdp) {
+ if (_m->body) {
return 0; /* Already parsed */
}
@@ -696,10 +701,10 @@ int parse_sdp(struct sip_msg* _m)
LM_ERR("Can't create sdp\n");
return -1;
}
- res = parse_sdp_session(&body, 0, NULL, _m->sdp);
+ res = parse_sdp_session(&body, 0, NULL, (sdp_info_t*)_m->body);
if (res != 0) {
LM_DBG("free_sdp\n");
- free_sdp((sdp_info_t**)(void*)&(_m->sdp));
+ free_sdp((sdp_info_t**)&_m->body);
}
return res;
break;
@@ -719,9 +724,9 @@ int parse_sdp(struct sip_msg* _m)
LM_ERR("Can't create sdp\n");
return -1;
}
- res = parse_mixed_content(&body, mp_delimiter, _m->sdp);
+ res = parse_mixed_content(&body, mp_delimiter, (sdp_info_t*)_m->body);
if (res != 0) {
- free_sdp((sdp_info_t**)(void*)&(_m->sdp));
+ free_sdp((sdp_info_t**)&_m->body);
}
return res;
} else {
@@ -1151,7 +1156,8 @@ error:
sdp_info_t * clone_sdp_info(struct sip_msg* _m)
{
- sdp_info_t *clone_sdp_info, *sdp_info=_m->sdp;
+ sdp_info_t *clone_sdp_info, *sdp_info=(sdp_info_t*)_m->body
+;
sdp_session_cell_t *clone_session, *prev_clone_session, *session;
int i, len;
@@ -1159,6 +1165,10 @@ sdp_info_t * clone_sdp_info(struct sip_msg* _m)
LM_ERR("no sdp to clone\n");
return NULL;
}
+ if (sdp_info->type != MSG_BODY_SDP) {
+ LM_ERR("Unsupported body type\n");
+ return NULL;
+ }
if (sdp_info->sessions_num == 0) {
LM_ERR("no sessions to clone\n");
return NULL;
diff --git a/parser/sdp/sdp.h b/parser/sdp/sdp.h
index 3f6c775..9c9b9c7 100644
--- a/parser/sdp/sdp.h
+++ b/parser/sdp/sdp.h
@@ -86,6 +86,8 @@ typedef struct sdp_session_cell {
* Here we hold the head of the parsed sdp structure
*/
typedef struct sdp_info {
+ msg_body_type_t type;
+ free_msg_body_f free;
int sessions_num; /**< number of SDP sessions */
struct sdp_session_cell *sessions;
} sdp_info_t;