Determine if both the caller and the callee are in the same group

How to use Attribute Value Pairs (AVP's) to determine if both the caller and the callee are in the same group?

A real world example would be to limit friends to only calling friends that are in the same group of friends.

1) Create two entries in the usr_preferences table.

One entry is associated with the caller and the other is associated with the callee. Both entries use “friend” as the attribute and “groupa” as the value.

2) Add the following AVP alias definition:

modparam("avpops","avp_aliases", "temp=i:59;......)

3) Add the following code to the INVITE section of your configuration:

avp_db_load("$from/username", "s:friend");
avp_copy("s:friend", "$temp");\\
avp_db_load("$ruri/username", "s:friend");

# xlog("L_NOTICE", "friend avp: ($avp(s:friend))\n");
# xlog("L_NOTICE", "temp avp: ($avp(i:59))\n");

if (avp_check("s:friend", "eq/$temp") ) {
  xlog("L_NOTICE", "friend avp: ($avp(s:friend))\n");
  xlog("L_NOTICE", "temp avp: ($avp(i:59))\n");
};