use of org.mobicents.diameter.dictionary.AvpRepresentation in project jain-slee.diameter by RestComm.
the class AvpUtilities method getAvpsAsCustom.
public static Object[] getAvpsAsCustom(int avpCode, AvpSet set, Class clazz) {
try {
AvpSet avpSet = set.getAvps(avpCode);
Object array = Array.newInstance(clazz, avpSet.size());
int i = 0;
Constructor c = clazz.getConstructor(int.class, long.class, int.class, int.class, byte[].class);
AvpRepresentation rep = null;
for (Avp avp : avpSet) {
rep = AvpDictionary.INSTANCE.getAvp(avpCode, avp.getVendorId());
Array.set(array, i++, c.newInstance(rep.getCode(), rep.getVendorId(), rep.getRuleMandatoryAsInt(), rep.getRuleProtectedAsInt(), avp.getRawData()));
}
return (Object[]) array;
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to obtain AVP with code " + avpCode + " as type Custom (Class '" + clazz.getName() + "').", e);
}
return (Object[]) Array.newInstance(clazz, 0);
}
}
use of org.mobicents.diameter.dictionary.AvpRepresentation in project jain-slee.diameter by RestComm.
the class GroupedAvpImpl method getExtensionAvpsInternal.
private DiameterAvp[] getExtensionAvpsInternal(AvpSet set) throws Exception {
List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
for (Avp a : set) {
AvpRepresentation avpRep = AvpDictionary.INSTANCE.getAvp(a.getCode(), a.getVendorId());
if (avpRep != null) {
if (avpRep.isGrouped()) {
// warning, this changes getRaw to return byte[0] if successful
AvpSet grouped = a.getGrouped();
GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
gAVP.setExtensionAvps(getExtensionAvpsInternal(grouped));
avps.add(gAVP);
} else {
avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw(), DiameterAvpType.fromString(avpRep.getType())));
}
} else {
// we don't have it in dictionary
try {
// warning, this changes getRaw to return byte[0] if successful
AvpSet grouped = a.getGrouped();
GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
gAVP.setExtensionAvps(getExtensionAvpsInternal(grouped));
avps.add(gAVP);
} catch (AvpDataException ade) {
avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw(), null));
}
}
}
return avps.toArray(new DiameterAvp[avps.size()]);
}
use of org.mobicents.diameter.dictionary.AvpRepresentation in project jain-slee.diameter by RestComm.
the class ShServerActivityImpl method fetchSessionData.
// #########################
// # DiameterActivityImpl
// #########################
public void fetchSessionData(DiameterMessage msg, boolean incoming) {
if (msg.getHeader().isRequest()) {
// Well it should always be getting this on request and only once ?
if (incoming) {
boolean changed = false;
if (remoteRealm == null) {
remoteRealm = msg.getOriginRealm();
changed = true;
}
if (remoteHost == null) {
changed = true;
remoteHost = msg.getOriginHost();
}
if (this.userIdentity == null) {
changed = true;
AvpRepresentation rep = AvpDictionary.INSTANCE.getAvp(DiameterShAvpCodes.USER_IDENTITY, DiameterShAvpCodes.SH_VENDOR_ID);
this.userIdentity = new UserIdentityAvpImpl(DiameterShAvpCodes.USER_IDENTITY, DiameterShAvpCodes.SH_VENDOR_ID, rep.getRuleMandatoryAsInt(), rep.getRuleProtectedAsInt(), AvpUtilities.getAvpAsGrouped(DiameterShAvpCodes.USER_IDENTITY, DiameterShAvpCodes.SH_VENDOR_ID, ((DiameterMessageImpl) msg).getGenericData().getAvps()));
}
// FIXME: is this true?
if (this.authSessionState == null) {
changed = true;
this.authSessionState = AuthSessionStateType.fromInt(AvpUtilities.getAvpAsInteger32(277, ((DiameterMessageImpl) msg).getGenericData().getAvps()));
}
stateMessages.add((DiameterMessageImpl) msg);
if (changed) {
super.baseListener.update(getActivityHandle(), this);
}
} else {
// FIXME, do more :)
}
}
}
use of org.mobicents.diameter.dictionary.AvpRepresentation in project jain-slee.diameter by RestComm.
the class ShClientSubscriptionActivityImpl method fetchSessionData.
/**
* @param request
*/
public void fetchSessionData(DiameterMessage msg, boolean incoming) {
if (msg.getHeader().isRequest()) {
// Well it should always be getting this on request and only once ?
if (incoming) {
if (this.userIdentity == null) {
// FIXME: make this diff.
AvpRepresentation rep = AvpDictionary.INSTANCE.getAvp(DiameterShAvpCodes.USER_IDENTITY, DiameterShAvpCodes.SH_VENDOR_ID);
this.userIdentity = new UserIdentityAvpImpl(DiameterShAvpCodes.USER_IDENTITY, DiameterShAvpCodes.SH_VENDOR_ID, rep.getRuleMandatoryAsInt(), rep.getRuleProtectedAsInt(), AvpUtilities.getAvpAsGrouped(DiameterShAvpCodes.USER_IDENTITY, DiameterShAvpCodes.SH_VENDOR_ID, ((DiameterMessageImpl) msg).getGenericData().getAvps()));
}
if (this.authSessionState == null) {
this.authSessionState = AuthSessionStateType.fromInt(AvpUtilities.getAvpAsInteger32(277, ((DiameterMessageImpl) msg).getGenericData().getAvps()));
}
stateMessages.add((DiameterMessageImpl) msg);
} else {
// FIXME: this should be up there... in incoming?
if (destinationRealm == null) {
this.remoteRealm = msg.getDestinationRealm();
}
if (msg instanceof SubscribeNotificationsRequest) {
SubscribeNotificationsRequest snr = (SubscribeNotificationsRequest) msg;
if (dataReferenceType == null || dataReferenceType.length == 0) {
dataReferenceType = snr.getDataReferences();
}
if (authSessionState == null && snr.hasAuthSessionState()) {
authSessionState = snr.getAuthSessionState();
}
if (userIdentity == null && snr.hasUserIdentity()) {
userIdentity = snr.getUserIdentity();
}
}
}
}
}
Aggregations