Browse code

modules/diaplan: dest pv is now optional in dp_translate()

- If dest pv is not given, only matching and storing of matching rule's
attributes is done.
- If replacement empty, dest pv is not set no matter what kind of pv it is.

Juha Heinanen authored on 30/03/2010 16:20:50
Showing 4 changed files
... ...
@@ -12,9 +12,9 @@ Edited by
12 12
 
13 13
 Juha Heinanen
14 14
 
15
-   Copyright � 2007-2008 voice-system.ro
15
+   Copyright © 2007-2008 voice-system.ro
16 16
 
17
-   Copyright � 2008 Juha Heinanen
17
+   Copyright © 2008-2010 Juha Heinanen
18 18
    Revision History
19 19
    Revision $Revision: 1.1 $ $Date: 2007/08/30 13:16:22 $
20 20
    Revision $Revision: 1.2 $ $Date: 2008/10/9 15:57 $
... ...
@@ -49,7 +49,7 @@ Juha Heinanen
49 49
 
50 50
         6. Exported Functions
51 51
 
52
-              6.1. dp_translate(id, src/dest)
52
+              6.1. dp_translate(id, src[/dest])
53 53
 
54 54
         7. Exported MI Functions
55 55
 
... ...
@@ -106,7 +106,7 @@ Chapter 1. Admin Guide
106 106
 
107 107
    6. Exported Functions
108 108
 
109
-        6.1. dp_translate(id, src/dest)
109
+        6.1. dp_translate(id, src[/dest])
110 110
 
111 111
    7. Exported MI Functions
112 112
 
... ...
@@ -191,7 +191,7 @@ Chapter 1. Admin Guide
191 191
 
192 192
    The translation rules will be loaded using this database URL.
193 193
 
194
-   Default value is "mysql://openser:openserrw@localhost/openser".
194
+   Default value is “mysql://openser:openserrw@localhost/openser”.
195 195
 
196 196
    Example 1.1. Set db_url parameter
197 197
 ...
... ...
@@ -202,7 +202,7 @@ modparam("dialplan", "db_url", "mysql://user:passwb@localhost/db")
202 202
 
203 203
    The table's name from which to load the translation rules.
204 204
 
205
-   Default value is "dialplan".
205
+   Default value is “dialplan”.
206 206
 
207 207
    Example 1.2. Set table_name parameter
208 208
 ...
... ...
@@ -213,7 +213,7 @@ modparam("dialplan", "table_name", "my_table")
213 213
 
214 214
    The column name used to store the dialplan ID group.
215 215
 
216
-   Default value is "dpid".
216
+   Default value is “dpid”.
217 217
 
218 218
    Example 1.3. Set dpid_col parameter
219 219
 ...
... ...
@@ -225,7 +225,7 @@ modparam("dialplan", "dpid_col", "column_name")
225 225
    The column name used to store the priority of the corresponding rule
226 226
    from the database row.
227 227
 
228
-   Default value is "pr".
228
+   Default value is “pr”.
229 229
 
230 230
    Example 1.4. Set pr_col parameter
231 231
 ...
... ...
@@ -236,7 +236,7 @@ modparam("dialplan", "pr_col", "column_name")
236 236
 
237 237
    The column name used to store the type of matching of the rule.
238 238
 
239
-   Default value is "match_op".
239
+   Default value is “match_op”.
240 240
 
241 241
    Example 1.5. Set match_op_col parameter
242 242
 ...
... ...
@@ -247,7 +247,7 @@ modparam("dialplan", "match_op_col", "column_name")
247 247
 
248 248
    The column name to store the rule match expression.
249 249
 
250
-   Default value is "match_exp".
250
+   Default value is “match_exp”.
251 251
 
252 252
    Example 1.6. Set match_exp_col parameter
253 253
 ...
... ...
@@ -259,7 +259,7 @@ modparam("dialplan", "match_exp_col", "column_name")
259 259
    The column name to store the length of a string matching the match
260 260
    expression.
261 261
 
262
-   Default value is "match_len".
262
+   Default value is “match_len”.
263 263
 
264 264
    Example 1.7. Set pr_col parameter
265 265
 ...
... ...
@@ -270,7 +270,7 @@ modparam("dialplan", "match_len_col", "column_name")
270 270
 
271 271
    The column name to store the rule's substitution expression.
272 272
 
273
-   Default value is "subst_exp".
273
+   Default value is “subst_exp”.
274 274
 
275 275
    Example 1.8. Set pr_col parameter
276 276
 ...
... ...
@@ -281,7 +281,7 @@ modparam("dialplan", "subst_exp_col", "column_name")
281 281
 
282 282
    The column name to store the rule's replacement expression.
283 283
 
284
-   Default value is "repl_exp".
284
+   Default value is “repl_exp”.
285 285
 
286 286
    Example 1.9. Set repl_exp_col parameter
287 287
 ...
... ...
@@ -293,7 +293,7 @@ modparam("dialplan", "repl_exp_col", "column_name")
293 293
    The column name to store the rule's attributes to be set to the
294 294
    message.
295 295
 
296
-   Default value is "attrs".
296
+   Default value is “attrs”.
297 297
 
298 298
    Example 1.10. Set attrs_col parameter
299 299
 ...
... ...
@@ -306,7 +306,7 @@ modparam("dialplan", "attrs_col", "column_name")
306 306
    (dp_translate() succeeds). This parameter can be an AVP or a SCRIPT
307 307
    VAR.
308 308
 
309
-   Default value is "NULL".
309
+   Default value is “NULL”.
310 310
 
311 311
    Example 1.11. Set attrs_pvar parameter
312 312
 ...
... ...
@@ -317,7 +317,7 @@ modparam("dialplan", "attrs_pvar", "$avp(s:dest)")
317 317
 
318 318
    The number of rows to be fetched at once from database
319 319
 
320
-   Default value is "1000".
320
+   Default value is “1000”.
321 321
 
322 322
    Example 1.12. Set fetch_rows parameter
323 323
 ...
... ...
@@ -326,12 +326,13 @@ modparam("dialplan", "fetch_rows", 4000)
326 326
 
327 327
 6. Exported Functions
328 328
 
329
-   6.1. dp_translate(id, src/dest)
329
+   6.1. dp_translate(id, src[/dest])
330 330
 
331
-6.1. dp_translate(id, src/dest)
331
+6.1.  dp_translate(id, src[/dest])
332 332
 
333
-   Will try to translate the src string into dest string according to the
334
-   translation rules with dialplan ID equal to id.
333
+   Will try to translate src into dest according to the translation rules
334
+   with dialplan ID equal to id. If dest is missing, only matching and
335
+   storing of matching rule's attributes is done.
335 336
 
336 337
    Meaning of the parameters is as follows:
337 338
      * id -the dialplan id of the possible matching rules. This parameter
... ...
@@ -342,12 +343,12 @@ modparam("dialplan", "fetch_rows", 4000)
342 342
           + script var - the dialplan id is the value of an existing
343 343
             script variable.
344 344
      * src/dest - input and output of the function. If this parameter is
345
-       missing the default parameter "ruri.user/ruri.user" will be used,
346
-       thus translating the request uri.
345
+       missing the default parameter “ruri.user/ruri.user” will be used,
346
+       thus translating the request uri user part.
347 347
        Input parameter src can be any pseudo variable. Output parameter
348 348
        dest can be:
349 349
           + R-URI
350
-            - the string is the r-uri or r-uri username
350
+            - the string is the r-uri or r-uri user part
351 351
           + avp var
352 352
             - At input the function will get the input string from an
353 353
             existing avp variable. At output the function will add an avp
... ...
@@ -267,13 +267,12 @@ static int dp_get_svalue(struct sip_msg * msg, pv_spec_t spec, str* val)
267 267
 
268 268
 
269 269
 static int dp_update(struct sip_msg * msg, pv_spec_t * src, pv_spec_t * dest,
270
-											str * repl, str * attrs)
270
+		     str * repl, str * attrs)
271 271
 {
272 272
 	int no_change;
273 273
 	pv_value_t val;
274 274
 
275
-	no_change = ((!repl->s) || (!repl->len)) && (src->type == dest->type) 
276
-		&& ((src->type == PVT_RURI) || (src->type == PVT_RURI_USERNAME));
275
+	no_change = (dest->type == PVT_NONE) || (!repl->s) || (!repl->len);
277 276
 
278 277
 	if (no_change)
279 278
 		goto set_attr_pvar;
... ...
@@ -380,7 +379,7 @@ static int dp_translate_f(struct sip_msg* msg, char* str1, char* str2)
380 380
 
381 381
 /* first param: DPID: type: INT, AVP, SVAR
382 382
  * second param: SRC type: any psedo variable type
383
- * second param: DST type: RURI, RURI_USERNAME, AVP, SVAR
383
+ * second param: DST type: RURI, RURI_USERNAME, AVP, SVAR, N/A
384 384
  * default value for the second param: $ru.user/$ru.user
385 385
  */
386 386
 static int dp_trans_fixup(void ** param, int param_no){
... ...
@@ -429,21 +428,29 @@ static int dp_trans_fixup(void ** param, int param_no){
429 429
 			dp_par->type = DP_VAL_SPEC;
430 430
 		}
431 431
 	} else {
432
-		if( ((s = strchr(p, '/')) == 0) ||( *(s+1)=='\0'))
433
-				goto error;
432
+
433
+	    if (((s = strchr(p, '/')) != 0) && (*(s+1)=='\0'))
434
+		goto error;
435
+
436
+	    if (s != 0) {
434 437
 		*s = '\0'; s++;
438
+	    }
435 439
 
436
-		lstr.s = p; lstr.len = strlen(p);
437
-		if(pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
438
-			goto error;
440
+	    lstr.s = p; lstr.len = strlen(p);
441
+	    if(pv_parse_spec( &lstr, &dp_par->v.sp[0])==NULL)
442
+		goto error;
439 443
 
444
+	    if (s != 0) {
440 445
 		lstr.s = s; lstr.len = strlen(s);
441 446
 		if (pv_parse_spec( &lstr, &dp_par->v.sp[1] )==NULL)
442
-			goto error;
443
-
447
+		    goto error;
444 448
 		verify_par_type(param_no, dp_par->v.sp[1]);
449
+	    } else {
450
+		dp_par->v.sp[1].type = PVT_NONE;
451
+	    }
452
+
453
+	    dp_par->type = DP_VAL_SPEC;
445 454
 
446
-		dp_par->type = DP_VAL_SPEC;
447 455
 	}
448 456
 	
449 457
 	*param = (void *)dp_par;
... ...
@@ -38,7 +38,7 @@
38 38
 		<holder>&voicesystem;</holder>
39 39
 	</copyright>
40 40
 	<copyright>
41
-		<year>2008</year>
41
+		<year>2008-2010</year>
42 42
 		<holder>Juha Heinanen</holder>
43 43
 	</copyright>
44 44
 	<revhistory>
... ...
@@ -357,11 +357,13 @@ modparam("dialplan", "fetch_rows", 4000)
357 357
 	
358 358
 	<section>
359 359
 	<title>
360
-		<function moreinfo="none">dp_translate(id, src/dest)</function>
360
+		<function moreinfo="none">dp_translate(id, src[/dest])</function>
361 361
 	</title>
362 362
 	<para>
363
-	Will try to translate the src string into dest string according to 
364
-	the translation rules with dialplan ID equal to id.
363
+	Will try to translate src into dest according to 
364
+	the translation rules with dialplan ID equal to id.  If dest is
365
+	missing, only matching and storing of matching rule's
366
+	attributes is done.
365 367
 	</para>
366 368
 	<para>Meaning of the parameters is as follows:</para>
367 369
 	<itemizedlist>
... ...
@@ -393,8 +395,8 @@ modparam("dialplan", "fetch_rows", 4000)
393 393
 		<para>
394 394
  		<emphasis>src/dest</emphasis> - input and output of the function.
395 395
 		If this parameter is missing the default parameter 
396
-		<quote>ruri.user/ruri.user</quote> will be used, thus translating 
397
-		the request uri. 
396
+		<quote>ruri.user/ruri.user</quote> will be used, thus
397
+		translating the request uri user part. 
398 398
  		</para>
399 399
 		<para>Input parameter src can be any pseudo variable.
400 400
 		Output parameter dest can be:
... ...
@@ -403,7 +405,7 @@ modparam("dialplan", "fetch_rows", 4000)
403 403
 			<listitem>
404 404
 			<para><emphasis>R-URI</emphasis></para>
405 405
 			<para>
406
-			- the string is the r-uri or r-uri username
406
+			- the string is the r-uri or r-uri user part
407 407
 			</para>
408 408
 			</listitem>
409 409