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

pana_message.h

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 #ifndef __PANA_MESSAGES_H__
00035 #define __PANA_MESSAGES_H__
00036 
00037 #include <list>
00038 #include "ace/Basic_Types.h"
00039 #include "ace/Message_Block.h"
00040 #include "pana_defs.h"
00041 #include "pana_exports.h"
00042 #include "pana_device_id.h"
00043 #include "diameter_parser_api.h"
00044 
00045 #if _MSC_VER > 1000
00046 #pragma once
00047 #endif // _MSC_VER > 1000
00048 
00049 #define PANA_DICT_PROTOCOL_ID  1
00050 
00055 typedef struct {
00056     AAA_UINT8 type; 
00057     diameter_octetstring_t value; 
00058 } PANA_TVData_t;
00059 
00063 #define PANA_MACGEN_HMACSHA1   1
00064 #define PANA_MACGEN_HMACSIZE   20
00065 
00066 // Data type assignment
00067 #define AAA_AVP_DEVICEID_TYPE (AAA_AVP_CUSTOM_TYPE+1)
00068 #define AAA_AVP_MAC_TYPE      (AAA_AVP_CUSTOM_TYPE+2)
00069 
00070 typedef AAATypeSpecificAvpContainerEntry<PANA_TVData_t> AAATVDataAvpContainerEntry;
00071 
00075 class PANA_TVDataParser : public AvpValueParser
00076 {
00077    public:
00081       void parseRawToApp() throw(AAAErrorStatus) {
00082           AAAMessageBlock* aBuffer = (AAAMessageBlock*)getRawData();
00083           AAAAvpContainerEntry* e = (AAAAvpContainerEntry*)getAppData();
00084           PANA_TVData_t &tve = reinterpret_cast<AAATVDataAvpContainerEntry*>(e)->dataRef();
00085           tve.type = *((AAA_UINT8*)aBuffer->base());
00086           tve.value.assign(aBuffer->base() + 1, aBuffer->size() - 1);
00087       }
00088 
00092       void parseAppToRaw() throw(AAAErrorStatus) {
00093           AAAMessageBlock* aBuffer = (AAAMessageBlock*)getRawData();
00094           AAAAvpContainerEntry* e = (AAAAvpContainerEntry*)getAppData();
00095           PANA_TVData_t &tve = reinterpret_cast<AAATVDataAvpContainerEntry*>(e)->dataRef();
00096           AAAErrorStatus st;
00097           if (aBuffer->size() - (size_t)aBuffer->wr_ptr() < (tve.value.size() + sizeof(AAA_UINT8))) {
00098               st.set(NORMAL, DIAMETER_OUT_OF_SPACE);
00099               throw st;
00100           }
00101           *((AAA_UINT8*)aBuffer->wr_ptr()) = tve.type;
00102           aBuffer->wr_ptr(sizeof(AAA_UINT8));
00103           aBuffer->copy(tve.value.data(), tve.value.size());
00104       }
00105 };
00106 
00110 class PANA_EXPORT PANA_MsgHeader 
00111 {
00112     public:
00116        typedef struct {
00117            UCHAR request   : 1;  
00118            UCHAR reserved1 : 3;  
00119            UCHAR separate  : 1;  
00120            UCHAR reserved2 : 3;  
00121        } Flags;
00122 
00126        typedef enum {
00127            HeaderLength = 16 // length in UCHAR
00128        };
00129 
00130     public:
00134        PANA_MsgHeader();
00135 
00139        virtual ~PANA_MsgHeader() { }
00140 
00144        inline UCHAR version() { return version_; }
00145 
00151        inline void version(UCHAR ver) { version_ = ver; }
00152 
00156        inline ACE_UINT32 length() { return length_; }
00157 
00163        inline void length(ACE_UINT32 len) { length_ = len; }
00164 
00168        inline PANA_MsgHeader::Flags &flags() { return flags_; }
00169 
00175        inline void flags(PANA_MsgHeader::Flags flg) { flags_ = flg; }
00176 
00180        inline ACE_UINT32 type() { return type_; }
00181 
00185        inline void type(ACE_UINT32 typ) { type_ = typ; }
00186 
00190        inline ACE_UINT32 tseq() { return tseq_; }
00191 
00197        inline void tseq(ACE_UINT32 seq) { tseq_ = seq; }
00198 
00202        inline ACE_UINT32 rseq() { return rseq_; }
00203 
00209        inline void rseq(ACE_UINT32 seq) { rseq_ = seq; }
00210 
00214        inline AAADictionaryHandle *getDictHandle() { return dictHandle_; }
00215 
00219        inline void setDictHandle(AAADictionaryHandle *handle) { dictHandle_ = handle; }
00220 
00221     protected:
00222 
00223        UCHAR version_; 
00225        ACE_UINT32 length_:24; 
00227        PANA_MsgHeader::Flags flags_; 
00229        ACE_UINT32 type_:24; 
00231        ACE_UINT32 tseq_; 
00233        ACE_UINT32 rseq_; 
00235        AAADictionaryHandle* dictHandle_; 
00236 };
00237 
00238 /* \brief PANA Message Header parser
00239  *
00240  */
00241 
00242 typedef AAAParser<AAAMessageBlock*,
00243                   PANA_MsgHeader*,
00244                   AAADictionaryOption*> PANA_HeaderParser;
00245 
00246 /*\brief PANA Message definition
00247  *
00248  */
00249 class PANA_EXPORT PANA_Message : public PANA_MsgHeader
00250 {
00251      public:
00255          PANA_Message();
00256 
00260         virtual ~PANA_Message();
00261 
00265         AAAAvpContainerList &avpList() { return avpList_; }
00266 
00270        PANA_DeviceIdContainer &srcDevices() { return srcDevices_; }
00271 
00275        ACE_UINT32 &srcPort() { return srcPort_; }
00276 
00280        void srcPort(ACE_UINT32 port) { srcPort_ = port; }
00281 
00282      protected:
00283 
00284         AAAAvpContainerList avpList_;
00285 
00286         PANA_DeviceIdContainer srcDevices_;
00287 
00288         ACE_UINT32 srcPort_;
00289 };
00290 
00294 typedef PayloadParser PANA_PayloadParser;
00295 
00296 #endif /* __PANA_MESSAGE_H__ */

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