dk.i1.diameter
Class Utils

Object
  extended by dk.i1.diameter.Utils

public final class Utils
extends Object

A mishmash of handy methods


Nested Class Summary
static class Utils.ABNFComponent
          A component in a message ABNF
static class Utils.CheckABNFFailure
          Result from checkABNF(dk.i1.diameter.Message, dk.i1.diameter.Utils.ABNFComponent[])
 
Field Summary
static Utils.ABNFComponent[] abnf_asa
          ABNF for ASA (section 8.5.2)
static Utils.ABNFComponent[] abnf_asr
          ABNF for ASR (section 8.5.1)
static Utils.ABNFComponent[] abnf_cea
          ABNF for CEA (section 5.3.2)
static Utils.ABNFComponent[] abnf_cer
          ABNF for CER (section 5.3.1)
static Utils.ABNFComponent[] abnf_dpa
          ABNF for DPA (section 5.4.2)
static Utils.ABNFComponent[] abnf_dpr
          ABNF for DPR (section 5.4.1)
static Utils.ABNFComponent[] abnf_dwa
          ABNF for DWA (section 5.5.2)
static Utils.ABNFComponent[] abnf_dwr
          ABNF for DWR (section 5.5.1)
static Utils.ABNFComponent[] abnf_raa
          ABNF for RAA (section 8.3.2)
static Utils.ABNFComponent[] abnf_rar
          ABNF for RAR (section 8.3.1)
static Utils.ABNFComponent[] abnf_sta
          ABNF for STA (section 8.4.1)
static Utils.ABNFComponent[] abnf_str
          ABNF for STR (section 8.4.1)
static int[] rfc3588_grouped_avps
          List of AVPs that are grouped according to RFC3588 section 4.5
static int[] rfc3588_mandatory_codes
          The AVP codes of the AVPs listen in RFC3588 section 4.5 that must be mandatory
static int[] rfc4006_grouped_avps
          List of AVPs that are grouped according to RFC4006 section 8
static int[] rfc4006_mandatory_codes
          The AVP codes of the AVPs listen in RFC4006 section 8 that must be mandatory
 
Method Summary
static Utils.CheckABNFFailure checkABNF(Message msg, Utils.ABNFComponent[] abnf)
          Check that a message conforms to an ABNF.
static void copyProxyInfo(Message from, Message to)
          Copies any Proxy-Info AVPs from one message to another.
static void setMandatory_RFC3588(Iterable<AVP> avps)
          Sets the M-bit on the AVPs that should have the M bit set according to RFC3588
static void setMandatory_RFC3588(Message msg)
          Sets the M-bit on the AVPs that should have the M bit set according to RFC3588
static void setMandatory_RFC4006(Iterable<AVP> avps)
          Sets the M-bit on the AVPs that must have the M bit set according to RFC4006
static void setMandatory_RFC4006(Message msg)
          Sets the M-bit on the AVPs that must have the M bit set according to RFC4006
static void setMandatory(Iterable<AVP> avps, java.util.Collection<Integer> codes)
          Sets the M-bit on the avps with the specified codes.
static void setMandatory(Iterable<AVP> avps, int[] codes)
          Sets the M-bit on the avps with the specified codes.
static void setMandatory(Iterable<AVP> avps, int[] codes, int[] grouped_avp_codes)
          Sets the M-bit on the avps with the specified codes.
static void setMandatory(Message msg, int[] codes)
          Sets the M-bit on the avps with the specified codes.
static void setMandatory(Message msg, int[] codes, int[] grouped_avp_codes)
          Sets the M-bit on the avps with the specified codes.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rfc3588_mandatory_codes

public static final int[] rfc3588_mandatory_codes
The AVP codes of the AVPs listen in RFC3588 section 4.5 that must be mandatory


rfc3588_grouped_avps

public static final int[] rfc3588_grouped_avps
List of AVPs that are grouped according to RFC3588 section 4.5

Since:
0.9.5

rfc4006_mandatory_codes

public static final int[] rfc4006_mandatory_codes
The AVP codes of the AVPs listen in RFC4006 section 8 that must be mandatory


rfc4006_grouped_avps

public static final int[] rfc4006_grouped_avps
List of AVPs that are grouped according to RFC4006 section 8

Since:
0.9.5

abnf_cer

public static final Utils.ABNFComponent[] abnf_cer
ABNF for CER (section 5.3.1)


abnf_cea

public static final Utils.ABNFComponent[] abnf_cea
ABNF for CEA (section 5.3.2)


abnf_dpr

public static final Utils.ABNFComponent[] abnf_dpr
ABNF for DPR (section 5.4.1)


abnf_dpa

public static final Utils.ABNFComponent[] abnf_dpa
ABNF for DPA (section 5.4.2)


abnf_dwr

public static final Utils.ABNFComponent[] abnf_dwr
ABNF for DWR (section 5.5.1)


abnf_dwa

public static final Utils.ABNFComponent[] abnf_dwa
ABNF for DWA (section 5.5.2)


abnf_rar

public static final Utils.ABNFComponent[] abnf_rar
ABNF for RAR (section 8.3.1)


abnf_raa

public static final Utils.ABNFComponent[] abnf_raa
ABNF for RAA (section 8.3.2)


abnf_str

public static final Utils.ABNFComponent[] abnf_str
ABNF for STR (section 8.4.1)


abnf_sta

public static final Utils.ABNFComponent[] abnf_sta
ABNF for STA (section 8.4.1)


abnf_asr

public static final Utils.ABNFComponent[] abnf_asr
ABNF for ASR (section 8.5.1)


abnf_asa

public static final Utils.ABNFComponent[] abnf_asa
ABNF for ASA (section 8.5.2)

Method Detail

setMandatory

public static final void setMandatory(Iterable<AVP> avps,
                                      int[] codes,
                                      int[] grouped_avp_codes)
Sets the M-bit on the avps with the specified codes. Vendor-specific AVPs are not modified. AVPs not listed are not modified.

Parameters:
avps - The AVPs to examine and possibly set the M-bit on.
codes - Array of codes
grouped_avp_codes - Array of AVP codes for AVPs that are grouped and should be examined deeper for other mandatory AVPs
Since:
0.9.5

setMandatory

public static final void setMandatory(Iterable<AVP> avps,
                                      int[] codes)
Sets the M-bit on the avps with the specified codes. Vendor-specific AVPs are not modified. AVPs not listed are not modified.

Parameters:
avps - The AVPs to examine and possibly set the M-bit on.
codes - Array of codes

setMandatory

public static final void setMandatory(Iterable<AVP> avps,
                                      java.util.Collection<Integer> codes)
Sets the M-bit on the avps with the specified codes. Vendor-specific AVPs are not modified. AVPs not listed are not modified.

Parameters:
avps - The AVPs to examine and possibly set the M-bit on.
codes - Array of codes

setMandatory

public static final void setMandatory(Message msg,
                                      int[] codes)
Sets the M-bit on the avps with the specified codes.

Parameters:
msg - The message AVPs to examine and possibly set the M-bit on.
codes - Array of codes

setMandatory

public static final void setMandatory(Message msg,
                                      int[] codes,
                                      int[] grouped_avp_codes)
Sets the M-bit on the avps with the specified codes.

Parameters:
msg - The message AVPs to examine and possibly set the M-bit on.
codes - Array of codes
grouped_avp_codes - Array of AVP codes for AVPs that are grouped and should be examined deeper for other mandatory AVPs
Since:
0.9.5

setMandatory_RFC3588

public static final void setMandatory_RFC3588(Iterable<AVP> avps)
Sets the M-bit on the AVPs that should have the M bit set according to RFC3588

New behaviour since 0.9.5: Also traverses grouped AVPs mentioned in rfc4006 and handles the M-bit properly.


setMandatory_RFC3588

public static final void setMandatory_RFC3588(Message msg)
Sets the M-bit on the AVPs that should have the M bit set according to RFC3588

New behaviour since 0.9.5: Also traverses grouped AVPs mentioned in rfc4006 and handles the M-bit properly.


setMandatory_RFC4006

public static final void setMandatory_RFC4006(Iterable<AVP> avps)
Sets the M-bit on the AVPs that must have the M bit set according to RFC4006

New behaviour since 0.9.5: Also traverses grouped AVPs mentioned in rfc4006 and handles the M-bit properly.

Since:
0.9.2

setMandatory_RFC4006

public static final void setMandatory_RFC4006(Message msg)
Sets the M-bit on the AVPs that must have the M bit set according to RFC4006

New behaviour since 0.9.5: Also traverses grouped AVPs mentioned in rfc4006 and handles the M-bit properly.

Since:
0.9.2

copyProxyInfo

public static final void copyProxyInfo(Message from,
                                       Message to)
Copies any Proxy-Info AVPs from one message to another.

Parameters:
from - The source message.
to - The destination message.

checkABNF

public static final Utils.CheckABNFFailure checkABNF(Message msg,
                                                     Utils.ABNFComponent[] abnf)
Check that a message conforms to an ABNF. The message is checked if it conforms to the ABNF specification. You can use it like this:
 public static final ABNFComponent abnf_my_message[] = {
     new ABNFComponent(true,   1,  1, ProtocolConstants.DI_SESSION_ID),
     new ABNFComponent(false,  1,  1, ProtocolConstants.DI_ORIGIN_HOST),
     new ABNFComponent(false,  1,  1, ProtocolConstants.DI_ORIGIN_REALM),
     new ABNFComponent(false,  1,  1, ProtocolConstants.DI_USER_NAME),
     ...
     new ABNFComponent(false,  0, -1, -1),  //special marker for arbitrary AVPs
 };
 CheckABNFFailure caf = Utils.checkABNF(msg,abnf_my_message);
 if(caf!=null) {
     //The message did not conform to the ABNF
     Message response = new Message();
     response.prepareResponse(msg);
     ...
     if(caf.failed_avp!=null)
         msg.add(caf.failed_avp);
     msg.add(new AVP_Unsigned32(ProtocolConstants.DI_RESULT_CODE,caf.result_code));
     if(caf.error_message!=null)
         msg.add(new AVP_UTF8String(ProtocolConstants.DI_ERROR_MESSAGE,caf.error_message));
                   ...
 }
 

Parameters:
msg - The message to be checked.
abnf - An array of ABNFComponents. You can use on of the predefined ones.
Returns:
Null on success. A CheckABNFFailure on failure.