Parcourir la source

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

Olle E. Johansson il y a 10 ans
Parent
commit
bef88a0daa

+ 47 - 21
modules/dispatcher/README

@@ -16,11 +16,19 @@ Carsten Bock
 
    ng-voice GmbH
 
+Edited by
+
+Olle E. Johansson
+
+   Edvina AB
+
    Copyright © 2004 FhG FOKUS
 
    Copyright © 2005 Voice Sistem
 
    Copyright © 2010 Daniel-Constantin Mierla (asipto.com)
+
+   Copyright © 2014 Olle E. Johansson, Edvina AB
      __________________________________________________________________
 
    Table of Contents
@@ -74,9 +82,10 @@ Carsten Bock
               4.3. ds_next_dst()
               4.4. ds_next_domain()
               4.5. ds_mark_dst([state])
-              4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
-              4.7. ds_load_update()
-              4.8. ds_load_unset()
+              4.6. ds_list_exist(groupid)
+              4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
+              4.8. ds_load_update()
+              4.9. ds_load_unset()
 
         5. MI Commands
 
@@ -138,10 +147,11 @@ Carsten Bock
    1.32. Set the "ds_default_socket" parameter
    1.33. ds_select_dst usage
    1.34. ds_mark_dst usage
-   1.35. ds_mark_dst usage
-   1.36. ds_load_unset usage
-   1.37. dispatcher list file
-   1.38. Kamailio config script - sample dispatcher usage
+   1.35. ds_list_exist usage
+   1.36. ds_mark_dst usage
+   1.37. ds_load_unset usage
+   1.38. dispatcher list file
+   1.39. Kamailio config script - sample dispatcher usage
 
 Chapter 1. Admin Guide
 
@@ -194,9 +204,10 @@ Chapter 1. Admin Guide
         4.3. ds_next_dst()
         4.4. ds_next_domain()
         4.5. ds_mark_dst([state])
-        4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
-        4.7. ds_load_update()
-        4.8. ds_load_unset()
+        4.6. ds_list_exist(groupid)
+        4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
+        4.8. ds_load_update()
+        4.9. ds_load_unset()
 
    5. MI Commands
 
@@ -733,9 +744,10 @@ Note
    4.3. ds_next_dst()
    4.4. ds_next_domain()
    4.5. ds_mark_dst([state])
-   4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
-   4.7. ds_load_update()
-   4.8. ds_load_unset()
+   4.6. ds_list_exist(groupid)
+   4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
+   4.8. ds_load_update()
+   4.9. ds_load_unset()
 
 4.1. ds_select_dst(set, alg[, limit])
 
@@ -872,7 +884,21 @@ failure_route[tryagain] {
 }
 ...
 
-4.6. ds_is_from_list([groupid [, mode [, uri] ] ])
+4.6. ds_list_exist(groupid)
+
+   Check if a specific group is defined in dispatcher list or database.
+     * groupid - A group ID to check.
+
+   This function can be used from ANY_ROUTE.
+
+   Example 1.35. ds_list_exist usage
+...
+if(ds_list_exist("10")) {
+    ...
+}
+...
+
+4.7. ds_is_from_list([groupid [, mode [, uri] ] ])
 
    This function returns true, if there is a match of source address or
    uri with an address in the given group of the dispatcher-list;
@@ -908,7 +934,7 @@ failure_route[tryagain] {
 
    This function can be used from ANY_ROUTE.
 
-   Example 1.35. ds_mark_dst usage
+   Example 1.36. ds_mark_dst usage
 ...
 if(ds_is_from_list()) {
     ...
@@ -921,7 +947,7 @@ if(ds_is_from_list("10", "sip:127.0.0.1:5080", "3")) {
 }
 ...
 
-4.7. ds_load_update()
+4.8. ds_load_update()
 
    Updates the load state:
      * 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")) {
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    BRANCH_ROUTE and ONREPLY_ROUTE.
 
-4.8. ds_load_unset()
+4.9. ds_load_unset()
 
    Remove the call load for the destination that routed the call.
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    BRANCH_ROUTE and ONREPLY_ROUTE.
 
-   Example 1.36. ds_load_unset usage
+   Example 1.37. ds_load_unset usage
 ...
 route {
     ...
@@ -1094,7 +1120,7 @@ kamcmd dispatcher.set_state ip 2 sip:127.0.0.1:5080
        probing destination (sending keep alives);
      * priority: sets the priority in destination list (based on it is
        done the initial ordering inside the set)
-     * attributes: extra field in form of name1=value1;...;nameN=valueN.
+     * attributes: extra fields in form of name1=value1;...;nameN=valueN.
        There are some predefined names:
           + 'duid' - used for call load dispatching
           + '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)
    For database, each element of a line resides in a different column.
    Next is a dispatcher.list file example:
 
-   Example 1.37. dispatcher list file
+   Example 1.38. dispatcher list file
 ...
 # $Id$
 # dispatcher destination sets
@@ -1138,7 +1164,7 @@ r,opt)
 
    Next picture shows a sample usage of the dispatcher module.
 
-   Example 1.38. Kamailio config script - sample dispatcher usage
+   Example 1.39. Kamailio config script - sample dispatcher usage
 ...
 #!KAMAILIO
 #

+ 27 - 0
modules/dispatcher/dispatch.c

@@ -1275,6 +1275,33 @@ static inline int ds_get_index(int group, ds_set_t **index)
 	return 0;
 }
 
+/*
+ * Check if a destination set exists
+ */
+int ds_list_exist(int set)
+{
+	ds_set_t *si = NULL;
+	LM_DBG("-- Looking for set %d\n", set);
+
+	/* get the index of the set */
+	si = _ds_list;
+	while(si)
+	{
+		if(si->id == set)
+		{
+			break;
+		}
+		si = si->next;
+	}
+
+	if(si==NULL)
+	{
+		LM_INFO("destination set [%d] not found\n", set);
+		return -1;	/* False */
+	}
+	LM_INFO("destination set [%d] found\n", set);
+	return 1;	/* True */
+}
 
 /**
  *

+ 2 - 0
modules/dispatcher/dispatch.h

@@ -124,6 +124,8 @@ int ds_mark_dst(struct sip_msg *msg, int mode);
 int ds_print_list(FILE *fout);
 int ds_print_mi_list(struct mi_node* rpl);
 int ds_print_sets(void);
+int ds_list_exist(int set);
+
 
 int ds_load_unset(struct sip_msg *msg);
 int ds_load_update(struct sip_msg *msg);

+ 26 - 0
modules/dispatcher/dispatcher.c

@@ -33,6 +33,7 @@
  *				to ds_is_from_list.  (carsten)
  * 2007-07-18  Added support for load/reload groups from DB 
  * 			   reload triggered from ds_reload MI_Command (ancuta)
+ * 2014-12-12  Added "ds_list_exist" function
  */
 
 /*! \file
@@ -167,7 +168,10 @@ static int w_ds_is_from_list0(struct sip_msg*, char*, char*);
 static int w_ds_is_from_list1(struct sip_msg*, char*, char*);
 static int w_ds_is_from_list2(struct sip_msg*, char*, char*);
 static int w_ds_is_from_list3(struct sip_msg*, char*, char*, char*);
+static int w_ds_list_exist(struct sip_msg*, char*);
+
 static int fixup_ds_is_from_list(void** param, int param_no);
+static int fixup_ds_list_exist(void** param,int param_no);
 
 static void destroy(void);
 
@@ -203,6 +207,8 @@ static cmd_export_t cmds[]={
 		fixup_ds_is_from_list, 0, ANY_ROUTE},
 	{"ds_is_from_list",  (cmd_function)w_ds_is_from_list3, 3,
 		fixup_ds_is_from_list, 0, ANY_ROUTE},
+	{"ds_list_exist",  (cmd_function)w_ds_list_exist, 1,
+		fixup_ds_list_exist, 0, ANY_ROUTE},
 	{"ds_load_unset",    (cmd_function)w_ds_load_unset,   0,
 		0, 0, ANY_ROUTE},
 	{"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)
 	return 0;
 }
 
+/* Check if a given set exist in memory */
+static int w_ds_list_exist(struct sip_msg *msg, char *param)
+{
+	int set;
+
+	if(fixup_get_ivalue(msg, (gparam_p)param, &set)!=0)
+	{
+		LM_ERR("cannot get set id param value\n");
+		return -1;
+	}
+	LM_DBG("--- Looking for dispatcher set %d\n", set);
+	return ds_list_exist(set);
+}
+
+static int fixup_ds_list_exist(void** param, int param_no)
+{
+	return fixup_igp_null(param, param_no);
+	return 0;
+}
+
 static int ds_parse_reply_codes() {
 	param_t* params_list = NULL;
 	param_t *pit=NULL;

+ 12 - 0
modules/dispatcher/doc/dispatcher.xml

@@ -31,6 +31,14 @@
                 <email>[email protected]</email>
                 </address>
             </editor>
+            <editor>
+                <firstname>Olle E.</firstname>
+                <surname>Johansson</surname>
+                <affiliation><orgname>Edvina AB</orgname></affiliation>
+                <address>
+                <email>[email protected]</email>
+                </address>
+            </editor>
 	</authorgroup>
 	<copyright>
 	    <year>2004</year>
@@ -44,6 +52,10 @@
 	    <year>2010</year>
 	    <holder>Daniel-Constantin Mierla (asipto.com)</holder>
 	</copyright>
+ 	<copyright>
+	    <year>2014</year>
+	    <holder>Olle E. Johansson, Edvina AB</holder>
+	</copyright>
    </bookinfo>
     <toc></toc>
     

+ 28 - 0
modules/dispatcher/doc/dispatcher_admin.xml

@@ -1036,6 +1036,34 @@ failure_route[tryagain] {
 </programlisting>
 		</example>
  	</section>
+  	<section  id="dispatcher.f.ds_list_exist">
+ 		<title>
+		<function moreinfo="none">ds_list_exist(groupid)</function>
+ 		</title>
+ 		<para>
+		Check if a specific group is defined in dispatcher list
+		or database.
+		</para>
+		<itemizedlist>
+		<listitem>
+			<para><emphasis>groupid</emphasis> - A group ID to check.
+			</para>
+		</listitem>
+		</itemizedlist>
+		<para>
+			This function can be used from ANY_ROUTE.
+		</para>
+		<example>
+		<title><function>ds_list_exist</function> usage</title>
+		<programlisting format="linespecific">
+...
+if(ds_list_exist("10")) {
+    ...
+}
+...
+</programlisting>
+	</example>
+	</section>
   	<section  id="dispatcher.f.ds_is_from_list">
  		<title>
 		<function moreinfo="none">ds_is_from_list([groupid [, mode [, uri] ] ])</function>