Skip to content

Commit bb2423b

Browse files
committed
Merge branch 'feature/sdp-vars'
Initial implementation draft!
2 parents 631c2f5 + cbe3e74 commit bb2423b

File tree

12 files changed

+647
-32
lines changed

12 files changed

+647
-32
lines changed

modules/rtpproxy/rtpproxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3901,7 +3901,7 @@ static int rtpproxy_offer_answer(struct sip_msg *msg, struct rtpp_args *args,
39013901
LM_ERR("could not allocate space for new body\n");
39023902
goto error;
39033903
}
3904-
allocated_body = args->body.len;
3904+
allocated_body = 1;
39053905
body->len = 0;
39063906
}
39073907

parser/msg_parser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "../core_stats.h"
5353
#include "../errinfo.h"
5454
#include "../dset.h"
55+
#include "../sdp_ops.h"
5556
#include "parse_hname2.h"
5657
#include "parse_uri.h"
5758
#include "parse_content.h"
@@ -975,6 +976,8 @@ void free_sip_msg(struct sip_msg* msg)
975976
free_lump_list(msg->add_rm);
976977
if (msg->body_lumps)
977978
free_lump_list(msg->body_lumps);
979+
if (msg->sdp_ops )
980+
free_sdp_ops(msg->sdp_ops);
978981
if (msg->reply_lump)
979982
free_reply_lump(msg->reply_lump);
980983
if (msg->body )

parser/msg_parser.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ struct sip_msg {
286286
struct hdr_field* security_verify;
287287

288288
struct sip_msg_body *body;
289+
/* optional, real-time changes performed on the first SDP body part */
290+
struct sdp_body_part_ops *sdp_ops;
289291

290292
char* eoh; /* pointer to the end of header (if found) or null */
291293
char* unparsed; /* here we stopped parsing*/
@@ -339,7 +341,7 @@ struct sip_msg {
339341

340342
/* flags used by core - allows to set various flags on the message; may
341343
* be used for simple inter-module communication or remembering
342-
* processing state reached */
344+
* processing state reached, e.g. FL_FORCE_RPORT */
343345
unsigned int msg_flags;
344346

345347
str set_global_address;
@@ -362,6 +364,7 @@ struct sip_msg {
362364
#define FAKED_REPLY ((struct sip_msg *) -1)
363365

364366
extern int via_cnt;
367+
extern int sdp_get_custom_body(struct sip_msg *msg, str *body);
365368

366369
#define parse_msg( _buf, _len, _msg) \
367370
parse_msg_opt( _buf, _len, _msg, 1)
@@ -430,6 +433,11 @@ inline static int get_body(struct sip_msg *msg, str *body)
430433
unsigned int hdrs_len;
431434
int ct_len;
432435

436+
if (sdp_get_custom_body(msg, body) == 0) {
437+
LM_DBG("found custom 'SDP ops' body, len: %d\n", body->len);
438+
return 0;
439+
}
440+
433441
if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
434442
return -1;
435443

parser/parse_body.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "../mem/mem.h"
2424
#include "../ut.h"
25+
#include "../sdp_ops.h"
2526
#include "parse_body.h"
2627
#include "parse_content.h"
2728
#include "parse_hname2.h"
@@ -230,7 +231,7 @@ static int parse_single_part(struct body_part *part, char * start, char * end)
230231
int parse_sip_body(struct sip_msg * msg)
231232
{
232233
char *start, *end;
233-
int type = 0;
234+
int type = 0, new_sdp = 0;
234235
struct body_part *part, *last;
235236
str delimiter, body;
236237

@@ -242,8 +243,12 @@ int parse_sip_body(struct sip_msg * msg)
242243
return 0;
243244

244245
type = parse_content_type_hdr(msg);
245-
if (type <= 0)
246-
return 0;
246+
if (type <= 0) {
247+
if (!msg->sdp_ops || msg->sdp_ops->sdp.len == 0)
248+
return 0;
249+
type = (TYPE_APPLICATION<<16) + SUBTYPE_SDP;
250+
new_sdp = 1;
251+
}
247252

248253
msg->body = pkg_malloc(sizeof (struct sip_msg_body));
249254
if (msg->body == 0)
@@ -255,7 +260,8 @@ int parse_sip_body(struct sip_msg * msg)
255260

256261
msg->body->body = body;
257262

258-
msg->body->boundary = ((content_t *) msg->content_type->parsed)->boundary;
263+
if (!new_sdp)
264+
msg->body->boundary = ((content_t *) msg->content_type->parsed)->boundary;
259265

260266
if ((type >> 16) == TYPE_MULTIPART)
261267
{
@@ -269,7 +275,7 @@ int parse_sip_body(struct sip_msg * msg)
269275
if (start == NULL) {
270276
LM_ERR("Unable to parse multipart type:"
271277
" malformed - missing start delimiters\n");
272-
return 0;
278+
goto out_free;
273279
}
274280

275281
/* mark as first part (no previous one) */
@@ -293,7 +299,7 @@ int parse_sip_body(struct sip_msg * msg)
293299
/* add 4 to delimiter 2 for "--"*/
294300
if (parse_single_part(part, start + delimiter.len + 2, end)!=0) {
295301
LM_ERR("Unable to parse part:[%.*s]\n",(int)(end-start),start);
296-
return -1;
302+
goto out_free;
297303
}
298304

299305
/* set the parsing for the next cycle */
@@ -314,7 +320,7 @@ int parse_sip_body(struct sip_msg * msg)
314320
part = &msg->body->first;
315321

316322
part->mime = type;
317-
part->mime_s = msg->content_type->body;
323+
part->mime_s = !new_sdp ? msg->content_type->body : str_init("application/sdp\r\n");
318324
part->body = body;
319325
part->headers.s = NULL;
320326
part->headers.len = 0;
@@ -325,7 +331,11 @@ int parse_sip_body(struct sip_msg * msg)
325331

326332
return 0;
327333

328-
};
334+
out_free:
335+
free_sip_body(msg->body);
336+
msg->body = NULL;
337+
return -1;
338+
}
329339

330340

331341
struct body_part* add_body_part(struct sip_msg *msg, str *mime_s,

parser/parse_body.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct sip_msg_body {
101101
* in the SIP parts */
102102
unsigned char updated_part_count;
103103

104-
/* multi purpose flags */
104+
/* multi purpose flags, e.g. SIP_BODY_FLAG_NEW */
105105
unsigned char flags;
106106

107107
/* entire body (as received) */

parser/parse_content.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ int parse_content_type_hdr( struct sip_msg *msg )
444444
}
445445
memset(rez, 0, sizeof (content_t));
446446

447-
448447
/* it seams we have to parse it! :-( */
449448
end = msg->content_type->body.s + msg->content_type->body.len;
450449
ret = decode_mime_type(msg->content_type->body.s, end , &mime, rez);

parser/sdp/sdp.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,6 @@
4444
#define HOLD_IP_STR "0.0.0.0"
4545
#define HOLD_IP_LEN 7
4646

47-
/**
48-
* Creates and initialize a new sdp_info structure
49-
*/
50-
static inline sdp_info_t* new_sdp(void)
51-
{
52-
sdp_info_t* sdp;
53-
54-
sdp = (sdp_info_t*)pkg_malloc(sizeof(sdp_info_t));
55-
if (sdp == NULL) {
56-
LM_ERR("No memory left\n");
57-
return NULL;
58-
}
59-
memset( sdp, 0, sizeof(sdp_info_t));
60-
61-
return sdp;
62-
}
63-
64-
6547
/**
6648
* Alocate a new session cell.
6749
*/
@@ -707,7 +689,7 @@ sdp_info_t* parse_sdp(struct sip_msg* _m)
707689
sdp_info_t *sdp, *ret;
708690

709691
if ( parse_sip_body(_m)<0 || _m->body==NULL) {
710-
LM_DBG("message body has length zero\n");
692+
LM_DBG("message body has length zero: %p\n", _m->body);
711693
return NULL;
712694
}
713695

parser/sdp/sdp.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ void print_sdp_session(sdp_session_cell_t* sdp_session, int log_level);
214214
*/
215215
void print_sdp_stream(sdp_stream_cell_t *stream, int log_level);
216216

217+
/**
218+
* Creates and initialize a new sdp_info structure
219+
*/
220+
static inline sdp_info_t* new_sdp(void)
221+
{
222+
sdp_info_t* sdp;
223+
224+
sdp = (sdp_info_t*)pkg_malloc(sizeof(sdp_info_t));
225+
if (sdp == NULL) {
226+
LM_ERR("No memory left\n");
227+
return NULL;
228+
}
229+
memset( sdp, 0, sizeof(sdp_info_t));
230+
231+
return sdp;
232+
}
233+
234+
217235
/**
218236
* Get the first SDP from the body
219237
*/

pvar.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "transformations.h"
5151
#include "script_var.h"
5252
#include "pvar.h"
53+
#include "sdp_ops.h"
5354
#include "flags.h"
5455
#include "xlog.h"
5556

@@ -1746,6 +1747,18 @@ static int pv_get_msg_body(struct sip_msg *msg, pv_param_t *param,
17461747
return pv_get_strval(msg, param, res, &s);
17471748
}
17481749

1750+
1751+
static int pv_get_sdp(struct sip_msg *msg, pv_param_t *_, pv_value_t *res)
1752+
{
1753+
pv_param_t param;
1754+
1755+
memset(&param, 0, sizeof param);
1756+
param.pvn.u.isname.name.n = ((TYPE_APPLICATION<<16)+SUBTYPE_SDP);
1757+
1758+
return pv_get_msg_body(msg, &param, res);
1759+
}
1760+
1761+
17491762
static int pv_get_authattr(struct sip_msg *msg, pv_param_t *param,
17501763
pv_value_t *res)
17511764
{
@@ -4284,6 +4297,21 @@ const pv_export_t _pv_names_table[] = {
42844297
{str_const_init("ruri.user"), /* */
42854298
PVT_RURI_USERNAME, pv_get_ruri_attr, pv_set_ruri_user,
42864299
0, 0, pv_init_iname, 1},
4300+
{str_const_init("sdp"), /* */
4301+
PVT_SDP, pv_get_sdp, pv_set_sdp,
4302+
0, 0, pv_init_iname, 1},
4303+
{str_const_init("sdp"), /* */
4304+
PVT_SDP, pv_get_sdp, pv_set_sdp,
4305+
pv_parse_sdp_name, 0, pv_init_iname, 1},
4306+
{str_const_init("sdp.line"), /* */
4307+
PVT_SDP_LINE, pv_get_sdp_line, pv_set_sdp_line,
4308+
pv_parse_sdp_line_name, 0, 0, 0},
4309+
{str_const_init("sdp.stream"), /* */
4310+
PVT_SDP_STREAM, pv_get_sdp_stream, pv_set_sdp_stream,
4311+
pv_parse_sdp_stream_name, 0, 0, 0},
4312+
{str_const_init("sdp.session"), /* */
4313+
PVT_SDP_SESSION, pv_get_sdp_session, pv_set_sdp_session,
4314+
pv_parse_sdp_session_name, 0, 0, 0},
42874315
{str_const_init("src_ip"), /* */
42884316
PVT_SRCIP, pv_get_srcip, 0,
42894317
0, 0, 0, 0},

pvar.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ enum _pv_type {
131131
PVT_LINE_NUMBER, PVT_CFG_FILE_NAME, PVT_LOG_LEVEL,
132132
PVT_XLOG_LEVEL, PVT_AF, PVT_HDR_NAME,
133133
PVT_SOCKET_IN, PVT_SOCKET_OUT, PVT_BRANCH_FLAG,
134-
PVT_MSG_FLAG,
134+
PVT_SDP, PVT_SDP_LINE, PVT_SDP_STREAM,
135+
PVT_SDP_SESSION, PVT_MSG_FLAG,
135136
/* registered by json module */
136137
PVT_JSON,
137138
/* registered by xml module */

0 commit comments

Comments
 (0)