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
00032
00033
00034 #include "ace/OS.h"
00035 #include "pana_defs.h"
00036 #include "pana_exceptions.h"
00037 #include "pana_message.h"
00038
00039 void PANA_HeaderParser::parseRawToApp()
00040 {
00041 AAAErrorStatus st;
00042 AAADictionaryOption *opt = getDictData();
00043 AAAMessageBlock *aBuffer = reinterpret_cast<AAAMessageBlock*>(getRawData());
00044 PANA_MsgHeader *h = reinterpret_cast<PANA_MsgHeader*>(getAppData());
00045
00046 char *p = aBuffer->rd_ptr();
00047
00048 h->version(*((AAA_UINT8*)(p)));
00049
00050 h->length(ACE_NTOHL(*((ACE_UINT32*)(p))) & 0x00ffffff);
00051
00052 p += sizeof(ACE_UINT32);
00053
00054 PANA_MsgHeader::Flags flg = { 0, 0, 0, 0 };
00055 flg.request = *((AAA_UINT8*)(p)) >> 7;
00056 flg.separate = *((AAA_UINT8*)(p)) >> 3;
00057
00058 h->flags(flg);
00059
00060 h->type(ACE_NTOHL(*((ACE_UINT32*)(p))) & 0x00ffffff);
00061
00062 p += sizeof(ACE_UINT32);
00063 h->tseq(ACE_NTOHL(*((ACE_UINT32*)(p))));
00064
00065 p += sizeof(ACE_UINT32);
00066 h->rseq(ACE_NTOHL(*((ACE_UINT32*)(p))));
00067
00068 p += sizeof(ACE_UINT32);
00069 aBuffer->rd_ptr(p);
00070
00071 if (opt->option == PARSE_LOOSE) {
00072 return;
00073 }
00074
00075 AAADictionaryManager dm(opt->protocolId);
00076 AAADictionaryHandle *handle = NULL;
00077
00078 if ((handle = dm.getDictHandle(h->type(), 0, flg.request)) == NULL) {
00079 ACE_DEBUG((LM_ERROR, "command (%d,r-flag=%1d,proto=%d) not found\n",
00080 h->type(), flg.request, opt->protocolId));
00081 st.set(NORMAL, DIAMETER_COMMAND_UNSUPPORTED);
00082 throw st;
00083 }
00084
00085 h->setDictHandle(handle);
00086 }
00087
00088 void PANA_HeaderParser::parseAppToRaw()
00089 {
00090 AAAErrorStatus st;
00091 AAADictionaryOption *opt = getDictData();
00092 AAAMessageBlock *aBuffer = reinterpret_cast<AAAMessageBlock*>(getRawData());
00093 PANA_MsgHeader *h = reinterpret_cast<PANA_MsgHeader*>(getAppData());
00094
00095 aBuffer->wr_ptr(aBuffer->base());
00096
00097 AAADictionaryManager dm(opt->protocolId);
00098 AAADictionaryHandle *handle = NULL;
00099
00100 if (opt->option != PARSE_LOOSE) {
00101 if ((handle = dm.getDictHandle(h->type(), 0, h->flags().request)) == NULL) {
00102 ACE_DEBUG((LM_ERROR, "command (%d,r-flag=%1d,proto=%d) not found\n",
00103 h->type(), h->flags().request, opt->protocolId));
00104 st.set(NORMAL, DIAMETER_COMMAND_UNSUPPORTED);
00105 throw st;
00106 }
00107 }
00108
00109 char *p = aBuffer->base();
00110
00111 *((ACE_UINT32*)(p)) = ACE_HTONL(h->length());
00112 *((AAA_UINT8*)(p)) = h->version();
00113
00114 p += sizeof(ACE_UINT32);
00115
00116 *((ACE_UINT32*)(p)) = ACE_HTONL(h->type());
00117 *((AAA_UINT8*)(p)) = ((h->flags().request << 7) | (h->flags().separate << 3));
00118
00119 p += sizeof(ACE_UINT32);
00120 *((ACE_UINT32*)(p)) = ACE_HTONL(h->tseq());
00121
00122 p += sizeof(ACE_UINT32);
00123 *((ACE_UINT32*)(p)) = ACE_HTONL(h->rseq());
00124
00125 p += sizeof(ACE_UINT32);
00126 aBuffer->wr_ptr(p);
00127
00128 h->setDictHandle(handle);
00129 }
00130
00131 PANA_MsgHeader::PANA_MsgHeader()
00132 {
00133 version_ = PANA_VERSION;
00134 length_ = 0;
00135 type_ = 0;
00136 rseq_ = 0;
00137 tseq_ = 0;
00138 dictHandle_ = NULL;
00139 ACE_OS::memset(&flags_, 0, sizeof(PANA_MsgHeader::Flags));
00140 }
00141
00142 PANA_Message::PANA_Message()
00143 {
00144 srcPort_ = 0;
00145 }
00146
00147 PANA_Message::~PANA_Message()
00148 {
00149 avpList_.releaseContainers();
00150 }
00151
00152