Browse code

- fix bug in encode_contact() - fix and extend documentation about contact encoding/decoding (cherry picked from commit 8929913f5edb519b7ed280a12728376ed872ec53)

Klaus Darilion authored on 30/12/2009 15:53:12
Showing 3 changed files
... ...
@@ -1,4 +1,3 @@
1
-
2 1
 siputils
3 2
 
4 3
 Hardy Kahl
... ...
@@ -40,45 +39,45 @@ Gabriel Vasile
40 39
    Copyright � 2008, 2005, 2003 1&1 Internet AG, FhG Fokus,
41 40
    voice-system.ro
42 41
    Revision History
43
-   Revision $Revision: 4872 $ $Date: 2008-09-09 17:39:38 +0200
44
-   (Di, 09 Sep 2008) $
45
-     _________________________________________________________
42
+   Revision $Revision: 4872 $ $Date: 2008-09-09 17:39:38 +0200 (Di, 09 Sep
43
+                              2008) $
44
+     __________________________________________________________________
46 45
 
47 46
    Table of Contents
48 47
 
49 48
    1. Admin Guide
50 49
 
51
-        1.1. Overview
52
-        1.2. Dependencies
53
-
54
-              1.2.1. Kamailio Modules
55
-              1.2.2. External Libraries or Applications
56
-
57
-        1.3. Exported Parameters
58
-
59
-              1.3.1. ring_timeout (int)
60
-              1.3.2. options_accept (string)
61
-              1.3.3. options_accept_encoding (string)
62
-              1.3.4. contact_flds_separator (string)
63
-              1.3.5. options_accept_language (string)
64
-              1.3.6. options_support (string)
65
-
66
-        1.4. Exported Functions
67
-
68
-              1.4.1. ring_insert_callid() 
69
-              1.4.2. options_reply() 
70
-              1.4.3. is_user(username) 
71
-              1.4.4. has_totag() 
72
-              1.4.5. uri_param(param) 
73
-              1.4.6. uri_param(param,value) 
74
-              1.4.7. add_uri_param(param) 
75
-              1.4.8. tel2sip() 
76
-              1.4.9. is_uri_user_e164(pseudo-variable) 
77
-              1.4.10. encode_contact(encoding_prefix) 
78
-              1.4.11. decode_contact() 
79
-              1.4.12. decode_contact_header() 
80
-              1.4.13. cmp_uri(str1, str2) 
81
-              1.4.14. cmp_aor(str1, str2) 
50
+        1. Overview
51
+        2. Dependencies
52
+
53
+              2.1. Kamailio Modules
54
+              2.2. External Libraries or Applications
55
+
56
+        3. Exported Parameters
57
+
58
+              3.1. ring_timeout (int)
59
+              3.2. options_accept (string)
60
+              3.3. options_accept_encoding (string)
61
+              3.4. contact_flds_separator (string)
62
+              3.5. options_accept_language (string)
63
+              3.6. options_support (string)
64
+
65
+        4. Exported Functions
66
+
67
+              4.1. ring_insert_callid()
68
+              4.2. options_reply()
69
+              4.3. is_user(username)
70
+              4.4. has_totag()
71
+              4.5. uri_param(param)
72
+              4.6. uri_param(param,value)
73
+              4.7. add_uri_param(param)
74
+              4.8. tel2sip()
75
+              4.9. is_uri_user_e164(pseudo-variable)
76
+              4.10. encode_contact(encoding_prefix,hostpart)
77
+              4.11. decode_contact()
78
+              4.12. decode_contact_header()
79
+              4.13. cmp_uri(str1, str2)
80
+              4.14. cmp_aor(str1, str2)
82 81
 
83 82
    List of Examples
84 83
 
... ...
@@ -105,96 +104,137 @@ Gabriel Vasile
105 104
 
106 105
 Chapter 1. Admin Guide
107 106
 
108
-1.1. Overview
107
+   Table of Contents
108
+
109
+   1. Overview
110
+   2. Dependencies
111
+
112
+        2.1. Kamailio Modules
113
+        2.2. External Libraries or Applications
114
+
115
+   3. Exported Parameters
116
+
117
+        3.1. ring_timeout (int)
118
+        3.2. options_accept (string)
119
+        3.3. options_accept_encoding (string)
120
+        3.4. contact_flds_separator (string)
121
+        3.5. options_accept_language (string)
122
+        3.6. options_support (string)
123
+
124
+   4. Exported Functions
125
+
126
+        4.1. ring_insert_callid()
127
+        4.2. options_reply()
128
+        4.3. is_user(username)
129
+        4.4. has_totag()
130
+        4.5. uri_param(param)
131
+        4.6. uri_param(param,value)
132
+        4.7. add_uri_param(param)
133
+        4.8. tel2sip()
134
+        4.9. is_uri_user_e164(pseudo-variable)
135
+        4.10. encode_contact(encoding_prefix,hostpart)
136
+        4.11. decode_contact()
137
+        4.12. decode_contact_header()
138
+        4.13. cmp_uri(str1, str2)
139
+        4.14. cmp_aor(str1, str2)
140
+
141
+1. Overview
109 142
 
110
-   This module implement various functions and checks related to
111
-   SIP message handling and URI handling.
143
+   This module implement various functions and checks related to SIP
144
+   message handling and URI handling.
112 145
 
113
-   It offers some functions related to handle ringing. In a
114
-   parallel forking scenario you get several 183s with SDP. You
115
-   don't want that your customers hear more than one ringtone or
116
-   answer machine in parallel on the phone. So its necessary to
117
-   drop the 183 in this cases and send a 180 instead.
146
+   It offers some functions related to handle ringing. In a parallel
147
+   forking scenario you get several 183s with SDP. You don't want that
148
+   your customers hear more than one ringtone or answer machine in
149
+   parallel on the phone. So its necessary to drop the 183 in this cases
150
+   and send a 180 instead.
118 151
 
119
-   This module provides a function to answer OPTIONS requests
120
-   which are directed to the server itself. This means an OPTIONS
121
-   request which has the address of the server in the request
122
-   URI, and no username in the URI. The request will be answered
123
-   with a 200 OK which the capabilities of the server.
152
+   This module provides a function to answer OPTIONS requests which are
153
+   directed to the server itself. This means an OPTIONS request which has
154
+   the address of the server in the request URI, and no username in the
155
+   URI. The request will be answered with a 200 OK which the capabilities
156
+   of the server.
124 157
 
125
-   To answer OPTIONS request directed to your server is the
126
-   easiest way for is-alive-tests on the SIP (application) layer
127
-   from remote (similar to ICMP echo requests, also known as
128
-   "ping", on the network layer).
158
+   To answer OPTIONS request directed to your server is the easiest way
159
+   for is-alive-tests on the SIP (application) layer from remote (similar
160
+   to ICMP echo requests, also known as "ping", on the network layer).
129 161
 
130
-1.2. Dependencies
162
+2. Dependencies
131 163
 
132
-1.2.1. Kamailio Modules
164
+   2.1. Kamailio Modules
165
+   2.2. External Libraries or Applications
166
+
167
+2.1. Kamailio Modules
133 168
 
134 169
    The following modules must be loaded before this module:
135 170
      * sl -- Stateless replies.
136 171
 
137
-1.2.2. External Libraries or Applications
172
+2.2. External Libraries or Applications
138 173
 
139
-   The following libraries or applications must be installed
140
-   before running Kamailio with this module loaded:
174
+   The following libraries or applications must be installed before
175
+   running Kamailio with this module loaded:
141 176
      * None.
142 177
 
143
-1.3. Exported Parameters
178
+3. Exported Parameters
179
+
180
+   3.1. ring_timeout (int)
181
+   3.2. options_accept (string)
182
+   3.3. options_accept_encoding (string)
183
+   3.4. contact_flds_separator (string)
184
+   3.5. options_accept_language (string)
185
+   3.6. options_support (string)
144 186
 
145
-1.3.1. ring_timeout (int)
187
+3.1. ring_timeout (int)
146 188
 
147
-   Timeout value in seconds, define how long the call-id is
148
-   stored in the internal list. A reasonable value is "30".
189
+   Timeout value in seconds, define how long the call-id is stored in the
190
+   internal list. A reasonable value is "30".
149 191
 
150
-   Default value is "0". 
192
+   Default value is "0".
151 193
 
152 194
    Example 1.1. Set ring_timeout parameter
153 195
 ...
154 196
 modparam("siputils", "ring_timeout", 30)
155 197
 ...
156 198
 
157
-1.3.2. options_accept (string)
199
+3.2. options_accept (string)
158 200
 
159
-   This parameter is the content of the Accept header field.
160
-   Note: it is not clearly written in RFC3261 if a proxy should
161
-   accept any content (the default "*/*") because it does not
162
-   care about content. Or if it does not accept any content,
163
-   which is "".
201
+   This parameter is the content of the Accept header field. Note: it is
202
+   not clearly written in RFC3261 if a proxy should accept any content
203
+   (the default "*/*") because it does not care about content. Or if it
204
+   does not accept any content, which is "".
164 205
 
165
-   Default value is "*/*". 
206
+   Default value is "*/*".
166 207
 
167 208
    Example 1.2. Set options_accept parameter
168 209
 ...
169 210
 modparam("siputils", "options_accept", "application/*")
170 211
 ...
171 212
 
172
-1.3.3. options_accept_encoding (string)
213
+3.3. options_accept_encoding (string)
173 214
 
174
-   This parameter is the content of the Accept-Encoding header
175
-   field. Please do not change the default value because Kamailio
176
-   does not support any encodings yet.
215
+   This parameter is the content of the Accept-Encoding header field.
216
+   Please do not change the default value because Kamailio does not
217
+   support any encodings yet.
177 218
 
178
-   Default value is "". 
219
+   Default value is "".
179 220
 
180 221
    Example 1.3. Set options_accept_encoding parameter
181 222
 ...
182 223
 modparam("siputils", "options_accept_encoding", "gzip")
183 224
 ...
184 225
 
185
-1.3.4. contact_flds_separator (string)
226
+3.4. contact_flds_separator (string)
186 227
 
187
-   First char of this parameter is used as separator for
188
-   encoding/decoding Contact header.
228
+   First char of this parameter is used as separator for encoding/decoding
229
+   Contact header.
189 230
 
190 231
 Warning
191 232
 
192
-   First char of this field must be set to a value which is not
193
-   used inside username,password or other fields of contact.
194
-   Otherwise it is possible for the decoding step to fail/produce
195
-   wrong results.
233
+   First char of this field must be set to a value which is not used
234
+   inside username,password or other fields of contact. Otherwise it is
235
+   possible for the decoding step to fail/produce wrong results.
196 236
 
197
-   Default value is "*". 
237
+   Default value is "*".
198 238
 
199 239
    Example 1.4. Set db_url parameter
200 240
 ...
... ...
@@ -204,73 +244,83 @@ modparam("siputils", "contact_flds_separator", "-")
204 244
    then an encoded uri might look
205 245
    sip:user-password-ip-port-protocol@PublicIP
206 246
 
207
-1.3.5. options_accept_language (string)
247
+3.5. options_accept_language (string)
208 248
 
209
-   This parameter is the content of the Accept-Language header
210
-   field. You can set any language code which you prefer for
211
-   error descriptions from other devices, but presumably there
212
-   are not much devices around which support other languages then
213
-   the default English.
249
+   This parameter is the content of the Accept-Language header field. You
250
+   can set any language code which you prefer for error descriptions from
251
+   other devices, but presumably there are not much devices around which
252
+   support other languages then the default English.
214 253
 
215
-   Default value is "en". 
254
+   Default value is "en".
216 255
 
217 256
    Example 1.5. Set options_accept_language parameter
218 257
 ...
219 258
 modparam("siputils", "options_accept_language", "de")
220 259
 ...
221 260
 
222
-1.3.6. options_support (string)
261
+3.6. options_support (string)
223 262
 
224
-   This parameter is the content of the Support header field.
225
-   Please do not change the default value, because Kamailio
226
-   currently does not support any of the SIP extensions
227
-   registered at the IANA.
263
+   This parameter is the content of the Support header field. Please do
264
+   not change the default value, because Kamailio currently does not
265
+   support any of the SIP extensions registered at the IANA.
228 266
 
229
-   Default value is "". 
267
+   Default value is "".
230 268
 
231 269
    Example 1.6. Set options_support parameter
232 270
 ...
233 271
 modparam("siputils", "options_support", "100rel")
234 272
 ...
235 273
 
236
-1.4. Exported Functions
274
+4. Exported Functions
275
+
276
+   4.1. ring_insert_callid()
277
+   4.2. options_reply()
278
+   4.3. is_user(username)
279
+   4.4. has_totag()
280
+   4.5. uri_param(param)
281
+   4.6. uri_param(param,value)
282
+   4.7. add_uri_param(param)
283
+   4.8. tel2sip()
284
+   4.9. is_uri_user_e164(pseudo-variable)
285
+   4.10. encode_contact(encoding_prefix,hostpart)
286
+   4.11. decode_contact()
287
+   4.12. decode_contact_header()
288
+   4.13. cmp_uri(str1, str2)
289
+   4.14. cmp_aor(str1, str2)
237 290
 
238
-1.4.1.  ring_insert_callid()
291
+4.1.  ring_insert_callid()
239 292
 
240
-   Inserting the call-id in the internal list, which is checked
241
-   when further replies arrive. Any 183 reply that is received
242
-   during the timeout value will be converted to a 180 message.
243
-   Please not that you need to set a positive timeout value in
244
-   order to use this function.
293
+   Inserting the call-id in the internal list, which is checked when
294
+   further replies arrive. Any 183 reply that is received during the
295
+   timeout value will be converted to a 180 message. Please not that you
296
+   need to set a positive timeout value in order to use this function.
245 297
 
246
-   The function returns TRUE on success, and FALSE during
247
-   processing failures.
298
+   The function returns TRUE on success, and FALSE during processing
299
+   failures.
248 300
 
249
-   This function can be used from REQUEST_ROUTE and
250
-   FAILURE_ROUTE.
301
+   This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
251 302
 
252 303
    Example 1.7. ring_insert_callid() usage
253 304
 ...
254 305
 ring_insert_callid();
255 306
 ...
256 307
 
257
-1.4.2.  options_reply()
308
+4.2.  options_reply()
258 309
 
259
-   This function checks if the request method is OPTIONS and if
260
-   the request URI does not contain an username. If both is true
261
-   the request will be answered stateless with "200 OK" and the
262
-   capabilities from the modules parameters.
310
+   This function checks if the request method is OPTIONS and if the
311
+   request URI does not contain an username. If both is true the request
312
+   will be answered stateless with "200 OK" and the capabilities from the
313
+   modules parameters.
263 314
 
264
-   It sends "500 Server Internal Error" for some errors and
265
-   returns false if it is called for a wrong request.
315
+   It sends "500 Server Internal Error" for some errors and returns false
316
+   if it is called for a wrong request.
266 317
 
267
-   The check for the request method and the missing username is
268
-   optional because it is also done by the function itself. But
269
-   you should not call this function outside the myself check
270
-   because in this case the function could answer OPTIONS
271
-   requests which are sent to you as outbound proxy but with an
272
-   other destination then your proxy (this check is currently
273
-   missing in the function).
318
+   The check for the request method and the missing username is optional
319
+   because it is also done by the function itself. But you should not call
320
+   this function outside the myself check because in this case the
321
+   function could answer OPTIONS requests which are sent to you as
322
+   outbound proxy but with an other destination then your proxy (this
323
+   check is currently missing in the function).
274 324
 
275 325
    This function can be used from REQUEST_ROUTE.
276 326
 
... ...
@@ -283,10 +333,9 @@ if (uri==myself) {
283 333
 }
284 334
 ...
285 335
 
286
-1.4.3.  is_user(username)
336
+4.3.  is_user(username)
287 337
 
288
-   Check if the username in credentials matches the given
289
-   username.
338
+   Check if the username in credentials matches the given username.
290 339
 
291 340
    Meaning of the parameters is as follows:
292 341
      * username - Username string.
... ...
@@ -300,7 +349,7 @@ if (is_user("john")) {
300 349
 };
301 350
 ...
302 351
 
303
-1.4.4.  has_totag()
352
+4.4.  has_totag()
304 353
 
305 354
    Check if To header field uri contains tag parameter.
306 355
 
... ...
@@ -313,7 +362,7 @@ if (has_totag()) {
313 362
 };
314 363
 ...
315 364
 
316
-1.4.5.  uri_param(param)
365
+4.5.  uri_param(param)
317 366
 
318 367
    Find if Request URI has a given parameter with no value
319 368
 
... ...
@@ -329,7 +378,7 @@ if (uri_param("param1")) {
329 378
 };
330 379
 ...
331 380
 
332
-1.4.6.  uri_param(param,value)
381
+4.6.  uri_param(param,value)
333 382
 
334 383
    Find if Request URI has a given parameter with matching value
335 384
 
... ...
@@ -346,7 +395,7 @@ if (uri_param("param1","value1")) {
346 395
 };
347 396
 ...
348 397
 
349
-1.4.7.  add_uri_param(param)
398
+4.7.  add_uri_param(param)
350 399
 
351 400
    Add to RURI a parameter (name=value);
352 401
 
... ...
@@ -360,17 +409,17 @@ if (uri_param("param1","value1")) {
360 409
 add_uri_param("nat=yes");
361 410
 ...
362 411
 
363
-1.4.8.  tel2sip()
412
+4.8.  tel2sip()
364 413
 
365
-   Converts RURI, if it is tel URI, to SIP URI. Returns true only
366
-   if conversion succeeded or if no conversion was needed (like
367
-   RURI was not tel URI).
414
+   Converts RURI, if it is tel URI, to SIP URI. Returns true only if
415
+   conversion succeeded or if no conversion was needed (like RURI was not
416
+   tel URI).
368 417
 
369 418
    The conversion follows the rules in RFC 3261 section 19.1.6:
370
-     * Visual separators ( "-", ".", "(", ")" ) are removed from
371
-       tel URI number before converting it to SIP URI userinfo.
372
-     * tel URI parameters are downcased before appending them to
373
-       SIP URI userinfo
419
+     * Visual separators ( "-", ".", "(", ")" ) are removed from tel URI
420
+       number before converting it to SIP URI userinfo.
421
+     * tel URI parameters are downcased before appending them to SIP URI
422
+       userinfo
374 423
 
375 424
    The SIP URI host is formed using the From URI host.
376 425
 
... ...
@@ -387,13 +436,11 @@ tel2sip();
387 436
 # RURI:  sip:+12345678;ext=200;isub=+123-456@foo.com;user=phone
388 437
 ...
389 438
 
390
-1.4.9.  is_uri_user_e164(pseudo-variable)
439
+4.9.  is_uri_user_e164(pseudo-variable)
391 440
 
392
-   Checks if userpart of URI stored in pseudo variable is E164
393
-   number.
441
+   Checks if userpart of URI stored in pseudo variable is E164 number.
394 442
 
395
-   This function can be used from REQUEST_ROUTE and
396
-   FAILURE_ROUTE.
443
+   This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
397 444
 
398 445
    Example 1.15. is_uri_user_e164 usage
399 446
 ...
... ...
@@ -406,35 +453,38 @@ if (is_uri_user_e164("$avp(i:705)") {
406 453
 };
407 454
 ...
408 455
 
409
-1.4.10.  encode_contact(encoding_prefix)
456
+4.10.  encode_contact(encoding_prefix,hostpart)
457
+
458
+   This function will encode uri-s inside Contact header in the following
459
+   manner sip:username:password@ip:port;transport=protocol goes
460
+   sip:encoding_prefix*username*ip*port*protocol@hostpart.
461
+
462
+   * is the default separator and can be changed by setting the
463
+   contact_flds_separator module parameter.
410 464
 
411
-   This function will encode uri-s inside Contact header in the
412
-   following manner
413
-   sip:username:password@ip:port;transport=protocol goes
414
-   sip:enc_pref*username*ip*port*protocol@public_ip * is the
415
-   default separator.
465
+   Note: This function discards all of the URI parameters. Thus, none of
466
+   the paramters (except the transport parameter which is encoded into the
467
+   userpart) can be restored.
416 468
 
417 469
    The function returns negative on error, 1 on success.
418 470
 
419 471
    Meaning of the parameters is as follows:
420
-     * encoding_prefix - Something to allow us to determine that
421
-       a contact is encoded publicip--a routable IP, most
422
-       probably you should put your external IP of your NAT box.
472
+     * encoding_prefix - Something to allow us to determine that a contact
473
+       is encoded.
474
+     * hostpart - An IP address or a hostname.
423 475
 
424 476
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE.
425 477
 
426 478
    Example 1.16. encode_contact usage
427 479
 ...
428
-if (src_ip == 10.0.0.0/8) encode_contact("enc_prefix","193.175.135.38")
429
-;
480
+if (src_ip == 10.0.0.0/8) encode_contact("natted_client","1.2.3.4");
430 481
 ...
431 482
 
432
-1.4.11.  decode_contact()
483
+4.11.  decode_contact()
433 484
 
434
-   This function will decode the URI in first line in packets
435
-   which come with encoded URI in the following manner
436
-   sip:enc_pref*username*ip*port*protocol@public_ip goes to
437
-   sip:username:password@ip:port;transport=protocol It uses the
485
+   This function will decode the request URI. If the RURI is in the format
486
+   sip:encoding_prefix*username*ip*port*protocol@hostpart it will be
487
+   decoded to sip:username:password@ip:port;transport=protocol It uses the
438 488
    default set parameter for contact encoding separator.
439 489
 
440 490
    The function returns negative on error, 1 on success.
... ...
@@ -445,16 +495,15 @@ if (src_ip == 10.0.0.0/8) encode_contact("enc_prefix","193.175.135.38")
445 495
 
446 496
    Example 1.17. decode_contact usage
447 497
 ...
448
-if (uri =~ "^enc*") { decode_contact(); }
498
+if (uri =~ "^sip:natted_client") { decode_contact(); }
449 499
 ...
450 500
 
451
-1.4.12.  decode_contact_header()
501
+4.12.  decode_contact_header()
452 502
 
453
-   This function will decode URIs inside Contact header in the
454
-   following manner
455
-   sip:enc_pref*username*ip*port*protocol@public_ip goes to
456
-   sip:username:password@ip:port;transport=protocol. It uses the
457
-   default set parameter for contact encoding separator.
503
+   This function will decode URIs inside Contact header. If the URI in the
504
+   format sip:encoding_prefix*username*ip*port*protocol@hostpart it will
505
+   be decoded to sip:username:password@ip:port;transport=protocol. It uses
506
+   the default set parameter for contact encoding separator.
458 507
 
459 508
    The function returns negative on error, 1 on success.
460 509
 
... ...
@@ -464,13 +513,16 @@ if (uri =~ "^enc*") { decode_contact(); }
464 513
 
465 514
    Example 1.18. decode_contact_header usage
466 515
 ...
467
-if (uri =~ "^enc*") { decode_contact_header(); }
516
+reply_route[2] {
517
+        ...
518
+        decode_contact_header();
519
+        ...
520
+}
468 521
 ...
469 522
 
470
-1.4.13.  cmp_uri(str1, str2)
523
+4.13.  cmp_uri(str1, str2)
471 524
 
472
-   The function returns true if the two parameters matches as SIP
473
-   URI.
525
+   The function returns true if the two parameters matches as SIP URI.
474 526
 
475 527
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
476 528
    FAILURE_ROUTE and BRANCH_ROUTE.
... ...
@@ -483,10 +535,10 @@ if(cmp_uri("$ru", "sip:kamailio@kamailio.org"))
483 535
 }
484 536
 ...
485 537
 
486
-1.4.14.  cmp_aor(str1, str2)
538
+4.14.  cmp_aor(str1, str2)
487 539
 
488
-   The function returns true if the two parameters matches as
489
-   AoR. The parameters have to be SIP URIs.
540
+   The function returns true if the two parameters matches as AoR. The
541
+   parameters have to be SIP URIs.
490 542
 
491 543
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
492 544
    FAILURE_ROUTE and BRANCH_ROUTE.
... ...
@@ -321,10 +321,10 @@ encode2format (str uri, struct uri_format *format)
321 321
 		return -1;
322 322
 	string = uri.s;
323 323
 
324
-
325 324
 	pos = memchr (string, '<', uri.len);
326 325
 	if (pos != NULL)	/* we are only interested of chars inside <> */
327 326
 	{
327
+		/* KD: I think this can be removed as the parsed contact removed <> already */
328 328
 		start = memchr (string, ':', uri.len);
329 329
 		if (start == NULL)	return -2;
330 330
 		if (start - pos < 4) return -3;
... ...
@@ -338,8 +338,9 @@ encode2format (str uri, struct uri_format *format)
338 338
 		start = memchr (string, ':', uri.len);
339 339
 		if (start == NULL)
340 340
 			return -5;
341
-		if (start - pos < 3)
341
+		if (start - string < 3)
342 342
 			return -6;
343
+		/* KD: FIXME: Looks like this code can not handle 'sips' URIs and discards all other URI parameters! */
343 344
 		start = start - 3;
344 345
 		end = string + uri.len;
345 346
 	}
... ...
@@ -490,14 +490,21 @@ if (is_uri_user_e164("$avp(i:705)") {
490 490
 
491 491
 	<section>
492 492
 		<title>
493
-		<function moreinfo="none">encode_contact(encoding_prefix)</function>
493
+		<function moreinfo="none">encode_contact(encoding_prefix,hostpart)</function>
494 494
 		</title>
495 495
 		<para>
496 496
 		This function will encode uri-s inside Contact header in the following 
497 497
 		manner
498 498
 		sip:username:password@ip:port;transport=protocol goes
499
-		sip:enc_pref*username*ip*port*protocol@public_ip * is the default 
500
-		separator.
499
+		sip:encoding_prefix*username*ip*port*protocol@hostpart.
500
+		</para>
501
+		<para>
502
+		* is the default separator and can be changed by setting the contact_flds_separator 
503
+		module parameter.
504
+		</para>
505
+		<para>
506
+		Note: This function discards all of the URI parameters. Thus, none of the paramters
507
+		(except the transport parameter which is encoded into the userpart) can be restored.
501 508
 		</para>
502 509
 		<para>
503 510
 		The function returns negative on error, 1 on success.
... ...
@@ -506,9 +513,11 @@ if (is_uri_user_e164("$avp(i:705)") {
506 513
 		<itemizedlist>
507 514
 		<listitem>
508 515
 			<para><emphasis>encoding_prefix</emphasis> - Something to allow us 
509
-			to determine that a contact is encoded publicip--a routable &ip;, 
510
-			most probably you should
511
-			put your external &ip; of your &nat; box.
516
+			to determine that a contact is encoded.
517
+			</para>
518
+		</listitem>
519
+		<listitem>
520
+			<para><emphasis>hostpart</emphasis> - An IP address or a hostname.
512 521
 			</para>
513 522
 		</listitem>
514 523
 		</itemizedlist>
... ...
@@ -519,7 +528,7 @@ if (is_uri_user_e164("$avp(i:705)") {
519 528
 		<title><function>encode_contact</function> usage</title>
520 529
 		<programlisting format="linespecific">
521 530
 ...
522
-if (src_ip == 10.0.0.0/8) encode_contact("enc_prefix","193.175.135.38"); 
531
+if (src_ip == 10.0.0.0/8) encode_contact("natted_client","1.2.3.4"); 
523 532
 ...
524 533
 </programlisting>
525 534
 		</example>
... ...
@@ -530,9 +539,8 @@ if (src_ip == 10.0.0.0/8) encode_contact("enc_prefix","193.175.135.38");
530 539
 		<function moreinfo="none">decode_contact()</function>
531 540
 		</title>
532 541
 		<para>
533
-		This function will decode the &uri; in first line in packets which 
534
-		come with encoded &uri; in the following manner 
535
-		sip:enc_pref*username*ip*port*protocol@public_ip goes to
542
+		This function will decode the request URI. If the RURI is in the format
543
+		sip:encoding_prefix*username*ip*port*protocol@hostpart it will be decoded to
536 544
 		sip:username:password@ip:port;transport=protocol It uses the default 
537 545
 		set parameter for contact encoding separator.
538 546
 		</para>
... ...
@@ -547,7 +555,7 @@ if (src_ip == 10.0.0.0/8) encode_contact("enc_prefix","193.175.135.38");
547 555
 		<title><function>decode_contact</function> usage</title>
548 556
 		<programlisting format="linespecific">
549 557
 ...
550
-if (uri =~ "^enc*") { decode_contact(); }
558
+if (uri =~ "^sip:natted_client") { decode_contact(); }
551 559
 ...
552 560
 </programlisting>
553 561
 		</example>
... ...
@@ -558,9 +566,9 @@ if (uri =~ "^enc*") { decode_contact(); }
558 566
 		<function moreinfo="none">decode_contact_header()</function>
559 567
 		</title>
560 568
 		<para>
561
-		This function will decode &uri;s inside Contact header in the 
562
-		following manner sip:enc_pref*username*ip*port*protocol@public_ip goes 
563
-		to sip:username:password@ip:port;transport=protocol. It uses the 
569
+		This function will decode &uri;s inside Contact header. If the URI in the format 
570
+		sip:encoding_prefix*username*ip*port*protocol@hostpart it will be decoded to
571
+		sip:username:password@ip:port;transport=protocol. It uses the 
564 572
 		default set parameter for contact encoding separator.
565 573
 		</para>
566 574
 		<para>
... ...
@@ -574,7 +582,11 @@ if (uri =~ "^enc*") { decode_contact(); }
574 582
 		<title><function>decode_contact_header</function> usage</title>
575 583
 		<programlisting format="linespecific">
576 584
 ...
577
-if (uri =~ "^enc*") { decode_contact_header(); }
585
+reply_route[2] {
586
+	...
587
+	decode_contact_header();
588
+	...
589
+}
578 590
 ...
579 591
 </programlisting>
580 592
 		</example>