Skip to content

Commit

Permalink
update registrar: now certain AOR, contact can be searched; easier to…
Browse files Browse the repository at this point in the history
… understand the api

three new functions added:
	* is_registered - whether or not an AOR is inside the usrloc table
	* is_contact_registered - whether or not a contact and/or a callid is inside the location table
	* is_ip_registered - whether or not an ip from an avp/pvar is registered or not
two old functions are now deprecated:
	* is_other_contact - replaced with is_ip_registered + all pvar support
	* registered - replaced with is_contact_registered
  • Loading branch information
ionutrazvanionita committed Oct 16, 2015
1 parent 3d91beb commit 0a826a9
Show file tree
Hide file tree
Showing 6 changed files with 696 additions and 208 deletions.
124 changes: 120 additions & 4 deletions modules/registrar/README
Expand Up @@ -57,7 +57,12 @@ Bogdan-Andrei Iancu
1.4.3. lookup(domain [, flags [, aor]])
1.4.4. registered(domain [,AOR[, callid]])
1.4.5. is_other_contact(domain , IPs)
1.4.6. add_sock_hdr(hdr_name)
1.4.6. is_registered(domain ,[AOR])
1.4.7. is_contact_registered(domain
,[AOR],[contact],[callid])

1.4.8. is_ip_registered(domain ,[AOR],IPvar)
1.4.9. add_sock_hdr(hdr_name)

1.5. Exported Statistics

Expand Down Expand Up @@ -92,7 +97,10 @@ Bogdan-Andrei Iancu
1.19. lookup usage
1.20. registered usage
1.21. is_other_contact usage
1.22. add_sock_hdr usage
1.22. is_registered usage
1.23. is_registered usage
1.24. is_registered usage
1.25. add_sock_hdr usage

Chapter 1. Admin Guide

Expand Down Expand Up @@ -660,6 +668,9 @@ switch ($retcode) {
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.

WARNING: THIS FUNCTION IS DEPRECATED! USE
is_contact_registered() INSTEAD.

Example 1.20. registered usage
...
if (registered("location")) {
Expand All @@ -684,6 +695,9 @@ if (registered("location","$fu")) {

This function can be used from REQUEST_ROUTE.

WARNING: THIS FUNCTION IS DEPRECATED! USE is_ip_registered()
INSTEAD.

Example 1.21. is_other_contact usage
...

Expand All @@ -693,7 +707,109 @@ if (is_other_contact("location", "$avp(ips)")) {
};
...

1.4.6. add_sock_hdr(hdr_name)
1.4.6. is_registered(domain ,[AOR])

The function returns true if an AOR is registered, false
otherwise. The function does not modify the message being
process.

Meaning of the parameters is as follows:
* domain - Name of table that should be used for the lookup.
* AOR (optional)- AOR to lookup for; if missing, the source
if the AOR is the "To" header for REGISTER request, "From"
header for any other sip request.

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.

Example 1.22. is_registered usage
...
/**/
if (is_method("REGISTER")) {
/* automatically uses the URI from the To header */
if (is_registered("location")) {
xlog("this AOR is registered\n")
...
}
};
/* check the From uri whether this aor is registered or not */
if (is_registered("location","$fu")) {
xlog("caller is registered\n");
}
...

1.4.7. is_contact_registered(domain ,[AOR],[contact],[callid])

The function returns true if a contact and/or a callid from a
certain AOR is registered, false otherwise. The function does
not modify the message being process.

Meaning of the parameters is as follows:
* domain - Name of table that should be used for the lookup.
* AOR (optional)- AOR to lookup for; if missing, the source
if the AOR is the "To" header for REGISTER request, "From"
header for any other sip request.
* contact (optional)- callid to check if a contact if
registered with this callid (this may help you to make
distinction between newly registered contact (callid not
registered so far) and re-registration (callid already
registered).
* callid (optional)- callid to check if a contact if
registered with this callid (this may help you to make
distinction between newly registered contact (callid not
registered so far) and re-registration (callid already
registered).

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.

Example 1.23. is_registered usage
...
/*let's say you want to block users that are not registered*/
if (is_method("INVITE")) {
if (!is_contact_registered("location")) {
sl_send_reply("401", "Unauthorized");
...
}
}
/* you want to check the second contact from the message whether it is
registered or not */
if(is_method("INVITE")) {
if (is_contact_registered("location","$fu","$(ct[1])",))
xlog("caller is registered\n");
}
...

1.4.8. is_ip_registered(domain ,[AOR],IPvar)

The function returns true if at least a contact has an IP from
the IPavp in it's received parameter,otherwise returns false.
The function does not modify the message being process. This
function replaces the "is_other_contact" function.

Meaning of the parameters is as follows:
* domain - Name of table that should be used for the lookup.
* AOR (optional)- AOR to lookup for; if missing, the source
if the AOR is the "To" header for REGISTER request, "From"
header for any other sip request.
* IPvar the pvar containing the IPs you want to check the
received parameter of the contacts in the AOR against.

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.

Example 1.24. is_registered usage
...
/* check the source ip whether it is already registered */
if (is_method("REGISTER")) {
if (is_ip_registered("location","$tu","$si")) {
xlog("already registered from this ip\n");
...
}
};
...

1.4.9. add_sock_hdr(hdr_name)

Adds to the current REGISTER request a new header with
“hdr_name” which contains the description of the received
Expand All @@ -706,7 +822,7 @@ if (is_other_contact("location", "$avp(ips)")) {

This function can be used from REQUEST_ROUTE.

Example 1.22. add_sock_hdr usage
Example 1.25. add_sock_hdr usage
...
add_sock_hdr("Sock-Info");
...
Expand Down
181 changes: 181 additions & 0 deletions modules/registrar/doc/registrar_admin.xml
Expand Up @@ -946,6 +946,10 @@ switch ($retcode) {
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.
</para>
<para>
WARNING: THIS FUNCTION IS DEPRECATED! USE
<emphasis>is_contact_registered()</emphasis> INSTEAD.
</para>
<example>
<title><function>registered</function> usage</title>
<programlisting format="linespecific">
Expand Down Expand Up @@ -988,6 +992,10 @@ if (registered("location","$fu")) {
<para>
This function can be used from REQUEST_ROUTE.
</para>
<para>
WARNING: THIS FUNCTION IS DEPRECATED! USE
<emphasis>is_ip_registered()</emphasis> INSTEAD.
</para>
<example>
<title><function>is_other_contact</function> usage</title>
<programlisting format="linespecific">
Expand All @@ -1002,6 +1010,179 @@ if (is_other_contact("location", "$avp(ips)")) {
</example>
</section>

<section>
<title>
<function moreinfo="none">is_registered(domain ,[AOR])</function>
</title>
<para>
The function returns true if an AOR is registered, false otherwise.
The function does not modify the message being process.
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para>
<emphasis>domain</emphasis> - Name of table that should be
used for the lookup.
</para>
</listitem>
<listitem>
<para>
<emphasis>AOR</emphasis> (optional)- AOR to lookup for; if
missing, the source if the AOR is the "To" header for REGISTER
request, "From" header for any other sip request.
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.
</para>
<example>
<title><function>is_registered</function> usage</title>
<programlisting format="linespecific">
...
/**/
if (is_method("REGISTER")) {
/* automatically uses the URI from the To header */
if (is_registered("location")) {
xlog("this AOR is registered\n")
...
}
};
/* check the From uri whether this aor is registered or not */
if (is_registered("location","$fu")) {
xlog("caller is registered\n");
}
...
</programlisting>
</example>
</section>


<section>
<title>
<function moreinfo="none">is_contact_registered(domain ,[AOR],[contact],[callid])</function>
</title>
<para>
The function returns true if a contact and/or a callid from a certain AOR is registered, false otherwise.
The function does not modify the message being process.
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para>
<emphasis>domain</emphasis> - Name of table that should be
used for the lookup.
</para>
</listitem>
<listitem>
<para>
<emphasis>AOR</emphasis> (optional)- AOR to lookup for; if
missing, the source if the AOR is the "To" header for REGISTER
request, "From" header for any other sip request.
</para>
</listitem>
<listitem>
<para>
<emphasis>contact</emphasis> (optional)- callid to check if a
contact if registered with this callid (this may help you to
make distinction between newly registered contact (callid
not registered so far) and re-registration (callid already
registered).
</para>
</listitem>

<listitem>
<para>
<emphasis>callid</emphasis> (optional)- callid to check if a
contact if registered with this callid (this may help you to
make distinction between newly registered contact (callid
not registered so far) and re-registration (callid already
registered).
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.
</para>
<example>
<title><function>is_registered</function> usage</title>
<programlisting format="linespecific">
...
/*let's say you want to block users that are not registered*/
if (is_method("INVITE")) {
if (!is_contact_registered("location")) {
sl_send_reply("401", "Unauthorized");
...
}
}
/* you want to check the second contact from the message whether it is
registered or not */
if(is_method("INVITE")) {
if (is_contact_registered("location","$fu","$(ct[1])",))
xlog("caller is registered\n");
}
...
</programlisting>
</example>
</section>

<section>
<title>
<function moreinfo="none">is_ip_registered(domain ,[AOR],IPvar)</function>
</title>
<para>
The function returns true if at least a contact has an IP from the IPavp in it's received parameter,otherwise
returns false. The function does not modify the message being process. This function replaces the "is_other_contact"
function.
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para>
<emphasis>domain</emphasis> - Name of table that should be
used for the lookup.
</para>
</listitem>
<listitem>
<para>
<emphasis>AOR</emphasis> (optional)- AOR to lookup for; if
missing, the source if the AOR is the "To" header for REGISTER
request, "From" header for any other sip request.
</para>
</listitem>
<listitem>
<para>
<emphasis>IPvar</emphasis> the pvar containing the IPs you want
to check the received parameter of the contacts in the AOR against.
</para>
</listitem>

</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE, ONREPLY_ROUTE, LOCAL_ROUTE.
</para>
<example>
<title><function>is_registered</function> usage</title>
<programlisting format="linespecific">
...
/* check the source ip whether it is already registered */
if (is_method("REGISTER")) {
if (is_ip_registered("location","$tu","$si")) {
xlog("already registered from this ip\n");
...
}
};
...
</programlisting>
</example>
</section>



<section>
<title>
<function moreinfo="none">add_sock_hdr(hdr_name)</function>
Expand Down

0 comments on commit 0a826a9

Please sign in to comment.