modules/cfgutils/README
d5de0975
 cfgutils Module
 
 Henning Westerholt
 
    1und1 Internet AG
d77df08a
    <henning.westerholt@1und1.de>
d5de0975
 
 Carsten Bock
 
    BASIS AudioNet GmbH
 
3c7cc85d
 Elena-Ramona Modroiu
 
    rosdev.ro
d34518a2
    <ramona@rosdev.ro>
3c7cc85d
 
e99b8424
 Jiri Kuthan
 
    <jiri@iptel.org>
 
0d69ffe8
 Olle E. Johansson
 
    <oej@edvina.net>
 
fd5013ee
 Juha Heinanen
 
    <jh@tutpro.com>
 
e99b8424
 Edited by
 
 Daniel-Constantin Mierla
 
    <miconda@gmail.com>
 
f680081a
    Copyright � 2014, 2013, 2007, 2008, 2004 Edvina AB, 1und1 Internet AG,
    BASIS AudioNet GmbH, Elena-Ramona Modroiu, Juha Heinanen, FhG FOKUS
1cf6e4a9
      __________________________________________________________________
d5de0975
 
    Table of Contents
d77df08a
 
9fc784c6
    1. Admin Guide
d5de0975
 
1cf6e4a9
         1. Overview
         2. Dependencies
ba7961bb
         3. Parameters
1cf6e4a9
 
               3.1. initial_probability (string)
               3.2. hash_file (string)
               3.3. initial_gflags (integer)
               3.4. lock_set_size (integer)
 
ba7961bb
         4. Functions
1cf6e4a9
 
               4.1. rand_event()
               4.2. rand_set_prob(probabiltiy)
               4.3. rand_reset_prob()
               4.4. rand_get_prob()
               4.5. sleep(time)
               4.6. usleep(time)
               4.7. abort()
               4.8. pkg_status()
c5505831
               4.9. pkg_summary()
               4.10. shm_status()
               4.11. shm_summary()
               4.12. set_gflag(flag)
               4.13. reset_gflag(flag)
               4.14. is_gflag(flag)
               4.15. lock(key)
               4.16. unlock(key)
0d69ffe8
               4.17. check_route_exists(route)
               4.18. route_if_exists(route)
               4.19. core_hash(string1, string2, size)
1cf6e4a9
 
         5. MI Commands
 
               5.1. rand_set_prop
               5.2. rand_reset_prob
               5.3. rand_get_prob
               5.4. check_config_hash
               5.5. get_config_hash
               5.6. set_gflag
               5.7. reset_gflag
               5.8. is_gflag
               5.9. get_gflags
 
fd5013ee
         6. RPC Commands
 
               6.1. cfgutils.set_gflag
               6.2. cfgutils.reset_gflag
               6.3. cfgutils.is_gflag
1cf6e4a9
 
fd5013ee
         7. Exported pseudo-variables
 
               7.1. $RANDOM
d5de0975
 
    List of Examples
d77df08a
 
    1.1. initial_probability parameter usage
    1.2. hash_file parameter usage
165d22e6
    1.3. initial parameter usage
0672c5ab
    1.4. lock_set_size parameter usage
    1.5. rand_event() usage
    1.6. rand_set_prob() usage
    1.7. rand_reset_prob() usage
    1.8. rand_get_prob() usage
    1.9. sleep usage
    1.10. usleep usage
    1.11. abort usage
    1.12. pkg_status usage
c5505831
    1.13. pkg_summary usage
    1.14. shm_status usage
    1.15. shm_summary usage
    1.16. set_gflag() usage
    1.17. reset_gflag() usage
    1.18. is_gflag() usage
    1.19. lock() usage
    1.20. unlock() usage
0d69ffe8
    1.21. check_route_exists() usage
    1.22. route_if_exists() usage
    1.23. core_hash() usage
    1.24. rand_set_prob usage
    1.25. rand_reset_prob usage
    1.26. rand_get_prob usage
    1.27. check_config_hash usage
    1.28. get_config_hash usage
    1.29. set_gflag usage
    1.30. reset_gflag usage
    1.31. is_gflag usage
    1.32. get_gflags usage
fd5013ee
    1.33. cfgutils.set_gflag usage
    1.34. cfgutils.reset_gflag usage
    1.35. cfgutils.is_gflag usage
    1.36. RANDOM pseudo-variable usage
d5de0975
 
9fc784c6
 Chapter 1. Admin Guide
d5de0975
 
1cf6e4a9
    Table of Contents
 
    1. Overview
    2. Dependencies
ba7961bb
    3. Parameters
1cf6e4a9
 
         3.1. initial_probability (string)
         3.2. hash_file (string)
         3.3. initial_gflags (integer)
         3.4. lock_set_size (integer)
 
ba7961bb
    4. Functions
1cf6e4a9
 
         4.1. rand_event()
         4.2. rand_set_prob(probabiltiy)
         4.3. rand_reset_prob()
         4.4. rand_get_prob()
         4.5. sleep(time)
         4.6. usleep(time)
         4.7. abort()
         4.8. pkg_status()
c5505831
         4.9. pkg_summary()
         4.10. shm_status()
         4.11. shm_summary()
         4.12. set_gflag(flag)
         4.13. reset_gflag(flag)
         4.14. is_gflag(flag)
         4.15. lock(key)
         4.16. unlock(key)
0d69ffe8
         4.17. check_route_exists(route)
         4.18. route_if_exists(route)
         4.19. core_hash(string1, string2, size)
1cf6e4a9
 
    5. MI Commands
 
         5.1. rand_set_prop
         5.2. rand_reset_prob
         5.3. rand_get_prob
         5.4. check_config_hash
         5.5. get_config_hash
         5.6. set_gflag
         5.7. reset_gflag
         5.8. is_gflag
         5.9. get_gflags
 
fd5013ee
    6. RPC Commands
 
         6.1. cfgutils.set_gflag
         6.2. cfgutils.reset_gflag
         6.3. cfgutils.is_gflag
1cf6e4a9
 
fd5013ee
    7. Exported pseudo-variables
 
         7.1. $RANDOM
1cf6e4a9
 
 1. Overview
d5de0975
 
3c7cc85d
    Useful extensions for the server configuration.
11fb900f
 
3c7cc85d
    The cfgutils module can be used to introduce randomness to the
    behaviour of the server. It provides setup functions and the
f5ccfeaa
    "rand_event" function. This function return either true or false,
1cf6e4a9
    depending on a random value and a specified probability. E.g. if you
    set via fifo or script a probability value of 5%, then 5% of all calls
f5ccfeaa
    to rand_event will return true. The pseudovariable "$RANDOM" could be
1cf6e4a9
    used to introduce random values e.g. into a SIP reply.
 
    The benefit of this module is the probability of the decision can be
    manipulated by external applications such as web interface or command
    line tools. The probability must be specified as percent value, ranging
    from 0 to 100.
 
    The module exports commands to FIFO server that can be used to change
    the global settings via FIFO interface. The FIFO commands are:
f5ccfeaa
    "set_prob", "reset_prob" and "get_prob".
1cf6e4a9
 
    This module can be used for simple load-shedding, e.g. reply 5% of the
    Invites with a 503 error and a adequate random Retry-After value.
 
    The module provides as well functions to delay the execution of the
f5ccfeaa
    server. The functions "sleep" and "usleep" could be used to let the
1cf6e4a9
    server wait a specific time interval.
 
    It can also hash the config file used from the server with a (weak)
    cryptographic hash function on startup. This value is saved and can be
    later compared to the actual hash, to detect modifications of this file
    after the server start. This functions are available as the FIFO
f5ccfeaa
    commands "check_config_hash" and "get_config_hash".
1cf6e4a9
 
    The gflags functionality (global flags) keeps a bitmap of flags in
    shared memory and may be used to change behaviour of server based on
    value of the flags. Example:
e99b8424
         if (is_gflag("1")) {
                 t_relay("udp:10.0.0.1:5060");
         } else {
                 t_relay("udp:10.0.0.2:5060");
         }
 
1cf6e4a9
    The benefit of this is the value of the switch flags can be manipulated
    by external applications such as web interface or command line tools.
    The size of bitmap is 32.
e99b8424
 
1cf6e4a9
    The module exports external commands that can be used to change the
fd5013ee
    global flags via Management Interface and RPC. See relevant sections
    below.
e99b8424
 
1cf6e4a9
 2. Dependencies
d5de0975
 
1cf6e4a9
    The module depends on the following modules (in the other words the
    listed modules must be loaded before this module):
d5de0975
      * none
 
ba7961bb
 3. Parameters
1cf6e4a9
 
    3.1. initial_probability (string)
    3.2. hash_file (string)
    3.3. initial_gflags (integer)
    3.4. lock_set_size (integer)
d5de0975
 
1cf6e4a9
 3.1. initial_probability (string)
d5de0975
 
    The initial value of the probability.
 
f5ccfeaa
    Default value is "10".
d5de0975
 
d77df08a
    Example 1.1. initial_probability parameter usage
8f4d56b7
 modparam("cfgutils", "initial_probability", 15)
d77df08a
 
1cf6e4a9
 3.2. hash_file (string)
989206bd
 
1cf6e4a9
    The config file name for that a hash value should be calculated on
    startup.
11fb900f
 
da210b37
    There is no default value, is no parameter is given the hash
    functionality is disabled.
11fb900f
 
d77df08a
    Example 1.2. hash_file parameter usage
9b64b9f3
 modparam("cfgutils", "hash_file", "/etc/kamailio/kamailio.cfg")
d77df08a
 
1cf6e4a9
 3.3. initial_gflags (integer)
e99b8424
 
    The initial value of global flags bitmap.
 
f5ccfeaa
    Default value is "0".
e99b8424
 
165d22e6
    Example 1.3. initial parameter usage
0672c5ab
 modparam("cfgutils", "initial_gflags", 15)
 
1cf6e4a9
 3.4. lock_set_size (integer)
0672c5ab
 
1cf6e4a9
    Size of lock set - the value is used as power of two to compute the
    size of lock array.
0672c5ab
 
f5ccfeaa
    Default value is "0" - no lock set created.
0672c5ab
 
    Example 1.4. lock_set_size parameter usage
 modparam("cfgutils", "lock_set_size", 4)
e99b8424
 
ba7961bb
 4. Functions
1cf6e4a9
 
    4.1. rand_event()
    4.2. rand_set_prob(probabiltiy)
    4.3. rand_reset_prob()
    4.4. rand_get_prob()
    4.5. sleep(time)
    4.6. usleep(time)
    4.7. abort()
    4.8. pkg_status()
c5505831
    4.9. pkg_summary()
    4.10. shm_status()
    4.11. shm_summary()
    4.12. set_gflag(flag)
    4.13. reset_gflag(flag)
    4.14. is_gflag(flag)
    4.15. lock(key)
    4.16. unlock(key)
0d69ffe8
    4.17. check_route_exists(route)
    4.18. route_if_exists(route)
    4.19. core_hash(string1, string2, size)
d5de0975
 
1cf6e4a9
 4.1. rand_event()
d5de0975
 
1cf6e4a9
    Return true or false, depending on a random value and a probability
    value.
d5de0975
 
0672c5ab
    Example 1.5. rand_event() usage
d5de0975
 ...
 if (rand_event()) {
   append_to_reply("Retry-After: 120\n");
   sl_send_reply("503", "Try later");
   exit;
 };
 # normal message processing follows
 ...
 
1cf6e4a9
 4.2. rand_set_prob(probabiltiy)
d5de0975
 
f5ccfeaa
    Set the "probability" of the decision.
d5de0975
 
f5ccfeaa
    "probability" can have a value from the range 0..100.
d5de0975
 
0672c5ab
    Example 1.6. rand_set_prob() usage
d5de0975
 ...
 rand_set_prob("4");
 ...
 
1cf6e4a9
 4.3. rand_reset_prob()
d5de0975
 
    Reset the probability back to the inital value.
 
0672c5ab
    Example 1.7. rand_reset_prob() usage
d5de0975
 ...
 rand_reset_prob();
 ...
 
1cf6e4a9
 4.4. rand_get_prob()
d5de0975
 
1cf6e4a9
    Return the current probability setting, e.g. for logging purposes.
d5de0975
 
0672c5ab
    Example 1.8. rand_get_prob() usage
d5de0975
 ...
 rand_get_prob();
 
f680081a
 4.5. sleep(time)
d5de0975
 
    Waits "time" seconds.
 
    Meaning of the parameters is as follows:
f680081a
      * time - Time to wait in seconds. It can be an integer or a variable
        holding an integer.
d5de0975
 
f680081a
    This function can be used from ANY_ROUTE.
d5de0975
 
0672c5ab
    Example 1.9. sleep usage
d5de0975
 ...
 sleep("1");
 ...
 
f680081a
 4.6. usleep(time)
d5de0975
 
8e937d26
    Waits "time" micro-seconds.
d5de0975
 
    Meaning of the parameters is as follows:
f680081a
      * time - Time to wait in micro-seconds (1/1000000 of a second). It
        can be an integer or a variable holding an integer.
d5de0975
 
f680081a
    This function can be used from ANY_ROUTE.
d5de0975
 
0672c5ab
    Example 1.10. usleep usage
d5de0975
 ...
8e937d26
 # wait 5 miliseconds
 usleep("5000");
d5de0975
 ...
 
f680081a
 4.7. abort()
0c041221
 
606aae53
    Debugging function that aborts the server. Depending on the
    configuration of the server a core dump will be created.
0c041221
 
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
    FAILURE_ROUTE, BRANCH_ROUTE.
 
0672c5ab
    Example 1.11. abort usage
0c041221
 ...
606aae53
 abort();
0c041221
 ...
 
f680081a
 4.8. pkg_status()
0c041221
 
1cf6e4a9
    Debugging function that dumps the status for the private (PKG) memory.
    This information is logged to the default log facility, depending on
    the general log level and the memlog setting. You need to compile the
    server with activated memory debugging to get detailed informations.
0c041221
 
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
    FAILURE_ROUTE, BRANCH_ROUTE.
 
0672c5ab
    Example 1.12. pkg_status usage
0c041221
 ...
606aae53
 pkg_status();
0c041221
 ...
 
f680081a
 4.9. pkg_summary()
c5505831
 
    Debugging function that dumps the summary for the private (PKG) memory
    usage. This information is logged to the default log facility,
    depending on the general log level and the memlog setting. You need to
    compile the server with activated memory debugging to get detailed
    informations.
 
    This function can be used from ANY_ROUTE.
 
    Example 1.13. pkg_summary usage
 ...
 pkg_summary();
 ...
 
f680081a
 4.10. shm_status()
0c041221
 
1cf6e4a9
    Debugging function that dumps the status for the shared (SHM) memory.
    This information is logged to the default log facility, depending on
    the general log level and the memlog setting. You need to compile the
    server with activated memory debugging to get detailed informations.
0c041221
 
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
    FAILURE_ROUTE, BRANCH_ROUTE.
 
c5505831
    Example 1.14. shm_status usage
0c041221
 ...
606aae53
 shm_status();
0c041221
 ...
 
f680081a
 4.11. shm_summary()
c5505831
 
    Debugging function that dumps the summary for the shared (SHM) memory
    usage. This information is logged to the default log facility,
    depending on the general log level and the memlog setting. You need to
    compile the server with activated memory debugging to get detailed
    informations.
 
    This function can be used from ANY_ROUTE.
 
    Example 1.15. shm_summary usage
 ...
 shm_summary();
 ...
 
 4.12. set_gflag(flag)
e99b8424
 
f5ccfeaa
    Set the bit at the position "flag" in global flags.
e99b8424
 
f5ccfeaa
    "flag" can have a value in the range of 0..31.
e99b8424
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
 
c5505831
    Example 1.16. set_gflag() usage
e99b8424
 ...
 set_gflag("4");
 ...
 
c5505831
 4.13. reset_gflag(flag)
e99b8424
 
f5ccfeaa
    Reset the bit at the position "flag" in global flags.
e99b8424
 
f5ccfeaa
    "flag" can have a value in the range of 0..31.
e99b8424
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
 
c5505831
    Example 1.17. reset_gflag() usage
e99b8424
 ...
 reset_gflag("4");
 ...
 
c5505831
 4.14. is_gflag(flag)
e99b8424
 
f5ccfeaa
    Check if bit at the position "flag" in global flags is set.
e99b8424
 
f5ccfeaa
    "flag" can have a value in the range of 0..31.
e99b8424
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
 
c5505831
    Example 1.18. is_gflag() usage
e99b8424
 ...
 if(is_gflag("4"))
 {
         log("global flag 4 is set\n");
 } else {
         log("global flag 4 is not set\n");
 };
 ...
 
c5505831
 4.15. lock(key)
0672c5ab
 
1cf6e4a9
    Lock the key. Can be used to syncronize operations in config file, a
    hash id is computed over the key and appropriate lock is set in the
    lock array controlled by parameter "lock_set_size". Do not use lock()
    after another lock() unless you are sure the keys hit different array
    entries.
0672c5ab
 
f5ccfeaa
    "key" can be static string or string with PVs.
0672c5ab
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
 
c5505831
    Example 1.19. lock() usage
0672c5ab
 ...
 lock("$rU");
 ...
 
c5505831
 4.16. unlock(key)
0672c5ab
 
    Unlock the key.
 
f5ccfeaa
    "key" can be static string or string with PVs.
0672c5ab
 
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
    ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
 
c5505831
    Example 1.20. unlock() usage
0672c5ab
 ...
 unlock("$rU");
 ...
 
0d69ffe8
 4.17. check_route_exists(route)
 
    Check if a route block exists
 
    Parameters:
 
    "name" of a route block in the config file, like "route[FROGJUMP]"
 
    This function can be used from any route. You can only check for
    route[] blocks, not reply, event or other routes.
 
    Example 1.21. check_route_exists() usage
 ...
 if(check_route_exists("FROGJUMP") {
         $var(jumping_frogs) = 1;
 };
 ...
 
 4.18. route_if_exists(route)
 
    Execute a routing block only if it is defined. If it's not defined,
    silently move to the next action in the configuration script.
 
    Parameters:
 
    "name" of a route block in the config file, like "route[FROGJUMP]"
 
    This function can be used from any route. You can only execute it for
    route[] blocks, not reply, event or other routes.
 
    Example 1.22. route_if_exists() usage
 ...
 route_if_exists("PRESENCE_SANTA_CLAUS");
 ...
 
 4.19. core_hash(string1, string2, size)
8afb4cdf
 
    Exported function that enables the core_hash() function to be used from
    the configuration file.
 
48e2695d
    This is a quick and simple hash function and it is not
    cryptographically secure. This function should not be used for any
    security related purposes.
 
8afb4cdf
    Parameters:
f5ccfeaa
      * "string1" first string to hash
      * "string2" (optional) second string to hash (set to "" if not
8afb4cdf
        needed)
f5ccfeaa
      * "size" size of the hash space (used as a power of 2)
8afb4cdf
 
    This function can be used from ANY_ROUTE.
 
0d69ffe8
    Example 1.23. core_hash() usage
8afb4cdf
 ...
 core_hash("$ci", "", 4);
 ...
 
1cf6e4a9
 5. MI Commands
d5de0975
 
1cf6e4a9
    5.1. rand_set_prop
    5.2. rand_reset_prob
    5.3. rand_get_prob
    5.4. check_config_hash
    5.5. get_config_hash
    5.6. set_gflag
    5.7. reset_gflag
    5.8. is_gflag
    5.9. get_gflags
e99b8424
 
1cf6e4a9
    Functions that check or change some global flags accepts one parameter
    which is the flag bitmap/mask specifing the corresponding flags. It is
    not possible to specify directly the flag position that should be
    changed as in the functions available in the routing script.
d5de0975
 
1cf6e4a9
 5.1. rand_set_prop
 
    Set the probability value to the given parameter. The parameter should
    be a percent value.
d5de0975
 
f50036f8
    The parameter value must be a number from 0 to 100.
d5de0975
 
0d69ffe8
    Example 1.24. rand_set_prob usage
d5de0975
 ...
bb30e4a8
 $ kamctl fifo rand_set_prob 10
d5de0975
 ...
 
1cf6e4a9
 5.2. rand_reset_prob
d5de0975
 
    Reset the probability value to the inital start value.
 
    This command don't need a parameter.
 
f680081a
    Example 1.25. rand_reset_prob usage
d5de0975
 ...
bb30e4a8
 $ kamctl fifo rand_reset_prob
d5de0975
 ...
 
1cf6e4a9
 5.3. rand_get_prob
d5de0975
 
    Return the actual probability setting.
 
    The function return the actual probability value.
 
0d69ffe8
    Example 1.26. rand_get_prob usage
d5de0975
 ...
bb30e4a8
 $ kamctl fifo get_prob
d5de0975
 The actual probability is 50 percent.
 ...
 
1cf6e4a9
 5.4. check_config_hash
11fb900f
 
1cf6e4a9
    Check if the actual config file hash is identical to the stored one.
11fb900f
 
1cf6e4a9
    The function returns 200 OK if the hash values are identical, 400 if
    there are not identical, 404 if no file for hashing has been configured
    and 500 on errors. Additional a short text message is printed.
11fb900f
 
0d69ffe8
    Example 1.27. check_config_hash usage
11fb900f
 ...
bb30e4a8
 $ kamctl fifo check_config_hash
11fb900f
 The actual config file hash is identical to the stored one.
 ...
 
1cf6e4a9
 5.5. get_config_hash
11fb900f
 
    Return the stored config file hash.
 
1cf6e4a9
    The function returns 200 OK and the hash value on success or 404 if no
    file for hashing has been configured.
11fb900f
 
0d69ffe8
    Example 1.28. get_config_hash usage
11fb900f
 ...
bb30e4a8
 $ kamctl fifo get_config_hash
11fb900f
 1580a37104eb4de69ab9f31ce8d6e3e0
 ...
 
1cf6e4a9
 5.6. set_gflag
e99b8424
 
    Set the value of some flags (specified by bitmask) to 1.
 
1cf6e4a9
    The parameter value must be a bitmask in decimal or hexadecimal format.
    The bitmask has a 32 bit size.
e99b8424
 
0d69ffe8
    Example 1.29. set_gflag usage
e99b8424
 ...
 $ kamctl fifo set_gflag 1
 $ kamctl fifo set_gflag 0x3
 ...
 
1cf6e4a9
 5.7. reset_gflag
e99b8424
 
    Reset the value of some flags to 0.
 
1cf6e4a9
    The parameter value must be a bitmask in decimal or hexadecimal format.
    The bitmask has a 32 bit size.
e99b8424
 
f680081a
    Example 1.30. reset_gflag usage
e99b8424
 ...
 $ kamctl fifo reset_gflag 1
 $ kamctl fifo reset_gflag 0x3
 ...
 
1cf6e4a9
 5.8. is_gflag
e99b8424
 
    Returns true if the all the flags from the bitmask are set.
 
1cf6e4a9
    The parameter value must be a bitmask in decimal or hexadecimal format.
    The bitmask has a 32 bit size.
e99b8424
 
1cf6e4a9
    The function returns TRUE if all the flags from the set are set and
    FALSE if at least one is not set.
e99b8424
 
0d69ffe8
    Example 1.31. is_gflag usage
e99b8424
 ...
 $ kamctl fifo set_gflag 1024
 $ kamctl fifo is_gflag 1024
 TRUE
 $ kamctl fifo is_gflag 1025
 TRUE
 $ kamctl fifo is_gflag 1023
 FALSE
 $ kamctl fifo set_gflag 0x10
 $ kamctl fifo is_gflag 1023
 TRUE
 $ kamctl fifo is_gflag 1007
 FALSE
 $ kamctl fifo is_gflag 16
 TRUE
 ...
 
1cf6e4a9
 5.9. get_gflags
e99b8424
 
1cf6e4a9
    Return the bitmap with all flags. The function gets no parameters and
    returns the bitmap in hexadecimal and decimal format.
e99b8424
 
f680081a
    Example 1.32. get_gflags usage
e99b8424
 ...
 $ kamctl fifo get_gflags
 0x3039
 12345
 ...
 
fd5013ee
 6. RPC Commands
 
    6.1. cfgutils.set_gflag
    6.2. cfgutils.reset_gflag
    6.3. cfgutils.is_gflag
 
 6.1. cfgutils.set_gflag
 
    Set the value of some flags (specified by bitmask) to 1.
 
    The parameter value must be a bitmask in decimal or hexadecimal format.
    The bitmask has a 32 bit size.
 
    Example 1.33. cfgutils.set_gflag usage
 ...
 $ kamctl cfgutils.set_gflag s:1
 ...
 
 6.2. cfgutils.reset_gflag
 
    Reset the value of some flags to 0.
 
    Reset the value of some flags (specified by bitmask) to 1.
 
    The parameter value must be a bitmask in decimal or hexadecimal format.
    The bitmask has a 32 bit size.
 
f680081a
    Example 1.34. cfgutils.reset_gflag usage
fd5013ee
 ...
 $ kamctl cfgutils.reset_gflag s:0x1
 ...
 
 6.3. cfgutils.is_gflag
 
    Returns string "TRUE" if all the flags from the given set are set and
    "FALSE" if at least one is not set.
 
    The parameter value must be a bitmask in decimal or hexadecimal format.
    The bitmask has a 32 bit size.
 
    Example 1.35. cfgutils.is_gflag usage
 ...
 $ kamctl cfgutils.set_gflag s:1024
 $ kamctl cfgutils.is_gflag s:1024
 TRUE
 $ kamctl cfgutils.is_gflag s:1023
 FALSE
 $ kamctl cfgutils.set_gflag s:0x7FFF
 $ kamctl cfgutils.is_gflag s:1023
 TRUE
 ...
 
 7. Exported pseudo-variables
1cf6e4a9
 
fd5013ee
    7.1. $RANDOM
d5de0975
 
fd5013ee
 7.1. $RANDOM
d5de0975
 
    Returns a random value from the [0 - 2^31) range.
 
fd5013ee
    Example 1.36. RANDOM pseudo-variable usage
d5de0975
 ...
2488aee5
 if (rand_event()) {
d5de0975
   $avp(i:10) = ($RANDOM / 16777216); # 2^24
   if ($avp(i:10) < 10) {
      $avp(i:10) = 10;
   }
   append_to_reply("Retry-After: $avp(i:10)\n");
   sl_send_reply("503", "Try later");
   exit;
 };
 # normal message processing follows