Module: kamailio
Branch: master
Commit: e1a5b5cefc18f194256ddd5790e11cde7447387e
URL:
https://github.com/kamailio/kamailio/commit/e1a5b5cefc18f194256ddd5790e11cd…
Author: Mikko Lehto <mslehto(a)iki.fi>
Committer: Mikko Lehto <mslehto(a)iki.fi>
Date: 2018-09-28T15:42:15+03:00
core: parse SDP origin line sess-version field
---
Modified: src/core/parser/sdp/sdp.c
Modified: src/core/parser/sdp/sdp.h
Modified: src/core/parser/sdp/sdp_helpr_funcs.c
Modified: src/core/parser/sdp/sdp_helpr_funcs.h
---
Diff:
https://github.com/kamailio/kamailio/commit/e1a5b5cefc18f194256ddd5790e11cd…
Patch:
https://github.com/kamailio/kamailio/commit/e1a5b5cefc18f194256ddd5790e11cd…
---
diff --git a/src/core/parser/sdp/sdp.c b/src/core/parser/sdp/sdp.c
index f49fc7e0c5..f922f1b0fd 100644
--- a/src/core/parser/sdp/sdp.c
+++ b/src/core/parser/sdp/sdp.c
@@ -410,6 +410,14 @@ static int parse_sdp_session(str *sdp_body, int session_num, str
*cnt_disp, sdp_
session = add_sdp_session(_sdp, session_num, cnt_disp);
if (session == NULL) return -1;
+ /* Get sess-version */
+ tmpstr1.s = o1p;
+ tmpstr1.len = eat_line(o1p,m1p-o1p) - o1p;
+ if ( extract_sess_version(&tmpstr1, &session->o_sess_version) == -1 ) {
+ LM_ERR("can't extract origin sess-version from the message\n");
+ return -1;
+ }
+
/* Get origin IP */
tmpstr1.s = o1p;
tmpstr1.len = bodylimit - tmpstr1.s; /* limit is session limit text */
diff --git a/src/core/parser/sdp/sdp.h b/src/core/parser/sdp/sdp.h
index ab32d93d86..84ebcfc8a2 100644
--- a/src/core/parser/sdp/sdp.h
+++ b/src/core/parser/sdp/sdp.h
@@ -102,6 +102,7 @@ typedef struct sdp_session_cell {
int pf; /**< connection address family: AF_INET/AF_INET6 */
str ip_addr; /**< connection address */
/* o=<username> <session id> <version> <network type>
<address type> <address> */
+ str o_sess_version; /** < origin session version number */
int o_pf; /**< origin address family: AF_INET/AF_INET6 */
str o_ip_addr; /**< origin address */
/* b=<bwtype>:<bandwidth> */
diff --git a/src/core/parser/sdp/sdp_helpr_funcs.c
b/src/core/parser/sdp/sdp_helpr_funcs.c
index e0680342f6..2562b33234 100644
--- a/src/core/parser/sdp/sdp_helpr_funcs.c
+++ b/src/core/parser/sdp/sdp_helpr_funcs.c
@@ -590,6 +590,74 @@ int extract_media_attr(str *body, str *mediamedia, str *mediaport,
str *mediatra
return 0;
}
+int extract_sess_version(str* oline, str* sess_version) {
+
+ char* cp0 = NULL;
+ char* cp = NULL;
+ int len = 0;
+ char ws = ' ';
+ int i=0;
+
+ /*
+ "o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5" CR LF
+ "o=W 1 2 IN IP4 0.0.0.0" CR LF -> 24
+ "o=W 1 2 IN IP6 ::1" CR LF -> 20
+ "o=W 1 2 X Y Z" CR LF -> 15
+ */
+ if ( oline->s == NULL || oline->len < 15 )
+ {
+ LM_ERR("invalid o -line\n");
+ return -1;
+ }
+
+ if ( sess_version == NULL )
+ {
+ LM_ERR("invalid result pointer\n");
+ return -1;
+ }
+
+ LM_DBG("oline(%d): >%.*s<\n", oline->len, oline->len,
oline->s);
+
+ // jump over o=
+ cp = oline->s + 2;
+ len = oline->len - 2;
+
+ // find whitespace 3 times
+ do
+ {
+ cp0=cp;
+ //LM_DBG("loop %d: >%.*s<\n", len, len, cp0);
+
+ cp = (char*)ser_memmem(cp0, &ws, len, 1);
+ if ( cp == NULL) { break; }
+
+ //LM_DBG("cp0: %p cp: %p (%ld)\n", cp0, cp, cp-cp0);
+ len-=cp-cp0;
+
+ // step over whitespace
+ if ( len > 0 )
+ {
+ cp++;
+ len--;
+ }
+
+ i++;
+ } while ( len < oline->len && i < 3 );
+
+ len = cp-cp0-1;
+ LM_DBG("end %d: >%.*s<\n", len, len, cp0);
+
+ sess_version->s = cp0;
+ sess_version->len = len;
+
+ if (!isdigit(*cp0))
+ {
+ LM_WARN("not digit >%.*s<\n", len, cp0);
+ }
+
+ return 1;
+}
+
/*
* Auxiliary for some functions.
diff --git a/src/core/parser/sdp/sdp_helpr_funcs.h
b/src/core/parser/sdp/sdp_helpr_funcs.h
index cc46375ad7..406f57b165 100644
--- a/src/core/parser/sdp/sdp_helpr_funcs.h
+++ b/src/core/parser/sdp/sdp_helpr_funcs.h
@@ -52,6 +52,7 @@ int extract_mediaip(str *body, str *mediaip, int *pf, char *line);
int extract_media_attr(str *body, str *mediamedia, str *mediaport, str *mediatransport,
str *mediapayload, int *is_rtp);
int extract_bwidth(str *body, str *bwtype, str *bwwitdth);
int extract_candidate(str *body, sdp_stream_cell_t *stream);
+int extract_sess_version(str* oline, str* sess_version);
/* RFC3605 attributes */
int extract_rtcp(str *body, str *rtcp);