Browse code

Merge 85f4de73ff4dcbbe8d13ea0b3be4f8cfa4e17716 into 77bc4c6c96cfb2ce5b7086ccfffd19750b085d74

alexyosifov authored on 28/10/2021 08:11:03 • GitHub committed on 28/10/2021 08:11:03
Showing 3 changed files
... ...
@@ -133,6 +133,8 @@ static int w_lookup_path_to_contact(struct sip_msg* _m, char* contact_uri);
133 133
 /*! \brief Fixup functions */
134 134
 static int domain_fixup(void** param, int param_no);
135 135
 static int assign_save_fixup3_async(void** param, int param_no);
136
+static int free_uint_fixup(void** param, int param_no);
137
+static int save_fixup3(void** param, int param_no);
136 138
 static int unreg_fixup(void** param, int param_no);
137 139
 static int fetchc_fixup(void** param, int param_no);
138 140
 /*! \brief Functions */
... ...
@@ -215,6 +217,8 @@ static pv_export_t mod_pvs[] = {
215 217
  */
216 218
 static cmd_export_t cmds[] = {
217 219
     {"save", (cmd_function) w_save, 2, assign_save_fixup3_async, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
220
+    {"save", (cmd_function) w_save, 3, assign_save_fixup3_async, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
221
+    {"save", (cmd_function) w_save, 4, save_fixup3, free_uint_fixup, REQUEST_ROUTE | ONREPLY_ROUTE},
218 222
     {"lookup", (cmd_function) w_lookup, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
219 223
     {"lookup", (cmd_function) w_lookup_ue_type, 2, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
220 224
     {"lookup_path_to_contact", (cmd_function) w_lookup_path_to_contact, 1, fixup_var_str_12, 0, REQUEST_ROUTE},
... ...
@@ -620,7 +624,11 @@ AAAMessage* callback_cdp_request(AAAMessage *request, void *param) {
620 624
  * Wrapper to save(location)
621 625
  */
622 626
 static int w_save(struct sip_msg* _m, char* _route, char* _d, char* mode, char* _cflags) {
623
-    return save(_m, _d, _route);
627
+    if(_cflags){
628
+        return save(_m, _d, _route, ((int)(*_cflags)));
629
+    }
630
+
631
+    return save(_m, _d, _route, 0);
624 632
 }
625 633
 
626 634
 static int w_assign_server_unreg(struct sip_msg* _m, char* _route, char* _d, char* _direction) {
... ...
@@ -701,6 +709,68 @@ static int assign_save_fixup3_async(void** param, int param_no) {
701 709
     return 0;
702 710
 }
703 711
 
712
+static int unit_fixup(void** param, int param_no)
713
+{
714
+	str s;
715
+	unsigned int* num;
716
+
717
+	if(*param){
718
+		num = (unsigned int*)pkg_malloc(sizeof(unsigned int));
719
+		*num = 0;
720
+
721
+		s.s = *param;
722
+		s.len = strlen(s.s);
723
+
724
+		if (likely(str2int(&s, num) == 0)) {
725
+			*param = (void*)(long)num;
726
+		}else{
727
+			LM_ERR("failed to convert to int\n");
728
+			pkg_free(num);
729
+			return E_UNSPEC;
730
+		}
731
+	}else{
732
+		return E_UNSPEC;
733
+	}
734
+
735
+	return 0;
736
+}
737
+
738
+static int free_uint_fixup(void** param, int param_no)
739
+{
740
+	if(*param && param_no == 2){
741
+		pkg_free(*param);
742
+		*param = 0;
743
+	}
744
+	return 0;
745
+}
746
+
747
+static int save_fixup3(void** param, int param_no) {
748
+    if (strlen((char*) *param) <= 0) {
749
+        LM_ERR("empty parameter %d not allowed\n", param_no);
750
+        return -1;
751
+    }
752
+
753
+    if (param_no == 1) {        //route name - static or dynamic string (config vars)
754
+        if (fixup_spve_null(param, param_no) < 0)
755
+            return -1;
756
+        return 0;
757
+    } else if (param_no == 2) {
758
+        udomain_t* d;
759
+
760
+        if (ul.register_udomain((char*) *param, &d) < 0) {
761
+            LM_ERR("Error doing fixup on save");
762
+            return -1;
763
+        }
764
+        *param = (void*) d;
765
+    } else if (param_no == 3) {
766
+        return 0;
767
+    } else if (param_no == 4) {
768
+        return unit_fixup(param, param_no);
769
+    }
770
+
771
+    return 0;
772
+}
773
+
704 774
 /*! \brief
705 775
  * Convert char* parameter to udomain_t* pointer
706 776
  * Convert char* parameter to pv_elem_t* pointer
... ...
@@ -84,6 +84,8 @@ extern int store_data_on_dereg; /**< should we store SAR user data on de-registr
84 84
 extern int ue_unsubscribe_on_dereg;
85 85
 extern int user_data_always;
86 86
 
87
+#define DO_NOT_USE_REALM_FOR_PRIVATE_IDENTITY         0x01
88
+
87 89
 /* \brief
88 90
  * Return randomized expires between expires-range% and expires.
89 91
  * RFC allows only value less or equal to the one provided by UAC.
... ...
@@ -1276,13 +1278,13 @@ error:
1276 1278
  */
1277 1279
 //int save(struct sip_msg* msg, udomain_t* _d) {
1278 1280
 
1279
-int save(struct sip_msg* msg, char* str1, char *route) {
1281
+int save(struct sip_msg* msg, char* str1, char *route, int _cflags) {
1280 1282
     int expires;
1281 1283
     int require_user_data = 0;
1282 1284
     int data_available;
1283 1285
     contact_t* c;
1284 1286
     int st;
1285
-    str public_identity, private_identity, realm;
1287
+    str public_identity, private_identity, realm={0,0};
1286 1288
     int sar_assignment_type = AVP_IMS_SAR_NO_ASSIGNMENT;
1287 1289
     str route_name;
1288 1290
 
... ...
@@ -1342,12 +1344,15 @@ int save(struct sip_msg* msg, char* str1, char *route) {
1342 1344
         rerrno = R_SAR_FAILED;
1343 1345
         goto error;
1344 1346
     }
1345
-    realm = cscf_get_realm_from_uri(public_identity);
1346
-    if (realm.len <= 0 || !realm.s) {
1347
-        LM_ERR("can't get realm\n");
1348
-        rerrno = R_SAR_FAILED;
1349
-        goto error;
1350
-    }
1347
+
1348
+    if (!(_cflags & DO_NOT_USE_REALM_FOR_PRIVATE_IDENTITY)) {
1349
+        realm = cscf_get_realm_from_uri(public_identity);
1350
+        if (realm.len <= 0 || !realm.s) {
1351
+            LM_ERR("can't get realm\n");
1352
+            rerrno = R_SAR_FAILED;
1353
+            goto error;
1354
+        }
1355
+     }
1351 1356
 
1352 1357
     private_identity = cscf_get_private_identity(msg, realm);
1353 1358
     if (private_identity.len <= 0 || !private_identity.s) {
... ...
@@ -58,7 +58,7 @@
58 58
  */
59 59
 int assign_server_unreg(struct sip_msg* _m, char* str1, str* direction, char* route);
60 60
 
61
-int save(struct sip_msg* msg, char* str1, char* route);
61
+int save(struct sip_msg* msg, char* str1, char* route, int _cflags);
62 62
 
63 63
 int unregister(struct sip_msg* _m, char* _d, char* _uri);
64 64