Browse code

- second parameter of get_user_group() takes full AVP spec format (coherence along the parameters)

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

Daniel-Constantin Mierla authored on 05/02/2008 11:46:11
Showing 5 changed files
... ...
@@ -255,8 +255,8 @@ modparam("group", "multiple_gid", 0)
255 255
           + To - Use To username and (optionally) domain.
256 256
           + From - Use From username and (optionally) domain.
257 257
           + Credentials - Use digest credentials username.
258
-          + $avp[avp_name|avp_alias] - Use the URI from the AVP
259
-            specified by this pseudo-variable.
258
+          + $avp(name) - Use the URI from the AVP specified by
259
+            this pseudo-variable.
260 260
      * group - Name of the group to check.
261 261
 
262 262
    This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
... ...
@@ -284,17 +284,16 @@ if (is_user_in("Request-URI", "ld")) {
284 284
           + From - Use From URI
285 285
           + Credentials - Use digest credentials username and
286 286
             realm.
287
-          + $avp[avp_name|avp_alias] - Use the URI from the AVP
288
-            specified by this pseudo-variable.
289
-     * AVP_ID - The matched group IDs are returned as AVPs named
290
-       "AVP". It accepts a full AVP specification: AVP, ID and
291
-       NAME. alias also
287
+          + $avp(name) - Use the URI from the AVP specified by
288
+            this pseudo-variable.
289
+     * AVP - $avp(name) - the matched group IDs are returned in
290
+       this AVP.
292 291
 
293 292
    This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
294 293
 
295 294
    Example 1-12. get_user_group usage
296 295
 ...
297
-if (get_user_group("Request-URI", "i:10")) {
296
+if (get_user_group("Request-URI", "$avp(i:10)")) {
298 297
     xgdb("User $ru belongs to $(avp(i:10)[*]) group(s)\n");
299 298
     ....
300 299
 };
... ...
@@ -318,7 +318,7 @@ modparam("group", "multiple_gid", 0)
318 318
 				<para>Credentials - Use digest credentials username.</para>
319 319
 				</listitem>
320 320
 				<listitem>
321
-				<para>$avp[avp_name|avp_alias] - Use the URI from the AVP
321
+				<para>$avp(name) - Use the URI from the AVP
322 322
 				specified by this pseudo-variable.</para>
323 323
 				</listitem>
324 324
 			</itemizedlist>
... ...
@@ -373,17 +373,15 @@ if (is_user_in("Request-URI", "ld")) {
373 373
 				and realm.</para>
374 374
 				</listitem>
375 375
 				<listitem>
376
-				<para>$avp[avp_name|avp_alias] - Use the URI from the AVP
376
+				<para>$avp(name) - Use the URI from the AVP
377 377
 				specified by this pseudo-variable.</para>
378 378
 				</listitem>
379 379
 			</itemizedlist>
380 380
 			</para>
381 381
 		</listitem>
382 382
 		<listitem>
383
-			<para><emphasis>AVP_ID</emphasis> - The matched group IDs are
384
-			returned as AVPs named <quote>AVP</quote>. It accepts a full AVP
385
-			specification: AVP, ID and NAME.
386
-			alias also</para>
383
+			<para><emphasis>AVP</emphasis> - $avp(name) - the matched group
384
+			IDs are returned in this AVP.</para>
387 385
 		</listitem>
388 386
 		</itemizedlist>
389 387
 		<para>
... ...
@@ -393,7 +391,7 @@ if (is_user_in("Request-URI", "ld")) {
393 393
 		<title><function>get_user_group</function> usage</title>
394 394
 		<programlisting format="linespecific">
395 395
 ...
396
-if (get_user_group("Request-URI", "i:10")) {
396
+if (get_user_group("Request-URI", "$avp(i:10)")) {
397 397
     xgdb("User $ru belongs to $(avp(i:10)[*]) group(s)\n");
398 398
     ....
399 399
 };
... ...
@@ -313,7 +313,7 @@ static int hf_fixup(void** param, int param_no)
313 313
 
314 314
 static int get_gid_fixup(void** param, int param_no)
315 315
 {
316
-	struct gid_spec *gid;
316
+	pv_spec_t *sp;
317 317
 	void *ptr;
318 318
 	str  name;
319 319
 
... ...
@@ -324,17 +324,19 @@ static int get_gid_fixup(void** param, int param_no)
324 324
 	} else if (param_no == 2) {
325 325
 		name.s = (char*)*param;
326 326
 		name.len = strlen(name.s);
327
-		gid = (struct gid_spec*)pkg_malloc(sizeof(struct gid_spec));
328
-		if (gid == NULL) {
327
+		sp = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t));
328
+		if (sp == NULL) {
329 329
 			LM_ERR("no more pkg memory\n");
330 330
 			return E_UNSPEC;
331 331
 		}
332
-		if ( parse_avp_spec( &name, &gid->avp_type, &gid->avp_name)!=0 ) {
332
+		if(pv_parse_spec(&name, sp)==NULL || sp->type!=PVT_AVP)
333
+		{
333 334
 			LM_ERR("bad AVP spec <%s>\n", name.s);
334
-			pkg_free( gid );
335
+			pv_spec_free(sp);
335 336
 			return E_UNSPEC;
336 337
 		}
337
-		*param = gid;
338
+
339
+		*param = sp;
338 340
 	}
339 341
 
340 342
 	return 0;
... ...
@@ -29,6 +29,7 @@
29 29
 
30 30
 #include "../../str.h"
31 31
 #include "../../mem/mem.h"
32
+#include "../../route_struct.h"
32 33
 #include "group_mod.h"
33 34
 #include "re_group.h"
34 35
 #include "group.h"
... ...
@@ -132,7 +133,8 @@ int get_user_group(struct sip_msg *req, char *user, char *avp)
132 132
 	static char uri_buf[MAX_URI_SIZE];
133 133
 	str  username;
134 134
 	str  domain;
135
-	struct gid_spec *gs;
135
+	pv_spec_t *pvs;
136
+	pv_value_t val;
136 137
 	struct re_grp *rg;
137 138
 	regmatch_t pmatch;
138 139
 	char *c;
... ...
@@ -163,16 +165,20 @@ int get_user_group(struct sip_msg *req, char *user, char *avp)
163 163
 	*c = 0;
164 164
 
165 165
 	LM_DBG("getting groups for <%s>\n",uri_buf);
166
-	gs = (struct gid_spec*)avp;
166
+	pvs = (pv_spec_t*)avp;
167
+	memset(&val, 0, sizeof(pv_value_t));
168
+	val.flags = PV_VAL_INT|PV_TYPE_INT;
167 169
 
168 170
 	/* check against all re groups */
169 171
 	for( rg=re_list,n=0 ; rg ; rg=rg->next ) {
170 172
 		if (regexec( &rg->re, uri_buf, 1, &pmatch, 0)==0) {
171 173
 			LM_DBG("user matched to group %d!\n", rg->gid.n);
174
+
172 175
 			/* match -> add the gid as AVP */
173
-			if ( add_avp( (unsigned short)gs->avp_type, gs->avp_name,
174
-			rg->gid )!= 0 ) {
175
-				LM_ERR("failed to add avp\n");
176
+			val.ri = rg->gid.n;
177
+			if(pvs->setf(req, &pvs->pvp, (int)EQ_T, &val)<0)
178
+			{
179
+				LM_ERR("setting PV AVP failed\n");
176 180
 				goto error;
177 181
 			}
178 182
 			n++;
... ...
@@ -28,15 +28,8 @@
28 28
 #define RE_GROUP_H
29 29
 
30 30
 #include "../../str.h"
31
-#include "../../usr_avp.h"
32 31
 #include "../../parser/msg_parser.h"
33 32
 
34
-typedef struct gid_spec {
35
-	int     avp_type;
36
-	int_str avp_name;
37
-} gid_spec_t;
38
-
39
-
40 33
 int load_re(str *table);
41 34
 
42 35
 int get_user_group(struct sip_msg *req, char *user, char *avp);