Browse code

- possibility to skip removing the prefix

Elena-Ramona Modroiu authored on 03/02/2005 22:05:27
Showing 3 changed files
... ...
@@ -34,7 +34,7 @@ Elena-Ramona Modroiu
34 34
 
35 35
         1.4. Exported Functions
36 36
 
37
-              1.4.1. prefix2domain()
37
+              1.4.1. prefix2domain(mode)
38 38
 
39 39
         1.5. Installation & Running
40 40
 
... ...
@@ -221,7 +221,7 @@ modparam("pdt", "clean_time", 600)
221 221
 
222 222
 1.4. Exported Functions
223 223
 
224
-1.4.1. prefix2domain()
224
+1.4.1. prefix2domain(mode)
225 225
 
226 226
    Build a new URI if it is necessary. Returns 1 when the
227 227
    translation was made or there was nothing to translate (user
... ...
@@ -229,10 +229,19 @@ modparam("pdt", "clean_time", 600)
229 229
    parameter or there is no domain associated with a possible
230 230
    prefix from user part). Returns -1 in error cases.
231 231
 
232
+   The "mode" parameter specifies whether to strip or not the
233
+   prefix from user part. If the parameter is missing or it has
234
+   the value "0", then the prefix is removed along with the
235
+   leading prefix. If the value is "1", only the leading prefix
236
+   is removed. If the values is "2" the user part of the URI is
237
+   not changed.
238
+
232 239
    Example 1-10. prefix2domain usage
233 240
 ...
234 241
 prefix2domain();
235 242
 ...
243
+prefix2domain("2");
244
+...
236 245
      _________________________________________________________
237 246
 
238 247
 1.5. Installation & Running
... ...
@@ -270,7 +270,7 @@ modparam("pdt", "clean_time", 600)
270 270
 	<title>Exported Functions</title>
271 271
 	<section>
272 272
 	    <title>
273
-		<function moreinfo="none">prefix2domain()</function>
273
+		<function moreinfo="none">prefix2domain(mode)</function>
274 274
 	    </title>
275 275
 	    <para>
276 276
 		Build a new &uri; if it is necessary. Returns 1 when the translation
... ...
@@ -279,12 +279,22 @@ modparam("pdt", "clean_time", 600)
279 279
 		associated with a possible prefix from user part).
280 280
 		Returns -1 in error cases.
281 281
 	    </para>
282
+		<para>
283
+		The <quote>mode</quote> parameter specifies whether to strip or not
284
+		the prefix from user part. If the parameter is missing or it has the
285
+		value <quote>0</quote>, then the prefix is removed along with the 
286
+		leading prefix. If the value is <quote>1</quote>, only the leading
287
+		prefix is removed. If the values is <quote>2</quote> the user part
288
+		of the URI is not changed.
289
+		</para>
282 290
 	    <example>
283 291
 		<title><function>prefix2domain</function> usage</title>
284 292
 		<programlisting format="linespecific">
285 293
 ...
286 294
 prefix2domain();
287 295
 ...
296
+prefix2domain("2");
297
+...
288 298
 </programlisting>
289 299
 	    </example>
290 300
 	</section>
... ...
@@ -89,23 +89,26 @@ str prefix = {"", 0};
89 89
 int sync_time = 600;
90 90
 int clean_time = 900;
91 91
 
92
-static int prefix2domain(struct sip_msg*, char*, char*);
92
+static int w_prefix2domain(struct sip_msg* msg, char* str1, char* str2);
93
+static int w_prefix2domain_1(struct sip_msg* msg, char* mode, char* str2);
93 94
 static int mod_init(void);
94 95
 static void mod_destroy(void);
95 96
 static int  child_init(int r);
96 97
 
98
+static int prefix2domain(struct sip_msg*, int mode);
97 99
 static int get_domainprefix_unixsock(str* msg);
98 100
 static int pdt_fifo_add(FILE *stream, char *response_file);
99 101
 static int pdt_fifo_delete(FILE *stream, char *response_file);
100 102
 static int pdt_fifo_list(FILE *stream, char *response_file);
101 103
 
102
-int update_new_uri(struct sip_msg *msg, int plen, str *d);
104
+int update_new_uri(struct sip_msg *msg, int plen, str *d, int mode);
103 105
 int pdt_load_db();
104 106
 int pdt_sync_cache();
105 107
 void pdt_clean_cache(unsigned int ticks, void *param);
106 108
 
107 109
 static cmd_export_t cmds[]={
108
-	{"prefix2domain", prefix2domain, 0, 0, REQUEST_ROUTE},
110
+	{"prefix2domain", w_prefix2domain,   0, 0, REQUEST_ROUTE|FAILURE_ROUTE},
111
+	{"prefix2domain", w_prefix2domain_1, 1, 0, REQUEST_ROUTE|FAILURE_ROUTE},
109 112
 	{0, 0, 0, 0, 0}
110 113
 };
111 114
 
... ...
@@ -320,8 +323,22 @@ static void mod_destroy(void)
320 320
 }
321 321
 
322 322
 
323
+static int w_prefix2domain(struct sip_msg* msg, char* str1, char* str2)
324
+{
325
+	return prefix2domain(msg, 0);
326
+}
327
+
328
+static int w_prefix2domain_1(struct sip_msg* msg, char* mode, char* str2)
329
+{
330
+	if(mode!=NULL && *mode=='1')
331
+		return prefix2domain(msg, 1);
332
+	else if(mode!=NULL && *mode=='2')
333
+			return prefix2domain(msg, 2);
334
+	else return prefix2domain(msg, 0);
335
+}
336
+
323 337
 /* change the r-uri if it is a PSTN format */
324
-static int prefix2domain(struct sip_msg* msg, char* str1, char* str2)
338
+static int prefix2domain(struct sip_msg* msg, int mode)
325 339
 {
326 340
 	str p;
327 341
 	str *d;
... ...
@@ -382,7 +399,7 @@ static int prefix2domain(struct sip_msg* msg, char* str1, char* str2)
382 382
 	}
383 383
 	
384 384
 	/* update the new uri */
385
-	if(update_new_uri(msg, plen, d)<0)
385
+	if(update_new_uri(msg, plen, d, mode)<0)
386 386
 	{
387 387
 		LOG(L_ERR, "PDT:prefix2domain: new_uri cannot be updated\n");
388 388
 		return -1;
... ...
@@ -391,7 +408,7 @@ static int prefix2domain(struct sip_msg* msg, char* str1, char* str2)
391 391
 }
392 392
 
393 393
 /* change the uri according to translation of the prefix */
394
-int update_new_uri(struct sip_msg *msg, int plen, str *d)
394
+int update_new_uri(struct sip_msg *msg, int plen, str *d, int mode)
395 395
 {
396 396
 	struct action act;
397 397
 	if(msg==NULL || d==NULL)
... ...
@@ -400,17 +417,23 @@ int update_new_uri(struct sip_msg *msg, int plen, str *d)
400 400
 		return -1;
401 401
 	}
402 402
 	
403
-	act.type = STRIP_T;
404
-	act.p1_type = NUMBER_ST;
405
-	act.p1.number = plen + prefix.len;
406
-	act.next = 0;
407
-
408
-	if (do_action(&act, msg) < 0)
403
+	if(mode==0 || (mode==1 && prefix.len>0))
409 404
 	{
410
-		LOG(L_ERR, "PDT:update_new_uri:Error removing prefix\n");
411
-		return -1;
412
-	}
405
+		act.type = STRIP_T;
406
+		act.p1_type = NUMBER_ST;
407
+		if(mode==0)
408
+			act.p1.number = plen + prefix.len;
409
+		else
410
+			act.p1.number = prefix.len;
411
+		act.next = 0;
413 412
 
413
+		if (do_action(&act, msg) < 0)
414
+		{
415
+			LOG(L_ERR, "PDT:update_new_uri:Error removing prefix\n");
416
+			return -1;
417
+		}
418
+	}
419
+	
414 420
 	act.type = SET_HOSTPORT_T;
415 421
 	act.p1_type = STRING_ST;
416 422
 	act.p1.string = d->s;