Module: sip-router
Branch: 3.1
Commit: ba80998055c95ae5f6dc730ecc4233981b432003
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ba80998…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Oct 24 20:48:56 2010 +0200
htable: updated example with www auth
- some more details about hash tables
(cherry picked from commit 8431de384b9fb6122203ed7388a26990cd4b025c)
---
modules_k/htable/README | 35 ++++++++++++++++++++++----------
modules_k/htable/doc/htable_admin.xml | 30 ++++++++++++++++++++-------
2 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/modules_k/htable/README b/modules_k/htable/README
index 9e8fe6f..facb147 100644
--- a/modules_k/htable/README
+++ b/modules_k/htable/README
@@ -11,7 +11,7 @@ Elena-Ramona Modroiu
<ramona(a)rosdev.ro>
- Copyright � 2008
http://www.asipto.com
+ Copyright © 2008
http://www.asipto.com
__________________________________________________________________
Table of Contents
@@ -116,9 +116,21 @@ Chapter 1. Admin Guide
The module adds a hash table container to configuration language. The
hash table is stored in shared memory and the access to it can be done
- via pseudo-variables: $sht(htname=>name).
+ via pseudo-variables: $sht(htname=>name). The module supports
+ definition of many hash tables and can load values at startup from a
+ database table.
- The "name" can be a static string or can include pseudo- variables that
+ A typical use case for the SIP server is to implement a cache system in
+ configuration file - if a value is not found in hash table, load it
+ from database and store it in hash table so next time the access to it
+ is very fast. In the definition of the table you can define the default
+ expiration time of cached items. The expiration time can be adjusted
+ per itme via assignment operation at runtime.
+
+ You can read more about hash tables at:
+
http://en.wikipedia.org/wiki/Hash_table.
+
+ The “name” can be a static string or can include pseudo- variables that
will be replaced at runtime.
Example 1.1. Accessing $sht(htname=>key)
@@ -141,7 +153,7 @@ $sht(a=>$ci::srcip) = $si;
the failed authentications per user and one for storing the time of
last authentication attempt. To ensure unique name per user, the hash
table uses a combination of authentication username and text
- "::auth_count" and "::last_auth".
+ “::auth_count” and “::last_auth”.
Example 1.2. Dictionary attack limitation
...
@@ -160,7 +172,7 @@ if(is_present_hf("Authorization"))
$sht(a=>$au::auth_count) = 0;
}
}
- if(!www_authorize(""))
+ if(!www_authenticate("$td", "subscriber"))
{
switch ($retcode) {
case -1:
@@ -175,12 +187,12 @@ if(is_present_hf("Authorization"))
$sht(a=>$au::last_auth) = $Ts;
break;
}
- www_challenge(""/*realm*/,"0"/*qop*/);
+ www_challenge("$td"/*realm*/,"0"/*qop*/);
exit;
}
$sht(a=>$au::auth_count) = 0;
} else {
- www_challenge("","0");
+ www_challenge("$td","0");
exit;
}
...
@@ -243,9 +255,10 @@ if(is_present_hf("Authorization"))
* htname - string specifying the name of the hash table. This string
is used by $sht(...) to refer to the hash table.
* size - number specifying the size of hash table. Larger value means
- less collisions. The number of entries in the table is 2^size. The
- possible range for this value is from 8 to 14, smaller or larger
- values will be increased or decreased respectivly.
+ less collisions. The number of entries (aka slots or buckets) in
+ the table is 2^size. The possible range for this value is from 2 to
+ 14, smaller or larger values will be increased or decreased
+ respectivly.
* autoexpire -time in seconds to delete an item from hash table if no
update was done to it. If is missing or set to 0, the items won't
expire.
@@ -257,7 +270,7 @@ if(is_present_hf("Authorization"))
Example 1.3. Set hash_size parameter
...
modparam("htable", "htable",
"a=>size=4;autoexpire=7200;dbtable=htable_a;")
-modparam("htable", "htable",
"a=>size=4;autoexpire=7200;dbtable=htable_a;")
+modparam("htable", "htable", "b=>size=5;")
...
3.2. db_url (str)
diff --git a/modules_k/htable/doc/htable_admin.xml
b/modules_k/htable/doc/htable_admin.xml
index 1257b6f..e2c2be6 100644
--- a/modules_k/htable/doc/htable_admin.xml
+++ b/modules_k/htable/doc/htable_admin.xml
@@ -18,7 +18,21 @@
<para>
The module adds a hash table container to configuration language. The
hash table is stored in shared memory and the access to it can be
- done via pseudo-variables: $sht(htname=>name).
+ done via pseudo-variables: $sht(htname=>name). The module supports
+ definition of many hash tables and can load values at startup from
+ a database table.
+ </para>
+ <para>
+ A typical use case for the SIP server is to implement a cache system
+ in configuration file - if a value is not found in hash table, load
+ it from database and store it in hash table so next time the access to
+ it is very fast. In the definition of the table you can define the
+ default expiration time of cached items. The expiration time can
+ be adjusted per itme via assignment operation at runtime.
+ </para>
+ <para>
+ You can read more about hash tables at:
+
http://en.wikipedia.org/wiki/Hash_table.
</para>
<para>
The <quote>name</quote> can be a static string or can include pseudo-
@@ -70,7 +84,7 @@ if(is_present_hf("Authorization"))
$sht(a=>$au::auth_count) = 0;
}
}
- if(!www_authorize(""))
+ if(!www_authenticate("$td", "subscriber"))
{
switch ($retcode) {
case -1:
@@ -85,12 +99,12 @@ if(is_present_hf("Authorization"))
$sht(a=>$au::last_auth) = $Ts;
break;
}
- www_challenge(""/*realm*/,"0"/*qop*/);
+ www_challenge("$td"/*realm*/,"0"/*qop*/);
exit;
}
$sht(a=>$au::auth_count) = 0;
} else {
- www_challenge("","0");
+ www_challenge("$td","0");
exit;
}
...
@@ -221,9 +235,9 @@ if(is_present_hf("Authorization"))
<para>
<emphasis>size</emphasis> - number specifying the size of hash
table. Larger value means less collisions. The number of entries
- in the table is 2^size. The possible range for this value is from
- 8 to 14, smaller or larger values will be increased or decreased
- respectivly.
+ (aka slots or buckets) in the table is 2^size. The possible range
+ for this value is from 2 to 14, smaller or larger values will be
+ increased or decreased respectivly.
</para>
</listitem>
<listitem>
@@ -250,7 +264,7 @@ if(is_present_hf("Authorization"))
<programlisting format="linespecific">
...
modparam("htable", "htable",
"a=>size=4;autoexpire=7200;dbtable=htable_a;")
-modparam("htable", "htable",
"a=>size=4;autoexpire=7200;dbtable=htable_a;")
+modparam("htable", "htable", "b=>size=5;")
...
</programlisting>
</example>