+++ /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
-/**\r
- * COPS Message Parser\r
- *\r
- * @version COPSMsgParser.java, v 1.00 2003\r
- *\r
- */\r
-\r
-// import org.umu.cops.common.COPSDebug;\r
-\r
-public class COPSMsgParser {\r
- ///\r
- public COPSMsgParser() {\r
-\r
- }\r
-\r
- /** Parses the given COPS data and returns a COPSMsg object\r
- * with COPS object filed in.The COPSMsg object is allocated in the\r
- * call and it is the responsibility of the caller to free the memory\r
- *\r
- * @param data a byte[]\r
- *\r
- * @return a COPSMsg\r
- *\r
- * @throws COPSException\r
- *\r
- */\r
- public COPSMsg parse(byte[] data) throws COPSException {\r
- COPSHeader hdr = new COPSHeader(data);\r
-\r
- byte[] buf = new byte[data.length - 8];\r
- System.arraycopy(data,8,buf,0,data.length - 8);\r
-\r
- return (parse(hdr, buf));\r
- }\r
-\r
- /**\r
- * Parse the message with given header , the data is pointing\r
- * to the data following the header\r
- *\r
- * @param hdr a COPSHeader\r
- * @param data a byte[]\r
- *\r
- * @return a COPSMsg\r
- *\r
- * @throws COPSException\r
- *\r
- */\r
- public COPSMsg parse(COPSHeader hdr, byte[] data) throws COPSException {\r
- COPSMsg copsMsg = null;\r
- short cCode = hdr.getOpCode();\r
- switch (cCode) {\r
- case COPSHeader.COPS_OP_REQ: {\r
- // COPSDebug.out(getClass().getName(), "Creating REQ msg");\r
- copsMsg = new COPSReqMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_DEC: {\r
- // COPSDebug.out(getClass().getName(), "Creating DEC msg");\r
- copsMsg = new COPSDecisionMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_RPT: {\r
- // COPSDebug.out(getClass().getName(), "Creating RPT msg");\r
- copsMsg = new COPSReportMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_DRQ: {\r
- // COPSDebug.out(getClass().getName(), "Creating DRQ msg");\r
- copsMsg = new COPSDeleteMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_OPN: {\r
- // COPSDebug.out(getClass().getName(), "Creating Client-Open msg");\r
- copsMsg = new COPSClientOpenMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_CAT: {\r
- // COPSDebug.out(getClass().getName(), "Creating Client-Accept msg");\r
- copsMsg = new COPSClientAcceptMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_CC: {\r
- // COPSDebug.out(getClass().getName(), "Creating Client-Close msg");\r
- copsMsg = new COPSClientCloseMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_KA: {\r
- // COPSDebug.out(getClass().getName(), "Creating KA msg");\r
- copsMsg = new COPSKAMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_SSQ: {\r
- // COPSDebug.out(getClass().getName(), "Creating Sync-State Request msg");\r
- copsMsg = new COPSSyncStateMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- case COPSHeader.COPS_OP_SSC: {\r
- // COPSDebug.out(getClass().getName(), "Creating Sync-State Complete msg");\r
- copsMsg = new COPSSyncStateMsg();\r
- copsMsg.parse(hdr, data);\r
- }\r
- break;\r
- default:\r
- // COPSDebug.out(getClass().getName(), "Unknown message type");\r
- break;\r
- }\r
-\r
-\r
- // if(copsMsg != null)\r
- // try { copsMsg.dump(COPSDebug.out); } catch (Exception e) {};\r
-\r
- return copsMsg;\r
- }\r
-}\r
-\r
-\r