Browse code

modules/interconnectroute: Added video_service_code

Richard Good authored on 03/12/2014 15:44:15
Showing 4 changed files
1 1
deleted file mode 100644
... ...
@@ -1 +0,0 @@
1
-
2 0
deleted file mode 100644
... ...
@@ -1,14 +0,0 @@
1
-/* 
2
- * File:   interconnect_data.h
3
- * Author: jaybeepee
4
- *
5
- * Created on 14 October 2014, 5:44 PM
6
- */
7
-
8
-#ifndef INTERCONNECT_DATA_H
9
-#define	INTERCONNECT_DATA_H
10
-
11
-typedef struct  
12
-
13
-#endif	/* INTERCONNECT_DATA_H */
14
-
... ...
@@ -8,23 +8,29 @@
8 8
 MODULE_VERSION
9 9
 
10 10
 str interconnectroute_db_url = str_init(DEFAULT_IXDB_URL);
11
-str service_code = str_init("ext.01.001.8.32260@3gpp.org_1000");
12
-	
11
+str voice_service_code = str_init("ext.01.001.8.32260@3gpp.org_1000");
12
+str video_service_code = str_init("ext.01.001.8.32260@3gpp.org_1001");	
13
+
13 14
 static int mod_init(void);
14 15
 static int child_init(int);
15
-static int mi_child_init(void);
16
+//static int mi_child_init(void);
16 17
 static void mod_destroy(void);
17 18
 
19
+
20
+static int w_ix_orig_trunk_query(struct sip_msg* msg);
21
+static int w_ix_term_trunk_query(struct sip_msg* msg, char* ext_trunk_id);
22
+
18 23
 /************* Module Exports **********************************************/
19 24
 static cmd_export_t cmds[]={
20
-	{"ix_orig_trunk_query",  (cmd_function)ix_orig_trunk_query,  0, 0, 0, REQUEST_ROUTE | FAILURE_ROUTE },
21
-	{"ix_term_trunk_query",  (cmd_function)ix_term_trunk_query,  1, ix_trunk_query_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
25
+	{"ix_orig_trunk_query",  (cmd_function)w_ix_orig_trunk_query,  0, 0, 0, REQUEST_ROUTE | FAILURE_ROUTE },
26
+	{"ix_term_trunk_query",  (cmd_function)w_ix_term_trunk_query,  1, ix_trunk_query_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
22 27
 	{0, 0, 0, 0, 0, 0}
23 28
 };
24 29
 
25 30
 static param_export_t params[]= {
26 31
     { "db_url", PARAM_STR, &interconnectroute_db_url },
27
-    { "service_code", PARAM_STR, &service_code },
32
+    { "voice_service_code", PARAM_STR, &voice_service_code },
33
+    { "video_service_code", PARAM_STR, &video_service_code },
28 34
     {0,0,0}
29 35
 };
30 36
 
... ...
@@ -68,12 +74,20 @@ static int child_init(int rank) {
68 74
 }
69 75
 
70 76
 
71
-static int mi_child_init(void) {
77
+static int w_ix_orig_trunk_query(struct sip_msg* msg) {
78
+    return ix_orig_trunk_query(msg);
79
+}
80
+
81
+static int w_ix_term_trunk_query(struct sip_msg* msg, char* ext_trunk_id) {
82
+    return ix_term_trunk_query(msg, ext_trunk_id);
83
+}
84
+
85
+//static int mi_child_init(void) {
72 86
 //	if(mode == CARRIERROUTE_MODE_DB){
73 87
 //		return carrierroute_db_open();
74 88
 //	}
75
-	return 0;
76
-}
89
+//	return 0;
90
+//}
77 91
 
78 92
 static void mod_destroy(void) {
79 93
 //	if(mode == CARRIERROUTE_MODE_DB){
... ...
@@ -82,15 +96,15 @@ static void mod_destroy(void) {
82 96
 //	destroy_route_data();
83 97
 }
84 98
 
85
-static const char *rpc_cr_reload_routes_doc[2] = {
86
-	"Reload routes", 0
87
-};
99
+//static const char *rpc_cr_reload_routes_doc[2] = {
100
+//	"Reload routes", 0
101
+//};
88 102
 
89
-static void rpc_cr_reload_routes(rpc_t *rpc, void *c) {
90
-
91
-}
103
+//static void rpc_cr_reload_routes(rpc_t *rpc, void *c) {
104
+//
105
+//}
92 106
 
93
-static rpc_export_t rpc_methods[] = {
94
-//	{ "cr.reload_routes",  rpc_cr_reload_routes, rpc_cr_reload_routes_doc, 0},
95
-	{0, 0, 0, 0}
96
-};
97 107
\ No newline at end of file
108
+//static rpc_export_t rpc_methods[] = {
109
+////	{ "cr.reload_routes",  rpc_cr_reload_routes, rpc_cr_reload_routes_doc, 0},
110
+//	{0, 0, 0, 0}
111
+//};
98 112
\ No newline at end of file
... ...
@@ -4,18 +4,56 @@
4 4
 #include "../../sr_module.h"
5 5
 #include "../../lib/ims/ims_getters.h"
6 6
 #include "interconnectroute.h"
7
+#include "../../parser/sdp/sdp.h"
7 8
 
8
-extern str service_code;
9
+extern str voice_service_code, video_service_code;
9 10
 
10 11
 /**We need to get the service code
11 12
  currently we hard code this to voice service context id _ voice service id
12 13
  This is Smile specific - think about making this more generic*/
13
-inline int get_service_code(str *sc) {
14
-    if(!service_code.s) {
14
+inline int get_service_code(str *sc, struct sip_msg* msg) {
15
+    int sdp_stream_num = 0;
16
+    sdp_session_cell_t* msg_sdp_session;
17
+    sdp_stream_cell_t* msg_sdp_stream;
18
+    int intportA;
19
+    
20
+    //check SDP - if there is video then use video service code otherwise use voice service code
21
+    if (parse_sdp(msg) < 0) {
22
+	LM_ERR("Unable to parse req SDP\n");
15 23
 	return -1;
16 24
     }
17
-    sc->s = service_code.s;
18
-    sc->len = service_code.len;
25
+
26
+    msg_sdp_session = get_sdp_session(msg, 0);
27
+    if (!msg_sdp_session ) {
28
+	LM_ERR("Missing SDP session information from rpl\n");
29
+    } else {
30
+	for (;;) {
31
+	    msg_sdp_stream = get_sdp_stream(msg, 0, sdp_stream_num);
32
+	    if (!msg_sdp_stream) {
33
+		break;
34
+	    }
35
+
36
+	    intportA = atoi(msg_sdp_stream->port.s);
37
+	    if(intportA != 0 && strncasecmp(msg_sdp_stream->media.s,"video",5)==0){
38
+		LM_DBG("This SDP has a video component and src ports not equal to 0 - so we use video service code: [%.*s]", 
39
+			video_service_code.len, video_service_code.s);
40
+		sc->s = video_service_code.s;
41
+		sc->len = video_service_code.len;
42
+		break;
43
+	    }
44
+
45
+	    sdp_stream_num++;
46
+	}
47
+    }
48
+
49
+    free_sdp((sdp_info_t**) (void*) &msg->body);
50
+    
51
+    if(sc->len == 0) {
52
+	LM_DBG("We use default voice service code: [%.*s]", 
53
+			voice_service_code.len, voice_service_code.s);
54
+		sc->s = voice_service_code.s;
55
+		sc->len = voice_service_code.len;
56
+    }
19 57
     return 1;
20 58
     
21 59
 }
... ...
@@ -63,7 +101,7 @@ int isonlydigits(str* s) {
63 101
 }
64 102
 
65 103
 int ix_orig_trunk_query(struct sip_msg* msg) {
66
-    str sc;
104
+    str sc = {0, 0};
67 105
     sip_uri_t calling_party_sip_uri, called_party_sip_uri;
68 106
     ix_route_list_t* ix_route_list;
69 107
     str called_asserted_identity = {0 , 0 },
... ...
@@ -139,7 +177,7 @@ int ix_orig_trunk_query(struct sip_msg* msg) {
139 177
 	goto error;
140 178
     }
141 179
     
142
-    if(!get_service_code(&sc)){
180
+    if(!get_service_code(&sc, msg)){
143 181
 	LM_ERR("Could not get service code\n");
144 182
 	goto error;
145 183
     }
... ...
@@ -188,7 +226,7 @@ error:
188 226
 int ix_term_trunk_query(struct sip_msg* msg, char* ext_trunk_id) {
189 227
     str external_trunk_id = {0, 0};
190 228
     ix_route_list_t* ix_route_list;
191
-    str sc;
229
+    str sc = {0, 0};
192 230
     sip_uri_t calling_party_sip_uri, called_party_sip_uri;
193 231
     str called_asserted_identity = {0 , 0 },
194 232
 	asserted_identity = {0 , 0 },
... ...
@@ -266,7 +304,7 @@ int ix_term_trunk_query(struct sip_msg* msg, char* ext_trunk_id) {
266 304
 	goto error;
267 305
     }
268 306
     
269
-    if(!get_service_code(&sc)){
307
+    if(!get_service_code(&sc, msg)){
270 308
 	LM_ERR("Could not get service code\n");
271 309
 	goto error;
272 310
     }