~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to modules/app_java/kamailio_java_folder/java-untested/Kamailio.java

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import java.lang.*;
 
3
import java.io.*; 
 
4
 
 
5
import org.siprouter.*;
 
6
import org.siprouter.NativeInterface.*;
 
7
 
 
8
//import org.siprouter.CoreMethods.*;
 
9
 
 
10
public class Kamailio extends NativeMethods
 
11
{
 
12
        static
 
13
        {
 
14
            System.load("/opt/kamailio/lib/kamailio/modules/app_java.so");
 
15
        }
 
16
 
 
17
        /* Constructor. Do not remove !!! */
 
18
        public Kamailio()
 
19
        {
 
20
        }
 
21
 
 
22
 
 
23
        public int child_init(int rank)
 
24
        {
 
25
            return 1;
 
26
        }
 
27
 
 
28
        public int TestMethod()
 
29
        {
 
30
 
 
31
            int retval = 0;
 
32
            boolean boolstate = false;
 
33
 
 
34
/*
 
35
            LM_INFO(String.format("Msg Type: %s\n", SipMsg.getMsgType()));
 
36
 
 
37
            IPPair src = SipMsg.getSrcAddress();
 
38
            if (src != null)
 
39
            {
 
40
                LM_INFO(String.format("src address=%s, src port=%d\n", src.ip, src.port));
 
41
            }
 
42
            else
 
43
            {
 
44
                LM_ERR("IPPair src is null!");
 
45
            }
 
46
 
 
47
            IPPair dst = SipMsg.getDstAddress();
 
48
            if (dst != null)
 
49
            {
 
50
                LM_INFO(String.format("dst address=%s, dst port=%d\n", dst.ip, dst.port));
 
51
            }
 
52
            else
 
53
            {
 
54
                LM_ERR("IPPair dst is null!");
 
55
            }
 
56
 
 
57
            LM_INFO(String.format("buffer:\n%s\n", SipMsg.getBuffer().trim()));
 
58
 
 
59
            SipMsg msg = SipMsg.ParseSipMsg();
 
60
            if (msg != null)
 
61
            {
 
62
                LM_INFO("msg:\n");
 
63
                LM_INFO(String.format("\tid=%d\n", msg.id));
 
64
                LM_INFO(String.format("\tpid=%d\n", msg.pid));
 
65
                LM_INFO(String.format("\teoh='%s'\n", msg.eoh));
 
66
                LM_INFO(String.format("\tunparsed='%s'\n", msg.unparsed));
 
67
                LM_INFO(String.format("\tbuf='%s'\n", msg.buf));
 
68
                LM_INFO(String.format("\tlen=%d\n", msg.len));
 
69
                LM_INFO(String.format("\tnew_uri='%s'\n", msg.new_uri));
 
70
                LM_INFO(String.format("\tdst_uri='%s'\n", msg.dst_uri));
 
71
                LM_INFO(String.format("\tparsed_uri_ok=%d\n", msg.parsed_uri_ok));
 
72
                LM_INFO(String.format("\tparsed_orig_ruri_ok=%d\n", msg.parsed_orig_ruri_ok));
 
73
                LM_INFO(String.format("\tadd_to_branch_s='%s'\n", msg.add_to_branch_s));
 
74
                LM_INFO(String.format("\tadd_to_branch_len=%d\n", msg.add_to_branch_len));
 
75
                LM_INFO(String.format("\thash_index=%d\n", msg.hash_index));
 
76
                LM_INFO(String.format("\tmsg_flags=%d\n", msg.msg_flags));
 
77
                LM_INFO(String.format("\tset_global_address='%s'\n", msg.set_global_address));
 
78
                LM_INFO(String.format("\tset_global_port='%s'\n", msg.set_global_port));
 
79
            }
 
80
            else
 
81
            {
 
82
                LM_ERR("SipMsg msg is null!\n");
 
83
            }
 
84
 
 
85
*/
 
86
//          retval = KamExec("append_hf", "P-hint: VOICEMAIL\r\n");
 
87
 
 
88
//          KamExec("sl_send_reply", "404", "Not relaying");
 
89
 
 
90
//          retval = KamExec("is_method", "INVITE|SUBSCRIBE");
 
91
 
 
92
//          LM_INFO(String.format("return value: %d\n", retval));
 
93
 
 
94
 
 
95
 
 
96
 
 
97
//          retval = CoreMethods.rewriteuri("sip:0002@192.168.254.99:5060");
 
98
 
 
99
 
 
100
//          retval = KamExec("rewriteuri", "sip:0002@192.168.254.99:5060");
 
101
//          retval = KamExec("sl_send_reply", "404", "relaying failed");
 
102
 
 
103
//          LM_INFO(String.format("return value: %d\n", retval));
 
104
 
 
105
 
 
106
//          retval = CoreMethods.add_local_rport();
 
107
//          retval = CoreMethods.drop();
 
108
//          retval = CoreMethods.force_rport();
 
109
//          retval = CoreMethods.force_send_socket("192.168.254.9", 50349);
 
110
//          retval = CoreMethods.forward("198.61.206.9", 5060);
 
111
//          retval = CoreMethods.forward();
 
112
 
 
113
 
 
114
//          CoreMethods.setflag(3);
 
115
 
 
116
//          boolstate = CoreMethods.isflagset(3);
 
117
//          LM_INFO("return state: " + boolstate + "\n");
 
118
 
 
119
//          retval = CoreMethods.revert_uri();
 
120
    
 
121
//          retval = CoreMethods.route("NATDETECT");
 
122
//          retval = CoreMethods.route("5");
 
123
 
 
124
            retval = KamExec("is_method", "INVITE");
 
125
 
 
126
            LM_INFO(String.format("return value: %d\n", retval));
 
127
 
 
128
 
 
129
 
 
130
            return 1;
 
131
        }
 
132
 
 
133
 
 
134
        public static final int FLT_ACC         = 1;
 
135
        public static final int FLT_ACCMISSED   = 2;
 
136
        public static final int FLT_ACCFAILED   = 3;
 
137
        public static final int FLT_NATS        = 5;
 
138
        public static final int FLB_NATB        = 6;
 
139
        public static final int FLB_NATSIPPING  = 7;
 
140
 
 
141
 
 
142
        /// route ///
 
143
        public int route()
 
144
        {
 
145
            return 1;
 
146
        }
 
147
 
 
148
 
 
149
 
 
150
        /// request_route ///
 
151
        public int request_route()
 
152
        {
 
153
 
 
154
            // per request initial checks
 
155
            CoreMethods.route("REQINIT");
 
156
 
 
157
            // NAT detection
 
158
            CoreMethods.route("NATDETECT");
 
159
 
 
160
            // CANCEL processing
 
161
            if (WrappedMethods.is_method("CANCEL"))
 
162
            {
 
163
                if (WrappedMethods.t_check_trans())
 
164
                {
 
165
                    WrappedMethods.t_relay();
 
166
                }
 
167
 
 
168
                return 1;
 
169
            }
 
170
 
 
171
/*
 
172
 
 
173
 
 
174
            // handle requests within SIP dialogs
 
175
            CoreMethods.route("WITHINDLG");
 
176
 
 
177
            //### only initial requests (no To tag)
 
178
            WrappedMethods.t_check_trans();
 
179
 
 
180
            // authentication
 
181
            CoreMethods.route("AUTH");
 
182
 
 
183
            // record routing for dialog forming requests (in case they are routed)
 
184
            // - remove preloaded route headers
 
185
            WrappedMethods.remove_hf("Route");
 
186
            if (WrappedMethods.is_method("INVITE|SUBSCRIBE"))
 
187
            {
 
188
                WrappedMethods.record_route();
 
189
            }
 
190
 
 
191
            // account only INVITEs
 
192
            if (WrappedMethods.is_method("INVITE"))
 
193
            {
 
194
                CoreMethods.setflag(FLT_ACC); // do accounting
 
195
            }
 
196
 
 
197
            // dispatch requests to foreign domains
 
198
            CoreMethods.route("SIPOUT");
 
199
 
 
200
            // ### requests for my local domains
 
201
 
 
202
            // handle presence related requests
 
203
            CoreMethods.route("PRESENCE");
 
204
 
 
205
            String ruri = SipMsg.getRURI();
 
206
            if (ruri == null || ruri.length() <= 0)
 
207
            {
 
208
                // request with no Username in RURI
 
209
                WrappedMethods.sl_send_reply("484", "Address Incomplete");
 
210
                return 1;
 
211
            }
 
212
 
 
213
            // dispatch destinations to PSTN
 
214
            CoreMethods.route("PSTN");
 
215
 
 
216
            // user location service
 
217
            CoreMethods.route("LOCATION");
 
218
 
 
219
            CoreMethods.route("RELAY");
 
220
 
 
221
*/
 
222
 
 
223
            return 1;
 
224
        }
 
225
 
 
226
 
 
227
 
 
228
 
 
229
 
 
230
 
 
231
 
 
232
 
 
233
        public int Route_REQINIT()
 
234
        {
 
235
            return 1;
 
236
        }
 
237
 
 
238
        public int Route_NATDETECT()
 
239
        {
 
240
            return 1;
 
241
        }
 
242
 
 
243
        public int Route_WITHINDLG()    
 
244
        {
 
245
            if (WrappedMethods.has_totag())
 
246
            {
 
247
                // sequential request withing a dialog should
 
248
                // take the path determined by record-routing
 
249
 
 
250
                if (WrappedMethods.loose_route())
 
251
                {
 
252
                    CoreMethods.route("DLGURI");
 
253
 
 
254
                    if (WrappedMethods.is_method("BYE"))
 
255
                    {
 
256
                        CoreMethods.setflag(FLT_ACC);           // do accounting ...
 
257
                        CoreMethods.setflag(FLT_ACCFAILED);     // ... even if the transaction fails
 
258
                    }
 
259
                    else if (WrappedMethods.is_method("ACK"))
 
260
                    {
 
261
                        // ACK is forwarded statelessy
 
262
                        CoreMethods.route("NATMANAGE");
 
263
                    }
 
264
                    else if (WrappedMethods.is_method("NOTIFY"))
 
265
                    {
 
266
                        // Add Record-Route for in-dialog NOTIFY as per RFC 6665.
 
267
                        WrappedMethods.record_route();
 
268
                    }
 
269
 
 
270
                    CoreMethods.route("RELAY");
 
271
                }
 
272
                else
 
273
                {
 
274
/* // this block would not work -- 'uri' and 'myself' aren't implemented yet //
 
275
                        if (is_method("SUBSCRIBE") && uri == myself) {
 
276
                                # in-dialog subscribe requests
 
277
                                route(PRESENCE);
 
278
                                exit;
 
279
                        }
 
280
*/
 
281
                        if (WrappedMethods.is_method("ACK"))
 
282
                        {
 
283
                            if (WrappedMethods.t_check_trans())
 
284
                            {
 
285
                                // no loose-route, but stateful ACK;
 
286
                                // must be an ACK after a 487
 
287
                                // or e.g. 404 from upstream server
 
288
                                WrappedMethods.t_relay();
 
289
                            }
 
290
                            else
 
291
                            {
 
292
                                // ACK without matching transaction ... ignore and discard
 
293
                                return 1;
 
294
                            }   
 
295
                        }
 
296
                        WrappedMethods.sl_send_reply("404", "Not here");
 
297
                }
 
298
 
 
299
            }
 
300
 
 
301
 
 
302
            return 1;
 
303
        }
 
304
 
 
305
        public int Route_AUTH()
 
306
        {
 
307
            return 1;
 
308
        }
 
309
 
 
310
        public int Route_SIPOUT()
 
311
        {
 
312
            return 1;
 
313
        }
 
314
 
 
315
        public int Route_PRESENCE()
 
316
        {
 
317
            return 1;
 
318
        }
 
319
 
 
320
        public int Route_PSTN()
 
321
        {
 
322
            return 1;
 
323
        }
 
324
 
 
325
        public int Route_LOCATION()
 
326
        {
 
327
            return 1;
 
328
        }
 
329
 
 
330
        public int Route_RELAY()
 
331
        {
 
332
            // enable additional event routes for forwarded requests
 
333
            //  - serial forking, RTP relaying handling, a.s.o.
 
334
            if (WrappedMethods.is_method("INVITE|SUBSCRIBE"))
 
335
            {
 
336
////                WrappedMethods.t_on_branch("MANAGE_BRANCH");
 
337
////                WrappedMethods.t_on_reply("MANAGE_REPLY");
 
338
            }
 
339
            
 
340
            if (WrappedMethods.is_method("INVITE"))
 
341
            {
 
342
////                WrappedMethods.t_on_failure("MANAGE_FAILURE");
 
343
            }
 
344
 
 
345
            if (!WrappedMethods.t_relay())
 
346
            {
 
347
                WrappedMethods.sl_reply_error();
 
348
            }
 
349
 
 
350
            return 1;
 
351
        }
 
352
 
 
353
        public int Route_REGISTRAR()
 
354
        {
 
355
            if (WrappedMethods.is_method("REGISTER"))
 
356
            {
 
357
                if (CoreMethods.isflagset(FLT_NATS))
 
358
                {
 
359
                    CoreMethods.setflag(FLB_NATB);
 
360
                    // uncomment next line to do SIP NAT pinging
 
361
                    // CoreMethods.setflag(FLB_NATSIPPING);
 
362
                }
 
363
 
 
364
                if (!WrappedMethods.save("location"))
 
365
                {
 
366
                    WrappedMethods.sl_reply_error();
 
367
                }
 
368
            }
 
369
 
 
370
            return 1;
 
371
        }
 
372
 
 
373
}
 
374
 
 
375
 
 
376
 
 
377
 
 
378
 
 
379
 
 
380
 
 
381
 
 
382
 
 
383
 
 
384
 
 
385
 
 
386
 
 
387
 
 
388