use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.
the class AvpAssistant method checkAvpFlags.
/**
* @param set
* the set to check
* @return an array of offending AVPs
*/
protected static ArrayList<String> checkAvpFlags(AvpSet set) {
ArrayList<String> failedAvps = new ArrayList<String>();
for (Avp avp : set) {
// System.out.println(avp.getVendorId() + ":" + avp.getCode() + " V[" + avp.isVendorId() + "] M[" +
// avp.isMandatory() + "] P[" + avp.isEncrypted() + "]");
AvpRepresentation avpRep = DictionaryImpl.INSTANCE.getAvp(avp.getCode(), avp.getVendorId());
// Mandatory must not be set if rule is MUST NOT or SHOULD NOT
if (avp.isMandatory() && (avpRep.getRuleMandatory().equals("mustnot") || avpRep.getRuleMandatory().equals("shouldnot"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[M / '" + avp.isMandatory() + "' vs '" + avpRep.getRuleMandatory() + "']");
}
// Protected must not be set if rule is MUST or MAY
if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
}
// Vendor must be set if rule is MUST or MAY
if (avp.isEncrypted() && !(avpRep.getRuleProtected().equals("must") || avpRep.getRuleProtected().equals("may"))) {
failedAvps.add("- Code[" + avp.getCode() + "], Vendor-Id[" + avp.getVendorId() + "], Flag[P / '" + avp.isEncrypted() + "' vs '" + avpRep.getRuleProtected() + "']");
}
AvpSet subAvps = null;
try {
subAvps = avp.getGrouped();
} catch (Exception e) {
}
if (subAvps != null) {
failedAvps.addAll(checkAvpFlags(subAvps));
}
}
return failedAvps;
}
use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.
the class AvpUtilities method setAvpAsString.
/**
* Adds AVP to {@link AvpSet} as String (Octet or UTF-8) with the given code and given Vendor-Id plus defined mandatory and protected flags.
*
* @param parent the Message/Grouped AVP where AVP will be added to, for validation purposes. if null, no validation is performed.
* @param avpCode the code of the AVP
* @param vendorId the Vendor-Id of the AVP
* @param isOctetString if true added as OctetString type, otherwise as UTF8String
* @param set the AvpSet to add AVP
* @param isMandatory the value for the mandatory bit
* @param isProtected the value for the protected bit
* @param value the value of the AVP to add
*/
public static void setAvpAsString(Object parent, int avpCode, long vendorId, boolean isOctetString, AvpSet set, boolean isMandatory, boolean isProtected, String value) {
performPreAddOperations(parent, avpCode, vendorId, set);
switch(avpCode) {
case Avp.SESSION_ID:
// (...) All messages pertaining to a specific session MUST include only one Session-Id AVP (...)
set.removeAvp(avpCode);
// (...) the Session-Id SHOULD appear immediately following the Diameter Header
set.insertAvp(0, avpCode, value, vendorId, isMandatory, isProtected, isOctetString);
break;
case Avp.ORIGIN_HOST:
case Avp.ORIGIN_REALM:
case Avp.DESTINATION_HOST:
case Avp.DESTINATION_REALM:
// This AVP SHOULD be placed as close to the Diameter header as possible.
Avp firstAvp = set.size() > 0 ? set.getAvpByIndex(0) : null;
int index = (firstAvp != null && firstAvp.getCode() == Avp.SESSION_ID) ? 1 : 0;
set.insertAvp(index, avpCode, value, vendorId, isMandatory, isProtected, isOctetString);
break;
default:
set.addAvp(avpCode, value, vendorId, isMandatory, isProtected, isOctetString);
break;
}
}
use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.
the class AvpUtilities method getAvpsAsUnsigned32.
public static long[] getAvpsAsUnsigned32(int avpCode, long vendorId, AvpSet set) {
try {
AvpSet avpSet = set.getAvps(avpCode, vendorId);
long[] values = new long[avpSet.size()];
int i = 0;
for (Avp avp : avpSet) {
values[i++] = avp.getUnsigned32();
}
return values;
} catch (AvpDataException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to obtain AVP with code " + avpCode + " and Vendor-Id " + vendorId + " as type Unsigned32.", e);
}
return new long[0];
}
}
use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.
the class AvpUtilities method getAvpsAsInteger32.
public static int[] getAvpsAsInteger32(int avpCode, AvpSet set) {
try {
AvpSet avpSet = set.getAvps(avpCode);
int[] values = new int[avpSet.size()];
int i = 0;
for (Avp avp : avpSet) {
values[i++] = avp.getInteger32();
}
return values;
} catch (AvpDataException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to obtain AVP with code " + avpCode + " as type Integer32.", e);
}
return new int[0];
}
}
use of org.jdiameter.api.Avp in project jain-slee.diameter by RestComm.
the class AvpUtilities method getAvpsAsOctetString.
public static byte[][] getAvpsAsOctetString(int avpCode, AvpSet set) {
try {
AvpSet avpSet = set.getAvps(avpCode);
byte[][] values = new byte[avpSet.size()][];
int i = 0;
for (Avp avp : avpSet) {
values[i++] = avp.getOctetString();
}
return values;
} catch (AvpDataException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to obtain AVP with code " + avpCode + " as type OctetString.", e);
}
return new byte[0][];
}
}
Aggregations