Browse code

1. Fix [1524079] bug reported for Scalable SIP server project in SourceForge. Please check OpenSER tracker for details. 2. Change getting destination protocol & OSP version. If these functions fail, using the default protocol & OSP version.

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1052 689a6050-402a-0410-94f2-e92a70836424

Di-Shi Sun authored on 31/07/2006 14:54:37
Showing 11 changed files
... ...
@@ -39,8 +39,8 @@
39 39
 #include "usage.h"
40 40
 
41 41
 /* Name of AVP item of OSP */
42
-str OSP_ORIGDEST_LABEL = {"_orig_osp_dests_", 16};
43
-str OSP_TERMDEST_LABEL = {"_term_osp_dests_", 16};
42
+str OSP_ORIGDEST_LABEL = {"_osp_orig_dests_", 16};
43
+str OSP_TERMDEST_LABEL = {"_osp_term_dests_", 16};
44 44
 
45 45
 static int ospSaveDestination(osp_dest* dest, str* label);
46 46
 static osp_dest* ospGetLastOrigDestination(void);
... ...
@@ -24,6 +24,7 @@ loadmodule "rr.so"
24 24
 loadmodule "textops.so"
25 25
 loadmodule "usrloc.so"
26 26
 loadmodule "registrar.so"
27
+loadmodule "auth.so"
27 28
 # Load OSP module
28 29
 loadmodule "osp.so"
29 30
 
... ...
@@ -89,6 +90,17 @@ modparam("osp", "sp1_uri", "http://osptestserver.transnexus.com:1080/osp")
89 90
 #  modparam("osp", "local_certificate","/usr/local/etc/openser/localcert.pem")
90 91
 #  modparam("osp", "ca_certificates",  "/usr/local/etc/openser/cacert_0.pem")
91 92
 
93
+#
94
+# Use Remote-Party-ID for calling number
95
+# ===========================================
96
+# This parameter is used to tell OSP module if the calling number should be obtained from RPID header. 
97
+# The default value is 1.
98
+#
99
+# 0 - OSP module will use the calling number in From header.
100
+# 1 - OSP module will use the calling number in RPID header if a RPID header exists.
101
+#
102
+# modparam("osp", "use_rpid_for_calling_number", 1)
103
+
92 104
 # -- usrloc params --
93 105
 modparam("usrloc", "db_mode",   0)
94 106
 
... ...
@@ -390,4 +402,16 @@ branch_route[1] {
390 402
 	log(1,"Prepare route specific OSP information\n");
391 403
 
392 404
 	prepareosproute();
405
+
406
+	# Only add/change Remote-Party-ID if calling number is translated
407
+    if (checkcallingtranslation()) {
408
+		log(1,"The calling number is translated, add a new RPID header\n");
409
+
410
+		# Remove the Remote_Party-ID from the received message
411
+		# Otherwise it will be forwarded on to the next hop
412
+		remove_hf("Remote-Party-ID");
413
+
414
+		# Append a new Remote_Party
415
+		append_rpid_hf();
416
+    }
393 417
 }
... ...
@@ -34,20 +34,21 @@
34 34
 
35 35
 char* _osp_sp_uris[OSP_DEF_SPS];
36 36
 unsigned long _osp_sp_weights[OSP_DEF_SPS] = {OSP_DEF_WEIGHT, OSP_DEF_WEIGHT};
37
+char* _osp_device_ip = NULL;
38
+char* _osp_device_port = NULL;
37 39
 unsigned char* _osp_private_key = NULL;
38 40
 unsigned char* _osp_local_certificate = NULL;
39 41
 unsigned char* _osp_ca_certificate = NULL;
40
-char* _osp_device_ip = NULL;
41
-char* _osp_device_port = NULL;
42
+int _osp_crypto_hw = OSP_DEF_HW;
43
+int _osp_validate_callid = OSP_DEF_CALLID;
44
+int _osp_token_format = OSP_DEF_TOKEN;
42 45
 int _osp_ssl_lifetime = OSP_DEF_SSLLIFE;
43 46
 int _osp_persistence = OSP_DEF_PERSISTENCE;
44 47
 int _osp_retry_delay = OSP_DEF_DELAY;
45 48
 int _osp_retry_limit = OSP_DEF_RETRY;
46 49
 int _osp_timeout = OSP_DEF_TIMEOUT;
47 50
 int _osp_max_dests = OSP_DEF_DESTS;
48
-int _osp_token_format = OSP_DEF_TOKEN;
49
-int _osp_crypto_hw = OSP_DEF_HW;
50
-int _osp_validate_callid = OSP_DEF_CALLID;
51
+int _osp_use_rpid = OSP_DEF_USERPID;
51 52
 char _osp_PRIVATE_KEY[OSP_KEYBUF_SIZE];
52 53
 char _osp_LOCAL_CERTIFICATE[OSP_KEYBUF_SIZE];
53 54
 char _osp_CA_CERTIFICATE[OSP_KEYBUF_SIZE];
... ...
@@ -33,6 +33,7 @@
33 33
 #include "../../dset.h"
34 34
 #include "../../usr_avp.h"
35 35
 #include "../../mem/mem.h"
36
+#include "../auth/api.h"
36 37
 #include "orig_transaction.h"
37 38
 #include "destination.h"
38 39
 #include "osptoolkit.h"
... ...
@@ -43,14 +44,17 @@ extern char* _osp_device_ip;
43 44
 extern char* _osp_device_port;
44 45
 extern int _osp_max_dests;
45 46
 extern OSPTPROVHANDLE _osp_provider;
47
+extern auth_api_t osp_auth;
46 48
 
47 49
 const int OSP_FIRST_ROUTE = 1;
48 50
 const int OSP_NEXT_ROUTE = 0;
49 51
 const int OSP_MAIN_ROUTE = 1;
50 52
 const int OSP_BRANCH_ROUTE = 0;
53
+const str OSP_CALLING_NAME = {"_osp_calling_translated_", 24};
51 54
 
52 55
 static int ospLoadRoutes(struct sip_msg* msg, OSPTTRANHANDLE transaction, int destcount, char* source, char* sourcedev, time_t authtime);
53 56
 static int ospPrepareDestination(struct sip_msg* msg, int isfirst, int type);
57
+static int ospSetRpid(struct sip_msg* msg, osp_dest* dest);
54 58
 
55 59
 /*
56 60
  * Get routes from AuthRsp
... ...
@@ -74,8 +78,8 @@ static int ospLoadRoutes(
74 78
     int errorcode;
75 79
     osp_dest* dest;
76 80
     osp_dest dests[OSP_DEF_DESTS];
77
-	OSPE_DEST_PROT protocol;
78
-	OSPE_DEST_OSP_ENABLED enabled;
81
+    OSPE_DEST_PROT protocol;
82
+    OSPE_DEST_OSP_ENABLED enabled;
79 83
     int result = MODULE_RETURNCODE_TRUE;
80 84
     
81 85
     LOG(L_DBG, "osp: ospLoadRoutes\n");
... ...
@@ -142,30 +146,28 @@ static int ospLoadRoutes(
142 146
 
143 147
         errorcode = OSPPTransactionGetDestProtocol(transaction, &protocol);
144 148
         if (errorcode != 0) {
145
-            LOG(L_ERR, "osp: ERROR: failed to get dest protocol (%d)\n", errorcode);
146
-            result = MODULE_RETURNCODE_FALSE;
147
-            break;
148
-        } else {
149
-            switch (protocol) {
150
-                case OSPE_DEST_PROT_H323_LRQ:
151
-                case OSPE_DEST_PROT_H323_SETUP:
152
-                case OSPE_DEST_PROT_IAX:
153
-                    dest->supported = 0;
154
-                    break;
155
-                case OSPE_DEST_PROT_SIP:
156
-                case OSPE_DEST_PROT_UNDEFINED:
157
-                case OSPE_DEST_PROT_UNKNOWN:
158
-                default:
159
-                    dest->supported = 1;
160
-                    break;
161
-            }
149
+            /* This does not mean an ERROR. The OSP server may not support OSP 2.1.1 */
150
+            LOG(L_DBG, "osp: cannot get dest protocol (%d)\n", errorcode);
151
+            protocol = OSPE_DEST_PROT_SIP;
152
+        }
153
+        switch (protocol) {
154
+            case OSPE_DEST_PROT_H323_LRQ:
155
+            case OSPE_DEST_PROT_H323_SETUP:
156
+            case OSPE_DEST_PROT_IAX:
157
+                dest->supported = 0;
158
+                break;
159
+            case OSPE_DEST_PROT_SIP:
160
+            case OSPE_DEST_PROT_UNDEFINED:
161
+            case OSPE_DEST_PROT_UNKNOWN:
162
+            default:
163
+                dest->supported = 1;
164
+                break;
162 165
         }
163 166
 
164 167
         errorcode = OSPPTransactionIsDestOSPEnabled(transaction, &enabled);
165 168
         if (errorcode != 0) {
166
-            LOG(L_ERR, "osp: ERROR: failed to get dest OSP version (%d)\n", errorcode);
167
-            result = MODULE_RETURNCODE_FALSE;
168
-            break;
169
+            /* This does not mean an ERROR. The OSP server may not support OSP 2.1.1 */
170
+            LOG(L_DBG, "osp: cannot get dest OSP version (%d)\n", errorcode);
169 171
         } else if (enabled == OSPE_OSP_FALSE) {
170 172
             /* Destination device does not support OSP. Do not send token to it */
171 173
             dest->token[0] = '\0';
... ...
@@ -254,9 +256,13 @@ int requestosprouting(
254 256
 
255 257
     if ((errorcode = OSPPTransactionNew(_osp_provider, &transaction)) != 0) {
256 258
         LOG(L_ERR, "osp: ERROR: failed to create new OSP transaction (%d)\n", errorcode);
257
-    } else if (ospGetFromUserpart(msg, source, sizeof(source)) != 0) {
259
+    } else if ((ospGetRpidUserpart(msg, source, sizeof(source)) != 0) &&
260
+        (ospGetFromUserpart(msg, source, sizeof(source)) != 0)) 
261
+    {
258 262
         LOG(L_ERR, "osp: ERROR: failed to extract calling number\n");
259
-    } else if (ospGetUriUserpart(msg, destination, sizeof(destination)) != 0) {
263
+    } else if ((ospGetUriUserpart(msg, destination, sizeof(destination)) != 0) &&
264
+        (ospGetToUserpart(msg, destination, sizeof(destination)) != 0)) 
265
+    {
260 266
         LOG(L_ERR, "osp: ERROR: failed to extract called number\n");
261 267
     } else if (ospGetCallId(msg, &(callids[0])) != 0) {
262 268
         LOG(L_ERR, "osp: ERROR: failed to extract call id\n");
... ...
@@ -347,7 +353,7 @@ int requestosprouting(
347 353
 
348 354
 /*
349 355
  * Check if there is a route
350
- * param msg ISP message
356
+ * param msg SIP message
351 357
  * param ignore1
352 358
  * param ignore2
353 359
  * return MODULE_RETURNCODE_TRUE success, MODULE_RETURNCODE_FALSE failure
... ...
@@ -366,6 +372,97 @@ int checkosproute(
366 372
     }
367 373
 }
368 374
 
375
+/*
376
+ * Create RPID AVP
377
+ * param msg SIP message
378
+ * param dest Destination structure
379
+ * return 0 success, 1 calling number same, -1 failure
380
+ */
381
+static int ospSetRpid(
382
+    struct sip_msg* msg, 
383
+    osp_dest* dest)
384
+{
385
+    str rpid;
386
+    char calling[OSP_STRBUF_SIZE];
387
+    char source[OSP_STRBUF_SIZE];
388
+    char buffer[OSP_STRBUF_SIZE];
389
+    int result = -1;
390
+
391
+    LOG(L_DBG, "osp: ospSetRpid\n");
392
+
393
+    if ((ospGetRpidUserpart(msg, calling, sizeof(calling)) != 0) &&
394
+        (ospGetFromUserpart(msg, calling, sizeof(calling)) !=0))
395
+    {
396
+        LOG(L_ERR, "osp: ERROR: failed to extract calling number\n");
397
+        return result;
398
+    } 
399
+
400
+    if (strcmp(calling, dest->calling) == 0) {
401
+        /* Do nothing for this case */ 
402
+        result = 1;
403
+    } else if ((osp_auth.rpid_avp.s.s == NULL) || (osp_auth.rpid_avp.s.len == 0)) {
404
+        LOG(L_WARN, "osp: WARN: rpid_avp is not foune, cannot set rpid avp\n");
405
+        result = -1;
406
+    } else {
407
+        if (dest->source[0] == '[') {
408
+            /* Strip "[]" */
409
+            strncpy(source, &dest->source[1], sizeof(source));
410
+            source[strlen(source) - 1] = '\0';
411
+        }
412
+    
413
+        snprintf(
414
+            buffer, 
415
+            sizeof(buffer), 
416
+            "\"%s\" <sip:%s@%s>", 
417
+            dest->calling, 
418
+            dest->calling, 
419
+            source);
420
+
421
+        rpid.s = buffer;
422
+        rpid.len = strlen(buffer);
423
+        add_avp(osp_auth.rpid_avp_type | AVP_VAL_STR, (int_str)osp_auth.rpid_avp, (int_str)rpid);
424
+
425
+        result = 0;
426
+    }
427
+
428
+    return result;
429
+}
430
+
431
+/*
432
+ * Check if the calling number is translated.
433
+ *     This function checks the avp set by ospPrepareDestination.
434
+ * param msg SIP message
435
+ * param ignore1
436
+ * param ignore2
437
+ * return MODULE_RETURNCODE_TRUE calling number translated MODULE_RETURNCODE_FALSE without transaltion
438
+ */
439
+int checkcallingtranslation(
440
+    struct sip_msg* msg, 
441
+    char* ignore1, 
442
+    char* ignore2)
443
+{
444
+    struct usr_avp* callingavp = NULL;
445
+    int_str callingval;
446
+    int result = MODULE_RETURNCODE_FALSE;
447
+
448
+    LOG(L_DBG, "osp: checkcallingtranslation\n");
449
+
450
+    callingavp = search_first_avp(AVP_NAME_STR, (int_str)OSP_CALLING_NAME, NULL, 0);
451
+    if (callingavp != NULL) {
452
+        get_avp_val(callingavp, &callingval);
453
+        if (callingval.n == 0) {
454
+            LOG(L_DBG, "osp: the calling number does not been translated\n");
455
+        } else {
456
+            LOG(L_DBG, "osp: the calling number is translated\n");
457
+            result = MODULE_RETURNCODE_TRUE;
458
+        }
459
+    } else {
460
+        LOG(L_ERR, "osp: ERROR: there is not calling translation avp\n");
461
+    }
462
+
463
+    return result;
464
+}
465
+
369 466
 /*
370 467
  * Build SIP message for destination
371 468
  * param msg SIP message
... ...
@@ -379,6 +476,8 @@ static int ospPrepareDestination(
379 476
     int type)
380 477
 {
381 478
     str newuri = {NULL, 0};
479
+    int_str val;
480
+    int res;
382 481
     int result = MODULE_RETURNCODE_TRUE;
383 482
 
384 483
     LOG(L_DBG, "osp: ospPrepareDestination\n");
... ...
@@ -404,9 +503,31 @@ static int ospPrepareDestination(
404 503
             }
405 504
             /* Do not add route specific OSP information */
406 505
         } else if (type == OSP_BRANCH_ROUTE) {
407
-            rewrite_uri(msg, &newuri);
408 506
             /* For branch route, add route specific OSP information */
507
+
508
+            /* Update the Request-Line */
509
+            rewrite_uri(msg, &newuri);
510
+
511
+            /* Add OSP token header */
409 512
             ospAddOspHeader(msg, dest->token, dest->tokensize);
513
+
514
+            /* Add rpid avp for calling number translation */
515
+            res = ospSetRpid(msg, dest);
516
+            switch (res) {
517
+                case 0:
518
+                    /* Calling number is translated */
519
+                    val.n = 1;
520
+                    add_avp(AVP_NAME_STR, (int_str)OSP_CALLING_NAME, val);
521
+                    break;
522
+                default:
523
+                    LOG(L_DBG, "osp: cannot set rpid avp\n");
524
+                    /* Just like without calling translation */
525
+                case 1:
526
+                    /* Calling number does not been translated */
527
+                    val.n = 0;
528
+                    add_avp(AVP_NAME_STR, (int_str)OSP_CALLING_NAME, val);
529
+                    break;
530
+            }
410 531
         } else {
411 532
             LOG(L_ERR, "osp: ERROR: unsupported route block type\n");
412 533
         }
... ...
@@ -428,7 +549,7 @@ static int ospPrepareDestination(
428 549
 /*
429 550
  * Prepare OSP route
430 551
  *     This function only works in branch route block.
431
- * param msg ISP message
552
+ * param msg SIP message
432 553
  * param ignore1
433 554
  * param ignore2
434 555
  * return MODULE_RETURNCODE_TRUE success, MODULE_RETURNCODE_FALSE failure
... ...
@@ -451,7 +572,7 @@ int prepareosproute(
451 572
 /*
452 573
  * Prepare all OSP routes
453 574
  *     This function does not work in branch route block.
454
- * param msg ISP message
575
+ * param msg SIP message
455 576
  * param ignore1
456 577
  * param ignore2
457 578
  * return MODULE_RETURNCODE_TRUE success, MODULE_RETURNCODE_FALSE failure
... ...
@@ -37,6 +37,7 @@ int requestosprouting(struct sip_msg*, char*, char*);
37 37
 int checkosproute(struct sip_msg*, char*, char*);
38 38
 int prepareosproute(struct sip_msg*, char*, char*);
39 39
 int prepareallosproutes(struct sip_msg*, char*, char*);
40
+int checkcallingtranslation(struct sip_msg*, char*, char*);
40 41
 
41 42
 #endif /* _OSP_MOD_ORIG_TRANSACTION_H_ */
42 43
 
... ...
@@ -34,6 +34,7 @@
34 34
 
35 35
 #include <osp/osp.h>
36 36
 #include "../rr/api.h"
37
+#include "../auth/api.h"
37 38
 #include "osp_mod.h"
38 39
 #include "orig_transaction.h"
39 40
 #include "term_transaction.h"
... ...
@@ -45,26 +46,28 @@ MODULE_VERSION
45 46
 
46 47
 extern char* _osp_sp_uris[];
47 48
 extern unsigned long _osp_sp_weights[];
49
+extern char* _osp_device_ip;
50
+extern char* _osp_device_port;
48 51
 extern unsigned char* _osp_private_key;
49 52
 extern unsigned char* _osp_local_certificate;
50 53
 extern unsigned char* _osp_ca_certificate;
51
-extern char* _osp_device_ip;
52
-extern char* _osp_device_port;
54
+extern int _osp_crypto_hw;
55
+extern int _osp_validate_callid;
56
+extern int _osp_token_format;
53 57
 extern int _osp_ssl_lifetime;
54 58
 extern int _osp_persistence;
55 59
 extern int _osp_retry_delay;
56 60
 extern int _osp_retry_limit;
57 61
 extern int _osp_timeout;
58 62
 extern int _osp_max_dests;
59
-extern int _osp_token_format;
60
-extern int _osp_crypto_hw;
61
-extern int _osp_validate_callid;
63
+extern int _osp_use_rpid;
62 64
 extern char _osp_PRIVATE_KEY[];
63 65
 extern char _osp_LOCAL_CERTIFICATE[];
64 66
 extern char _osp_CA_CERTIFICATE[];
65 67
 extern OSPTPROVHANDLE _osp_provider;
66 68
 
67
-struct rr_binds osp_rrb;
69
+struct rr_binds osp_rr;
70
+auth_api_t osp_auth;
68 71
 
69 72
 static int ospInitMod(void);
70 73
 static void ospDestMod(void);
... ...
@@ -73,13 +76,14 @@ static int  ospVerifyParameters(void);
73 76
 static void ospDumpParameters(void);
74 77
 
75 78
 static cmd_export_t cmds[]={
76
-    {"checkospheader",       checkospheader,       0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
77
-    {"validateospheader",    validateospheader,    0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
78
-    {"requestosprouting",    requestosprouting,    0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
79
-    {"checkosproute",        checkosproute,        0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
80
-    {"prepareosproute",      prepareosproute,      0, 0, BRANCH_ROUTE}, 
81
-    {"prepareallosproutes",  prepareallosproutes,  0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
82
-    {"reportospusage",       reportospusage,       1, 0, REQUEST_ROUTE}, 
79
+    {"checkospheader",          checkospheader,             0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
80
+    {"validateospheader",       validateospheader,          0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
81
+    {"requestosprouting",       requestosprouting,          0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
82
+    {"checkosproute",           checkosproute,              0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
83
+    {"prepareosproute",         prepareosproute,            0, 0, BRANCH_ROUTE}, 
84
+    {"checkcallingtranslation", checkcallingtranslation,    0, 0, BRANCH_ROUTE}, 
85
+    {"prepareallosproutes",     prepareallosproutes,        0, 0, REQUEST_ROUTE|FAILURE_ROUTE}, 
86
+    {"reportospusage",          reportospusage,             1, 0, REQUEST_ROUTE}, 
83 87
     {0, 0, 0, 0, 0}
84 88
 };
85 89
 
... ...
@@ -102,6 +106,7 @@ static param_export_t params[]={
102 106
     {"retry_limit",                    INT_PARAM, &_osp_retry_limit},
103 107
     {"timeout",                        INT_PARAM, &_osp_timeout},
104 108
     {"max_destinations",               INT_PARAM, &_osp_max_dests},
109
+    {"use_rpid_for_calling_number",    INT_PARAM, &_osp_use_rpid},
105 110
     {0,0,0} 
106 111
 };
107 112
 
... ...
@@ -122,6 +127,8 @@ struct module_exports exports = {
122 127
  */
123 128
 static int ospInitMod(void)
124 129
 {
130
+    bind_auth_t bind_auth;
131
+
125 132
     LOG(L_DBG, "osp: ospInitMod\n");
126 133
 
127 134
     if (ospVerifyParameters() != 0) {
... ...
@@ -130,10 +137,18 @@ static int ospInitMod(void)
130 137
     }
131 138
 
132 139
     /* Load the RR API */
133
-    if (load_rr_api(&osp_rrb) != 0) {
140
+    if (load_rr_api(&osp_rr) != 0) {
134 141
         LOG(L_WARN, "osp: WARN: failed to load RR API\n");
135 142
         LOG(L_WARN, "osp: WARN: add_rr_param is required for reporting duration for OSP transactions\n");
136
-        memset(&osp_rrb, 0, sizeof(osp_rrb));
143
+        memset(&osp_rr, 0, sizeof(osp_rr));
144
+    }
145
+
146
+    /* Load the AUTH API */
147
+    bind_auth = (bind_auth_t)find_export("bind_auth", 0, 0);
148
+    if ((bind_auth == NULL) || (bind_auth(&osp_auth) != 0)) {
149
+        LOG(L_WARN, "osp: WARN: failed to load AUTH API\n");
150
+        LOG(L_WARN, "osp: WARN: rpid_avp & rpid_avp_type is required for calling number translation\n");
151
+        memset(&osp_auth, 0, sizeof(osp_auth));
137 152
     }
138 153
 
139 154
     if (ospInitTm() < 0) {
... ...
@@ -257,6 +272,7 @@ static void ospDumpParameters(void)
257 272
         "retry_limit '%d' "
258 273
         "timeout '%d' "
259 274
         "validate_call_id '%d' "
275
+        "use_rpid_for_calling_number '%d' "
260 276
         "max_destinations '%d'\n",
261 277
         _osp_sp_uris[0],
262 278
         _osp_sp_weights[0],
... ...
@@ -275,6 +291,7 @@ static void ospDumpParameters(void)
275 291
         _osp_retry_limit,
276 292
         _osp_timeout,
277 293
         _osp_validate_callid,
294
+        _osp_use_rpid,
278 295
         _osp_max_dests);
279 296
 }
280 297
 
... ...
@@ -37,15 +37,16 @@
37 37
 
38 38
 #define OSP_DEF_SPS                     2
39 39
 #define OSP_DEF_WEIGHT                  1000
40
+#define OSP_DEF_HW                      0
41
+#define OSP_DEF_CALLID                  1    /* Validate call ids, set to 0 to disable */
42
+#define OSP_DEF_TOKEN                   2
40 43
 #define OSP_DEF_SSLLIFE                 300
41 44
 #define OSP_DEF_PERSISTENCE             (60 * 1000)
42 45
 #define OSP_DEF_DELAY                   0
43 46
 #define OSP_DEF_RETRY                   2
44 47
 #define OSP_DEF_TIMEOUT                 (60 * 1000)
45 48
 #define OSP_DEF_DESTS                   5
46
-#define OSP_DEF_TOKEN                   2
47
-#define OSP_DEF_HW                      0
48
-#define OSP_DEF_CALLID                  1    /* Validate call ids, set to 0 to disable */
49
+#define OSP_DEF_USERPID                 1
49 50
 
50 51
 #define OSP_KEYBUF_SIZE                 256
51 52
 #define OSP_STRBUF_SIZE                 256
... ...
@@ -31,14 +31,17 @@
31 31
 #include <osp/osp.h>
32 32
 #include <osp/ospb64.h>
33 33
 #include "../../forward.h"
34
-#include "../../parser/parse_uri.h"
35 34
 #include "../../parser/parse_from.h"
35
+#include "../../parser/parse_rpid.h"
36 36
 #include "../../parser/parse_rr.h"
37
+#include "../../parser/parse_uri.h"
37 38
 #include "../../data_lump.h"
38 39
 #include "../../mem/mem.h"
39 40
 #include "osp_mod.h"
40 41
 #include "sipheader.h"
41 42
 
43
+extern int _osp_use_rpid;
44
+
42 45
 static void ospCopyStrToBuffer(str* source, char* buffer, int buffersize);
43 46
 static void ospSkipPlus(char* e164);
44 47
 static int ospAppendHeader(struct sip_msg* msg, str* header); 
... ...
@@ -128,6 +131,50 @@ int ospGetFromUserpart(
128 131
     return result;
129 132
 }
130 133
 
134
+/* 
135
+ * Get calling number from Remote-Party-ID header
136
+ * param msg SIP message
137
+ * param rpiduser User part of Remote-Party-ID header
138
+ * param buffersize Size of fromuser buffer
139
+ * return 0 success, 1 failure
140
+ */
141
+int ospGetRpidUserpart(
142
+    struct sip_msg* msg, 
143
+    char* rpiduser, 
144
+    int buffersize)
145
+{
146
+    struct to_body* rpid;
147
+    struct sip_uri uri;
148
+    int result = 1;
149
+
150
+    LOG(L_DBG, "osp: ospGetRpidUserpart\n");
151
+
152
+    rpiduser[0] = '\0';
153
+
154
+    if (_osp_use_rpid != 0) {
155
+        if (msg->rpid != NULL) {
156
+            if (parse_rpid_header(msg) == 0) {
157
+                rpid = (struct to_body*)msg->rpid->parsed;
158
+                if (parse_uri(rpid->uri.s, rpid->uri.len, &uri) == 0) {
159
+                    ospCopyStrToBuffer(&uri.user, rpiduser, buffersize);
160
+                    ospSkipPlus(rpiduser);
161
+                    result = 0;
162
+                } else {
163
+                    LOG(L_ERR, "osp: ERROR: failed to parse RPID uri\n");
164
+                }
165
+            } else {
166
+                LOG(L_ERR, "osp: ERROR: failed to parse RPID header\n");
167
+            }
168
+        } else {
169
+            LOG(L_DBG, "osp: without RPID header\n");
170
+        }
171
+    } else {
172
+        LOG(L_DBG, "osp: do not use RPID header\n");
173
+    }
174
+
175
+    return result;
176
+}
177
+
131 178
 /* 
132 179
  * Get called number from To header
133 180
  * param msg SIP message
... ...
@@ -38,6 +38,7 @@
38 38
 #define OSP_HEADER_SIZE         strlen(OSP_TOKEN_HEADER)
39 39
 
40 40
 int ospGetFromUserpart(struct sip_msg* msg, char* fromuser, int buffersize);
41
+int ospGetRpidUserpart(struct sip_msg* msg, char* fromuser, int buffersize);
41 42
 int ospGetToUserpart(struct sip_msg* msg, char* touser, int buffersize);
42 43
 int ospGetUriUserpart(struct sip_msg* msg, char* touser, int buffersize);
43 44
 int ospAddOspHeader(struct sip_msg* msg, unsigned char* token, unsigned int tokensize);
... ...
@@ -95,9 +95,13 @@ int validateospheader (
95 95
 
96 96
     if ((errorcode = OSPPTransactionNew(_osp_provider, &transaction) != 0)) {
97 97
         LOG(L_ERR, "osp: ERROR: failed to create a new OSP transaction handle (%d)\n", errorcode);
98
-    } else if (ospGetFromUserpart(msg, dest.calling, sizeof(dest.calling)) != 0) {
98
+    } else if ((ospGetRpidUserpart(msg, dest.calling, sizeof(dest.calling)) != 0) && 
99
+        (ospGetFromUserpart(msg, dest.calling, sizeof(dest.calling)) != 0))
100
+    {
99 101
         LOG(L_ERR, "osp: ERROR: failed to extract calling number\n");
100
-    } else if (ospGetUriUserpart(msg, dest.called, sizeof(dest.called)) != 0) {
102
+    } else if ((ospGetUriUserpart(msg, dest.called, sizeof(dest.called)) != 0) &&
103
+        (ospGetToUserpart(msg, dest.called, sizeof(dest.called)) != 0))
104
+    {
101 105
         LOG(L_ERR, "osp: ERROR: failed to extract called number\n");
102 106
     } else if (ospGetCallId(msg, &callid) != 0) {
103 107
         LOG(L_ERR, "osp: ERROR: failed to extract call id\n");
... ...
@@ -48,7 +48,7 @@
48 48
 extern char* _osp_device_ip;
49 49
 extern OSPTPROVHANDLE _osp_provider;
50 50
 extern str OSP_ORIGDEST_LABEL;
51
-extern struct rr_binds osp_rrb;
51
+extern struct rr_binds osp_rr;
52 52
 
53 53
 static void ospRecordTransaction(struct sip_msg* msg, OSPTTRANHANDLE transaction, char* uac, char* from, char* to, time_t authtime, int isorig);
54 54
 static int ospReportUsageFromCookie(struct sip_msg* msg, char* cooky, OSPTCALLID* callid, int release, int isorig);
... ...
@@ -80,7 +80,7 @@ static void ospRecordTransaction(
80 80
 
81 81
     LOG(L_DBG, "osp: ospRecordTransaction\n");
82 82
 
83
-    if (osp_rrb.add_rr_param == 0) {
83
+    if (osp_rr.add_rr_param == 0) {
84 84
         LOG(L_WARN,
85 85
             "osp: WARN: add_rr_param function is not found, "
86 86
             "cannot record information about the "
... ...
@@ -107,7 +107,7 @@ static void ospRecordTransaction(
107 107
     }
108 108
 
109 109
     LOG(L_DBG, "osp: adding RR parameter '%s'\n", buffer);
110
-    osp_rrb.add_rr_param(msg, &s);
110
+    osp_rr.add_rr_param(msg, &s);
111 111
 }
112 112
 
113 113
 /*
... ...
@@ -227,10 +227,11 @@ static int ospReportUsageFromCookie(
227 227
 
228 228
     ospGetSourceAddress(msg, firstvia, sizeof(firstvia));
229 229
     ospGetFromUserpart(msg, from, sizeof(from));
230
-    ospGetUriUserpart(msg, to, sizeof(to));
230
+    if (ospGetUriUserpart(msg, to, sizeof(to)) != 0) {
231
+        ospGetToUserpart(msg, to, sizeof(to));
232
+    }
231 233
     ospGetNextHop(msg, nexthop, sizeof(nexthop));
232 234
 
233
-    
234 235
     if (release == OSP_RELEASE_ORIG) {
235 236
         LOG(L_INFO,
236 237
             "osp: originator '%s' released the call, call_id '%.*s' transaction_id '%lld'\n",