Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_message.cxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
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 

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5