Search in sources :

Example 6 with AvpRepresentation

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);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation) URISyntaxException(java.net.URISyntaxException) ParseException(org.jdiameter.client.api.parser.ParseException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AvpDataException(org.jdiameter.api.AvpDataException)

Example 7 with AvpRepresentation

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()]);
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation)

Example 8 with AvpRepresentation

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 :)
        }
    }
}
Also used : AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation) UserIdentityAvpImpl(org.mobicents.slee.resource.diameter.sh.events.avp.UserIdentityAvpImpl) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)

Example 9 with AvpRepresentation

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();
                }
            }
        }
    }
}
Also used : SubscribeNotificationsRequest(net.java.slee.resource.diameter.sh.events.SubscribeNotificationsRequest) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation) UserIdentityAvpImpl(org.mobicents.slee.resource.diameter.sh.events.avp.UserIdentityAvpImpl) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)

Aggregations

AvpRepresentation (org.mobicents.diameter.dictionary.AvpRepresentation)9 Avp (org.jdiameter.api.Avp)5 Constructor (java.lang.reflect.Constructor)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 AvpDataException (org.jdiameter.api.AvpDataException)4 URISyntaxException (java.net.URISyntaxException)3 AvpSet (org.jdiameter.api.AvpSet)3 ParseException (org.jdiameter.client.api.parser.ParseException)3 ArrayList (java.util.ArrayList)2 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)2 DiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)2 UserIdentityAvpImpl (org.mobicents.slee.resource.diameter.sh.events.avp.UserIdentityAvpImpl)2 InetAddress (java.net.InetAddress)1 FailedAvp (net.java.slee.resource.diameter.base.events.avp.FailedAvp)1 GroupedAvp (net.java.slee.resource.diameter.base.events.avp.GroupedAvp)1 ProxyInfoAvp (net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp)1 VendorSpecificApplicationIdAvp (net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp)1 SubscribeNotificationsRequest (net.java.slee.resource.diameter.sh.events.SubscribeNotificationsRequest)1 DiameterAvpImpl (org.mobicents.slee.resource.diameter.base.events.avp.DiameterAvpImpl)1 GroupedAvpImpl (org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl)1