11.2.8.7 Rewrite Built-in Functions
The following built-in functions are provided:
- Function: integer length (string s)
- Returns the length of the string s.
- Function: integer index (string s, integer c)
- Returns the index of the first occurrence of the character c in
the string s. Returns -1 if no such occurrence is found.
| index("/raddb/users", 47) => 0
index("/raddb/users", 45) => -1
|
- Function: integer rindex (string s, integer i)
- Returns the index of the last occurrence of the character c in
the string s. Returns -1 if no such occurrence is found.
| rindex("/raddb/users", 47) => 6
|
- Function: string substr (string s, integer start, integer length)
- Returns the substring of s of length at most length starting at
position start.
| substr("foo-bar-baz", 3, 5) => "-bar-"
|
All character positions in strings are counted from 0.
- Function: string field (string buffer, integer n)
- This function regards the buffer argument as consisting of
fields separated with any amount of whitespace. It extracts and
returns the nth field. n is counted from 1.
| field("GNU's not UNIX", 1) => "GNU's"
field("GNU's not UNIX", 2) => "not"
field("GNU's not UNIX", 3) => "UNIX"
field("GNU's not UNIX", 4) => ""
|
- Function: integer logit (string msg)
- Outputs its argument to the Radius log channel
info
. Returns 0.
For debugging purposes.
- Function: integer inet_aton (string str)
- Converts the Internet host address str from the
standard numbers-and-dots notation into the equivalent integer in
host byte order.
| inet_aton("127.0.0.1") => 2130706433
|
- Function: string inet_ntoa (integer ip)
- Converts the Internet host address ip given
in host byte order to a string in standard numbers-and-dots notation.
| inet_ntoa(2130706433) => "127.0.0.1"
|
- Function: integer htonl (integer n)
- Converts the integer n, regarded as long, from host to network byte
order.
- Function: integer ntohl (integer n)
- Converts the integer n, regarded as long, from network to host byte
order.
- Function: integer htons (integer n)
- Converts the integer n, regarded as short, from host to network byte
order.
- Function: integer ntohs (integer n)
- Converts the integer n, regarded as short, from network to host byte
order.
- Function: string gsub (string regex, string repl, string str)
- For each substring matching the regular expression regex in the string
str, substitute the string repl, and return the resulting
string.
| gsub("s","S","strings")
=> "StringS"
gsub("[0-9][0-9]*","N","28 or 29 days")
=> "N or N days"
gsub("[()'\"]","/","\"a\" (quoted) 'string'")
=> "/a/ /quoted/ /string/"
|
- Function: string qprn (string str)
- Replace all non-printable characters in string S by their
corresponding hex value preceeded by a percent sign. Return the
resulting string. Printable are alphabetical characters, decimal
digits and dash (`-'). Other characters are considered non-printable.
For example:
| qprn("a string/value") => "a%20string%2Fvalue"
|
- Function: string quote_string (string str)
- Replace all non-printable characters in string str by their
three-digit octal code prefixed with a backslash, or by their C
escape notation, as appropriate. Non-printable characters
depend on the locale settings. For example, suppose that the current
locale is set to ISO-8859-1 (a so called "Latin-1" character set)
and -!- represents a tab character. Then:
| quote_string("François contains non-!-printable chars")
=> "Fran\347ois contains non\tprintable chars"
|
- Function: string unquote_string (string str)
- Replace C escape notations in string str with corresponding
characters using current locale. For example, for ISO-8859-1 locale:
| unquote_string("Fran\347ois") => "François"
|
- Function: string toupper (string str)
- Returns the copy of the string str with all alphabetical characters
converted to upper case. For example:
| toupper("a-string") => "A-STRING"
|
- Function: string tolower (string str)
- Returns the copy of the string str with all alphabetical characters
converted to lower case. For example:
| tolower("A-STRING") => "a-string"
|
- Function: string request_code_string (integer code)
- Converts integer RADIUS request code to its textual representation as
per RFC 3575. This function is useful in logging hooks (see section 5.1.2.1 Logging hooks).
| request_code_string(4) => "Accounting-Request"
|
Native Language Support
The native language support is provided via the functions described
below. These functions are interfaces to GNU gettext
library.
For the information about general concepts and principles of
Native Language Support, please refer to
section `gettext' in GNU gettext
utilities.
The default current textual domain is `radius'.
- Function: string textdomain (string domain)
- Sets the new value for the current textual domain. This domain is used by
the functions
gettext
and ngettext
.
Returns the name of the previously used domain.
- Function: string gettext (string msgid)
-
- Function: string _ (string msgid)
- The function returns the translation of the string msgid if it
is available in the current domain. If it is not available, the
argument itself is returned.
The second form of this function provides a traditional shortcut
notation.
For a detailed description of the GNU gettext
interface,
refer to section `Interface to gettext' in GNU gettext
utilities.
- Function: string dgettext (string domain, string msgid)
- Returns the translation of the string msgid if it
is available in the domain domain. If it is not available, the
argument itself is returned.
- Function: string ngettext (string msgid_singular, string msgid_plural, integer number)
- The
ngettext
function is used to translate the messages that
have singular and plural forms. The msgid_singular parameter
must contain the singular form of the string to be converted. It is
also used as the key for the search in the catalog. The
msgid_plural
parameter is the plural form. The parameter
number is used to determine the plural form. If no message
catalog is found msgid_singular is returned if
number == 1
, otherwise msgid_plural.
For a detailed description of the GNU gettext
interface for the
plural translation,
refer to section `Additional functions for plural forms' in GNU gettext
utilities.
- Function: string dngettext (string domain, string msg_sing, string msg_plur, integer number)
- Similar to
ngettext
, but searches translation in the given domain.
Request Accessors
The following functions are used to read some internal fields of a
RADIUS request.
- Function: Integer request_source_ip ()
- Returns source IP address of the currently processed request. This function
can be used to add
NAS-IP-Address
attribute to the requests
lacking one, e.g.:
| integer
restore_nas_ip()
{
if (!*%[NAS-IP-Address])
%[NAS-IP-Address] = request_source_ip();
return 0;
}
|
- Function: Integer request_source_port ()
- Returns the source UDP port.
- Function: Integer request_id ()
- Returns the request identifier.
- Function: Integer request_code ()
- Returns the request code.
This document was generated
by Sergey Poznyakoff on November, 20 2004
using texi2html