-
Notifications
You must be signed in to change notification settings - Fork 909
/
functions.xml
130 lines (125 loc) · 5.02 KB
/
functions.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<section id="domain.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
<sectioninfo>
</sectioninfo>
<title>Functions</title>
<section id="is_local">
<title><function>is_local(domain)</function></title>
<para>
This function can be used to test whether a given domain name in
parameter belongs to one of the virtual domains defined in the
domain table. Such domain name is said to be local. The function
returns 1 if the domain name is found in the domain table and -1
otherwise.
</para>
<para>
The first parameter of the function can be anything that returns a
string with domain name. In its simplest form it can be a string
with domain name: is_local("iptel.org"). You can also test a
domain name stored in an attribute: is_local("$my_domain"). And
finally you can test a domain name present in the SIP message with
selects: is_local("@ruri.host").
</para>
<para>
Note: Unlike function <function>lookup_domain</function>, this
function does not make domain attributes of the virtual domain
available to the script. Domain attributes are simply ignored by
this function.
</para>
<example>
<title>is_uri_host_local_local usage</title>
<programlisting>
...
if (is_local("@ruri.host")) {
/* Domain part of Request-URI is local */
}
...
</programlisting>
</example>
</section>
<section id="lookup_domain">
<title><function>lookup_domain(attr_group, domain)</function></title>
<para>
This is the main function of the domain module. It can be used to
implement support for virtual domains in the SIP server. Each
virtual domain is identified by a unique identifier (opaque
string) and it can have one or more associated domain names. Given
a domain name in the second parameter, this function finds the
associated virtual domain identifier (known as DID) and stores it
in an attribute for later use. In addition to that the function
also loads all domain-level attributes for the virtual domain and
makes them available to the configuration script.
</para>
<para>
The first parameter of the function identifies the group of
attributes where the DID and domain-level attributes shall be
stored. The value of the first parameter can be either "$fd" for
the domain-level attribute group that belongs to the calling party
(From), or "$td" for the domain-level attribute group that belongs
to the called party (Request-URI).
</para>
<para>
The value of the second parameter can be a simple string, an
attribute name, or a select. See the documentation of function
<function>is_local</function> for more details.
</para>
<para>
If a match is found then the DID of the virtual domain will be
stored either in $fd.did or in $td.did, depending on the value of
the first parameter. In addition to that domain-level attributes,
if any, will be available as either $fd.<name> or $td.</name>.
</para>
<para>
The function returns 1 when a matching virtual domain for the
given domain name was found and -1 otherwise.
</para>
<para>
The following example shows a typical use of the function. In a
multi domain setup, one has usually to figure out whether both
the calling and the called domains are local (i.e. configured on
the server as the domains the server is responsible for). This is
typically done by calling function
<function>lookup_domain</function> twice, once with the hostname
part of the From header as parameter and secondly with the
hostname part of the Request-URI as parameter.
</para>
<para>
The type of the situation can be then determined from the value of
corresponding attributes ($td.did and $fd.did). A non-existing
attribute value indicates that the domain name is not local (it
does not belong to any virtual domain configured in the domain
table).
</para>
<example>
<title>lookup_domain usage</title>
<programlisting>
lookup_domain("$fd", "@from.uri.host");
lookup_domain("$td", "@ruri.host");
if (strempty($fd.did) && strempty($td.did)) {
# Neither the calling nor the called domain is local
# This is a relaying attempt which should be forbidden
sl_reply("403", "Relaying Forbidden");
drop;
}
if (strempty($fd.did) && $td.did) {
# The calling domain is not local and the called domain
# is local, this is an inbound call from a 3rd party
# user to one of local users
}
if ($fd.did && strempty($td.did)) {
# The calling domain is local and the called domain
# is not local, this is an outbound call from one of
# our users to a 3rd party user
}
if ($fd.did && $td.did) {
# Both the calling and the called domains are local,
# one of our local users calls another local user,
# either in the same virtual domain or in another
# virtual domain hosted on the same server
}
</programlisting>
</example>
</section>
</section>