Browse Source

modules/carrierroute Ser cfg framework for some carrierroute parameters (fetch_rows, use_domain and fallback_default)

Added support for cfg framework for some parameters
Updated documentation to reflect the changes
Marius Zbihlei 15 years ago
parent
commit
1c327b736b

+ 35 - 33
modules/carrierroute/README

@@ -12,7 +12,7 @@ Henning Westerholt
 
    1&1 Internet AG
 
-   Copyright © 2007 1&1 Internet AG
+   Copyright © 2007 1&1 Internet AG
    Revision History
    Revision $Revision$ $Date$
      __________________________________________________________________
@@ -273,7 +273,7 @@ Chapter 1. Admin Guide
    use the lcr and dispatcher module.
 
    If you want to use this module in failure routes, then you need to call
-   "append_branch()" after rewriting the request URI in order to relay the
+   “append_branch()� after rewriting the request URI in order to relay the
    message to the new target. Its also supportes the usage of database
    derived failure routing descisions with the carrierfailureroute table.
 
@@ -290,7 +290,7 @@ Chapter 1. Admin Guide
        needs the capability to issue raw queries. Its not possible to use
        the dbtext or db_berkeley module at the moment.
      * The tm module, when you want to use the $T_reply_code
-       pseudo-variable in the "cr_next_domain" function.
+       pseudo-variable in the “cr_next_domain� function.
 
 2.2. External Libraries or Applications
 
@@ -317,7 +317,7 @@ Chapter 1. Admin Guide
 
    The name of the table containing the subscribers
 
-   Default value is "subscriber".
+   Default value is “subscriber�.
 
    Example 1.1. Set subscriber_table parameter
 ...
@@ -329,7 +329,7 @@ modparam("carrierroute", "subscriber_table", "subscriber")
    The name of the column in the subscriber table containing the
    usernames.
 
-   Default value is "username".
+   Default value is “username�.
 
    Example 1.2. Set subscriber_user_col parameter
 ...
@@ -341,7 +341,7 @@ modparam("carrierroute", "subscriber_user_col", "username")
    The name of the column in the subscriber table containing the domain of
    the subscriber.
 
-   Default value is "domain".
+   Default value is “domain�.
 
    Example 1.3. Set subscriber_domain_col parameter
 ...
@@ -353,7 +353,7 @@ modparam("carrierroute", "subscriber_domain_col", "domain")
    The name of the column in the subscriber table containing the carrier
    id of the subscriber.
 
-   Default value is "cr_preferred_carrier".
+   Default value is “cr_preferred_carrier�.
 
    Example 1.4. Set subscriber_carrier_col parameter
 ...
@@ -365,7 +365,7 @@ modparam("carrierroute", "subscriber_carrier_col", "cr_preferred_carrier")
    Specifies whether the module loads its config data from a file or from
    a database. Possible values are file or db.
 
-   Default value is "file".
+   Default value is “file�.
 
    Example 1.5. Set config_source parameter
 ...
@@ -376,7 +376,7 @@ modparam("carrierroute", "config_source", "file")
 
    Specifies the path to the config file.
 
-   Default value is "/etc/kamailio/carrierroute.conf".
+   Default value is “/etc/kamailio/carrierroute.conf�.
 
    Example 1.6. Set config_file parameter
 ...
@@ -388,7 +388,7 @@ modparam("carrierroute", "config_file", "/etc/kamailio/carrierroute.conf")
    The name of the carrier tree used per default (if the current
    subscriber has no preferred tree)
 
-   Default value is "default".
+   Default value is “default�.
 
    Example 1.7. Set default_tree parameter
 ...
@@ -398,9 +398,10 @@ modparam("carrierroute", "default_tree", "default")
 3.8. use_domain (int)
 
    When using tree lookup per user, this parameter specifies whether to
-   use the domain part for user matching or not.
+   use the domain part for user matching or not. This parameter is tunable
+   via the ser cfg framework.
 
-   Default value is "0".
+   Default value is “0�.
 
    Example 1.8. Set use_domain parameter
 ...
@@ -412,9 +413,9 @@ modparam("carrierroute", "use_domain", 0)
    This parameter defines the behaviour when using user-based tree lookup.
    If the user has a non-existing tree set and fallback_default is set to
    1, the default tree is used. Otherwise, cr_user_rewrite_uri returns an
-   error.
+   error. This parameter is tunable via the ser cfg framework.
 
-   Default value is "1".
+   Default value is “1�.
 
    Example 1.9. Set fallback_default parameter
 ...
@@ -426,9 +427,10 @@ modparam("carrierroute", "fallback_default", 1)
    The number of the rows to be fetched at once from database when loading
    the routing data. This value can be used to tune the load time at
    startup. For 1MB of private memory (default) it should be below 3750.
-   The database driver must support the fetch_result() capability.
+   The database driver must support the fetch_result() capability. This
+   parameter is tunable via the ser cfg framework.
 
-   Default value is "2000".
+   Default value is “2000�.
 
    Example 1.10. Set fetch_rows parameter
 ...
@@ -444,7 +446,7 @@ modparam("carrierroute", "fetch_rows", 3000)
    matching. Please be aware that memory requirements for storing the
    routing tree in shared memory will also increase by a factor of 12.8.
 
-   Default value is "10".
+   Default value is “10�.
 
    Example 1.11. Set match_mode parameter
 ...
@@ -487,7 +489,7 @@ cr_tree_rewrite_uri(tree, domain)
    used in the config file mode, as it needs a mapping of the given user
    to a certain carrier. The is derived from a database entry belonging to
    the user parameter. This mapping must be available in the table that is
-   specified in the "subscriber_table" variable. This data is not cached
+   specified in the “subscriber_table� variable. This data is not cached
    in memory, that means for every execution of this function a database
    query will be done.
 
@@ -517,7 +519,7 @@ descavp)
 
    If flags and masks values are specified in the routing rule, they will
    be compared by this function to the message flags. Specify a flag and
-   mask value of "0" to match to all possible message flags (this is the
+   mask value of “0� to match to all possible message flags (this is the
    default value). If flags and mask are not zero, and no match to the
    message flags is possible, no routing will be done. The calculation of
    the hash and the load-balancing is done after the flags matching.
@@ -826,7 +828,7 @@ failure_route[1] {
    Don't use a hash index value of zero. If you ommit the hash completly,
    the module gives them a autogenerated value, starting from one.
 
-   Use the "NULL" prefix to specify an empty prefix in the config file.
+   Use the “NULL� prefix to specify an empty prefix in the config file.
    Please note that the prefix is matched against the request URI (or to
    URI), if they did not contain a valid (numerical) URI, no match is
    possible. So for loadbalancing purposes e.g. for your registrars, you
@@ -917,21 +919,21 @@ domain register {
 +----+---------+--------+-------------+-------+------+---------------+
 ...
 
-   This table contains three routes to two gateways for the "49" prefix,
+   This table contains three routes to two gateways for the “49� prefix,
    and a default route for other prefixes over carrier 2 and carrier 1.
    The gateways for the default carrier will be used for functions that
    don't support the user specific carrier lookup. The routing rules for
-   carrier 1 and carrier 2 for the "49" prefix contains a additional rule
+   carrier 1 and carrier 2 for the “49� prefix contains a additional rule
    with the domain 2, that can be used for example as fallback if the
    gateways in domain 1 are not reachable. Two more fallback rules (domain
    3 and 4) for carrier 1 are also supplied to support the functionality
    of the carrierfailureroute table example that is provided in the next
    section.
 
-   This table provides also a "carrier 1" routing rule for the "49"
+   This table provides also a “carrier 1� routing rule for the “49�
    prefix, that is only choosen if some message flags are set. If this
-   flags are not set, the other two rules are used. The "strip", "mask"
-   and "comment" colums are omitted for brevity.
+   flags are not set, the other two rules are used. The “strip�, “mask�
+   and “comment� colums are omitted for brevity.
 
    Example 1.21. Example database content - simple carrierfailureroute
    table
@@ -944,10 +946,10 @@ domain register {
 +----+---------+--------+---------------+------------+-------------+
 ...
 
-   This table contains two failure routes for the "gw.carrier1-1" and "-2"
+   This table contains two failure routes for the “gw.carrier1-1� and “-2�
    gateways. For any (failure) reply code the respective next domain is
    choosen. After that no more failure routes are available, an error will
-   be returned from the "cr_next_domain" function. Not all table colums
+   be returned from the “cr_next_domain� function. Not all table colums
    are show here for brevity.
 
    For each failure route domain and carrier that is added to the
@@ -1008,7 +1010,7 @@ domain register {
 
 7.3. User specific routing
 
-   For a functional routing the "cr_preferred_carrier" column must be
+   For a functional routing the “cr_preferred_carrier� column must be
    added to the subscriber table (or to the table and column that you
    specified as modul parameter) to choose the actual carrier for the
    users.
@@ -1060,7 +1062,7 @@ Chapter 2. Module parameter for database access.
 
    URL to the database containing the data.
 
-   Default value is "mysql://openserro:openserro@localhost/openser".
+   Default value is “mysql://openserro:openserro@localhost/openser�.
 
    Example 2.1. Set db_url parameter
 ...
@@ -1071,7 +1073,7 @@ modparam("carrierroute", "db_url", "dbdriver://username:password@dbhost/dbname")
 
    Name of the carrierroute table for the carrierroute module.
 
-   Default value is "carrierroute".
+   Default value is “carrierroute�.
 
    Example 2.2. Set carrierroute_table parameter
 ...
@@ -1214,7 +1216,7 @@ modparam("carrierroute", "carrierroute_description_col", "description")
 
    Name of the carrierfailureroute table for the carrierroute module.
 
-   Default value is "carrierfailureroute".
+   Default value is “carrierfailureroute�.
 
    Example 2.15. Set carrierfailureroute_table parameter
 ...
@@ -1325,7 +1327,7 @@ modparam("carrierroute", "carrierfailureroute_description_col", "description")
 
    Name of the carrier_name table for the carrierroute module.
 
-   Default value is "carrier_name".
+   Default value is “carrier_name�.
 
    Example 2.26. Set carrier_name_table parameter
 ...
@@ -1354,7 +1356,7 @@ modparam("carrierroute", "carrier_name_carrier_col", "carrier")
 
    Name of the domain_name table for the carrierroute module.
 
-   Default value is "domain_name".
+   Default value is “domain_name�.
 
    Example 2.29. Set domain_name_table parameter
 ...

+ 9 - 6
modules/carrierroute/carrierroute.c

@@ -47,6 +47,7 @@
 #include "cr_data.h"
 #include "cr_func.h"
 #include "db_carrierroute.h"
+#include "config.h"
 #include <sys/stat.h>
 
 MODULE_VERSION
@@ -71,9 +72,6 @@ str default_tree = str_init("default");
 const str CR_EMPTY_PREFIX = str_init("null");
 
 int mode = 0;
-int use_domain = 0;
-int fallback_default = 1;
-int cr_fetch_rows = 2000;
 int cr_match_mode = 10;
 
 
@@ -112,9 +110,9 @@ static param_export_t params[]= {
 	{"config_source",          STR_PARAM, &config_source },
 	{"default_tree",           STR_PARAM, &default_tree.s },
 	{"config_file",            STR_PARAM, &config_file },
-	{"use_domain",             INT_PARAM, &use_domain },
-	{"fallback_default",       INT_PARAM, &fallback_default },
-	{"fetch_rows",             INT_PARAM, &cr_fetch_rows },
+	{"use_domain",             INT_PARAM, &default_carrierroute_cfg.use_domain },
+	{"fallback_default",       INT_PARAM, &default_carrierroute_cfg.fallback_default },
+	{"fetch_rows",             INT_PARAM, &default_carrierroute_cfg.fetch_rows },
 	{"match_mode",             INT_PARAM, &cr_match_mode },
 	{0,0,0}
 };
@@ -211,6 +209,11 @@ static int mod_init(void) {
 		return -1;
 	}
 
+	if(cfg_declare("carrierroute", carrierroute_cfg_def, &default_carrierroute_cfg, cfg_sizeof(carrierroute), &carrierroute_cfg)){
+		LM_ERR("Fail to declare the configuration\n");
+		return -1;
+	}
+
 	if (init_route_data() < 0) {
 		LM_ERR("could not init route data\n");
 		return -1;

+ 0 - 3
modules/carrierroute/carrierroute.h

@@ -51,9 +51,6 @@ extern str default_tree;
 extern const str CR_EMPTY_PREFIX;
 
 extern int mode;
-extern int use_domain;
-extern int fallback_default;
-extern int cr_fetch_rows;
 extern int cr_match_mode;
 
 #endif

+ 53 - 0
modules/carrierroute/config.c

@@ -0,0 +1,53 @@
+/*
+ * $Id$
+ * This file is part of SIP-router, a free SIP server.
+ *
+ * SIP-router is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * SIP-router is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History
+ * -------
+ *  2008-02-05	adapting tm module for the configuration framework (Miklos)
+ */
+
+/*!
+ * \file 
+ * \brief Siputils :: Configuration
+ * \ingroup Siputils
+ */
+
+
+#include "../../cfg/cfg.h"
+#include "../../parser/msg_parser.h" /* method types */
+
+#include "config.h"
+
+struct cfg_group_carrierroute	default_carrierroute_cfg = {
+		0, 	/* use_domain */
+		1, 	/* fallback_default */
+		2000	/* fetch_rows*/ 
+	};
+
+void	*carrierroute_cfg = &default_carrierroute_cfg;
+
+cfg_def_t	carrierroute_cfg_def[] = {
+	{"use_domain",		CFG_VAR_INT ,	0, 1, 0, 0,
+		"When using tree lookup per user, this parameter specifies whether to use the domain part for user matching or not." },
+	{"fallback_default",	CFG_VAR_INT ,	0, 1, 0, 0,
+		"If the user has a non-existing tree set and fallback_default is set to 1, the default tree is used. Else error is returned" },
+	{"fetch_rows",	CFG_VAR_INT ,	0, 0, 0, 0,
+		"The number of the rows to be fetched at once from database when loading the routing data."},
+	{0, 0, 0, 0, 0, 0}
+};
+

+ 39 - 0
modules/carrierroute/config.h

@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ *
+ * SIP-router is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*!
+ * \file 
+ * \brief Carrierroute :: Configuration
+ * \ingroup carrierroute
+ */
+
+
+#ifndef _CARRIERROUTE_CONFIG_H
+#define _CARRIERROUTE_CONFIG_H
+
+
+#include "../../cfg/cfg.h"
+#include "../../str.h"
+
+struct cfg_group_carrierroute {
+	unsigned int	use_domain;
+	unsigned int	fallback_default;
+	unsigned int	fetch_rows;
+};
+
+extern struct cfg_group_carrierroute	default_carrierroute_cfg;
+extern void	*carrierroute_cfg;
+extern cfg_def_t	carrierroute_cfg_def[];
+
+
+#endif

+ 5 - 3
modules/carrierroute/cr_db.c

@@ -33,6 +33,7 @@
 #include "carrierroute.h"
 #include "cr_db.h"
 #include "cr_carrier.h"
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -196,7 +197,8 @@ int load_user_carrier(str * user, str * domain) {
 	db_val_t vals[2];
 	db_op_t op[2];
 	int id;
-	if (!user || (use_domain && !domain)) {
+	int use_domain = cfg_get(carrierroute, carrierroute_cfg, use_domain);
+	if (!user || (use_domain  && !domain)) {
 		LM_ERR("NULL pointer in parameter\n");
 		return -1;
 	}
@@ -327,7 +329,7 @@ int load_route_data_db(struct route_data_t * rd) {
 			LM_ERR("Failed to query database to prepare fetch row.\n");
 			return -1;
 		}
-		if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res, cr_fetch_rows) < 0) {
+		if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res, cfg_get(carrierroute, carrierroute_cfg, fetch_rows)) < 0) {
 			LM_ERR("Fetching rows failed\n");
 			return -1;
 		}
@@ -379,7 +381,7 @@ int load_route_data_db(struct route_data_t * rd) {
 			}
 		}
 		if (DB_CAPABILITY(carrierroute_dbf, DB_CAP_FETCH)) {
-			if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res, cr_fetch_rows) < 0) {
+			if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res,  cfg_get(carrierroute, carrierroute_cfg, fetch_rows)) < 0) {
 				LM_ERR("fetching rows failed\n");
 				carrierroute_dbf.free_result(carrierroute_dbh, res);
 				return -1;

+ 5 - 6
modules/carrierroute/cr_func.c

@@ -47,7 +47,7 @@
 #include "cr_domain.h"
 #include "cr_carrier.h"
 #include "carrierroute.h"
-
+#include "config.h"
 
 enum hash_algorithm {
 	alg_crc32 = 1, /*!< hashing algorithm is CRC32 */
@@ -546,7 +546,7 @@ int cr_do_route(struct sip_msg * _msg, gparam_t *_carrier,
 	
 	carrier_data=NULL;
 	if (carrier_id < 0) {
-		if (fallback_default) {
+		if (cfg_get(carrierroute, carrierroute_cfg, fallback_default)) {
 			LM_NOTICE("invalid tree id %i specified, using default tree\n", carrier_id);
 			carrier_data = get_carrier_data(rd, rd->default_carrier_id);
 		}
@@ -555,7 +555,7 @@ int cr_do_route(struct sip_msg * _msg, gparam_t *_carrier,
 	} else {
 		carrier_data = get_carrier_data(rd, carrier_id);
 		if (carrier_data == NULL) {
-			if (fallback_default) {
+			if (cfg_get(carrierroute, carrierroute_cfg, fallback_default)) {
 				LM_NOTICE("invalid tree id %i specified, using default tree\n", carrier_id);
 				carrier_data = get_carrier_data(rd, rd->default_carrier_id);
 			}
@@ -622,7 +622,6 @@ int cr_load_user_carrier(struct sip_msg * _msg, gparam_t *_user, gparam_t *_doma
 		LM_ERR("cannot print the domain\n");
 		return -1;
 	}
-	
 	/* get carrier id */
 	if ((avp_val.n = load_user_carrier(&user, &domain)) < 0) {
 		LM_ERR("error in load user carrier");
@@ -764,7 +763,7 @@ int cr_load_next_domain(struct sip_msg * _msg, gparam_t *_carrier,
 
 	carrier_data=NULL;
 	if (carrier_id < 0) {
-		if (fallback_default) {
+		if (cfg_get(carrierroute, carrierroute_cfg, fallback_default)) {
 			LM_NOTICE("invalid tree id %i specified, using default tree\n", carrier_id);
 			carrier_data = get_carrier_data(rd, rd->default_carrier_id);
 		}
@@ -773,7 +772,7 @@ int cr_load_next_domain(struct sip_msg * _msg, gparam_t *_carrier,
 	} else {
 		carrier_data = get_carrier_data(rd, carrier_id);
 		if (carrier_data == NULL) {
-			if (fallback_default) {
+			if (cfg_get(carrierroute, carrierroute_cfg, fallback_default)) {
 				LM_NOTICE("invalid tree id %i specified, using default tree\n", carrier_id);
 				carrier_data = get_carrier_data(rd, rd->default_carrier_id);
 			}

+ 5 - 3
modules/carrierroute/doc/carrierroute_admin.xml

@@ -262,7 +262,8 @@ modparam("carrierroute", "default_tree", "default")
 	    <title><varname>use_domain</varname> (int)</title>
 	    <para>
 		    When using tree lookup per user, this parameter specifies whether
-		    to use the domain part for user matching or not.
+		    to use the domain part for user matching or not. This parameter
+		    is tunable via the ser cfg framework.
 	    </para>
 	    <para>
 		    <emphasis>
@@ -285,7 +286,7 @@ modparam("carrierroute", "use_domain", 0)
 		    This parameter defines the behaviour when using user-based tree
 		    lookup. If the user has a non-existing tree set and fallback_default
 		    is set to 1, the default tree is used. Otherwise, cr_user_rewrite_uri
-		    returns an error.
+		    returns an error. This parameter is tunable via the ser cfg framework.
 	    </para>
 	    <para>
 		    <emphasis>
@@ -308,7 +309,8 @@ modparam("carrierroute", "fallback_default", 1)
 		when loading the routing data. This value can be used to tune
 		the load time at startup. For 1MB of private memory (default)
 		it should be below 3750. The database driver must support the
-		fetch_result() capability.
+		fetch_result() capability. This parameter is tunable via the ser
+		cfg framework.
 		</para>
 		<para>
 		<emphasis>