Browse code

- terminating code removed - prefix hash replaced with a tree index - table definition updated - new fifo commands: add, delete and list - automatic prefix generating removed - documentation updated

Elena-Ramona Modroiu authored on 30/01/2005 21:17:48
Showing 14 changed files
... ...
@@ -3,7 +3,7 @@ pdt Module
3 3
 
4 4
 Elena-Ramona Modroiu
5 5
 
6
-   FhG FOKUS
6
+   Voice-System
7 7
 
8 8
 Edited by
9 9
 
... ...
@@ -25,10 +25,12 @@ Elena-Ramona Modroiu
25 25
 
26 26
               1.3.1. db_url (string)
27 27
               1.3.2. db_table (string)
28
-              1.3.3. terminator (integer)
29
-              1.3.4. start_range (integer)
28
+              1.3.3. prefix_column (string)
29
+              1.3.4. domain_column (string)
30 30
               1.3.5. prefix (string)
31 31
               1.3.6. hsize_2pow (integer)
32
+              1.3.7. sync_time (integer)
33
+              1.3.8. clean_time (integer)
32 34
 
33 35
         1.4. Exported Functions
34 36
 
... ...
@@ -36,57 +38,60 @@ Elena-Ramona Modroiu
36 36
 
37 37
         1.5. Installation & Running
38 38
 
39
+              1.5.1. FIFO Commands
40
+
39 41
    2. Developer's Guide
40 42
    3. Frequently Asked Questions
41 43
 
42 44
    List of Examples
43
-   1-1. 
45
+   1-1. prefix-domain translation
44 46
    1-2. Set db_url parameter
45 47
    1-3. Set db_table parameter
46
-   1-4. Set terminator parameter
47
-   1-5. Set start_range parameter
48
+   1-4. Set prefix_column parameter
49
+   1-5. Set domain_column parameter
48 50
    1-6. Set prefix parameter
49 51
    1-7. Set hsize_2pow parameter
50
-   1-8. prefix2domain usage
52
+   1-8. Set sync_time parameter
53
+   1-9. Set clean_time parameter
54
+   1-10. prefix2domain usage
51 55
      _________________________________________________________
52 56
 
53 57
 Chapter 1. User's Guide
54 58
 
55 59
 1.1. Overview
56 60
 
57
-   This module translates numerical codes into domains and update
58
-   accordingly the R-URI.
61
+   This module translates a numerical prefix into a domain and
62
+   updates accordingly the request URI.
59 63
 
60 64
    The module looks up at the R-URI part of a message and if the
61 65
    user part begins with an established prefix it will update the
62
-   URI. Updating the uri consists of: read the code after the
63
-   prefix from the user part of the uri and keep the rest as the
64
-   user part of the new uri. The host part will be the domain
65
-   matched for the leading code.
66
+   URI. Updating the uri consists of: remove the prefix from the
67
+   user part of the uri and keep the rest as the user part of the
68
+   new uri. The host and port are changed with the domain matched
69
+   for the leading prefix.
66 70
 
67
-   [<prefix>]<code><userid><:password>@<mydomain.com> ...
71
+   <prefix><userid><:password>@<mydomain.com> ...
68 72
 
69 73
    and the result will be:
70 74
 
71 75
    <userid><:password>@<domain[:port]>...
72 76
 
73
-   Example 1-1. 
74
-prefix=2
75
-code=3330
76
-domain[3330]=iptel.org
77
+   Example 1-1. prefix-domain translation
78
+prefix=123
79
+domain[123]=alpha.org
77 80
 
78
-2333091001@mydomain.com  => 91001@iptel.org
81
+sip:12391001@mydomain.com  => sip:91001@alpha.org
79 82
 
80
-   The code is always ended with a special digit (a parameter of
81
-   the module). This digit will not be inside the code at all.
83
+   The prefix could be prefixed by other digits. These digits
84
+   will not be used to look up the domain (the classic example,
85
+   00 used for international calls, then follows the country
86
+   prefix). For more information on this, see 'prefix' parameter.
82 87
 
83
-     * See SQL script for creating databases and a sample of cfg
84
-       file in './doc/'.
85
-     * The web interface is in doc/web/ and the SQL script for
86
-       creating the database for user interface is
87
-       './doc/admin.sql'.
88
-     * Sample shell script to use with fifo interface is
89
-       './doc/fifo.sh'.
88
+     * A sample config file and the MySQL script to create the
89
+       database needed by PDT are located in './doc/'.
90
+     * Sample shell scripts to manage prefix-domain pairs are
91
+       also located in './doc/' (pdt_fifo_add.sh,
92
+       pdt_fifo_delete.sh, pdt_fifo_list.sh).
90 93
      _________________________________________________________
91 94
 
92 95
 1.2. Dependencies
... ...
@@ -95,7 +100,7 @@ domain[3330]=iptel.org
95 95
 
96 96
    The following modules must be loaded before this module:
97 97
 
98
-     * A SER database module.
98
+     * A SER database module (e.g., mysql, dbtext).
99 99
      _________________________________________________________
100 100
 
101 101
 1.2.2. External Libraries or Applications
... ...
@@ -117,7 +122,7 @@ domain[3330]=iptel.org
117 117
 
118 118
    Example 1-2. Set db_url parameter
119 119
 ...
120
-modparam("pdt", "param_name", "param_value")
120
+modparam("pdt", "db_url", "mysql://user:xxx@127.0.0.1/ser")
121 121
 ...
122 122
      _________________________________________________________
123 123
 
... ...
@@ -125,51 +130,51 @@ modparam("pdt", "param_name", "param_value")
125 125
 
126 126
    Table name.
127 127
 
128
-   Default value is "domains". 
128
+   Default value is "prefix_domain". 
129 129
 
130 130
    Example 1-3. Set db_table parameter
131 131
 ...
132
-modparam("pdt", "db_table", "domains")
132
+modparam("pdt", "db_table", "pdt")
133 133
 ...
134 134
      _________________________________________________________
135 135
 
136
-1.3.3. terminator (integer)
136
+1.3.3. prefix_column (string)
137 137
 
138
-   The digit ending a code.
138
+   Name of 'prefix' column.
139 139
 
140
-   Default value is 0. 
140
+   Default value is "prefix". 
141 141
 
142
-   Example 1-4. Set terminator parameter
142
+   Example 1-4. Set prefix_column parameter
143 143
 ...
144
-modparam("pdt", "terminator", 1)
144
+modparam("pdt", "prefix_column", "code")
145 145
 ...
146 146
      _________________________________________________________
147 147
 
148
-1.3.4. start_range (integer)
148
+1.3.4. domain_column (string)
149 149
 
150
-   Default start value for allocating prefixes.
150
+   Name of 'domain' column.
151 151
 
152
-   Default value is 10. 
152
+   Default value is "domain". 
153 153
 
154
-   Example 1-5. Set start_range parameter
154
+   Example 1-5. Set domain_column parameter
155 155
 ...
156
-modparam("pdt", "start_range", 10)
156
+modparam("pdt", "domain_column", "hostname")
157 157
 ...
158 158
      _________________________________________________________
159 159
 
160 160
 1.3.5. prefix (string)
161 161
 
162
-   Default prefix who denotes what URI needs to be translated--if
163
-   it is NULL the module will not check the R-URI against it and
164
-   the code is considered starting from the first digit.
165
-   Otherwise, the module will check first if the R-URI starts
166
-   with it and will skip it to find the code.
162
+   Default leading prefix who denotes what URI needs to be
163
+   translated - if it is NULL the module will not check the R-URI
164
+   against it and the PDT prefix is considered starting from the
165
+   first digit. Otherwise, the module will check first if the
166
+   R-URI starts with it and will skip it to look up the domain.
167 167
 
168 168
    Default value is NULL. 
169 169
 
170 170
    Example 1-6. Set prefix parameter
171 171
 ...
172
-modparam("pdt", "prefix", "123")
172
+modparam("pdt", "prefix", "00")
173 173
 ...
174 174
      _________________________________________________________
175 175
 
... ...
@@ -185,16 +190,46 @@ modparam("pdt", "hsize_2pow", 4)
185 185
 ...
186 186
      _________________________________________________________
187 187
 
188
+1.3.7. sync_time (integer)
189
+
190
+   Time in seconds to synchronize the cache of each process with
191
+   the changes made through FIFO. Any prefix-domain change made
192
+   through FIFO is guaranteed to have efect after this period of
193
+   time past.
194
+
195
+   Default value is 600. 
196
+
197
+   Example 1-8. Set sync_time parameter
198
+...
199
+modparam("pdt", "sync_time", 300)
200
+...
201
+     _________________________________________________________
202
+
203
+1.3.8. clean_time (integer)
204
+
205
+   Time in seconds to clean the changes inserted via FIFO. The
206
+   changes will be removed from FIFO diff list only when all SER
207
+   processes applied these changes.
208
+
209
+   Default value is 900. 
210
+
211
+   Example 1-9. Set clean_time parameter
212
+...
213
+modparam("pdt", "clean_time", 600)
214
+...
215
+     _________________________________________________________
216
+
188 217
 1.4. Exported Functions
189 218
 
190 219
 1.4.1. prefix2domain()
191 220
 
192 221
    Build a new URI if it is necessary. Returns 1 when the
193 222
    translation was made or there was nothing to translate (user
194
-   part of the URI is empty or it does not match the prefix
195
-   parameter). Returns -1 in error cases.
223
+   part of the URI is empty, it does not match the prefix
224
+   parameter or there is no domain associated with a possible
225
+   prefix from user part). Returns -1 in error cases.
196 226
 
197
-   Example 1-8. prefix2domain usage
227
+   Example 1-10. prefix2domain usage
198 228
 ...
199 229
 prefix2domain();
200 230
 ...
... ...
@@ -202,49 +237,39 @@ prefix2domain();
202 202
 
203 203
 1.5. Installation & Running
204 204
 
205
-   Notes about installation and running.
205
+   Make sure you have created the table needed by this module.
206 206
      _________________________________________________________
207 207
 
208
-Chapter 2. Developer's Guide
208
+1.5.1. FIFO Commands
209
+
210
+   The modules uses only the cache to look up domains. If you
211
+   want to add or delete a new prefix-domain pair you have to use
212
+   FIFO commands. All changes made via FIFO are applied to
213
+   database. The database is loaded only at SER start up time.
214
+
215
+   There are three FIFO commands to use with PDT.
209 216
 
210
-   The module registers also a function that works with the fifo
211
-   server ( get_domaincode ). That will provide support for a web
212
-   user interface which will be used by admins to register new
213
-   domains and by simple users to find the code for a domain.
214
-
215
-   Registered domains are stored in a database and in tables in
216
-   share memory. The database is kept consistent with the tables
217
-   in memory. When a new domain is registered the information
218
-   goes first in the database and only than in tables in share
219
-   memory.
220
-
221
-   Data in share memory is kept in hashtables to have fast
222
-   searches. Searches are possible for domains, but also for
223
-   codes. Searches for codes are necessary more often, every time
224
-   when a message that needs to be translated passes through SER
225
-   Searches for domains are requested by the user interface only.
226
-
227
-   Through the web interface a normal user can find the code for
228
-   a domain and a privileged user (i.e., admins) can register new
229
-   domains too. The web interface also encounters problems of
230
-   mutual exclusion. Any user of the interface posts a request to
231
-   the fifo server and waits his response in a file. The file
232
-   must be unique per user to avoid interfering responses for
233
-   different simultaneous user. That problem is solved using
234
-   session per user offered by the PHP language.
217
+     * pdt_add - add a new prefix-domain pair
218
+     * pdt_delete - remove a prefix-domain pair
219
+     * pdt_list - list the prefixes and the domains
220
+
221
+   Example shell scripts for these commands are placed in
222
+   './doc/' (pdt_fifo_add.sh, pdt_fifo_delete.sh,
223
+   pdt_fifo_list.sh). More about, in the comments before the
224
+   implementation of the functions, inside the 'pdt.c' file.
235 225
      _________________________________________________________
236 226
 
237
-Chapter 3. Frequently Asked Questions
227
+Chapter 2. Developer's Guide
238 228
 
239
-   3.1. Where can I find more about SER?
240
-   3.2. Where can I post a question about this module?
241
-   3.3. How can I report a bug?
229
+   No function exported for use in another SER module.
230
+     _________________________________________________________
242 231
 
243
-   3.1. Where can I find more about SER?
232
+Chapter 3. Frequently Asked Questions
244 233
 
245
-   Take a look at http://iptel.org/ser.
234
+   3.1. Where can I post a question about this module?
235
+   3.2. How can I report a bug?
246 236
 
247
-   3.2. Where can I post a question about this module?
237
+   3.1. Where can I post a question about this module?
248 238
 
249 239
    First at all check if your question was already answered on
250 240
    one of our mailing lists:
... ...
@@ -257,9 +282,9 @@ Chapter 3. Frequently Asked Questions
257 257
    or CVS snapshots should be send to <serdev@iptel.org>.
258 258
 
259 259
    If you want to keep the mail private, send it to
260
-   <serhelp@iptel.org>.
260
+   <ramona@voice-system.ro>.
261 261
 
262
-   3.3. How can I report a bug?
262
+   3.2. How can I report a bug?
263 263
 
264
-   Please follow the guidelines provided at:
265
-   http://iptel.org/ser/bugs
264
+   Please send a mail to <serdev@iptel.org> or to
265
+   <ramona@voice-system.ro>
... ...
@@ -19,16 +19,16 @@
19 19
 	    <author>
20 20
 		<firstname>Elena-Ramona</firstname>
21 21
 		<surname>Modroiu</surname>
22
-		<affiliation><orgname>&fhg;</orgname></affiliation>
22
+		<affiliation><orgname>Voice-System</orgname></affiliation>
23 23
 		<address>
24
-		    <email>modroiu@fokus.fraunhofer.de</email>
24
+		    <email>ramona@voice-system.ro</email>
25 25
 		</address>
26 26
 	    </author>
27 27
 	    <editor>
28 28
 		<firstname>Elena-Ramona</firstname>
29 29
 		<surname>Modroiu</surname>
30 30
 		<address>
31
-		    <email>modroiu@fokus.fraunhofer.de</email>
31
+		    <email>ramona@voice-system.ro</email>
32 32
 		</address>
33 33
 	    </editor>
34 34
 	</authorgroup>
... ...
@@ -7,8 +7,8 @@ CREATE DATABASE pdt;
7 7
 USE pdt;
8 8
 
9 9
 -- create table
10
-CREATE TABLE domains(
11
-	code INTEGER NOT NULL PRIMARY KEY,
10
+CREATE TABLE prefix_domain (
11
+	prefix VARCHAR(32) NOT NULL PRIMARY KEY,
12 12
 	domain VARCHAR(255) NOT NULL DEFAULT ""
13 13
 );
14 14
 
... ...
@@ -11,29 +11,8 @@
11 11
     </chapterinfo>
12 12
     <title>Developer's Guide</title>
13 13
     <para>
14
-	The module registers also a function that works with the fifo server ( get_domaincode ).
15
-	That will provide support for a web user interface which will be used by admins to register
16
-	new domains and by simple users to find the code for a domain.
17
-    </para>
18
-    <para>
19
-	Registered domains are stored in a database and in tables in share memory. The database is
20
-	kept consistent with the tables in memory. When a new domain is registered the information
21
-	goes first in the database and only than in tables in share memory.
22
-    </para>
23
-    <para>
24
-	Data in share memory is kept in hashtables to have fast searches. Searches are 
25
-	possible for domains, but also for codes. Searches for codes are necessary more 
26
-	often, every time when a message that needs to be translated passes through &ser;
27
-	Searches for domains are requested by the user interface only.
28
-    </para>
29
-    <para>
30
-	Through the web interface a normal user can find the code for a domain and a privileged user
31
-	(i.e., admins) can register new domains too. The web interface also encounters problems of
32
-	mutual exclusion. Any user of the interface posts a request to the fifo server and waits his
33
-	response in a file. The file must be unique per user to avoid interfering responses for
34
-	different simultaneous user. That problem is solved using session per user offered by the
35
-	<acronym>PHP</acronym> language.
36
-    </para>
14
+	No function exported for use in another SER module.
15
+	</para>
37 16
 </chapter>
38 17
 
39 18
 <!-- Keep this element at the end of the file
... ...
@@ -13,16 +13,6 @@
13 13
     <qandaset defaultlabel="number">
14 14
 	<qandaentry>
15 15
 	    <question>
16
-		<para>Where can I find more about &ser;?</para>
17
-	    </question>
18
-	    <answer>
19
-		<para>
20
-		    Take a look at &serhomelink;.
21
-		</para>
22
-	    </answer>
23
-	</qandaentry>
24
-	<qandaentry>
25
-	    <question>
26 16
 		<para>Where can I post a question about this module?</para>
27 17
 	    </question>
28 18
 	    <answer>
... ...
@@ -39,11 +29,13 @@
39 39
 		    </listitem>
40 40
 		</itemizedlist>
41 41
 		<para>
42
-		    E-mails regarding any stable version should be sent to &serusersmail; and e-mail
43
-		    regarding development versions or CVS snapshots should be send to &serdevmail;.
42
+		    E-mails regarding any stable version should be sent to
43
+			&serusersmail; and e-mail regarding development versions or CVS
44
+			snapshots should be send to &serdevmail;.
44 45
 		</para>
45 46
 		<para>
46
-		    If you want to keep the mail private, send it to &serhelpmail;.
47
+		    If you want to keep the mail private, send it to 
48
+			<email>ramona@voice-system.ro</email>.
47 49
 		</para>
48 50
 	    </answer>
49 51
 	</qandaentry>
... ...
@@ -53,7 +45,8 @@
53 53
 	    </question>
54 54
 	    <answer>
55 55
 		<para>
56
-		    Please follow the guidelines provided at: &serbugslink;
56
+		    Please send a mail to &serdevmail; or to 
57
+			<email>ramona@voice-system.ro</email>
57 58
 		</para>
58 59
 	    </answer>
59 60
 	</qandaentry>
60 61
new file mode 100755
... ...
@@ -0,0 +1,7 @@
0
+cat /tmp/ser_reply &
1
+cat > /tmp/ser_fifo << EOF
2
+:pdt_add:ser_reply
3
+55
4
+123.com
5
+
6
+EOF
0 7
new file mode 100755
... ...
@@ -0,0 +1,6 @@
0
+cat /tmp/ser_reply &
1
+cat > /tmp/ser_fifo << EOF
2
+:pdt_delete:ser_reply
3
+123.com
4
+
5
+EOF
0 6
new file mode 100755
... ...
@@ -0,0 +1,7 @@
0
+cat /tmp/ser_reply &
1
+cat > /tmp/ser_fifo << EOF
2
+:pdt_list:ser_reply
3
+1
4
+.
5
+
6
+EOF
... ...
@@ -14,16 +14,18 @@
14 14
     <section>
15 15
 	<title>Overview</title>
16 16
 	<para>
17
-	    This module translates numerical codes into domains and update accordingly the R-&uri;.
17
+	    This module translates a numerical prefix into a domain and updates
18
+		accordingly the request &uri;.
18 19
 	</para>
19 20
 	<para>
20
-	    The module looks up at the R-&uri; part of a message and if the user part begins with an
21
-	    established prefix it will update the &uri;. Updating the uri consists of: read the code
22
-	    after the prefix from the user part of the uri and keep the rest as the user part of the
23
-	    new uri. The host part will be the domain matched for the leading code.
21
+	    The module looks up at the R-&uri; part of a message and if the user
22
+		part begins with an established prefix it will update the &uri;.
23
+		Updating the uri consists of: remove the prefix from the user part of
24
+		the uri and keep the rest as the user part of the new uri. The host
25
+		and port are changed with the domain matched for the leading prefix.
24 26
 	</para>
25 27
 	<para>
26
-	    [&lt;prefix&gt;]&lt;code&gt;&lt;userid&gt;&lt;:password&gt;@&lt;mydomain.com&gt; ...
28
+	    &lt;prefix&gt;&lt;userid&gt;&lt;:password&gt;@&lt;mydomain.com&gt; ...
27 29
 	</para>
28 30
 	<para>
29 31
 	    and the result will be:
... ...
@@ -32,34 +34,31 @@
32 32
 	    &lt;userid&gt;&lt;:password&gt;@&lt;domain[:port]&gt;...
33 33
 	</para>
34 34
 	<example>
35
-	    <title></title>
35
+	    <title>prefix-domain translation</title>
36 36
 	    <programlisting format="linespecific">
37
-prefix=2
38
-code=3330
39
-domain[3330]=iptel.org
37
+prefix=123
38
+domain[123]=alpha.org
40 39
 
41
-2333091001@mydomain.com  => 91001@iptel.org    
40
+sip:12391001@mydomain.com  => sip:91001@alpha.org    
42 41
 </programlisting>
43 42
 	</example>
44 43
 	<para>
45
-	    The code is always ended with a special digit (a parameter of the module). This digit
46
-	    will not be inside the code at all.
44
+	    The prefix could be prefixed by other digits. These digits
45
+	    will not be used to look up the domain (the classic example, 00 used
46
+		for international calls, then follows the country prefix). For more
47
+		information on this, see 'prefix' parameter.
47 48
 	</para>
48 49
 	<itemizedlist>
49 50
 	    <listitem>
50 51
 		<para>
51
-		    See <acronym>SQL</acronym> script for creating databases and a sample of cfg file in './doc/'.
52
+		    A sample config file and the <acronym>MySQL</acronym> script to
53
+			create the database needed by PDT are located in './doc/'.
52 54
 		</para>
53 55
 	    </listitem>
54 56
 	    <listitem>
55 57
 		<para>
56
-		    The web interface is in doc/web/ and the <acronym>SQL</acronym> script for
57
-		    creating the database for user interface is './doc/admin.sql'.
58
-		</para>
59
-	    </listitem>
60
-	    <listitem>
61
-		<para>
62
-		    Sample shell script to use with fifo interface is './doc/fifo.sh'.
58
+		    Sample shell scripts to manage prefix-domain pairs are also located
59
+			in './doc/' (pdt_fifo_add.sh, pdt_fifo_delete.sh, pdt_fifo_list.sh).
63 60
 		</para>
64 61
 	    </listitem>
65 62
 	</itemizedlist>
... ...
@@ -73,7 +72,8 @@ domain[3330]=iptel.org
73 73
 	    	<itemizedlist>
74 74
 		    <listitem>
75 75
 			<para>
76
-			    <emphasis>A &ser; database module</emphasis>.
76
+			    <emphasis>A &ser; database module (e.g., mysql,
77
+				dbtext)</emphasis>.
77 78
 			</para>
78 79
 		    </listitem>
79 80
 	    	</itemizedlist>
... ...
@@ -99,8 +99,8 @@ domain[3330]=iptel.org
99 99
 	<section>
100 100
 	    <title><varname>db_url</varname> (string)</title>
101 101
 	    <para>
102
-		<acronym>SQL</acronym> &url; of database--username, password, host, port and
103
-		database (ex: mysql://username:password@hostname.com/database)
102
+		<acronym>SQL</acronym> &url; of database--username, password, host,
103
+		port and database (ex: mysql://username:password@hostname.com/database)
104 104
 	    </para>
105 105
 	    <para>
106 106
 		<emphasis>
... ...
@@ -111,7 +111,7 @@ domain[3330]=iptel.org
111 111
 		<title>Set <varname>db_url</varname> parameter</title>
112 112
 		<programlisting format="linespecific">
113 113
 ...
114
-modparam("pdt", "param_name", "param_value")
114
+modparam("pdt", "db_url", "mysql://user:xxx@127.0.0.1/ser")
115 115
 ...
116 116
 </programlisting>
117 117
 	    </example>
... ...
@@ -124,54 +124,54 @@ modparam("pdt", "param_name", "param_value")
124 124
 	    </para>
125 125
 	    <para>
126 126
 		<emphasis>
127
-		    Default value is <quote>domains</quote>.
127
+		    Default value is <quote>prefix_domain</quote>.
128 128
 		</emphasis>
129 129
 	    </para>
130 130
 	    <example>
131 131
 		<title>Set <varname>db_table</varname> parameter</title>
132 132
 		<programlisting format="linespecific">
133 133
 ...
134
-modparam("pdt", "db_table", "domains")
134
+modparam("pdt", "db_table", "pdt")
135 135
 ...
136 136
 </programlisting>
137 137
 	    </example>
138 138
 	</section>
139 139
 
140 140
 	<section>
141
-	    <title><varname>terminator</varname> (integer)</title>
141
+	    <title><varname>prefix_column</varname> (string)</title>
142 142
 	    <para>
143
-		The digit ending a code.
143
+		Name of 'prefix' column.
144 144
 	    </para>
145 145
 	    <para>
146 146
 		<emphasis>
147
-		    Default value is 0.
147
+		    Default value is <quote>prefix</quote>.
148 148
 		</emphasis>
149 149
 	    </para>
150 150
 	    <example>
151
-		<title>Set <varname>terminator</varname> parameter</title>
151
+		<title>Set <varname>prefix_column</varname> parameter</title>
152 152
 		<programlisting format="linespecific">
153 153
 ...
154
-modparam("pdt", "terminator", 1)
154
+modparam("pdt", "prefix_column", "code")
155 155
 ...
156 156
 </programlisting>
157 157
 	    </example>
158 158
 	</section>
159 159
 
160 160
 	<section>
161
-	    <title><varname>start_range</varname> (integer)</title>
161
+	    <title><varname>domain_column</varname> (string)</title>
162 162
 	    <para>
163
-		Default start value for allocating prefixes.
163
+		Name of 'domain' column.
164 164
 	    </para>
165 165
 	    <para>
166 166
 		<emphasis>
167
-		    Default value is 10.
167
+		    Default value is <quote>domain</quote>.
168 168
 		</emphasis>
169 169
 	    </para>
170 170
 	    <example>
171
-		<title>Set <varname>start_range</varname> parameter</title>
171
+		<title>Set <varname>domain_column</varname> parameter</title>
172 172
 		<programlisting format="linespecific">
173 173
 ...
174
-modparam("pdt", "start_range", 10)
174
+modparam("pdt", "domain_column", "hostname")
175 175
 ...
176 176
 </programlisting>
177 177
 	    </example>
... ...
@@ -180,10 +180,11 @@ modparam("pdt", "start_range", 10)
180 180
 	<section>
181 181
 	    <title><varname>prefix</varname> (string)</title>
182 182
 	    <para>
183
-		Default prefix who denotes what &uri; needs to be translated--if it is NULL the
184
-		module will not check the R-&uri; against it and the code is considered starting
185
-		from the first digit. Otherwise, the module will check first if the R-&uri; starts
186
-		with it and will skip it to find the code.
183
+		Default leading prefix who denotes what &uri; needs to be translated
184
+		- if it is NULL the module will not check the R-&uri; against it and
185
+		the PDT prefix is considered starting from the first digit. Otherwise,
186
+		the module will check first if the R-&uri; starts with it and will
187
+		skip it to look up the domain.
187 188
 	    </para>
188 189
 	    <para>
189 190
 		<emphasis>
... ...
@@ -194,7 +195,7 @@ modparam("pdt", "start_range", 10)
194 194
 		<title>Set <varname>prefix</varname> parameter</title>
195 195
 		<programlisting format="linespecific">
196 196
 ...
197
-modparam("pdt", "prefix", "123")
197
+modparam("pdt", "prefix", "00")
198 198
 ...
199 199
 </programlisting>
200 200
 	    </example>
... ...
@@ -220,6 +221,50 @@ modparam("pdt", "hsize_2pow", 4)
220 220
 	    </example>
221 221
 	</section>
222 222
 
223
+	<section>
224
+	    <title><varname>sync_time</varname> (integer)</title>
225
+	    <para>
226
+		Time in seconds to synchronize the cache of each process with the
227
+		changes made through FIFO. Any prefix-domain change made through FIFO
228
+		is guaranteed to have efect after this period of time past.
229
+		</para>
230
+	    <para>
231
+		<emphasis>
232
+		    Default value is 600.
233
+		</emphasis>
234
+	    </para>
235
+	    <example>
236
+		<title>Set <varname>sync_time</varname> parameter</title>
237
+		<programlisting format="linespecific">
238
+...
239
+modparam("pdt", "sync_time", 300)
240
+...
241
+</programlisting>
242
+	    </example>
243
+	</section>
244
+
245
+	<section>
246
+	    <title><varname>clean_time</varname> (integer)</title>
247
+	    <para>
248
+		Time in seconds to clean the changes inserted via FIFO. The changes
249
+		will be removed from FIFO diff list only when all SER processes applied
250
+		these changes.
251
+		</para>
252
+	    <para>
253
+		<emphasis>
254
+		    Default value is 900.
255
+		</emphasis>
256
+	    </para>
257
+	    <example>
258
+		<title>Set <varname>clean_time</varname> parameter</title>
259
+		<programlisting format="linespecific">
260
+...
261
+modparam("pdt", "clean_time", 600)
262
+...
263
+</programlisting>
264
+	    </example>
265
+	</section>
266
+
223 267
     </section>
224 268
     <section>
225 269
 	<title>Exported Functions</title>
... ...
@@ -228,9 +273,11 @@ modparam("pdt", "hsize_2pow", 4)
228 228
 		<function moreinfo="none">prefix2domain()</function>
229 229
 	    </title>
230 230
 	    <para>
231
-		Build a new &uri; if it is necessary. Returns 1 when the translation was made or there
232
-		was nothing to translate (user part of the &uri; is empty or it does not match the
233
-		prefix parameter). Returns -1 in error cases.
231
+		Build a new &uri; if it is necessary. Returns 1 when the translation
232
+		was made or there was nothing to translate (user part of the &uri; is
233
+		empty, it does not match the prefix parameter or there is no domain
234
+		associated with a possible prefix from user part).
235
+		Returns -1 in error cases.
234 236
 	    </para>
235 237
 	    <example>
236 238
 		<title><function>prefix2domain</function> usage</title>
... ...
@@ -244,7 +291,42 @@ prefix2domain();
244 244
     </section>
245 245
     <section>
246 246
 	<title>Installation & Running</title>
247
-	<para>Notes about installation and running.</para>
247
+	<para>Make sure you have created the table needed by this module.</para>
248
+		<section>
249
+		<title>FIFO Commands</title>
250
+		<para>
251
+		The modules uses only the cache to look up domains. If you want to
252
+		add or delete a new prefix-domain pair you have to use FIFO commands.
253
+		All changes made via FIFO are applied to database. The database is
254
+		loaded only at SER start up time.
255
+		</para>
256
+		<para>
257
+		There are three FIFO commands to use with PDT.
258
+		</para>
259
+		<itemizedlist>
260
+	    <listitem>
261
+		<para>
262
+		    pdt_add - add a new prefix-domain pair
263
+		</para>
264
+	    </listitem>
265
+	    <listitem>
266
+		<para>
267
+		    pdt_delete - remove a prefix-domain pair
268
+		</para>
269
+	    </listitem>
270
+	    <listitem>
271
+		<para>
272
+		    pdt_list - list the prefixes and the domains
273
+		</para>
274
+	    </listitem>
275
+		</itemizedlist>
276
+		<para>
277
+		Example shell scripts for these commands are placed in './doc/'
278
+		(pdt_fifo_add.sh, pdt_fifo_delete.sh, pdt_fifo_list.sh). More about,
279
+		in the comments before the implementation of the functions, inside
280
+		the 'pdt.c' file.
281
+		</para>
282
+		</section>
248 283
     </section>
249 284
 </chapter>
250 285
 
... ...
@@ -1,4 +1,6 @@
1 1
 /**
2
+ * $Id$
3
+ *
2 4
  * Copyright (C) 2001-2003 FhG Fokus
3 5
  *
4 6
  * This file is part of ser, a free SIP server.
... ...
@@ -27,6 +29,9 @@
27 27
   * History
28 28
   * -------
29 29
   * 2003-04-07: a structure for both hashes introduced (ramona)
30
+  * 2005-01-26: double hash removed (ramona)
31
+  *             FIFO operations are kept as a diff list (ramona)
32
+  *             domain hash kept in share memory along with FIFO ops (ramona)
30 33
   * 
31 34
   */
32 35
 
... ...
@@ -42,99 +47,128 @@
42 42
 
43 43
 #include "domains.h"
44 44
 
45
-#define get_hash_entry(c,s) (c)&((s)-1)
45
+pd_op_t* new_pd_op(pd_t *cell, int id, int op)
46
+{
47
+	pd_op_t *pdo;
48
+	
49
+	if(cell==NULL)
50
+	{
51
+		LOG(L_ERR, "PDT:new_pd_op: bad parameters\n");
52
+		return NULL;
53
+	}
54
+	
55
+	pdo = (pd_op_t*)shm_malloc(sizeof(pd_op_t));
56
+	if(pdo==NULL)
57
+	{
58
+		LOG(L_ERR, "PDT:new_pd_op: no more shm\n");
59
+		return NULL;
60
+	}
61
+	memset(pdo, 0, sizeof(pd_op_t));
62
+	pdo->cell = cell;
63
+	pdo->id = id;
64
+	pdo->op = op;
65
+
66
+	return pdo;
67
+}
68
+
69
+void free_pd_op(pd_op_t *pdo)
70
+{
71
+	if(pdo==NULL)
72
+		return;
73
+	free_cell(pdo->cell);
74
+	shm_free(pdo);
75
+	pdo = NULL;
76
+
77
+	return;
78
+}
46 79
 
47
-/* return a new cell stored in share memory for this domain */
48
-dc_t* new_cell(char* domain, code_t code)
80
+pd_t* new_cell(str* p, str *d)
49 81
 {
50
-	dc_t* cell = NULL; 
82
+	pd_t* cell = NULL; 
51 83
 	
52
-	if(!domain)
84
+	if(p==NULL || p->s==NULL || d==NULL || d->s==NULL)
85
+	{
86
+		LOG(L_ERR, "PDT:new_cell: bad parameters\n");
53 87
 		return NULL;
88
+	}
54 89
 	
55 90
 	/* the cell is in share memory */
56
-	cell = (dc_t*)shm_malloc(sizeof(dc_t));
91
+	cell = (pd_t*)shm_malloc(sizeof(pd_t));
57 92
     
58 93
 	/* if there is no space return just NULL */
59
-	if(!cell)
94
+	if(cell==NULL)
95
+	{
96
+		LOG(L_ERR, "PDT:new_cell: no more shm memory.\n");
60 97
 		return NULL;
98
+	}
99
+	memset(cell, 0, sizeof(pd_t));
61 100
 	
62
-	/* otherwise, fill in the structure fields */
63
-	/* domain name */
64
-	cell->domain = (char*)shm_malloc((1+strlen(domain))*sizeof(char));
65
-	strcpy(cell->domain, domain);
101
+	cell->prefix.s = (char*)shm_malloc((1+p->len)*sizeof(char));
102
+	if(cell->prefix.s==NULL)
103
+	{
104
+		shm_free(cell);
105
+		LOG(L_ERR, "PDT:new_cell: no more shm memory\n");
106
+		return NULL;
107
+	}
108
+	strncpy(cell->prefix.s, p->s, p->len);
109
+	cell->prefix.len = p->len;
110
+	cell->prefix.s[p->len] = '\0';
66 111
 
67
-	/* domain code */
68
-	cell->code = code; 
112
+	cell->domain.s = (char*)shm_malloc((1+d->len)*sizeof(char));
113
+	if(cell->domain.s==NULL)
114
+	{
115
+		shm_free(cell->prefix.s);
116
+		shm_free(cell);
117
+		LOG(L_ERR, "PDT:new_cell: no more shm memory!\n");
118
+		return NULL;
119
+	}
120
+	strncpy(cell->domain.s, d->s, d->len);
121
+	cell->domain.len = d->len;
122
+	cell->domain.s[d->len] = '\0';
69 123
 
70
-	cell->dhash = compute_hash(domain);
124
+	cell->dhash = pdt_compute_hash(cell->domain.s);
71 125
     
72 126
 	/* return the newly allocated in share memory cell */
73 127
 	return cell;
74 128
 }
75 129
 
76
-void free_cell(dc_t* cell)
130
+void free_cell(pd_t* cell)
77 131
 {
78
-	/* if it is not already NULL */
79
-	if(!cell)
132
+	if(cell==NULL)
80 133
 		return;	
81 134
 	
82
-	if(cell->domain)
83
-		shm_free(cell->domain);
135
+	if(cell->prefix.s)
136
+		shm_free(cell->prefix.s);
137
+
138
+	if(cell->domain.s)
139
+		shm_free(cell->domain.s);
84 140
 		
85
-	/* free the memory */
86 141
 	shm_free(cell);
87 142
 }
88 143
 
89
-entry_t* new_entry(dc_t* cell)
90
-{
91
-    entry_t* e = NULL;
92
-
93
-    if(!cell)
94
-	return NULL;
95
-    
96
-    e = (entry_t*)shm_malloc(sizeof(entry_t));
97
-    if(!e)
98
-	return NULL;        
99
-
100
-    e->dc = cell;
101
-    e->p = NULL;
102
-    e->n = NULL;
103
-
104
-    /* return the newly allocated in share memory entry */
105
-    return e;
106
-}
107
-
108
-/* free allocated space for an entry */
109
-void free_entry(entry_t *e, int erase_cell)
110
-{
111
-	if(!e)
112
-		return;
113
-	
114
-	if(erase_cell && e->dc)
115
-		free_cell(e->dc);
116
-	
117
-	shm_free(e);
118
-}
119
-
120 144
 /* returns a pointer to a hashtable */
121
-h_entry_t* init_hash(unsigned int hash_size)
145
+pd_entry_t* init_hash(unsigned int hash_size)
122 146
 {
123 147
 	int i, j;
124
-	
125
-	/* initialized to NULL */
126
-	h_entry_t *hash = NULL; 
148
+	pd_entry_t *hash = NULL; 
127 149
 
128 150
 	/* space for the hash is allocated in share memory */
129
-	hash = (h_entry_t*)shm_malloc(hash_size*sizeof(h_entry_t));
151
+	hash = (pd_entry_t*)shm_malloc(hash_size*sizeof(pd_entry_t));
130 152
 	if(hash == NULL)
153
+	{
154
+		LOG(L_ERR, "PDT:init_hash: no more shm\n");
131 155
 		return NULL;
156
+	}
157
+	memset(hash, 0, hash_size*sizeof(pd_entry_t));
132 158
 
133 159
 	/* create mutex semaphores for each entry of the hash */
134 160
 	for(i=0; i<hash_size; i++)
135 161
 	{
136 162
 		if(lock_init(&hash[i].lock) == 0)
163
+		{
164
+			LOG(L_ERR, "PDT:init_hash: cannot init the lock\n");
137 165
 			goto error;
166
+		}
138 167
 	
139 168
 		hash[i].e = NULL;
140 169
 	}
... ...
@@ -152,9 +186,9 @@ error:
152 152
 }
153 153
 
154 154
 
155
-double_hash_t* init_double_hash(int hs_two_pow)
155
+pdt_hash_t* pdt_init_hash(int hs_two_pow)
156 156
 {
157
-	double_hash_t* hash = NULL;
157
+	pdt_hash_t* hash = NULL;
158 158
 	int hash_size;
159 159
 
160 160
 	if(hs_two_pow>MAX_HSIZE_TWO_POW || hs_two_pow<0)
... ...
@@ -164,305 +198,274 @@ double_hash_t* init_double_hash(int hs_two_pow)
164 164
 
165 165
 
166 166
 	/* space for the double_hash is allocated in share memory */
167
-	hash = (double_hash_t*)shm_malloc(sizeof(double_hash_t));
167
+	hash = (pdt_hash_t*)shm_malloc(sizeof(pdt_hash_t));
168 168
 	if(hash == NULL)
169
+	{
170
+		LOG(L_ERR, "PDT:pdt_init_hash: no more shm\n");
169 171
 		return NULL;
172
+	}
170 173
 
171
-	if( (hash->dhash = init_hash(hash_size)) == NULL )
174
+	if(lock_init(&hash->diff_lock) == 0)
172 175
 	{
173 176
 		shm_free(hash);
177
+		LOG(L_ERR, "PDT:pdt_init_hash: cannot init the diff lock\n");
174 178
 		return NULL;
175 179
 	}
176 180
 	
177
-	if( (hash->chash = init_hash(hash_size)) == NULL )
181
+	if( (hash->dhash = init_hash(hash_size)) == NULL )
178 182
 	{
179
-		free_hash(hash->dhash, hash_size, ERASE_CELL);
183
+		lock_destroy(&hash->diff_lock);
180 184
 		shm_free(hash);
185
+		LOG(L_ERR, "PDT:pdt_init_hash: no more shm!\n");
181 186
 		return NULL;
182 187
 	}
183
-
188
+	
184 189
 	hash->hash_size = hash_size;
185 190
 
186 191
 	return hash;
187 192
 }
188 193
 
189 194
 
190
-void free_hash(h_entry_t* hash, unsigned int hash_size, int do_cell)
195
+void free_hash(pd_entry_t* hash, unsigned int hash_size)
191 196
 {
192
-    int   i;   /* index for hash entries */
193
-    entry_t *tmp, /* just a temporary variable */
194
-			*it;  /* iterator through cells of a has entry */
195
-    if(!hash || hash_size<=0)
197
+    int   i;
198
+    pd_t *tmp, *it;
199
+    if(hash==NULL || hash_size<=0)
196 200
 		return;
197 201
     
198
-	/* free memory occupied by all hash entries */
199 202
 	for(i=0; i<hash_size; i++)
200 203
 	{
201
-		/* iterator through the i-th entry of the hash */
202 204
 		it = hash[i].e;
203
-		
204
-		/* as long as we have a cell */
205 205
 		while(it != NULL)
206 206
 		{
207
-			/* retains the next cell */
208 207
 	    	tmp = it->n;
209
-			free_entry(it, do_cell);
210
-			/* the iterator points up to the next cell */
208
+			free_cell(it);
211 209
 			it = tmp;
212 210
 		}
213 211
 		lock_destroy(&hash[i].lock);
214 212
     }
215
-
216 213
 	shm_free(hash);
217 214
 }
218 215
 
219
-void free_double_hash(double_hash_t* hash)
216
+void pdt_free_hash(pdt_hash_t* hash)
220 217
 {
221
-	free_hash(hash->dhash, hash->hash_size, ERASE_CELL);	
222
-	free_hash(hash->chash, hash->hash_size, NOT_ERASE_CELL);
223
-	shm_free(hash);
224
-}
225
-
226
-int add_to_double_hash(double_hash_t* hash, dc_t* cell)
227
-{
228
-	if(add_to_hash(hash->dhash, hash->hash_size, cell, DHASH)<0)
229
-		return -1;
218
+	free_hash(hash->dhash, hash->hash_size);	
219
+	lock_destroy(&hash->diff_lock);
230 220
 	
231
-	if(add_to_hash(hash->chash, hash->hash_size, cell, CHASH)<0)
232
-	{
233
-		remove_from_hash(hash->dhash, hash->hash_size, cell, DHASH);
234
-		return -1;
235
-	}	
221
+	/* todo: destroy diff list */
236 222
 	
237
-	return 0;
223
+	shm_free(hash);
238 224
 }
239 225
 
240
-int add_to_hash(h_entry_t* hash, unsigned int hash_size, dc_t* cell, int type)
226
+int pdt_add_to_hash(pdt_hash_t *hash, str *sp, str *sd)
241 227
 {
242 228
 	int hash_entry=0;
243
-	entry_t *it, *tmp;
244
-	entry_t * e;
229
+	unsigned int dhash;
230
+	pd_t *it, *tmp;
231
+	pd_t *cell;
245 232
 	
246
-	if(!hash || !cell || hash_size>MAX_HASH_SIZE)
233
+	if(hash==NULL || sp==NULL || sd==NULL)
234
+	{
235
+		LOG(L_ERR, "PDT:pdt_add_to_hash: bad parameters\n");
247 236
 		return -1;
237
+	}
248 238
     
249
-	/* find the list where we have to introduce the new cell */
250
-	if(type==DHASH)
251
-		hash_entry = get_hash_entry(cell->dhash, hash_size);
252
-	else 
253
-	if(type==CHASH)
254
-		hash_entry = get_hash_entry(cell->code, hash_size);
255
-	else
256
-		return -1;	
239
+	dhash = pdt_compute_hash(sd->s);
240
+	hash_entry = get_hash_entry(dhash, hash->hash_size);
257 241
 
258
-
259
-	lock_get(&hash[hash_entry].lock);
242
+	lock_get(&hash->dhash[hash_entry].lock);
260 243
 	
261
-	/* first element of the list */	
262
-	it = hash[hash_entry].e;
244
+	it = hash->dhash[hash_entry].e;
263 245
 
264
-	/* find the place where to insert the new cell */
265
-	/* a double linked list in the hash is kept alphabetically
266
-	 * or numerical ordered */    
267
-	if(type==DHASH)
268
-	{		
269
-		tmp = NULL;
270
-		while(it!=NULL && it->dc->dhash < cell->dhash)
271
-		{
272
-			tmp = it;
273
-			it = it->n;
274
-		}
275
-	}
276
-	else
246
+	tmp = NULL;
247
+	while(it!=NULL && it->dhash < dhash)
277 248
 	{
278
-		tmp = NULL;
279
-		while( it!=NULL && it->dc->code < cell->code )
280
-		{
281
-			tmp = it;
282
-			it = it->n;
283
-		}
249
+		tmp = it;
250
+		it = it->n;
284 251
 	}
285 252
     
286 253
 	/* we need a new entry for this cell */
287
-	e = new_entry(cell);	
288
-	if(e == NULL)
254
+	cell = new_cell(sp, sd);	
255
+	if(cell == NULL)
289 256
 	{
290
-		lock_release(&hash[hash_entry].lock);
257
+		lock_release(&hash->dhash[hash_entry].lock);
291 258
 		return -1;
292 259
 	}
293 260
 	
294 261
 
295 262
 	if(tmp)
296
-		tmp->n=e;
263
+		tmp->n=cell;
297 264
 	else
298
-		hash[hash_entry].e = e;
265
+		hash->dhash[hash_entry].e = cell;
299 266
 	
300
-	e->p=tmp;
301
-	e->n=it;
267
+	cell->p=tmp;
268
+	cell->n=it;
302 269
 	
303 270
 	if(it)
304
-	it->p=e;
271
+		it->p=cell;
305 272
 
306
-	lock_release(&hash[hash_entry].lock);
273
+	lock_release(&hash->dhash[hash_entry].lock);
307 274
 
308 275
 	return 0;
309 276
 }
310 277
 
311
-int remove_from_double_hash(double_hash_t* hash, dc_t* cell)
278
+int pdt_remove_from_hash(pdt_hash_t *hash, str *sd)
312 279
 {
313
-	if(!cell)
280
+	int hash_entry=0;
281
+	unsigned int dhash;
282
+	pd_t *it, *tmp;
283
+
284
+	if(sd==NULL)
314 285
 		return 0;	
315 286
 		
316
-	if(!hash)
317
-		return -1;	
318
-
319
-	/* DHASH frees the memory of cell */
320
-	remove_from_hash(hash->dhash, hash->hash_size, cell, DHASH);
321
-	remove_from_hash(hash->chash, hash->hash_size, cell, CHASH);
322
-
323
-	return 0;	
324
-}
325
-
326
-int remove_from_hash(h_entry_t* hash, unsigned int hash_size, dc_t* cell, int type)
327
-{
328
-	int hash_entry=0;
329
-	entry_t *it, *tmp;
330
-	
331
-	if(!cell)
332
-		return 0;
333
-	
334
-	if(!hash) 
287
+	if(hash==NULL)
288
+	{
289
+		LOG(L_ERR, "PDT:pdt_remove_from_hash: bad parameters\n");
335 290
 		return -1;
336
-    
291
+	}
292
+	
337 293
 	/* find the list where the cell must be */
338
-	if(type==DHASH)
339
-		hash_entry = get_hash_entry(cell->dhash, hash_size);
340
-	else 
341
-		if(type==CHASH)
342
-			hash_entry = get_hash_entry(cell->code, hash_size);
343
-	else
344
-		return -1;	
294
+	dhash = pdt_compute_hash(sd->s);
295
+	hash_entry = get_hash_entry(dhash, hash->hash_size);
345 296
 
346 297
 
347
-	lock_get(&hash[hash_entry].lock);
298
+	lock_get(&hash->dhash[hash_entry].lock);
348 299
 	
349 300
 	/* first element of the list */	
350
-	it = hash[hash_entry].e;
301
+	it = hash->dhash[hash_entry].e;
351 302
 
352 303
 	/* find the cell in the list */
353 304
 	/* a double linked list in the hash is kept alphabetically
354 305
 	* or numerical ordered */    
355 306
 	tmp = NULL;
356
-	while(it!=NULL && it->dc != cell)
307
+	while(it!=NULL)
357 308
 	{
309
+		if( it->dhash==dhash && it->domain.len==sd->len
310
+				&& strncasecmp(it->domain.s, sd->s, sd->len)==0)
311
+			break;
358 312
 		tmp = it;
359 313
 		it = it->n;
360 314
 	}
361 315
 	
362
-	if(it)
316
+	if(it!=NULL)
363 317
 	{
364
-		if(tmp)
318
+		if(tmp!=NULL)
365 319
 			tmp->n = it->n;
366 320
 		else
367
-			hash[hash_entry].e = it->n;
321
+			hash->dhash[hash_entry].e = it->n;
368 322
 
369 323
 		if(it->n)
370 324
 			it->n->p = it->p;
371 325
 
372
-		free_entry(it, (type==DHASH?ERASE_CELL:NOT_ERASE_CELL));
326
+		free_cell(it);
373 327
 	}
374 328
 	
375
-	lock_release(&hash[hash_entry].lock);
329
+	lock_release(&hash->dhash[hash_entry].lock);
376 330
 
377 331
 	return 0;
378 332
 }
379 333
 
380
-char* get_domain_from_hash(h_entry_t* hash, unsigned int hash_size, code_t code)
334
+str* pdt_get_prefix(pdt_hash_t *ph, str* sd)
381 335
 {
382 336
 	int hash_entry;
383
-	entry_t* it;
337
+	unsigned int dhash;
338
+	pd_t* it;
384 339
 	
385
-	if(!hash || hash_size>MAX_HASH_SIZE)
340
+	if(ph==NULL || ph->dhash==NULL || ph->hash_size>MAX_HASH_SIZE)
341
+	{
342
+		LOG(L_ERR, "PDT:pdt_get_prefix: bad parameters\n");
386 343
 		return NULL;
387
-	
388
-	/* find out the list in the hash where this code could be */
389
-	hash_entry = get_hash_entry(code, hash_size);
344
+	}
345
+
346
+	dhash = pdt_compute_hash(sd->s);
347
+	hash_entry = get_hash_entry(dhash, ph->hash_size);
390 348
 
391
-	lock_get(&hash[hash_entry].lock);
349
+	lock_get(&ph->dhash[hash_entry].lock);
392 350
 	
393
-	/* parsing the list */
394
-	it = hash[hash_entry].e;
395
-	while(it!=NULL && it->dc->code<code)
396
-			it = it->n;
351
+	it = ph->dhash[hash_entry].e;
352
+	while(it!=NULL && it->dhash<=dhash)
353
+	{
354
+		if(it->dhash==dhash && it->domain.len==sd->len
355
+				&& strncasecmp(it->domain.s, sd->s, sd->len)==0)
356
+		{
357
+			lock_release(&ph->dhash[hash_entry].lock);
358
+			return &it->prefix;
359
+		}
360
+		it = it->n;
361
+	}
397 362
 
398
-	lock_release(&hash[hash_entry].lock);
363
+	lock_release(&ph->dhash[hash_entry].lock);
399 364
 
400
-	/* the code does not exist */	
401
-	if(it==NULL || it->dc->code > code )
402
-		return NULL;
403
-	else
404
-		/* returns the associated domain name */	
405
-		return it->dc->domain;	
406
-			
365
+	return NULL;
407 366
 }
408 367
 
409
-dc_t* get_code_from_hash(h_entry_t* hash, unsigned int hash_size, char* domain)
368
+int pdt_check_pd(pdt_hash_t *ph, str *sp, str *sd)
410 369
 {
411
-	int hash_entry;
370
+	int i;
412 371
 	unsigned int dhash;
413
-	entry_t* it;
372
+	pd_t* it;
414 373
 	
415
-	if(!hash || hash_size>MAX_HASH_SIZE)
416
-		return NULL;
417
-	
418
-	dhash = compute_hash(domain);
419
-	hash_entry = get_hash_entry(dhash, hash_size);
420
-
421
-	lock_get(&hash[hash_entry].lock);
374
+	if(ph==NULL || sp==NULL || sd==NULL)
375
+	{
376
+		LOG(L_ERR, "PDT:pdt_check_pd: bad parameters\n");
377
+		return -1;
378
+	}
379
+    
380
+	dhash = pdt_compute_hash(sd->s);
422 381
 	
423
-	/* parsing the list */
424
-	it = hash[hash_entry].e;
425
-	while(it!=NULL && it->dc->dhash<=dhash)
382
+	for(i=0; i<ph->hash_size; i++)
426 383
 	{
427
-		if(it->dc->dhash == dhash && strcasecmp(it->dc->domain, domain)==0)
384
+		lock_get(&ph->dhash[i].lock);
385
+		it = ph->dhash[i].e;
386
+		while(it != NULL)
428 387
 		{
429
-			lock_release(&hash[hash_entry].lock);
430
-			return it->dc;
388
+			if((it->domain.len==sd->len
389
+					&& strncasecmp(it->domain.s, sd->s, sd->len)==0)
390
+				|| (it->prefix.len==sp->len
391
+					&& strncasecmp(it->prefix.s, sp->s, sp->len)==0))
392
+			{
393
+				lock_release(&ph->dhash[i].lock);
394
+				return 1;
395
+			}
396
+			
397
+	    	it = it->n;
431 398
 		}
432
-		it = it->n;
433
-	}
434
-
435
-	lock_release(&hash[hash_entry].lock);
399
+		lock_release(&ph->dhash[i].lock);
400
+    }
436 401
 
437
-	return NULL;
402
+	return 0;
438 403
 }
439 404
 
440
-void print_hash(h_entry_t* hash, unsigned int hash_size)
405
+void pdt_print_hash(pdt_hash_t* hash)
441 406
 {
442 407
 	int i, count;
443
-	entry_t *it;
408
+	pd_t *it;
444 409
 	
445
-	if(!hash || hash_size>MAX_HASH_SIZE)
410
+	if(hash==NULL)
411
+	{
412
+		DBG("PDT:pdt_print_hash: empty...\n");
446 413
 		return;
447
-
448
-	for(i=0; i<hash_size; i++)
414
+	}
415
+	
416
+	for(i=0; i<hash->hash_size; i++)
449 417
 	{
450
-		lock_get(&hash[i].lock);
418
+		lock_get(&hash->dhash[i].lock);
451 419
 
452
-		it = hash[i].e;
453
-		printf("Entry<%d>:\n", i);
420
+		it = hash->dhash[i].e;
421
+		DBG("PDT:pdt_print_hash: entry<%d>:\n", i);
454 422
 		count = 0;
455 423
 		while(it!=NULL)
456 424
 		{
457
-			printf("|Domain: %s |Code: %d | DHash:%u \n",
458
-					it->dc->domain, it->dc->code, it->dc->dhash);
425
+			DBG("PDT:pdt_print_hash: |Domain: %.*s |Code: %.*s | DHash:%u \n",
426
+					it->domain.len, it->domain.s,
427
+					it->prefix.len, it->prefix.s, it->dhash);
459 428
 			it = it->n;
460 429
 			count++;
461 430
 		}
462 431
 
463