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