--- /dev/null
+/*\r
+ * Copyright (c) 2003 University of Murcia. All rights reserved.\r
+ * --------------------------------------------------------------\r
+ * For more information, please see <http://www.umu.euro6ix.org/>.\r
+ */\r
+\r
+package org.umu.cops.stack;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.net.Socket;\r
+\r
+/**\r
+ * COPS Report Type (RFC 2748 pag. 16\r
+ *\r
+ * The Type of Report on the request state associated with a handle:\r
+ *\r
+ * C-Num = 12, C-Type = 1\r
+ *\r
+ * 0 1 2 3\r
+ * +--------------+--------------+--------------+--------------+\r
+ * | Report-Type | ///////////// |\r
+ * +--------------+--------------+--------------+--------------+\r
+ *\r
+ * Report-Type:\r
+ * 1 = Success : Decision was successful at the PEP\r
+ * 2 = Failure : Decision could not be completed by PEP\r
+ * 3 = Accounting: Accounting update for an installed state\r
+ *\r
+ *\r
+ * @version COPSReportType.java, v 1.00 2003\r
+ *\r
+ */\r
+public class COPSReportType extends COPSPrObjBase {\r
+\r
+ public final static String[] msgMap = {\r
+ "Unknown",\r
+ "Success",\r
+ "Failure",\r
+ "Accounting",\r
+ };\r
+\r
+ private COPSObjHeader _objHdr;\r
+ private short _rType;\r
+ private short _reserved;\r
+\r
+ public final static short SUCCESS = 1;\r
+ public final static short FAILURE = 2;\r
+ public final static short ACCT = 3;\r
+\r
+ public COPSReportType(short rType) {\r
+ _objHdr = new COPSObjHeader();\r
+ _objHdr.setCNum(COPSObjHeader.COPS_RPT);\r
+ _objHdr.setCType((byte) 1);\r
+ _rType = rType;\r
+ _objHdr.setDataLength((short) 4);\r
+ }\r
+\r
+ /**\r
+ Parse data and create COPSReportType object\r
+ */\r
+ protected COPSReportType(byte[] dataPtr) {\r
+ _objHdr = new COPSObjHeader();\r
+ _objHdr.parse(dataPtr);\r
+ // _objHdr.checkDataLength();\r
+\r
+ _rType |= ((short) dataPtr[4]) << 8;\r
+ _rType |= ((short) dataPtr[5]) & 0xFF;\r
+ _reserved |= ((short) dataPtr[6]) << 8;\r
+ _reserved |= ((short) dataPtr[7]) & 0xFF;\r
+\r
+ _objHdr.setDataLength((short) 4);\r
+ }\r
+\r
+ /**\r
+ * Returns size in number of octects, including header\r
+ *\r
+ * @return a short\r
+ *\r
+ */\r
+ public short getDataLength() {\r
+ //Add the size of the header also\r
+ return (_objHdr.getDataLength());\r
+ }\r
+\r
+ /**\r
+ * If it is Success, return true\r
+ *\r
+ * @return a boolean\r
+ *\r
+ */\r
+ public boolean isSuccess() {\r
+ return (_rType == SUCCESS );\r
+ };\r
+\r
+ /**\r
+ * If it is Failure, return true\r
+ *\r
+ * @return a boolean\r
+ *\r
+ */\r
+ public boolean isFailure() {\r
+ return (_rType == FAILURE);\r
+ };\r
+\r
+ /**\r
+ * If it is Accounting, return true\r
+ *\r
+ * @return a boolean\r
+ *\r
+ */\r
+ public boolean isAccounting() {\r
+ return (_rType == ACCT);\r
+ };\r
+\r
+ /**\r
+ * Always return true\r
+ *\r
+ * @return a boolean\r
+ *\r
+ */\r
+ public boolean isReport() {\r
+ return true;\r
+ };\r
+\r
+ /**\r
+ * Write data in network byte order on a given network socket\r
+ *\r
+ * @param id a Socket\r
+ *\r
+ * @throws IOException\r
+ *\r
+ */\r
+ public void writeData(Socket id) throws IOException {\r
+ _objHdr.writeData(id);\r
+\r
+ byte[] buf = new byte[4];\r
+\r
+ buf[0] = (byte) (_rType >> 8);\r
+ buf[1] = (byte) _rType;\r
+ buf[2] = (byte) (_reserved >> 8);\r
+ buf[3] = (byte) _reserved;\r
+\r
+ COPSUtil.writeData(id, buf, 4);\r
+ }\r
+\r
+ /**\r
+ * Write an object textual description in the output stream\r
+ *\r
+ * @param os an OutputStream\r
+ *\r
+ * @throws IOException\r
+ *\r
+ */\r
+ public void dump(OutputStream os) throws IOException {\r
+ _objHdr.dump(os);\r
+ os.write(new String("Report: " + msgMap[_rType] + "\n").getBytes());\r
+ }\r
+}\r
+\r
+\r
+\r
+\r
+\r