Browse code

Merge 33f6d72929228bd1e1ebb7b35608e9b530b6c346 into abdb02d3d2eec9fb45646f68996da3526c92ef58

Muhammad Shahzad Shafi authored on 26/09/2022 11:17:49 • GitHub committed on 26/09/2022 11:17:49
Showing 6 changed files
... ...
@@ -44,6 +44,7 @@
44 44
 #include "cr_map.h"
45 45
 #include "cr_data.h"
46 46
 #include "cr_func.h"
47
+#include "cr_kemi.h"
47 48
 #include "db_carrierroute.h"
48 49
 #include "config.h"
49 50
 #include "cr_db.h"
... ...
@@ -269,3 +270,52 @@ static void mod_destroy(void) {
269 270
 	}
270 271
 	destroy_route_data();
271 272
 }
273
+
274
+/**
275
+ *
276
+ */
277
+/* clang-format off */
278
+static sr_kemi_t sr_kemi_carrierroute_exports[] = {
279
+	{ str_init("carrierroute"), str_init("cr_user_carrier"),
280
+		SR_KEMIP_INT, ki_cr_user_carrier,
281
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
282
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
283
+	},
284
+	{ str_init("carrierroute"), str_init("cr_route"),
285
+		SR_KEMIP_INT, ki_cr_route5,
286
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
287
+			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE }
288
+	},
289
+	{ str_init("carrierroute"), str_init("cr_route_info"),
290
+		SR_KEMIP_INT, ki_cr_route,
291
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
292
+			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR }
293
+	},
294
+	{ str_init("carrierroute"), str_init("cr_nofallback_route"),
295
+		SR_KEMIP_INT, ki_cr_nofallback_route5,
296
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
297
+			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE }
298
+	},
299
+	{ str_init("carrierroute"), str_init("cr_nofallback_route_info"),
300
+		SR_KEMIP_INT, ki_cr_nofallback_route,
301
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
302
+			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR }
303
+	},
304
+	{ str_init("carrierroute"), str_init("cr_next_domain"),
305
+		SR_KEMIP_INT, ki_cr_load_next_domain,
306
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
307
+			SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR }
308
+	},
309
+
310
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
311
+};
312
+/* clang-format on */
313
+
314
+/**
315
+ *
316
+ */
317
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
318
+{
319
+    sr_kemi_modules_add(sr_kemi_carrierroute_exports);
320
+    return 0;
321
+}
... ...
@@ -29,6 +29,7 @@
29 29
 #define CARRIERROUTE_H
30 30
 
31 31
 #include "../../core/str.h"
32
+#include "../../core/kemi.h"
32 33
 #include "../../core/usr_avp.h"
33 34
 
34 35
 #define DICE_MAX 1000
... ...
@@ -43,20 +43,12 @@
43 43
 #include "../../core/rand/kam_rand.h"
44 44
 #include "cr_map.h"
45 45
 #include "cr_rule.h"
46
+#include "cr_fixup.h"
46 47
 #include "cr_domain.h"
47 48
 #include "cr_carrier.h"
48 49
 #include "carrierroute.h"
49 50
 #include "config.h"
50 51
 
51
-#define MAX_DESTINATIONS 64
52
-
53
-enum hash_algorithm {
54
-	alg_crc32 = 1, /*!< hashing algorithm is CRC32 */
55
-	alg_crc32_nofallback, /*!< same algorithm as alg_crc32, with only a backup rule, but no fallback tree is chosen
56
-                           if there is something wrong. */
57
-	alg_error
58
-};
59
-
60 52
 
61 53
 static const str SIP_URI  = { .s="sip:",  .len=4 };
62 54
 static const str SIPS_URI = { .s="sips:", .len=5 };
... ...
@@ -721,6 +713,111 @@ unlock_and_out:
721 713
 }
722 714
 
723 715
 
716
+/**
717
+ * KEMI wrapper that rewrites the request URI of msg after determining the
718
+ * new destination URI
719
+ *
720
+ * @param _msg the current SIP message
721
+ * @param _carrier the requested carrier
722
+ * @param _domain the requested routing domain
723
+ * @param _prefix_matching the user to be used for prefix matching
724
+ * @param _rewrite_user the localpart of the URI to be rewritten
725
+ * @param _hsrc the SIP header used for hashing
726
+ * @param _halg the hash algorithm used for hashing
727
+ * @param _dstavp the name of the destination AVP where the used host name is stored
728
+ *
729
+ * @return 1 on success, -1 on failure
730
+ */
731
+int w_cr_do_route(struct sip_msg * _msg, char *_carrier,
732
+		char *_domain, char *_prefix_matching,
733
+		char *_rewrite_user, char *_hsrc,
734
+		enum hash_algorithm _halg, char *_dstavp) {
735
+
736
+	gparam_t *pv_carrier, *pv_domain, *pv_prefix_matching;
737
+	gparam_t *pv_rewrite_user, *pv_dstavp;
738
+	enum hash_source i_hsrc;
739
+
740
+	if (_carrier == NULL) {
741
+		LM_ERR("cannot get the carrier parameter\n");
742
+		return -1;
743
+	} else {
744
+		pv_carrier = (gparam_t*) _carrier;
745
+		if (cr_route_fixup((void**)&pv_carrier, 1) != 0) {
746
+			LM_ERR("cannot parse the carrier parameter\n");
747
+			return -1;
748
+		}
749
+	}
750
+
751
+	if (_domain == NULL) {
752
+		LM_ERR("cannot get the domain parameter\n");
753
+		return -1;
754
+	} else {
755
+		pv_domain = (gparam_t*)_domain;
756
+		if (cr_route_fixup((void**)&pv_domain, 2) != 0) {
757
+			LM_ERR("cannot parse the domain parameter\n");
758
+			return -1;
759
+		}
760
+	}
761
+
762
+	if (_prefix_matching == NULL) {
763
+		LM_ERR("cannot get the prefix matching parameter\n");
764
+		return -1;
765
+	} else {
766
+		pv_prefix_matching = (gparam_t*)_prefix_matching;
767
+		if (cr_route_fixup((void**)&pv_prefix_matching, 3) != 0) {
768
+			LM_ERR("cannot parse the prefix matching parameter\n");
769
+			return -1;
770
+		}
771
+	}
772
+
773
+	if (_rewrite_user == NULL) {
774
+		LM_ERR("cannot get the rewrite user parameter\n");
775
+		return -1;
776
+	} else {
777
+		pv_rewrite_user = (gparam_t*)_rewrite_user;
778
+		if (cr_route_fixup((void**)&pv_rewrite_user, 4) != 0) {
779
+			LM_ERR("cannot parse the rewrite user parameter\n");
780
+			return -1;
781
+		}
782
+	}
783
+
784
+	if (_hsrc == NULL) {
785
+		LM_ERR("cannot get the hash source parameter\n");
786
+		return -1;
787
+	} else {
788
+		if (strcasecmp("call_id", _hsrc) == 0) {
789
+			i_hsrc = shs_call_id;
790
+		} else if (strcasecmp("from_uri", _hsrc) == 0) {
791
+			i_hsrc = shs_from_uri;
792
+		} else if (strcasecmp("from_user", _hsrc) == 0) {
793
+			i_hsrc = shs_from_user;
794
+		} else if (strcasecmp("to_uri", _hsrc) == 0) {
795
+			i_hsrc = shs_to_uri;
796
+		} else if (strcasecmp("to_user", _hsrc) == 0) {
797
+			i_hsrc = shs_to_user;
798
+		} else if (strcasecmp("rand", _hsrc) == 0) {
799
+			i_hsrc = shs_rand;
800
+		} else {
801
+			LM_ERR("cannot parse the hash source parameter\n");
802
+			return -1;
803
+		}
804
+	}
805
+
806
+	if (_dstavp == NULL) {
807
+		pv_dstavp = NULL;
808
+	} else {
809
+		pv_dstavp = (gparam_t*)_dstavp;
810
+		if (cr_route_fixup((void**)&pv_dstavp, 6) != 0) {
811
+			LM_ERR("cannot parse the dstavp parameter\n");
812
+			return -1;
813
+		}
814
+	}
815
+
816
+	return cr_do_route(_msg, pv_carrier, pv_domain, pv_prefix_matching,
817
+		pv_rewrite_user, i_hsrc, _halg, pv_dstavp);
818
+}
819
+
820
+
724 821
 /**
725 822
  * Loads user carrier from subscriber table and stores it in an AVP.
726 823
  *
... ...
@@ -760,6 +857,56 @@ int cr_load_user_carrier(struct sip_msg * _msg, gparam_t *_user, gparam_t *_doma
760 857
 }
761 858
 
762 859
 
860
+/**
861
+ * KEMI wrapper that loads user carrier from subscriber table and stores it in an AVP.
862
+ *
863
+ * @param _msg the current SIP message
864
+ * @param _user the user to determine the carrier data
865
+ * @param _domain the domain to determine the domain data
866
+ * @param _dstavp the name of the AVP where to store the carrier id
867
+ *
868
+ * @return 1 on success, -1 on failure
869
+ */
870
+int w_cr_load_user_carrier(struct sip_msg * _msg, char *_user, char *_domain, char *_dstavp) {
871
+	gparam_t *pv_user, *pv_domain, *pv_dstavp;
872
+
873
+	if (_user == NULL) {
874
+		LM_ERR("cannot get the user parameter\n");
875
+		return -1;
876
+	} else {
877
+		pv_user = (gparam_t*)_user;
878
+		if (cr_load_user_carrier_fixup((void**)&pv_user, 1) != 0) {
879
+			LM_ERR("cannot parse the user parameter\n");
880
+			return -1;
881
+		}
882
+	}
883
+
884
+	if (_domain == NULL) {
885
+		LM_ERR("cannot get the domain parameter\n");
886
+		return -1;
887
+	} else {
888
+		pv_domain = (gparam_t*)_domain;
889
+		if (cr_load_user_carrier_fixup((void**)&pv_domain, 2) != 0) {
890
+			LM_ERR("cannot parse the domain parameter\n");
891
+			return -1;
892
+		}
893
+	}
894
+
895
+	if (_dstavp == NULL) {
896
+		LM_ERR("cannot get the dstavp parameter\n");
897
+		return -1;
898
+	} else {
899
+		pv_dstavp = (gparam_t*)_dstavp;
900
+		if (cr_load_user_carrier_fixup((void**)&pv_dstavp, 3) != 0) {
901
+			LM_ERR("cannot parse the dstavp parameter\n");
902
+			return -1;
903
+		}
904
+	}
905
+
906
+	return cr_load_user_carrier(_msg, pv_user, pv_domain, pv_dstavp);
907
+}
908
+
909
+
763 910
 /**
764 911
  * rewrites the request URI of msg after determining the
765 912
  * new destination URI with the crc32 hash algorithm.
... ...
@@ -912,10 +1059,101 @@ int cr_load_next_domain(struct sip_msg * _msg, gparam_t *_carrier,
912 1059
 			prefix_matching.s, carrier_id, domain_id);
913 1060
 		goto unlock_and_out;
914 1061
 	}
915
-	
1062
+
916 1063
 	ret = 1;
917
-	
1064
+
918 1065
 unlock_and_out:
919 1066
 	release_data(rd);
920 1067
 	return ret;
921 1068
 }
1069
+
1070
+
1071
+/**
1072
+ * KEMI wrapper that loads next domain from failure routing table and stores it in an AVP.
1073
+ *
1074
+ * @param _msg the current SIP message
1075
+ * @param _carrier the requested carrier
1076
+ * @param _domain the requested routing domain
1077
+ * @param _prefix_matching the user to be used for prefix matching
1078
+ * @param _host the host name to be used for rule matching
1079
+ * @param _reply_code the reply code to be used for rule matching
1080
+ * @param _dstavp the name of the destination AVP
1081
+ *
1082
+ * @return 1 on success, -1 on failure
1083
+ */
1084
+int w_cr_load_next_domain(struct sip_msg * _msg, char *_carrier,
1085
+		char *_domain, char *_prefix_matching, char *_host,
1086
+		char *_reply_code, char *_dstavp) {
1087
+
1088
+	gparam_t *pv_carrier, *pv_domain, *pv_prefix_matching;
1089
+	gparam_t *pv_host, *pv_reply_code, *pv_dstavp;
1090
+
1091
+	if (_carrier == NULL) {
1092
+		LM_ERR("cannot get the carrier parameter\n");
1093
+		return -1;
1094
+	} else {
1095
+		pv_carrier = (gparam_t*)_carrier;
1096
+		if (cr_load_next_domain_fixup((void**)&pv_carrier, 1) != 0) {
1097
+			LM_ERR("cannot parse the carrier parameter\n");
1098
+			return -1;
1099
+		}
1100
+	}
1101
+
1102
+	if (_domain == NULL) {
1103
+		LM_ERR("cannot get the domain parameter\n");
1104
+		return -1;
1105
+	} else {
1106
+		pv_domain = (gparam_t*)_domain;
1107
+		if (cr_load_next_domain_fixup((void**)&pv_domain, 2) != 0) {
1108
+			LM_ERR("cannot parse the domain parameter\n");
1109
+			return -1;
1110
+		}
1111
+	}
1112
+
1113
+	if (_prefix_matching == NULL) {
1114
+		LM_ERR("cannot get the prefix matching parameter\n");
1115
+		return -1;
1116
+	} else {
1117
+		pv_prefix_matching = (gparam_t*)_prefix_matching;
1118
+		if (cr_load_next_domain_fixup((void**)&pv_prefix_matching, 3) != 0) {
1119
+			LM_ERR("cannot parse the prefix matching parameter\n");
1120
+			return -1;
1121
+		}
1122
+	}
1123
+
1124
+	if (_host == NULL) {
1125
+		LM_ERR("cannot get the host parameter\n");
1126
+		return -1;
1127
+	} else {
1128
+		pv_host = (gparam_t*)_host;
1129
+		if (cr_load_next_domain_fixup((void**)&pv_host, 4) != 0) {
1130
+			LM_ERR("cannot parse the host parameter\n");
1131
+			return -1;
1132
+		}
1133
+	}
1134
+
1135
+	if (_reply_code == NULL) {
1136
+		LM_ERR("cannot get the reply code parameter\n");
1137
+		return -1;
1138
+	} else {
1139
+		pv_reply_code = (gparam_t*)_reply_code;
1140
+		if (cr_load_next_domain_fixup((void**)&pv_reply_code, 5) != 0) {
1141
+			LM_ERR("cannot parse the reply code parameter\n");
1142
+			return -1;
1143
+		}
1144
+	}
1145
+
1146
+	if (_dstavp == NULL) {
1147
+		LM_ERR("cannot get the dstavp parameter\n");
1148
+		return -1;
1149
+	} else {
1150
+		pv_dstavp = (gparam_t*)_dstavp;
1151
+		if (cr_load_next_domain_fixup((void**)&pv_dstavp, 6) != 0) {
1152
+			LM_ERR("cannot parse the dstavp parameter\n");
1153
+			return -1;
1154
+		}
1155
+	}
1156
+
1157
+	return cr_load_next_domain(_msg, pv_carrier, pv_domain,
1158
+			pv_prefix_matching, pv_host, pv_reply_code, pv_dstavp);
1159
+}
... ...
@@ -35,6 +35,16 @@
35 35
 #include "prime_hash.h"
36 36
 
37 37
 
38
+#define MAX_DESTINATIONS 64
39
+
40
+enum hash_algorithm {
41
+	alg_crc32 = 1, /*!< hashing algorithm is CRC32 */
42
+	alg_crc32_nofallback, /*!< same algorithm as alg_crc32, with only a backup rule, but no fallback tree is chosen
43
+                           if there is something wrong. */
44
+	alg_error
45
+};
46
+
47
+
38 48
 /**
39 49
  * Loads user carrier from subscriber table and stores it in an AVP.
40 50
  *
... ...
@@ -49,6 +59,20 @@ int cr_load_user_carrier(struct sip_msg * _msg, gparam_t *_user,
49 59
 		gparam_t *_domain, gparam_t *_dstavp);
50 60
 
51 61
 
62
+/**
63
+ * KEMI wrapper that loads user carrier from subscriber table and stores it in an AVP.
64
+ *
65
+ * @param _msg the current SIP message
66
+ * @param _user the user to determine the carrier data
67
+ * @param _domain the domain to determine the domain data
68
+ * @param _dstavp the name of the AVP where to store the carrier id
69
+ *
70
+ * @return 1 on success, -1 on failure
71
+ */
72
+int w_cr_load_user_carrier(struct sip_msg * _msg, char *_user,
73
+		char *_domain, char *_dstavp);
74
+
75
+
52 76
 /**
53 77
  * rewrites the request URI of msg after determining the
54 78
  * new destination URI
... ...
@@ -72,6 +96,27 @@ int cr_route5(struct sip_msg * _msg, gparam_t *_carrier,
72 96
 		gparam_t *_rewrite_user, enum hash_source _hsrc);
73 97
 
74 98
 
99
+/**
100
+ * KEMI wrapper that rewrites the request URI of msg after determining the
101
+ * new destination URI
102
+ *
103
+ * @param _msg the current SIP message
104
+ * @param _carrier the requested carrier
105
+ * @param _domain the requested routing domain
106
+ * @param _prefix_matching the user to be used for prefix matching
107
+ * @param _rewrite_user the localpart of the URI to be rewritten
108
+ * @param _hsrc the SIP header used for hashing
109
+ * @param _halg the hash algorithm used for hashing
110
+ * @param _dstavp the name of the destination AVP where the used host name is stored
111
+ *
112
+ * @return 1 on success, -1 on failure
113
+ */
114
+int w_cr_do_route(struct sip_msg * _msg, char *_carrier,
115
+		char *_domain, char *_prefix_matching,
116
+		char *_rewrite_user, char *_hsrc,
117
+		enum hash_algorithm _halg, char *_dstavp);
118
+
119
+
75 120
 /**
76 121
  *
77 122
  * rewrites the request URI of msg after determining the
... ...
@@ -115,4 +160,22 @@ int cr_load_next_domain(struct sip_msg * _msg, gparam_t *_carrier,
115 160
 		gparam_t *_domain, gparam_t *_prefix_matching, gparam_t *_host,
116 161
 		gparam_t *_reply_code, gparam_t *_dstavp);
117 162
 
163
+
164
+/**
165
+ * KEMI wrapper that loads next domain from failure routing table and stores it in an AVP.
166
+ *
167
+ * @param _msg the current SIP message
168
+ * @param _carrier the requested carrier
169
+ * @param _domain the requested routing domain
170
+ * @param _prefix_matching the user to be used for prefix matching
171
+ * @param _host the host name to be used for rule matching
172
+ * @param _reply_code the reply code to be used for rule matching
173
+ * @param _dstavp the name of the destination AVP
174
+ *
175
+ * @return 1 on success, -1 on failure
176
+ */
177
+int w_cr_load_next_domain(struct sip_msg * _msg, char *_carrier,
178
+		char *_domain, char *_prefix_matching, char *_host,
179
+		char *_reply_code, char *_dstavp);
180
+
118 181
 #endif
119 182
new file mode 100644
... ...
@@ -0,0 +1,199 @@
1
+/*
2
+ * Copyright (C) 2007-2008 1&1 Internet AG
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ */
20
+
21
+/**
22
+ * \file cr_kemi.c
23
+ * \brief Routing and balancing functions for KEMI interface
24
+ * \ingroup carrierroute
25
+ * - Module; \ref carrierroute
26
+ */
27
+
28
+#include <ctype.h>
29
+#include <assert.h>
30
+#include <stdlib.h>
31
+#include "cr_func.h"
32
+#include "cr_db.h"
33
+#include "../../core/sr_module.h"
34
+#include "../../core/action.h"
35
+#include "../../core/parser/parse_uri.h"
36
+#include "../../core/parser/parse_from.h"
37
+#include "../../core/ut.h"
38
+#include "../../core/parser/digest/digest.h"
39
+#include "../../core/parser/hf.h"
40
+#include "../../core/mem/mem.h"
41
+#include "../../core/qvalue.h"
42
+#include "../../core/dset.h"
43
+#include "../../core/rand/kam_rand.h"
44
+#include "cr_map.h"
45
+#include "cr_rule.h"
46
+#include "cr_domain.h"
47
+#include "cr_carrier.h"
48
+#include "carrierroute.h"
49
+#include "config.h"
50
+
51
+
52
+/**
53
+ * KEMI wrapper that loads user carrier from subscriber table and stores it in an AVP.
54
+ *
55
+ * @param _msg the current SIP message
56
+ * @param _user the user to determine the carrier data
57
+ * @param _domain the domain to determine the domain data
58
+ * @param _dstavp the name of the AVP where to store the carrier id
59
+ *
60
+ * @return 1 on success, -1 on failure
61
+ */
62
+int ki_cr_user_carrier(struct sip_msg * _msg, str *_user,
63
+		str *_domain, str *_dstavp) {
64
+
65
+	// native api already checks if any of required argument is null
66
+	// so this is not strictly necessary.
67
+	if (!_msg || !_user || !_domain || !_dstavp) {
68
+		LM_ERR("missing a required parameter\n");
69
+		return -1;
70
+	};
71
+
72
+	return w_cr_load_user_carrier(_msg, _user->s, _domain->s, _dstavp->s);
73
+}
74
+
75
+
76
+/**
77
+ * KEMI wrapper that rewrites the request URI of msg after determining the
78
+ * new destination URI with the crc32 hash algorithm.
79
+ *
80
+ * @param _msg the current SIP message
81
+ * @param _carrier the requested carrier
82
+ * @param _domain the requested routing domain
83
+ * @param _prefix_matching the user to be used for prefix matching
84
+ * @param _rewrite_user the localpart of the URI to be rewritten
85
+ * @param _hsrc the SIP header used for hashing
86
+ * @param _descavp the name of the AVP where the description is stored
87
+ *
88
+ * @return 1 on success, -1 on failure
89
+ */
90
+int ki_cr_route(struct sip_msg * _msg, str *_carrier,
91
+		str *_domain, str *_prefix_matching, str *_rewrite_user,
92
+		str *_hsrc, str *_descavp) {
93
+
94
+	// native api already checks if any of required argument is null
95
+	// so this is not strictly necessary.
96
+	if (!_msg || !_carrier || !_domain || !_prefix_matching ||
97
+		!_rewrite_user || !_hsrc || !_descavp) {
98
+		LM_ERR("missing a required parameter\n");
99
+		return -1;
100
+	};
101
+
102
+	return w_cr_do_route(_msg, _carrier->s, _domain->s, _prefix_matching->s,
103
+		_rewrite_user->s, _hsrc->s, alg_crc32, _descavp->s);
104
+}
105
+
106
+int ki_cr_route5(struct sip_msg * _msg, str *_carrier,
107
+		str *_domain, str *_prefix_matching,
108
+		str *_rewrite_user, str *_hsrc) {
109
+
110
+	// native api already checks if any of required argument is null
111
+	// so this is not strictly necessary.
112
+	if (!_msg || !_carrier || !_domain || !_prefix_matching ||
113
+		!_rewrite_user || !_hsrc) {
114
+		LM_ERR("missing a required parameter\n");
115
+		return -1;
116
+	};
117
+
118
+	return w_cr_do_route(_msg, _carrier->s, _domain->s, _prefix_matching->s,
119
+		_rewrite_user->s, _hsrc->s, alg_crc32, NULL);
120
+}
121
+
122
+
123
+/**
124
+ * KEMI wrapper that rewrites the request URI of msg after determining the
125
+ * new destination URI with the crc32 hash algorithm. The difference
126
+ * to cr_route is that no fallback rule is chosen if there is something
127
+ * wrong (like now obselete cr_prime_route)
128
+ *
129
+ * @param _msg the current SIP message
130
+ * @param _carrier the requested carrier
131
+ * @param _domain the requested routing domain
132
+ * @param _prefix_matching the user to be used for prefix matching
133
+ * @param _rewrite_user the localpart of the URI to be rewritten
134
+ * @param _hsrc the SIP header used for hashing
135
+ * @param _dstavp the name of the destination AVP where the used host name is stored
136
+ *
137
+ * @return 1 on success, -1 on failure
138
+ */
139
+int ki_cr_nofallback_route(struct sip_msg * _msg, str *_carrier,
140
+		str *_domain, str *_prefix_matching, str *_rewrite_user,
141
+		str *_hsrc, str *_descavp) {
142
+
143
+	// native api already checks if any of required argument is null
144
+	// so this is not strictly necessary.
145
+	if (!_msg || !_carrier || !_domain || !_prefix_matching ||
146
+		!_rewrite_user || !_hsrc || !_descavp) {
147
+		LM_ERR("missing a required parameter\n");
148
+		return -1;
149
+	};
150
+
151
+	return w_cr_do_route(_msg, _carrier->s, _domain->s, _prefix_matching->s,
152
+		_rewrite_user->s, _hsrc->s, alg_crc32_nofallback, _descavp ? _descavp->s : NULL);
153
+}
154
+
155
+int ki_cr_nofallback_route5(struct sip_msg * _msg, str *_carrier,
156
+		str *_domain, str *_prefix_matching, str *_rewrite_user,
157
+		str *_hsrc) {
158
+
159
+	// native api already checks if any of required argument is null
160
+	// so this is not strictly necessary.
161
+	if (!_msg || !_carrier || !_domain || !_prefix_matching ||
162
+		!_rewrite_user || !_hsrc) {
163
+		LM_ERR("missing a required parameter\n");
164
+		return -1;
165
+	};
166
+
167
+	return w_cr_do_route(_msg, _carrier->s, _domain->s, _prefix_matching->s,
168
+		_rewrite_user->s, _hsrc->s, alg_crc32_nofallback, NULL);
169
+}
170
+
171
+
172
+/**
173
+ * KEMI wrapper that loads next domain from failure routing table and stores it in an AVP.
174
+ *
175
+ * @param _msg the current SIP message
176
+ * @param _carrier the requested carrier
177
+ * @param _domain the requested routing domain
178
+ * @param _prefix_matching the user to be used for prefix matching
179
+ * @param _host the host name to be used for rule matching
180
+ * @param _reply_code the reply code to be used for rule matching
181
+ * @param _dstavp the name of the destination AVP
182
+ *
183
+ * @return 1 on success, -1 on failure
184
+ */
185
+int ki_cr_load_next_domain(struct sip_msg * _msg, str *_carrier,
186
+		str *_domain, str *_prefix_matching,
187
+		str *_host, str *_reply_code, str *_dstavp) {
188
+
189
+	// native api already checks if any of required argument is null
190
+	// so this is not strictly necessary.
191
+	if (!_msg || !_carrier || !_domain || !_prefix_matching ||
192
+		!_host || !_reply_code || !_dstavp) {
193
+		LM_ERR("missing a required parameter\n");
194
+		return -1;
195
+	};
196
+
197
+	return w_cr_load_next_domain(_msg, _carrier->s, _domain->s,
198
+			_prefix_matching->s, _host->s, _reply_code->s, _dstavp->s);
199
+}
0 200
new file mode 100644
... ...
@@ -0,0 +1,119 @@
1
+/*
2
+ * Copyright (C) 2007-2008 1&1 Internet AG
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ *
20
+ */
21
+
22
+/**
23
+ * \file cr_kemi.h
24
+ * \brief Routing and balancing functions for KEMI interface
25
+ * \ingroup carrierroute
26
+ * - Module; \ref carrierroute
27
+ */
28
+
29
+#ifndef CR_KEMI_H
30
+#define CR_KEMI_H
31
+
32
+#include "../../core/parser/msg_parser.h"
33
+#include "../../core/pvar.h"
34
+#include "../../core/mod_fix.h"
35
+#include "prime_hash.h"
36
+#include "cr_func.h"
37
+
38
+
39
+/**
40
+ * KEMI wrapper that loads user carrier from subscriber table and stores it in an AVP.
41
+ *
42
+ * @param _msg the current SIP message
43
+ * @param _user the user to determine the carrier data
44
+ * @param _domain the domain to determine the domain data
45
+ * @param _dstavp the name of the AVP where to store the carrier id
46
+ *
47
+ * @return 1 on success, -1 on failure
48
+ */
49
+int ki_cr_user_carrier(struct sip_msg * _msg, str *_user,
50
+		str *_domain, str *_dstavp);
51
+
52
+
53
+/**
54
+ * KEMI wrapper that rewrites the request URI of msg after determining the
55
+ * new destination URI with the crc32 hash algorithm.
56
+ *
57
+ * @param _msg the current SIP message
58
+ * @param _carrier the requested carrier
59
+ * @param _domain the requested routing domain
60
+ * @param _prefix_matching the user to be used for prefix matching
61
+ * @param _rewrite_user the localpart of the URI to be rewritten
62
+ * @param _hsrc the SIP header used for hashing
63
+ * @param _descavp the name of the AVP where the description is stored
64
+ *
65
+ * @return 1 on success, -1 on failure
66
+ */
67
+int ki_cr_route(struct sip_msg * _msg, str *_carrier,
68
+		str *_domain, str *_prefix_matching,
69
+		str *_rewrite_user, str *_hsrc,
70
+		str *_descavp);
71
+
72
+int ki_cr_route5(struct sip_msg * _msg, str *_carrier,
73
+		str *_domain, str *_prefix_matching,
74
+		str *_rewrite_user, str *_hsrc);
75
+
76
+
77
+/**
78
+ * KEMI wrapper that rewrites the request URI of msg after determining the
79
+ * new destination URI with the crc32 hash algorithm. The difference
80
+ * to cr_route is that no fallback rule is chosen if there is something
81
+ * wrong (like now obselete cr_prime_route)
82
+ *
83
+ * @param _msg the current SIP message
84
+ * @param _carrier the requested carrier
85
+ * @param _domain the requested routing domain
86
+ * @param _prefix_matching the user to be used for prefix matching
87
+ * @param _rewrite_user the localpart of the URI to be rewritten
88
+ * @param _hsrc the SIP header used for hashing
89
+ * @param _dstavp the name of the destination AVP where the used host name is stored
90
+ *
91
+ * @return 1 on success, -1 on failure
92
+ */
93
+int ki_cr_nofallback_route(struct sip_msg * _msg, str *_carrier,
94
+		str *_domain, str *_prefix_matching, str *_rewrite_user,
95
+		str *_hsrc, str *_dstavp);
96
+
97
+int ki_cr_nofallback_route5(struct sip_msg * _msg, str *_carrier,
98
+		str *_domain, str *_prefix_matching, str *_rewrite_user,
99
+		str *_hsrc);
100
+
101
+
102
+/**
103
+ * KEMI wrapper that loads next domain from failure routing table and stores it in an AVP.
104
+ *
105
+ * @param _msg the current SIP message
106
+ * @param _carrier the requested carrier
107
+ * @param _domain the requested routing domain
108
+ * @param _prefix_matching the user to be used for prefix matching
109
+ * @param _host the host name to be used for rule matching
110
+ * @param _reply_code the reply code to be used for rule matching
111
+ * @param _dstavp the name of the destination AVP
112
+ *
113
+ * @return 1 on success, -1 on failure
114
+ */
115
+int ki_cr_load_next_domain(struct sip_msg * _msg, str *_carrier,
116
+		str *_domain, str *_prefix_matching, str *_host,
117
+		str *_reply_code, str *_dstavp);
118
+
119
+#endif