Browse code

dispatcher Add a function to check if a given set exist is memory

Olle E. Johansson authored on 12/12/2014 22:38:37
Showing 6 changed files
... ...
@@ -16,11 +16,19 @@ Carsten Bock
16 16
 
17 17
    ng-voice GmbH
18 18
 
19
+Edited by
20
+
21
+Olle E. Johansson
22
+
23
+   Edvina AB
24
+
19 25
    Copyright � 2004 FhG FOKUS
20 26
 
21 27
    Copyright � 2005 Voice Sistem
22 28
 
23 29
    Copyright � 2010 Daniel-Constantin Mierla (asipto.com)
30
+
31
+   Copyright � 2014 Olle E. Johansson, Edvina AB
24 32
      __________________________________________________________________
25 33
 
26 34
    Table of Contents
... ...
@@ -74,9 +82,10 @@ Carsten Bock
74 82
               4.3. ds_next_dst()
75 83
               4.4. ds_next_domain()
76 84
               4.5. ds_mark_dst([state])
77
-              4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
78
-              4.7. ds_load_update()
79
-              4.8. ds_load_unset()
85
+              4.6. ds_list_exist(groupid)
86
+              4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
87
+              4.8. ds_load_update()
88
+              4.9. ds_load_unset()
80 89
 
81 90
         5. MI Commands
82 91
 
... ...
@@ -138,10 +147,11 @@ Carsten Bock
138 147
    1.32. Set the "ds_default_socket" parameter
139 148
    1.33. ds_select_dst usage
140 149
    1.34. ds_mark_dst usage
141
-   1.35. ds_mark_dst usage
142
-   1.36. ds_load_unset usage
143
-   1.37. dispatcher list file
144
-   1.38. Kamailio config script - sample dispatcher usage
150
+   1.35. ds_list_exist usage
151
+   1.36. ds_mark_dst usage
152
+   1.37. ds_load_unset usage
153
+   1.38. dispatcher list file
154
+   1.39. Kamailio config script - sample dispatcher usage
145 155
 
146 156
 Chapter 1. Admin Guide
147 157
 
... ...
@@ -194,9 +204,10 @@ Chapter 1. Admin Guide
194 204
         4.3. ds_next_dst()
195 205
         4.4. ds_next_domain()
196 206
         4.5. ds_mark_dst([state])
197
-        4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
198
-        4.7. ds_load_update()
199
-        4.8. ds_load_unset()
207
+        4.6. ds_list_exist(groupid)
208
+        4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
209
+        4.8. ds_load_update()
210
+        4.9. ds_load_unset()
200 211
 
201 212
    5. MI Commands
202 213
 
... ...
@@ -733,9 +744,10 @@ Note
733 744
    4.3. ds_next_dst()
734 745
    4.4. ds_next_domain()
735 746
    4.5. ds_mark_dst([state])
736
-   4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
737
-   4.7. ds_load_update()
738
-   4.8. ds_load_unset()
747
+   4.6. ds_list_exist(groupid)
748
+   4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
749
+   4.8. ds_load_update()
750
+   4.9. ds_load_unset()
739 751
 
740 752
 4.1. ds_select_dst(set, alg[, limit])
741 753
 
... ...
@@ -872,7 +884,21 @@ failure_route[tryagain] {
872 884
 }
873 885
 ...
874 886
 
875
-4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
887
+4.6. ds_list_exist(groupid)
888
+
889
+   Check if a specific group is defined in dispatcher list or database.
890
+     * groupid - A group ID to check.
891
+
892
+   This function can be used from ANY_ROUTE.
893
+
894
+   Example 1.35. ds_list_exist usage
895
+...
896
+if(ds_list_exist("10")) {
897
+    ...
898
+}
899
+...
900
+
901
+4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
876 902
 
877 903
    This function returns true, if there is a match of source address or
878 904
    uri with an address in the given group of the dispatcher-list;
... ...
@@ -908,7 +934,7 @@ failure_route[tryagain] {
908 934
 
909 935
    This function can be used from ANY_ROUTE.
910 936
 
911
-   Example 1.35. ds_mark_dst usage
937
+   Example 1.36. ds_mark_dst usage
912 938
 ...
913 939
 if(ds_is_from_list()) {
914 940
     ...
... ...
@@ -921,7 +947,7 @@ if(ds_is_from_list("10", "sip:127.0.0.1:5080", "3")) {
921 947
 }
922 948
 ...
923 949
 
924
-4.7. ds_load_update()
950
+4.8. ds_load_update()
925 951
 
926 952
    Updates the load state:
927 953
      * if it is a BYE or CANCEL - remove the load from destination address
... ...
@@ -932,14 +958,14 @@ if(ds_is_from_list("10", "sip:127.0.0.1:5080", "3")) {
932 958
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
933 959
    BRANCH_ROUTE and ONREPLY_ROUTE.
934 960
 
935
-4.8. ds_load_unset()
961
+4.9. ds_load_unset()
936 962
 
937 963
    Remove the call load for the destination that routed the call.
938 964
 
939 965
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
940 966
    BRANCH_ROUTE and ONREPLY_ROUTE.
941 967
 
942
-   Example 1.36. ds_load_unset usage
968
+   Example 1.37. ds_load_unset usage
943 969
 ...
944 970
 route {
945 971
     ...
... ...
@@ -1094,7 +1120,7 @@ kamcmd dispatcher.set_state ip 2 sip:127.0.0.1:5080
1094 1120
        probing destination (sending keep alives);
1095 1121
      * priority: sets the priority in destination list (based on it is
1096 1122
        done the initial ordering inside the set)
1097
-     * attributes: extra field in form of name1=value1;...;nameN=valueN.
1123
+     * attributes: extra fields in form of name1=value1;...;nameN=valueN.
1098 1124
        There are some predefined names:
1099 1125
           + 'duid' - used for call load dispatching
1100 1126
           + 'weight' - used for weight based load distribution
... ...
@@ -1113,7 +1139,7 @@ setid(int) destination(sip uri) flags(int,opt) priority(int,opt) attrs(str,opt)
1113 1139
    For database, each element of a line resides in a different column.
1114 1140
    Next is a dispatcher.list file example:
1115 1141
 
1116
-   Example 1.37. dispatcher list file
1142
+   Example 1.38. dispatcher list file
1117 1143
 ...
1118 1144
 # $Id$
1119 1145
 # dispatcher destination sets
... ...
@@ -1138,7 +1164,7 @@ r,opt)
1138 1164
 
1139 1165
    Next picture shows a sample usage of the dispatcher module.
1140 1166
 
1141
-   Example 1.38. Kamailio config script - sample dispatcher usage
1167
+   Example 1.39. Kamailio config script - sample dispatcher usage
1142 1168
 ...
1143 1169
 #!KAMAILIO
1144 1170
 #
... ...
@@ -1275,6 +1275,33 @@ static inline int ds_get_index(int group, ds_set_t **index)
1275 1275
 	return 0;
1276 1276
 }
1277 1277
 
1278
+/*
1279
+ * Check if a destination set exists
1280
+ */
1281
+int ds_list_exist(int set)
1282
+{
1283
+	ds_set_t *si = NULL;
1284
+	LM_DBG("-- Looking for set %d\n", set);
1285
+
1286
+	/* get the index of the set */
1287
+	si = _ds_list;
1288
+	while(si)
1289
+	{
1290
+		if(si->id == set)
1291
+		{
1292
+			break;
1293
+		}
1294
+		si = si->next;
1295
+	}
1296
+
1297
+	if(si==NULL)
1298
+	{
1299
+		LM_INFO("destination set [%d] not found\n", set);
1300
+		return -1;	/* False */
1301
+	}
1302
+	LM_INFO("destination set [%d] found\n", set);
1303
+	return 1;	/* True */
1304
+}
1278 1305
 
1279 1306
 /**
1280 1307
  *
... ...
@@ -124,6 +124,8 @@ int ds_mark_dst(struct sip_msg *msg, int mode);
124 124
 int ds_print_list(FILE *fout);
125 125
 int ds_print_mi_list(struct mi_node* rpl);
126 126
 int ds_print_sets(void);
127
+int ds_list_exist(int set);
128
+
127 129
 
128 130
 int ds_load_unset(struct sip_msg *msg);
129 131
 int ds_load_update(struct sip_msg *msg);
... ...
@@ -33,6 +33,7 @@
33 33
  *				to ds_is_from_list.  (carsten)
34 34
  * 2007-07-18  Added support for load/reload groups from DB 
35 35
  * 			   reload triggered from ds_reload MI_Command (ancuta)
36
+ * 2014-12-12  Added "ds_list_exist" function
36 37
  */
37 38
 
38 39
 /*! \file
... ...
@@ -167,7 +168,10 @@ static int w_ds_is_from_list0(struct sip_msg*, char*, char*);
167 168
 static int w_ds_is_from_list1(struct sip_msg*, char*, char*);
168 169
 static int w_ds_is_from_list2(struct sip_msg*, char*, char*);
169 170
 static int w_ds_is_from_list3(struct sip_msg*, char*, char*, char*);
171
+static int w_ds_list_exist(struct sip_msg*, char*);
172
+
170 173
 static int fixup_ds_is_from_list(void** param, int param_no);
174
+static int fixup_ds_list_exist(void** param,int param_no);
171 175
 
172 176
 static void destroy(void);
173 177
 
... ...
@@ -203,6 +207,8 @@ static cmd_export_t cmds[]={
203 207
 		fixup_ds_is_from_list, 0, ANY_ROUTE},
204 208
 	{"ds_is_from_list",  (cmd_function)w_ds_is_from_list3, 3,
205 209
 		fixup_ds_is_from_list, 0, ANY_ROUTE},
210
+	{"ds_list_exist",  (cmd_function)w_ds_list_exist, 1,
211
+		fixup_ds_list_exist, 0, ANY_ROUTE},
206 212
 	{"ds_load_unset",    (cmd_function)w_ds_load_unset,   0,
207 213
 		0, 0, ANY_ROUTE},
208 214
 	{"ds_load_update",   (cmd_function)w_ds_load_update,  0,
... ...
@@ -947,6 +953,26 @@ static int fixup_ds_is_from_list(void** param, int param_no)
947 953
 	return 0;
948 954
 }
949 955
 
956
+/* Check if a given set exist in memory */
957
+static int w_ds_list_exist(struct sip_msg *msg, char *param)
958
+{
959
+	int set;
960
+
961
+	if(fixup_get_ivalue(msg, (gparam_p)param, &set)!=0)
962
+	{
963
+		LM_ERR("cannot get set id param value\n");
964
+		return -1;
965
+	}
966
+	LM_DBG("--- Looking for dispatcher set %d\n", set);
967
+	return ds_list_exist(set);
968
+}
969
+
970
+static int fixup_ds_list_exist(void** param, int param_no)
971
+{
972
+	return fixup_igp_null(param, param_no);
973
+	return 0;
974
+}
975
+
950 976
 static int ds_parse_reply_codes() {
951 977
 	param_t* params_list = NULL;
952 978
 	param_t *pit=NULL;
... ...
@@ -31,6 +31,14 @@
31 31
                 <email>carsten@ng-voice.com</email>
32 32
                 </address>
33 33
             </editor>
34
+            <editor>
35
+                <firstname>Olle E.</firstname>
36
+                <surname>Johansson</surname>
37
+                <affiliation><orgname>Edvina AB</orgname></affiliation>
38
+                <address>
39
+                <email>oej@edvina.net</email>
40
+                </address>
41
+            </editor>
34 42
 	</authorgroup>
35 43
 	<copyright>
36 44
 	    <year>2004</year>
... ...
@@ -44,6 +52,10 @@
44 52
 	    <year>2010</year>
45 53
 	    <holder>Daniel-Constantin Mierla (asipto.com)</holder>
46 54
 	</copyright>
55
+ 	<copyright>
56
+	    <year>2014</year>
57
+	    <holder>Olle E. Johansson, Edvina AB</holder>
58
+	</copyright>
47 59
    </bookinfo>
48 60
     <toc></toc>
49 61
     
... ...
@@ -1036,6 +1036,34 @@ failure_route[tryagain] {
1036 1036
 </programlisting>
1037 1037
 		</example>
1038 1038
  	</section>
1039
+  	<section  id="dispatcher.f.ds_list_exist">
1040
+ 		<title>
1041
+		<function moreinfo="none">ds_list_exist(groupid)</function>
1042
+ 		</title>
1043
+ 		<para>
1044
+		Check if a specific group is defined in dispatcher list
1045
+		or database.
1046
+		</para>
1047
+		<itemizedlist>
1048
+		<listitem>
1049
+			<para><emphasis>groupid</emphasis> - A group ID to check.
1050
+			</para>
1051
+		</listitem>
1052
+		</itemizedlist>
1053
+		<para>
1054
+			This function can be used from ANY_ROUTE.
1055
+		</para>
1056
+		<example>
1057
+		<title><function>ds_list_exist</function> usage</title>
1058
+		<programlisting format="linespecific">
1059
+...
1060
+if(ds_list_exist("10")) {
1061
+    ...
1062
+}
1063
+...
1064
+</programlisting>
1065
+	</example>
1066
+	</section>
1039 1067
   	<section  id="dispatcher.f.ds_is_from_list">
1040 1068
  		<title>
1041 1069
 		<function moreinfo="none">ds_is_from_list([groupid [, mode [, uri] ] ])</function>