00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package de.fhg.fokus.diameter.DiameterPeer.data;
00032
00033 import java.util.Vector;
00034
00056 public class AVP {
00057
00059 public int code=0;
00060
00062 public boolean flag_vendor_specific=false;
00063
00065 public boolean flag_mandatory=true;
00066
00068 public boolean flag_protected=false;
00069
00071 public int vendor_id=0;
00072
00074 public int encoded_length=0;
00075
00076
00078 public byte[] data={};
00079
00081 public int int_data;
00082
00084 public Vector childs = null;
00085
00087 public boolean is_ungrouped=false;
00088
00089
00093 public AVP()
00094 {
00095 }
00096
00106 public AVP(int Code,boolean Vendor_Specific,boolean Mandatory,boolean Protected,
00107 int Vendor_id)
00108 {
00109 this.code = Code;
00110 this.flag_vendor_specific = Vendor_Specific;
00111 this.flag_mandatory = Mandatory;
00112 this.flag_protected = Protected;
00113 this.vendor_id = Vendor_id;
00114 if (this.vendor_id!=0) this.flag_vendor_specific = true;
00115 }
00116
00117
00125 public AVP(int Code,boolean Mandatory,int Vendor_id)
00126 {
00127 this.code = Code;
00128 this.flag_mandatory = Mandatory;
00129 this.vendor_id = Vendor_id;
00130 if (this.vendor_id!=0) this.flag_vendor_specific = true;
00131 }
00132
00138 public void setData(byte[] Data)
00139 {
00140 this.data = Data;
00141 for(int i=0;i<4&&i<data.length;i++)
00142 int_data = (int_data<<8)|(0xFF & data[i]);
00143 }
00144
00152 public void setData(byte[] Data,int start,int len)
00153 {
00154 if (len<Data.length - start)
00155 len = Data.length - start;
00156 this.data = new byte[len];
00157 System.arraycopy(Data,start,this.data,0,len);
00158 for(int i=0;i<4&&i<data.length;i++)
00159 int_data = (int_data<<8)|(0xFF & data[i]);
00160
00161 }
00162
00168 public void setData(char[] Data)
00169 {
00170 this.data = new byte[Data.length];
00171 System.arraycopy(Data,0,this.data,0,Data.length);
00172 for(int i=0;i<4&&i<data.length;i++)
00173 int_data = (int_data<<8)|(0xFFFF & data[i]);
00174 }
00175
00181 public void setData(String Data)
00182 {
00183 this.data = Data.getBytes();
00184 for(int i=0;i<4&&i<data.length;i++)
00185 int_data = (int_data<<8)|(0xFF & data[i]);
00186 }
00187
00193 public void setData(int Data)
00194 {
00195 data = new byte[4];
00196 data[0] = (byte)((Data>>24) &0xFF);
00197 data[1] = (byte)((Data>>16) &0xFF);
00198 data[2] = (byte)((Data>> 8) &0xFF);
00199 data[3] = (byte)((Data ) &0xFF);
00200 int_data = Data;
00201 }
00202
00208 public int getIntData() {
00209 return int_data;
00210 }
00211
00217 public byte[] getData() {
00218 return data;
00219 }
00220
00226 public void addChildAVP(AVP child)
00227 {
00228 if (!is_ungrouped) is_ungrouped = true;
00229 if (childs == null) childs = new Vector();
00230 childs.add(child);
00231 }
00232
00238 public int getChildCount()
00239 {
00240 if (!is_ungrouped||childs==null) return 0;
00241 return childs.size();
00242 }
00243
00250 public AVP getChildAVP(int index)
00251 {
00252 if (!is_ungrouped||childs==null) return null;
00253 if (index<childs.size())
00254 return (AVP)childs.get(index);
00255 else return null;
00256 }
00257
00263 public void deleteChildAVP(AVP avp)
00264 {
00265 if (!is_ungrouped||childs==null) return;
00266 childs.remove(avp);
00267 }
00268
00276 public AVP findChildAVP(int Code)
00277 {
00278 AVP avp;
00279 if (!is_ungrouped) return null;
00280 for(int i=0;i<childs.size();i++){
00281 avp = (AVP) childs.get(i);
00282 if (avp.code == Code) {
00283 return avp;
00284 }
00285 }
00286 return null;
00287 }
00288
00297 public AVP findChildAVP(int Code,boolean Mandatory,int Vendor_id)
00298 {
00299 AVP avp;
00300 if (!is_ungrouped) return null;
00301 for(int i=0;i<childs.size();i++){
00302 avp = (AVP) childs.get(i);
00303 if (avp.code == Code &&
00304 avp.flag_mandatory == Mandatory &&
00305 avp.vendor_id == Vendor_id)
00306 return avp;
00307 }
00308 return null;
00309 }
00310
00318 public AVP[] findChildAVPs(int Code)
00319 {
00320
00321 AVP[] avpset;
00322 int j = 0, count = 0;
00323 AVP avp;
00324
00325 if (!is_ungrouped) return null;
00326
00327 for(int i=0;i<childs.size();i++){
00328 avp = (AVP) childs.get(i);
00329 if (avp.code == Code)
00330 count++;
00331 }
00332
00333 if (count == 0) return null;
00334 avpset = new AVP[count];
00335 for(int i=0;i<childs.size();i++){
00336 avp = (AVP) childs.get(i);
00337 if (avp.code == Code) {
00338 avpset[j++] = avp;
00339 if (j == count) break;
00340 }
00341 }
00342
00343 return avpset;
00344 }
00345
00351 public void ungroup() throws AVPDecodeException
00352 {
00353 int i = 0;
00354 AVP x;
00355 if (is_ungrouped) return;
00356 is_ungrouped = true;
00357 childs = new Vector();
00358 while (i<data.length){
00359 x = Codec.decodeAVP(data,i);
00360 childs.add(x);
00361 i+=x.encoded_length;
00362 }
00363 }
00364
00369 public void group()
00370 {
00371 Vector temp;
00372 int i,len=0;
00373 byte[] t;
00374 if (!is_ungrouped||childs==null||childs.size()==0) {
00375 data = new byte[0];
00376 }
00377 temp = new Vector();
00378 for(i=0;i<childs.size();i++){
00379 t = Codec.encodeAVP((AVP)childs.get(i));
00380 temp.add(t);
00381 len += t.length;
00382 }
00383 data = new byte[len];
00384 len = 0;
00385 for(i=0;i<temp.size();i++){
00386 t = (byte[]) temp.get(i);
00387 System.arraycopy(t,0,data,len,t.length);
00388 len += t.length;
00389 }
00390 }
00391
00395 public String toString()
00396 {
00397 StringBuffer x = new StringBuffer();
00398
00399 int i;
00400 x.append("AVP:");
00401 x.append(" Code=");x.append(code);
00402 if (flag_vendor_specific) x.append(" V");
00403 if (flag_mandatory) x.append(" M");
00404 if (flag_protected) x.append(" P");
00405 x.append(" Len=");x.append(data.length);
00406 if (flag_vendor_specific){
00407 x.append(" V_ID=");x.append(vendor_id);
00408 }
00409 x.append(" Data=0x");
00410 for(i=0;i<data.length;i++){
00411 x.append(hexa[(data[i]>>4)&0x0F]);
00412 x.append(hexa[data[i]&0x0F]);
00413 }
00414 x.append(" INT_Data=");x.append(int_data);
00415 x.append(" Char_Data=\"");
00416 for(i=0;i<data.length;i++)
00417 if (data[i]>=32&&data[i]<=126)
00418 x.append((char)data[i]);
00419 else
00420 x.append(".");
00421 x.append("\"");
00422 if (is_ungrouped){
00423 x.append(" {");
00424 for(i=0;i<childs.size();i++){
00425 if (i!=0) x.append(",");
00426 x.append(childs.get(i).toString());
00427 }
00428 x.append("}");
00429 }
00430 return x.toString();
00431 }
00432
00433
00434 private static char[] hexa={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
00435
00437 public static final int Session_Id = 263;
00438
00440 public static final int Origin_Host = 264;
00441
00443 public static final int Origin_Realm = 296;
00444
00446 public static final int Destination_Host = 293;
00447
00449 public static final int Destination_Realm = 283;
00450
00452 public static final int Auth_Application_Id = 258;
00453
00455 public static final int Acct_Application_Id = 259;
00456
00458 public static final int Vendor_Specific_Application_Id = 260;
00459
00461 public static final int Vendor_Id = 266;
00462
00464 public static final int Result_Code = 268;
00465
00467 public static final int Host_IP_Address = 257;
00468
00470 public static final int Product_Name = 269;
00471
00473 public static final int Disconnect_Cause = 273;
00474
00475 }