Browse code

- new set of function to work on the body of the message: - search_body() - search_append_body() - replace_body() - replace_body_all() - subst_body()

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@681 689a6050-402a-0410-94f2-e92a70836424

Daniel-Constantin Mierla authored on 21/02/2006 10:33:21
Showing 3 changed files
... ...
@@ -29,22 +29,27 @@ Daniel-Constantin Mierla
29 29
         1.3. Exported Functions
30 30
 
31 31
               1.3.1. search(re)
32
-              1.3.2. search_append(re, txt)
33
-              1.3.3. replace(re, txt)
34
-              1.3.4. replace_all(re, txt)
35
-              1.3.5. subst('/re/repl/flags')
36
-              1.3.6. subst_uri('/re/repl/flags')
37
-              1.3.7. subst_user('/re/repl/flags')
38
-              1.3.8. append_to_reply(txt)
39
-              1.3.9. append_hf(txt)
40
-              1.3.10. append_hf(txt, hdr)
41
-              1.3.11. insert_hf(txt)
42
-              1.3.12. insert_hf(txt, hdr)
43
-              1.3.13. append_urihf(prefix, suffix)
44
-              1.3.14. is_present_hf(hf_name)
45
-              1.3.15. append_time()
46
-              1.3.16. is_method(name)
47
-              1.3.17. remove_hf(hname)
32
+              1.3.2. search_body(re)
33
+              1.3.3. search_append(re, txt)
34
+              1.3.4. search_append_body(re, txt)
35
+              1.3.5. replace(re, txt)
36
+              1.3.6. replace_body(re, txt)
37
+              1.3.7. replace_all(re, txt)
38
+              1.3.8. replace_body_all(re, txt)
39
+              1.3.9. subst('/re/repl/flags')
40
+              1.3.10. subst_uri('/re/repl/flags')
41
+              1.3.11. subst_user('/re/repl/flags')
42
+              1.3.12. subst_body('/re/repl/flags')
43
+              1.3.13. append_to_reply(txt)
44
+              1.3.14. append_hf(txt)
45
+              1.3.15. append_hf(txt, hdr)
46
+              1.3.16. insert_hf(txt)
47
+              1.3.17. insert_hf(txt, hdr)
48
+              1.3.18. append_urihf(prefix, suffix)
49
+              1.3.19. is_present_hf(hf_name)
50
+              1.3.20. append_time()
51
+              1.3.21. is_method(name)
52
+              1.3.22. remove_hf(hname)
48 53
 
49 54
         1.4. Known Limitations
50 55
 
... ...
@@ -53,22 +58,27 @@ Daniel-Constantin Mierla
53 58
 
54 59
    List of Examples
55 60
    1-1. search usage
56
-   1-2. search_append usage
57
-   1-3. replace usage
58
-   1-4. replace_all usage
59
-   1-5. subst usage
60
-   1-6. subst_uri usage
61
-   1-7. subst usage
62
-   1-8. append_to_reply usage
63
-   1-9. append_hf usage
64
-   1-10. append_hf usage
65
-   1-11. insert_hf usage
66
-   1-12. insert_hf usage
67
-   1-13. append_urihf usage
68
-   1-14. is_present_hf usage
69
-   1-15. append_time usage
70
-   1-16. is_method usage
71
-   1-17. remove_hf usage
61
+   1-2. search_body usage
62
+   1-3. search_append usage
63
+   1-4. search_append_body usage
64
+   1-5. replace usage
65
+   1-6. replace_body usage
66
+   1-7. replace_all usage
67
+   1-8. replace_body_all usage
68
+   1-9. subst usage
69
+   1-10. subst_uri usage
70
+   1-11. subst usage
71
+   1-12. subst_body usage
72
+   1-13. append_to_reply usage
73
+   1-14. append_hf usage
74
+   1-15. append_hf usage
75
+   1-16. insert_hf usage
76
+   1-17. insert_hf usage
77
+   1-18. append_urihf usage
78
+   1-19. is_present_hf usage
79
+   1-20. append_time usage
80
+   1-21. is_method usage
81
+   1-22. remove_hf usage
72 82
      _________________________________________________________
73 83
 
74 84
 Chapter 1. User's Guide
... ...
@@ -124,7 +134,24 @@ if ( search("[Ss][Ii][Pp]" ) { /*....*/ };
124 134
 ...
125 135
      _________________________________________________________
126 136
 
127
-1.3.2. search_append(re, txt)
137
+1.3.2. search_body(re)
138
+
139
+   Searches for the re in the body of the message.
140
+
141
+   Meaning of the parameters is as follows:
142
+
143
+     * re - Regular expression.
144
+
145
+   This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
146
+   FAILURE_ROUTE, BRANCH_ROUTE.
147
+
148
+   Example 1-2. search_body usage
149
+...
150
+if ( search_body("[Ss][Ii][Pp]" ) { /*....*/ };
151
+...
152
+     _________________________________________________________
153
+
154
+1.3.3. search_append(re, txt)
128 155
 
129 156
    Searches for the first match of re and appends txt after it.
130 157
 
... ...
@@ -136,13 +163,32 @@ if ( search("[Ss][Ii][Pp]" ) { /*....*/ };
136 163
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
137 164
    FAILURE_ROUTE, BRANCH_ROUTE.
138 165
 
139
-   Example 1-2. search_append usage
166
+   Example 1-3. search_append usage
140 167
 ...
141 168
 search_append("[Oo]pen[Ss]er", " SIP Proxy");
142 169
 ...
143 170
      _________________________________________________________
144 171
 
145
-1.3.3. replace(re, txt)
172
+1.3.4. search_append_body(re, txt)
173
+
174
+   Searches for the first match of re in the body of the message
175
+   and appends txt after it.
176
+
177
+   Meaning of the parameters is as follows:
178
+
179
+     * re - Regular expression.
180
+     * txt - String to be appended.
181
+
182
+   This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
183
+   FAILURE_ROUTE, BRANCH_ROUTE.
184
+
185
+   Example 1-4. search_append_body usage
186
+...
187
+search_append_body("[Oo]pen[Ss]er", " SIP Proxy");
188
+...
189
+     _________________________________________________________
190
+
191
+1.3.5. replace(re, txt)
146 192
 
147 193
    Replaces the first occurrence of re with txt.
148 194
 
... ...
@@ -154,13 +200,32 @@ search_append("[Oo]pen[Ss]er", " SIP Proxy");
154 200
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
155 201
    FAILURE_ROUTE, BRANCH_ROUTE.
156 202
 
157
-   Example 1-3. replace usage
203
+   Example 1-5. replace usage
158 204
 ...
159 205
 replace("openser", "OpenSER SIP Proxy");
160 206
 ...
161 207
      _________________________________________________________
162 208
 
163
-1.3.4. replace_all(re, txt)
209
+1.3.6. replace_body(re, txt)
210
+
211
+   Replaces the first occurrence of re in the body of the message
212
+   with txt.
213
+
214
+   Meaning of the parameters is as follows:
215
+
216
+     * re - Regular expression.
217
+     * txt - String.
218
+
219
+   This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
220
+   FAILURE_ROUTE, BRANCH_ROUTE.
221
+
222
+   Example 1-6. replace_body usage
223
+...
224
+replace_body("openser", "OpenSER SIP Proxy");
225
+...
226
+     _________________________________________________________
227
+
228
+1.3.7. replace_all(re, txt)
164 229
 
165 230
    Replaces all occurrence of re with txt.
166 231
 
... ...
@@ -172,13 +237,32 @@ replace("openser", "OpenSER SIP Proxy");
172 237
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
173 238
    FAILURE_ROUTE, BRANCH_ROUTE.
174 239
 
175
-   Example 1-4. replace_all usage
240
+   Example 1-7. replace_all usage
176 241
 ...
177 242
 replace_all("openser", "OpenSER SIP Proxy");
178 243
 ...
179 244
      _________________________________________________________
180 245
 
181
-1.3.5. subst('/re/repl/flags')
246
+1.3.8. replace_body_all(re, txt)
247
+
248
+   Replaces all occurrence of re in the body of the message with
249
+   txt.
250
+
251
+   Meaning of the parameters is as follows:
252
+
253
+     * re - Regular expression.
254
+     * txt - String.
255
+
256
+   This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
257
+   FAILURE_ROUTE, BRANCH_ROUTE.
258
+
259
+   Example 1-8. replace_body_all usage
260
+...
261
+replace_body_all("openser", "OpenSER SIP Proxy");
262
+...
263
+     _________________________________________________________
264
+
265
+1.3.9. subst('/re/repl/flags')
182 266
 
183 267
    Replaces re with repl (sed or perl like).
184 268
 
... ...
@@ -195,7 +279,7 @@ replace_all("openser", "OpenSER SIP Proxy");
195 279
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
196 280
    FAILURE_ROUTE, BRANCH_ROUTE.
197 281
 
198
-   Example 1-5. subst usage
282
+   Example 1-9. subst usage
199 283
 ...
200 284
 # replace the uri in to: with the message uri (just an example)
201 285
 if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1\u\2/ig') ) {};
... ...
@@ -208,7 +292,7 @@ if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1$avp(sip_address)
208 292
 ...
209 293
      _________________________________________________________
210 294
 
211
-1.3.6. subst_uri('/re/repl/flags')
295
+1.3.10. subst_uri('/re/repl/flags')
212 296
 
213 297
    Runs the re substitution on the message uri (like subst but
214 298
    works only on the uri)
... ...
@@ -226,7 +310,7 @@ if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1$avp(sip_address)
226 310
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
227 311
    FAILURE_ROUTE, BRANCH_ROUTE.
228 312
 
229
-   Example 1-6. subst_uri usage
313
+   Example 1-10. subst_uri usage
230 314
 ...
231 315
 # adds 3463 prefix to numeric uris, and save the original uri (\0 match
232 316
 )
... ...
@@ -242,7 +326,7 @@ if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:$avp(uri_prefix)\1@\2;orig_uri=
242 326
 ...
243 327
      _________________________________________________________
244 328
 
245
-1.3.7. subst_user('/re/repl/flags')
329
+1.3.11. subst_user('/re/repl/flags')
246 330
 
247 331
    Runs the re substitution on the message uri (like subst_uri
248 332
    but works only on the user portion of the uri)
... ...
@@ -260,7 +344,7 @@ if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:$avp(uri_prefix)\1@\2;orig_uri=
260 344
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
261 345
    FAILURE_ROUTE, BRANCH_ROUTE.
262 346
 
263
-   Example 1-7. subst usage
347
+   Example 1-11. subst usage
264 348
 ...
265 349
 # adds 3463 prefix to uris ending with 3642 (just an example)
266 350
 if (subst_user('/3642$/36423463/')){$
... ...
@@ -273,7 +357,32 @@ if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$
273 357
 ...
274 358
      _________________________________________________________
275 359
 
276
-1.3.8. append_to_reply(txt)
360
+1.3.12. subst_body('/re/repl/flags')
361
+
362
+   Replaces re with repl (sed or perl like) in the body of the
363
+   message.
364
+
365
+   Meaning of the parameters is as follows:
366
+
367
+     * '/re/repl/flags' - sed like regular expression. flags can
368
+       be a combination of i (case insensitive), g (global) or s
369
+       (match newline don't treat it as end of line).
370
+       're' - is regular expresion
371
+       'repl' - is replacement string - may contain
372
+       pseudo-varibales
373
+       'flags' - substitution flags (i - ignore case, g - global)
374
+
375
+   This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
376
+   FAILURE_ROUTE, BRANCH_ROUTE.
377
+
378
+   Example 1-12. subst_body usage
379
+...
380
+if ( subst_body('/^o=(.*) /o=$fU ') ) {};
381
+
382
+...
383
+     _________________________________________________________
384
+
385
+1.3.13. append_to_reply(txt)
277 386
 
278 387
    Append txt as header to the reply.
279 388
 
... ...
@@ -283,14 +392,14 @@ if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$
283 392
 
284 393
    This function can be used from REQUEST_ROUTE, BRANCH_ROUTE.
285 394
 
286
-   Example 1-8. append_to_reply usage
395
+   Example 1-13. append_to_reply usage
287 396
 ...
288 397
 append_to_reply("Foo: bar\r\n");
289 398
 append_to_reply("Foo: $rm at $Ts\r\n");
290 399
 ...
291 400
      _________________________________________________________
292 401
 
293
-1.3.9. append_hf(txt)
402
+1.3.14. append_hf(txt)
294 403
 
295 404
    Appends 'txt' as header after the last header field.
296 405
 
... ...
@@ -302,14 +411,14 @@ append_to_reply("Foo: $rm at $Ts\r\n");
302 411
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
303 412
    FAILURE_ROUTE, BRANCH_ROUTE.
304 413
 
305
-   Example 1-9. append_hf usage
414
+   Example 1-14. append_hf usage
306 415
 ...
307 416
 append_hf("P-hint: VOICEMAIL\r\n");
308 417
 append_hf("From-username: $fU\r\n");
309 418
 ...
310 419
      _________________________________________________________
311 420
 
312
-1.3.10. append_hf(txt, hdr)
421
+1.3.15. append_hf(txt, hdr)
313 422
 
314 423
    Appends 'txt' as header after first 'hdr' header field.
315 424
 
... ...
@@ -322,14 +431,14 @@ append_hf("From-username: $fU\r\n");
322 431
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
323 432
    FAILURE_ROUTE, BRANCH_ROUTE.
324 433
 
325
-   Example 1-10. append_hf usage
434
+   Example 1-15. append_hf usage
326 435
 ...
327 436
 append_hf("P-hint: VOICEMAIL\r\n", "Call-ID");
328 437
 append_hf("From-username: $fU\r\n", "Call-ID");
329 438
 ...
330 439
      _________________________________________________________
331 440
 
332
-1.3.11. insert_hf(txt)
441
+1.3.16. insert_hf(txt)
333 442
 
334 443
    Inserts 'txt' as header before the first header field.
335 444
 
... ...
@@ -341,14 +450,14 @@ append_hf("From-username: $fU\r\n", "Call-ID");
341 450
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
342 451
    FAILURE_ROUTE, BRANCH_ROUTE.
343 452
 
344
-   Example 1-11. insert_hf usage
453
+   Example 1-16. insert_hf usage
345 454
 ...
346 455
 insert_hf("P-hint: VOICEMAIL\r\n");
347 456
 insert_hf("To-username: $tU\r\n");
348 457
 ...
349 458
      _________________________________________________________
350 459
 
351
-1.3.12. insert_hf(txt, hdr)
460
+1.3.17. insert_hf(txt, hdr)
352 461
 
353 462
    Inserts 'txt' as header before first 'hdr' header field.
354 463
 
... ...
@@ -361,14 +470,14 @@ insert_hf("To-username: $tU\r\n");
361 470
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
362 471
    FAILURE_ROUTE, BRANCH_ROUTE.
363 472
 
364
-   Example 1-12. insert_hf usage
473
+   Example 1-17. insert_hf usage
365 474
 ...
366 475
 insert_hf("P-hint: VOICEMAIL\r\n", "Call-ID");
367 476
 insert_hf("To-username: $tU\r\n", "Call-ID");
368 477
 ...
369 478
      _________________________________________________________
370 479
 
371
-1.3.13. append_urihf(prefix, suffix)
480
+1.3.18. append_urihf(prefix, suffix)
372 481
 
373 482
    Append header field name with original Request-URI in middle.
374 483
 
... ...
@@ -380,13 +489,13 @@ insert_hf("To-username: $tU\r\n", "Call-ID");
380 489
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
381 490
    BRANCH_ROUTE.
382 491
 
383
-   Example 1-13. append_urihf usage
492
+   Example 1-18. append_urihf usage
384 493
 ...
385 494
 append_urihf("CC-Diversion: ", "\r\n");
386 495
 ...
387 496
      _________________________________________________________
388 497
 
389
-1.3.14. is_present_hf(hf_name)
498
+1.3.19. is_present_hf(hf_name)
390 499
 
391 500
    Return true if a header field is present in message.
392 501
 
... ...
@@ -402,13 +511,13 @@ append_urihf("CC-Diversion: ", "\r\n");
402 511
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
403 512
    FAILURE_ROUTE, BRANCH_ROUTE.
404 513
 
405
-   Example 1-14. is_present_hf usage
514
+   Example 1-19. is_present_hf usage
406 515
 ...
407 516
 if (is_present_hf("From")) log(1, "From HF Present");
408 517
 ...
409 518
      _________________________________________________________
410 519
 
411
-1.3.15. append_time()
520
+1.3.20. append_time()
412 521
 
413 522
    Adds a time header to the message. Header format is: "Date:
414 523
    %a, %d %b %Y %H:%M:%S GMT", with the legend:
... ...
@@ -426,13 +535,13 @@ if (is_present_hf("From")) log(1, "From HF Present");
426 535
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
427 536
    BRANCH_ROUTE.
428 537
 
429
-   Example 1-15. append_time usage
538
+   Example 1-20. append_time usage
430 539
 ...
431 540
 append_time();
432 541
 ...
433 542
      _________________________________________________________
434 543
 
435
-1.3.16. is_method(name)
544
+1.3.21. is_method(name)
436 545
 
437 546
    Check if the method of the message matches the name. If name
438 547
    is a known method (invite, cancel, ack, bye, options, info,
... ...
@@ -457,7 +566,7 @@ append_time();
457 566
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
458 567
    FAILURE_ROUTE, and BRANCH_ROUTE.
459 568
 
460
-   Example 1-16. is_method usage
569
+   Example 1-21. is_method usage
461 570
 ...
462 571
 if(is_method("INVITE"))
463 572
 {
... ...
@@ -470,7 +579,7 @@ if(is_method("OPTION|UPDATE"))
470 579
 ...
471 580
      _________________________________________________________
472 581
 
473
-1.3.17. remove_hf(hname)
582
+1.3.22. remove_hf(hname)
474 583
 
475 584
    Remove from message all headers with name "hname"
476 585
 
... ...
@@ -483,7 +592,7 @@ if(is_method("OPTION|UPDATE"))
483 592
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
484 593
    FAILURE_ROUTE and BRANCH_ROUTE.
485 594
 
486
-   Example 1-17. remove_hf usage
595
+   Example 1-22. remove_hf usage
487 596
 ...
488 597
 if(remove_hf("User-Agent"))
489 598
 {
... ...
@@ -93,6 +93,34 @@ if ( search("[Ss][Ii][Pp]" ) { /*....*/ };
93 93
 		</example>
94 94
 	</section>
95 95
 
96
+	<section>
97
+		<title>
98
+		<function moreinfo="none">search_body(re)</function>
99
+		</title>
100
+		<para>
101
+		Searches for the re in the body of the message.
102
+		</para>
103
+		<para>Meaning of the parameters is as follows:</para>
104
+		<itemizedlist>
105
+		<listitem>
106
+			<para><emphasis>re</emphasis> - Regular expression.
107
+			</para>
108
+		</listitem>
109
+		</itemizedlist>
110
+		<para>
111
+		This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, 
112
+		FAILURE_ROUTE, BRANCH_ROUTE.
113
+		</para>
114
+		<example>
115
+		<title><function>search_body</function> usage</title>
116
+		<programlisting format="linespecific">
117
+...
118
+if ( search_body("[Ss][Ii][Pp]" ) { /*....*/ };
119
+...
120
+</programlisting>
121
+		</example>
122
+	</section>
123
+
96 124
 	<section>
97 125
 		<title>
98 126
 		<function moreinfo="none">search_append(re, txt)</function>
... ...
@@ -125,6 +153,39 @@ search_append("[Oo]pen[Ss]er", " SIP Proxy");
125 153
 		</example>
126 154
 	</section>
127 155
 
156
+	<section>
157
+		<title>
158
+		<function moreinfo="none">search_append_body(re, txt)</function>
159
+		</title>
160
+		<para>
161
+		Searches for the first match of re in the body of the message
162
+		and appends txt after it.
163
+		</para>
164
+		<para>Meaning of the parameters is as follows:</para>
165
+		<itemizedlist>
166
+		<listitem>
167
+			<para><emphasis>re</emphasis> - Regular expression.
168
+			</para>
169
+		</listitem>
170
+		<listitem>
171
+			<para><emphasis>txt</emphasis> - String to be appended.
172
+			</para>
173
+		</listitem>
174
+		</itemizedlist>
175
+		<para>
176
+		This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, 
177
+		FAILURE_ROUTE, BRANCH_ROUTE.
178
+		</para>
179
+		<example>
180
+		<title><function>search_append_body</function> usage</title>
181
+		<programlisting format="linespecific">
182
+...
183
+search_append_body("[Oo]pen[Ss]er", " SIP Proxy");
184
+...
185
+</programlisting>
186
+		</example>
187
+	</section>
188
+
128 189
 	<section>
129 190
 		<title>
130 191
 		<function moreinfo="none">replace(re, txt)</function>
... ...
@@ -157,6 +218,39 @@ replace("openser", "OpenSER SIP Proxy");
157 218
 		</example>
158 219
 	</section>
159 220
 
221
+	<section>
222
+		<title>
223
+		<function moreinfo="none">replace_body(re, txt)</function>
224
+		</title>
225
+		<para>
226
+		Replaces the first occurrence of re in the body of the message
227
+		with txt.
228
+		</para>
229
+		<para>Meaning of the parameters is as follows:</para>
230
+		<itemizedlist>
231
+		<listitem>
232
+			<para><emphasis>re</emphasis> - Regular expression.
233
+			</para>
234
+		</listitem>
235
+		<listitem>
236
+			<para><emphasis>txt</emphasis> - String.
237
+			</para>
238
+		</listitem>
239
+		</itemizedlist>
240
+		<para>
241
+		This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, 
242
+		FAILURE_ROUTE, BRANCH_ROUTE.
243
+		</para>
244
+		<example>
245
+		<title><function>replace_body</function> usage</title>
246
+		<programlisting format="linespecific">
247
+...
248
+replace_body("openser", "OpenSER SIP Proxy");
249
+...
250
+</programlisting>
251
+		</example>
252
+	</section>
253
+
160 254
 	<section>
161 255
 		<title>
162 256
 		<function moreinfo="none">replace_all(re, txt)</function>
... ...
@@ -189,6 +283,39 @@ replace_all("openser", "OpenSER SIP Proxy");
189 283
 		</example>
190 284
 	</section>
191 285
 
286
+	<section>
287
+		<title>
288
+		<function moreinfo="none">replace_body_all(re, txt)</function>
289
+		</title>
290
+		<para>
291
+		Replaces all occurrence of re in the body of the message
292
+		with txt.
293
+		</para>
294
+		<para>Meaning of the parameters is as follows:</para>
295
+		<itemizedlist>
296
+		<listitem>
297
+			<para><emphasis>re</emphasis> - Regular expression.
298
+			</para>
299
+		</listitem>
300
+		<listitem>
301
+			<para><emphasis>txt</emphasis> - String.
302
+			</para>
303
+		</listitem>
304
+		</itemizedlist>
305
+		<para>
306
+		This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, 
307
+		FAILURE_ROUTE, BRANCH_ROUTE.
308
+		</para>
309
+		<example>
310
+		<title><function>replace_body_all</function> usage</title>
311
+		<programlisting format="linespecific">
312
+...
313
+replace_body_all("openser", "OpenSER SIP Proxy");
314
+...
315
+</programlisting>
316
+		</example>
317
+	</section>
318
+
192 319
 	<section>
193 320
 		<title>
194 321
 		<function moreinfo="none">subst('/re/repl/flags')</function>
... ...
@@ -321,6 +448,46 @@ if (subst_user('/3642$/36423463/')){$
321 448
 # adds avp 'user_prefix' as prefix to username in r-uri ending with 3642
322 449
 if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$
323 450
 
451
+...
452
+</programlisting>
453
+		</example>
454
+	</section>
455
+
456
+	<section>
457
+		<title>
458
+		<function moreinfo="none">subst_body('/re/repl/flags')</function>
459
+		</title>
460
+		<para>
461
+		Replaces re with repl (sed or perl like) in the body of the message.
462
+		</para>
463
+		<para>Meaning of the parameters is as follows:</para>
464
+		<itemizedlist>
465
+		<listitem>
466
+			<para><emphasis>'/re/repl/flags'</emphasis> - sed like regular 
467
+				expression. flags can be a combination of i (case insensitive),
468
+				g (global) or s (match newline don't treat it as end of line).
469
+			</para>
470
+			<para>
471
+			're' - is regular expresion
472
+			</para>
473
+			<para>
474
+			'repl' - is replacement string - may contain pseudo-varibales
475
+			</para>
476
+			<para>
477
+			'flags' - substitution flags (i - ignore case, g - global)
478
+			</para>
479
+		</listitem>
480
+		</itemizedlist>
481
+		<para>
482
+		This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, 
483
+		FAILURE_ROUTE, BRANCH_ROUTE.
484
+		</para>
485
+		<example>
486
+		<title><function>subst_body</function> usage</title>
487
+		<programlisting format="linespecific">
488
+...
489
+if ( subst_body('/^o=(.*) /o=$fU ') ) {};
490
+
324 491
 ...
325 492
 </programlisting>
326 493
 		</example>
... ...
@@ -59,6 +59,7 @@
59 59
 #include "../../data_lump_rpl.h"
60 60
 #include "../../error.h"
61 61
 #include "../../mem/mem.h"
62
+#include "../../str.h"
62 63
 #include "../../re.h"
63 64
 #include "../../parser/parse_uri.h"
64 65
 #include "../../parser/parse_hname2.h"
... ...
@@ -85,14 +86,19 @@ MODULE_VERSION
85 86
 
86 87
 
87 88
 static int search_f(struct sip_msg*, char*, char*);
89
+static int search_body_f(struct sip_msg*, char*, char*);
88 90
 static int replace_f(struct sip_msg*, char*, char*);
91
+static int replace_body_f(struct sip_msg*, char*, char*);
92
+static int replace_all_f(struct sip_msg*, char*, char*);
93
+static int replace_body_all_f(struct sip_msg*, char*, char*);
89 94
 static int subst_f(struct sip_msg*, char*, char*);
90 95
 static int subst_uri_f(struct sip_msg*, char*, char*);
91 96
 static int subst_user_f(struct sip_msg*, char*, char*);
97
+static int subst_body_f(struct sip_msg*, char*, char*);
92 98
 static int remove_hf_f(struct sip_msg* msg, char* str_hf, char* foo);
93 99
 static int is_present_hf_f(struct sip_msg* msg, char* str_hf, char* foo);
94
-static int replace_all_f(struct sip_msg* msg, char* key, char* str);
95 100
 static int search_append_f(struct sip_msg*, char*, char*);
101
+static int search_append_body_f(struct sip_msg*, char*, char*);
96 102
 static int append_to_reply_f(struct sip_msg* msg, char* key, char* str);
97 103
 static int append_hf_1(struct sip_msg* msg, char* str1, char* str2);
98 104
 static int append_hf_2(struct sip_msg* msg, char* str1, char* str2);
... ...
@@ -116,12 +122,20 @@ static int mod_init(void);
116 122
 static cmd_export_t cmds[]={
117 123
 	{"search",           search_f,          1, fixup_regex, 
118 124
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
125
+	{"search_body",      search_body_f,     1, fixup_regex, 
126
+			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
119 127
 	{"search_append",    search_append_f,   2, fixup_regex, 
120 128
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
129
+	{"search_append_body", search_append_body_f,   2, fixup_regex, 
130
+			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
121 131
 	{"replace",          replace_f,         2, fixup_regex, 
122 132
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
133
+	{"replace_body",     replace_body_f,    2, fixup_regex, 
134
+			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
123 135
 	{"replace_all",      replace_all_f,     2, fixup_regex, 
124 136
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
137
+	{"replace_body_all", replace_body_all_f,2, fixup_regex, 
138
+			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
125 139
 	{"append_to_reply",  append_to_reply_f, 1, it_list_fixup,
126 140
 			REQUEST_ROUTE|BRANCH_ROUTE},
127 141
 	{"append_hf",        append_hf_1,       1, add_header_fixup,
... ...
@@ -144,6 +158,8 @@ static cmd_export_t cmds[]={
144 158
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
145 159
 	{"subst_user",       subst_user_f,      1, fixup_substre,
146 160
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
161
+	{"subst_body",       subst_body_f,      1, fixup_substre,
162
+			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
147 163
 	{"append_time",      append_time_f,     0, 0,
148 164
 		REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
149 165
 	{"is_method",        is_method_f,       1, fixup_method,
... ...
@@ -188,8 +204,29 @@ static int search_f(struct sip_msg* msg, char* key, char* str2)
188 204
 }
189 205
 
190 206
 
207
+static int search_body_f(struct sip_msg* msg, char* key, char* str2)
208
+{
209
+	str body;
210
+	/*we registered only 1 param, so we ignore str2*/
211
+	regmatch_t pmatch;
191 212
 
192
-static int search_append_f(struct sip_msg* msg, char* key, char* str)
213
+	body.s = get_body(msg);
214
+	if (body.s==0) {
215
+		LOG(L_ERR, "ERROR:search_body_f: failed to get the message body\n");
216
+		return -1;
217
+	}
218
+	body.len = msg->len -(int)(body.s-msg->buf);
219
+	if (body.len==0) {
220
+		DBG("ERROR:search_body_f: message body has zero length\n");
221
+		return -1;
222
+	}
223
+
224
+	if (regexec((regex_t*) key, body.s, 1, &pmatch, 0)!=0) return -1;
225
+	return 1;
226
+}
227
+
228
+
229
+static int search_append_f(struct sip_msg* msg, char* key, char* str2)
193 230
 {
194 231
 	struct lump* l;
195 232
 	regmatch_t pmatch;
... ...
@@ -205,13 +242,13 @@ static int search_append_f(struct sip_msg* msg, char* key, char* str)
205 242
 	if (pmatch.rm_so!=-1){
206 243
 		if ((l=anchor_lump(msg, off+pmatch.rm_eo, 0, 0))==0)
207 244
 			return -1;
208
-		len=strlen(str);
245
+		len=strlen(str2);
209 246
 		s=pkg_malloc(len);
210 247
 		if (s==0){
211 248
 			LOG(L_ERR, "ERROR: search_append_f: mem. allocation failure\n");
212 249
 			return -1;
213 250
 		}
214
-		memcpy(s, str, len); 
251
+		memcpy(s, str2, len); 
215 252
 		if (insert_new_lump_after(l, s, len, 0)==0){
216 253
 			LOG(L_ERR, "ERROR: could not insert new lump\n");
217 254
 			pkg_free(s);
... ...
@@ -222,11 +259,53 @@ static int search_append_f(struct sip_msg* msg, char* key, char* str)
222 259
 	return -1;
223 260
 }
224 261
 
225
-
226
-static int replace_all_f(struct sip_msg* msg, char* key, char* str)
262
+static int search_append_body_f(struct sip_msg* msg, char* key, char* str2)
227 263
 {
264
+	struct lump* l;
265
+	regmatch_t pmatch;
266
+	char* s;
267
+	int len;
268
+	int off;
269
+	str body;
270
+
271
+	body.s = get_body(msg);
272
+	if (body.s==0) {
273
+		LOG(L_ERR,
274
+				"ERROR:search_append_body_f: failed to get the message body\n");
275
+		return -1;
276
+	}
277
+	body.len = msg->len -(int)(body.s-msg->buf);
278
+	if (body.len==0) {
279
+		DBG("ERROR:search_append_body_f: message body has zero length\n");
280
+		return -1;
281
+	}
282
+
283
+	off=body.s-msg->buf;
284
+
285
+	if (regexec((regex_t*) key, body.s, 1, &pmatch, 0)!=0) return -1;
286
+	if (pmatch.rm_so!=-1){
287
+		if ((l=anchor_lump(msg, off+pmatch.rm_eo, 0, 0))==0)
288
+			return -1;
289
+		len=strlen(str2);
290
+		s=pkg_malloc(len);
291
+		if (s==0){
292
+			LOG(L_ERR, "ERROR: search_append_f: mem. allocation failure\n");
293
+			return -1;
294
+		}
295
+		memcpy(s, str2, len); 
296
+		if (insert_new_lump_after(l, s, len, 0)==0){
297
+			LOG(L_ERR, "ERROR: could not insert new lump\n");
298
+			pkg_free(s);
299
+			return -1;
300
+		}
301
+		return 1;
302
+	}
303
+	return -1;
304
+}
228 305
 
229 306
 
307
+static int replace_all_f(struct sip_msg* msg, char* key, char* str2)
308
+{
230 309
 	struct lump* l;
231 310
 	regmatch_t pmatch;
232 311
 	char* s;
... ...
@@ -238,7 +317,7 @@ static int replace_all_f(struct sip_msg* msg, char* key, char* str)
238 317
 
239 318
 	begin=get_header(msg); /* msg->orig previously .. uri problems */
240 319
 	ret=-1; /* pessimist: we will not find any */
241
-	len=strlen(str);
320
+	len=strlen(str2);
242 321
 	eflags=0; /* match ^ at the beginning of the string*/
243 322
 
244 323
 	while (begin<msg->buf+msg->len 
... ...
@@ -257,12 +336,74 @@ static int replace_all_f(struct sip_msg* msg, char* key, char* str)
257 336
 		}
258 337
 		s=pkg_malloc(len);
259 338
 		if (s==0){
260
-			LOG(L_ERR, "ERROR: replace_f: mem. allocation failure\n");
339
+			LOG(L_ERR, "ERROR: replace_all_f: mem. allocation failure\n");
261 340
 			return -1;
262 341
 		}
263
-		memcpy(s, str, len); 
342
+		memcpy(s, str2, len); 
264 343
 		if (insert_new_lump_after(l, s, len, 0)==0){
265
-			LOG(L_ERR, "ERROR: could not insert new lump\n");
344
+			LOG(L_ERR, "ERROR: replace_all_f: could not insert new lump\n");
345
+			pkg_free(s);
346
+			return -1;
347
+		}
348
+		/* new cycle */
349
+		begin=begin+pmatch.rm_eo;
350
+		ret=1;
351
+	} /* while found ... */
352
+	return ret;
353
+}
354
+
355
+static int replace_body_all_f(struct sip_msg* msg, char* key, char* str2)
356
+{
357
+	struct lump* l;
358
+	regmatch_t pmatch;
359
+	char* s;
360
+	int len;
361
+	char* begin;
362
+	int off;
363
+	int ret;
364
+	int eflags;
365
+	str body;
366
+
367
+	body.s = get_body(msg);
368
+	if (body.s==0) {
369
+		LOG(L_ERR,
370
+				"ERROR:replace_body_all_f: failed to get the message body\n");
371
+		return -1;
372
+	}
373
+	body.len = msg->len -(int)(body.s-msg->buf);
374
+	if (body.len==0) {
375
+		DBG("ERROR:replace_body_all_f: message body has zero length\n");
376
+		return -1;
377
+	}
378
+
379
+	begin=body.s; /* msg->orig previously .. uri problems */
380
+	ret=-1; /* pessimist: we will not find any */
381
+	len=strlen(str2);
382
+	eflags=0; /* match ^ at the beginning of the string*/
383
+
384
+	while (begin<msg->buf+msg->len 
385
+				&& regexec((regex_t*) key, begin, 1, &pmatch, eflags)==0) {
386
+		off=begin-msg->buf;
387
+		/* change eflags, not to match any more at string start */
388
+		eflags|=REG_NOTBOL;
389
+		if (pmatch.rm_so==-1){
390
+			LOG(L_ERR, "ERROR: replace_body_all_f: offset unknown\n");
391
+			return -1;
392
+		}
393
+		if ((l=del_lump(msg, pmatch.rm_so+off,
394
+						pmatch.rm_eo-pmatch.rm_so, 0))==0) {
395
+			LOG(L_ERR, "ERROR: replace_body_all_f: del_lump failed\n");
396
+			return -1;
397
+		}
398
+		s=pkg_malloc(len);
399
+		if (s==0){
400
+			LOG(L_ERR, "ERROR: replace_body_all_f: mem. allocation failure\n");
401
+			return -1;
402
+		}
403
+		memcpy(s, str2, len); 
404
+		if (insert_new_lump_after(l, s, len, 0)==0){
405
+			LOG(L_ERR,
406
+				"ERROR: replace_body_all_f: could not insert new lump\n");
266 407
 			pkg_free(s);
267 408
 			return -1;
268 409
 		}
... ...
@@ -273,7 +414,7 @@ static int replace_all_f(struct sip_msg* msg, char* key, char* str)
273 414
 	return ret;
274 415
 }
275 416
 
276
-static int replace_f(struct sip_msg* msg, char* key, char* str)
417
+static int replace_f(struct sip_msg* msg, char* key, char* str2)
277 418
 {
278 419
 	struct lump* l;
279 420
 	regmatch_t pmatch;
... ...
@@ -291,13 +432,13 @@ static int replace_f(struct sip_msg* msg, char* key, char* str)
291 432
 		if ((l=del_lump(msg, pmatch.rm_so+off,
292 433
 						pmatch.rm_eo-pmatch.rm_so, 0))==0)
293 434
 			return -1;
294
-		len=strlen(str);
435
+		len=strlen(str2);
295 436
 		s=pkg_malloc(len);
296 437
 		if (s==0){
297 438
 			LOG(L_ERR, "ERROR: replace_f: mem. allocation failure\n");
298 439
 			return -1;
299 440
 		}
300
-		memcpy(s, str, len); 
441
+		memcpy(s, str2, len); 
301 442
 		if (insert_new_lump_after(l, s, len, 0)==0){
302 443
 			LOG(L_ERR, "ERROR: could not insert new lump\n");
303 444
 			pkg_free(s);
... ...
@@ -309,6 +450,54 @@ static int replace_f(struct sip_msg* msg, char* key, char* str)
309 450
 	return -1;
310 451
 }
311 452
 
453
+static int replace_body_f(struct sip_msg* msg, char* key, char* str2)
454
+{
455
+	struct lump* l;
456
+	regmatch_t pmatch;
457
+	char* s;
458
+	int len;
459
+	char* begin;
460
+	int off;
461
+	str body;
462
+
463
+	body.s = get_body(msg);
464
+	if (body.s==0) {
465
+		LOG(L_ERR,
466
+				"ERROR:replace_body_f: failed to get the message body\n");
467
+		return -1;
468
+	}
469
+	body.len = msg->len -(int)(body.s-msg->buf);
470
+	if (body.len==0) {
471
+		DBG("ERROR:replace_body_f: message body has zero length\n");
472
+		return -1;
473
+	}
474
+
475
+	begin=body.s; /* msg->orig previously .. uri problems */
476
+
477
+	if (regexec((regex_t*) key, begin, 1, &pmatch, 0)!=0) return -1;
478
+	off=begin-msg->buf;
479
+
480
+	if (pmatch.rm_so!=-1){
481
+		if ((l=del_lump(msg, pmatch.rm_so+off,
482
+						pmatch.rm_eo-pmatch.rm_so, 0))==0)
483
+			return -1;
484
+		len=strlen(str2);
485
+		s=pkg_malloc(len);
486
+		if (s==0){
487
+			LOG(L_ERR, "ERROR: replace_body_f: mem. allocation failure\n");
488
+			return -1;
489
+		}
490
+		memcpy(s, str2, len); 
491
+		if (insert_new_lump_after(l, s, len, 0)==0){
492
+			LOG(L_ERR, "ERROR: replace_body_f: could not insert new lump\n");
493
+			pkg_free(s);
494
+			return -1;
495
+		}
496
+		
497
+		return 1;
498
+	}
499
+	return -1;
500
+}
312 501
 
313 502
 
314 503
 /* sed-perl style re: s/regular expression/replacement/flags */
... ...
@@ -445,6 +634,66 @@ static int subst_user_f(struct sip_msg* msg, char*  subst, char* ignored)
445 634
 }
446 635
 
447 636
 
637
+/* sed-perl style re: s/regular expression/replacement/flags */
638
+static int subst_body_f(struct sip_msg* msg, char*  subst, char* ignored)
639
+{
640
+	struct lump* l;
641
+	struct replace_lst* lst;
642
+	struct replace_lst* rpl;
643
+	char* begin;
644
+	struct subst_expr* se;
645
+	int off;
646
+	int ret;
647
+	int nmatches;
648
+	str body;
649
+
650
+	body.s = get_body(msg);
651
+	if (body.s==0) {
652
+		LOG(L_ERR,
653
+				"ERROR:subst_body_f: failed to get the message body\n");
654
+		return -1;
655
+	}
656
+	body.len = msg->len -(int)(body.s-msg->buf);
657
+	if (body.len==0) {
658
+		DBG("ERROR:subst_body_f: message body has zero length\n");
659
+		return -1;
660
+	}
661
+	
662
+	se=(struct subst_expr*)subst;
663
+	begin=body.s;
664
+	
665
+	off=begin-msg->buf;
666
+	ret=-1;
667
+	if ((lst=subst_run(se, begin, msg, &nmatches))==0)
668
+		goto error; /* not found */
669
+	for (rpl=lst; rpl; rpl=rpl->next){
670
+		DBG("%s:subst_body_f: replacing at offset %d [%.*s] with [%.*s]\n",
671
+				exports.name, rpl->offset+off,
672
+				rpl->size, rpl->offset+off+msg->buf,
673
+				rpl->rpl.len, rpl->rpl.s);
674
+		if ((l=del_lump(msg, rpl->offset+off, rpl->size, 0))==0)
675
+			goto error;
676
+		/* hack to avoid re-copying rpl, possible because both 
677
+		 * replace_lst & lumps use pkg_malloc */
678
+		if (insert_new_lump_after(l, rpl->rpl.s, rpl->rpl.len, 0)==0){
679
+			LOG(L_ERR, "ERROR:%s: subst_body_f: could not insert new lump\n",
680
+					exports.name);
681
+			goto error;
682
+		}
683
+		/* hack continued: set rpl.s to 0 so that replace_lst_free will
684
+		 * not free it */
685
+		rpl->rpl.s=0;
686
+		rpl->rpl.len=0;
687
+	}
688
+	ret=1;
689
+error:
690
+	DBG("subst_body_f: lst was %p\n", lst);
691
+	if (lst) replace_lst_free(lst);
692
+	if (nmatches<0)
693
+		LOG(L_ERR, "ERROR:%s:subst_body_f: subst_run failed\n", exports.name);
694
+	return ret;
695
+}
696
+
448 697
 
449 698
 static int remove_hf_f(struct sip_msg* msg, char* str_hf, char* foo)
450 699
 {