protected void printAvpTree(AvpRepresentation rep, String tab) { String x = tab + "+-- " + rep.getCode() + "/" + rep.getVendorId(); while (x.length() < 25) { x += "."; } System.out.println(x + rep.getName() + " > " + rep.getType()); if (rep.isGrouped()) { for (AvpRepresentation repC : rep.getChildren()) { printAvpTree(repC, " " + tab); } } }
@Override public boolean isAllowed(int avpCode, long vendorId) { if (this.isGrouped()) { // make better get ? for (AvpRepresentation rep : this.children) { if (rep.getCode() == avpCode && rep.getVendorId() == vendorId) { return rep.isAllowed(); } else { continue; } } return true; } else { return false; } }
@Override public void validate(Message msg, ValidatorLevel validatorLevel) throws AvpNotAllowedException { if (validatorLevel == ValidatorLevel.OFF) { return; } // if its !OFF, we will go down, at least to this section for (AvpRepresentation ap : this.unmuttableMessageAvps.values()) { AvpSet innerSet = msg.getAvps().getAvps(ap.getCode(), ap.getVendorId()); int count = 0; if (innerSet != null) { count = innerSet.size(); } if (!ap.isCountValidForMultiplicity(count)) { throw new AvpNotAllowedException("AVP: \n" + ap + "\n, has wrong count in message - " + (count), ap.getCode(), ap.getVendorId()); } // if its ALL, we need to go down deeper in AVPs if (validatorLevel != ValidatorLevel.ALL) { continue; } if (count != 0 && ap.isGrouped()) { // we are grouped validateGrouped(ap, innerSet); } } }
if (avp.isGrouped()) { if (avp.getName().equals(newAvp.getName())) { continue; List<AvpRepresentation> avpChilds = avp.getChildren(); for (int n = 0; n < avpChilds.size(); n++) { AvpRepresentation avpChild = avpChilds.get(n); if (avpChild.getName().equals(newAvp.getName())) { try { AvpRepresentationImpl strongAvp = (AvpRepresentationImpl) newAvp.clone(); strongAvp.setMultiplicityIndicator(avpChild.getMultiplicityIndicator()); strongAvp.markFixPosition(avpChild.getPositionIndex()); strongAvp.markWeak(false);
if (!parentAvpRep.isAllowed(avpCode, vendorId)) { throw new AvpNotAllowedException("AVP with Code '" + avpCode + "' and Vendor-Id '" + vendorId + "' is not allowed as a child of AVP with Code '" + parentAvpRep.getCode() + "' and Vendor-Id '" + parentAvpRep.getVendorId() + "'.", avpCode, vendorId); if (avpRep.isCountValidForMultiplicity(gAvp.getGenericData(), 1)) { // 1 --> +1
@Override public void validate(AvpSet avpSet) throws AvpNotAllowedException { //this is used in RAs, cause ... AvpSet is asexual AVP, no code, no vendor // let it rip for (AvpRepresentation childrenVAvp : getChildren()) { AvpSet childSset = avpSet.getAvps(childrenVAvp.getCode(), childrenVAvp.getVendorId()); int count = childSset.size(); if (!childrenVAvp.isCountValidForMultiplicity(count)) { throw new AvpNotAllowedException("AVP: " + childrenVAvp + " has wrong count, in grouped parent avp - " + (count) + ", allowed: " + childrenVAvp.getMultiplicityIndicator(), getCode(), getVendorId()); } if (childrenVAvp.isGrouped()) { for (int index = 0; index < childSset.size(); index++) { Avp presumablyGrouped = childSset.getAvpByIndex(index); childrenVAvp.validate(presumablyGrouped); } } // else we are good ? } }
@Override public void validate(DiameterAvp avp) throws AvpNotAllowedException { Dictionary dictionary = DictionarySingleton.getDictionary(); if (dictionary.isConfigured() && dictionary.isEnabled()) { AvpRepresentation rep = dictionary.getAvp(avp.getCode(), avp.getVendorId()); // check for grouped? if (rep != null && rep.isGrouped()) { try { GroupedAvpImpl impl = (GroupedAvpImpl) avp; rep.validate(impl.getGenericData()); } catch (ClassCastException cce) { throw new AvpNotAllowedException("Failed to validate avp, its not grouped!", cce, avp.getCode(), avp.getVendorId()); } } } }
@Override public boolean isCountValidForMultiplicity(int code, long vendorId, int avpCount) { AvpRepresentation avpRep = getAvp(code, vendorId); if (avpRep == null) { return true; } return avpRep.isCountValidForMultiplicity(avpCount); }
@Override public boolean isAllowed(int code, long vendorId) { AvpRepresentation avpRep = new AvpRepresentationImpl(code, vendorId); avpRep = this.unmuttableMessageAvps.get(avpRep); if (avpRep == null) { return true; } return avpRep.isAllowed(); }
/** * @param ap * @param innerSet */ private void validateGrouped(AvpRepresentation ap, AvpSet innerSet) { // we have set of grouped avps, and ap is grouped, lets validate // NOTE this methods can be called multiple time, until we dont have for (int index = 0; index < innerSet.size(); index++) { Avp presumablyGrouped = innerSet.getAvpByIndex(index); ap.validate(presumablyGrouped); // AvpSet groupedPart = null; // try { // groupedPart = presumablyGrouped.getGrouped(); // } // catch (AvpDataException e) { // logger.debug("Failed to get grouped AVP.", e); // } // // if (groupedPart == null) { // logger.error("Avp should be grouped, but its not: " + ap); // // continue; // } // else { // validateGroupedChildren(ap, groupedPart); // } } }
@Override public Object clone() throws CloneNotSupportedException { MessageRepresentationImpl clone = (MessageRepresentationImpl) super.clone(); clone.applicationId = this.applicationId; clone.commandCode = this.commandCode; clone.isRequest = this.isRequest; clone.name = this.name; // clone.messageAvps = new HashMap<AvpRepresentation, // AvpRepresentation>(); Map<AvpRepresentation, AvpRepresentation> map = new HashMap<AvpRepresentation, AvpRepresentation>(); for (Entry<AvpRepresentation, AvpRepresentation> entry : this.unmuttableMessageAvps.entrySet()) { map.put((AvpRepresentation) entry.getKey().clone(), (AvpRepresentation) entry.getValue().clone()); } clone.setMessageAvps(map); return clone; }
if (!parentAvpRep.isAllowed(avpCode, vendorId)) { throw new AvpNotAllowedException("AVP with Code '" + avpCode + "' and Vendor-Id '" + vendorId + "' is not allowed as a child of AVP with Code '" + parentAvpRep.getCode() + "' and Vendor-Id '" + parentAvpRep.getVendorId() + "'.", avpCode, vendorId); if (avpRep.isCountValidForMultiplicity(gAvp.getGenericData(), 1)) { // 1 --> +1
@Override public boolean isCountValidForMultiplicity(AvpSet destination, int code, long vendorId, int numberToAdd) { AvpRepresentation avpRep = getAvp(code, vendorId); if (avpRep == null) { return true; } return avpRep.isCountValidForMultiplicity(destination, numberToAdd); }
clone.children = cloneChildren; for (AvpRepresentation c : this.children) { cloneChildren.add((AvpRepresentation) c.clone());
if (childRep != null) { try { child = (AvpRepresentationImpl) childRep.clone();