Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

eap.hxx

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 /* $Id: eap.hxx,v 1.10 2004/06/17 21:13:36 yohba Exp $ */
00034 /* 
00035    EAP header file.
00036    EAP application programs and programs for each of EAP mechanisms 
00037    MUST include this file.
00038 
00039    Written by Yoshihiro Ohba
00040    
00041 */
00042 
00043 #ifndef __EAP_HXX__
00044 #define __EAP_HXX__
00045 
00046 /* Structure for EAP Finite State Machine */
00047 
00048 #include <ace/Basic_Types.h>
00049 #include <ace/Message_Block.h>
00050 #include <ace/Message_Queue.h>
00051 #include <ace/Message_Queue.h>
00052 #include <ace/Synch.h>
00053 #include <list>
00054 #include "diameter_parser_api.h"
00055 
00059 #ifdef WIN32
00060    #if defined(EAP_EXPORT)
00061        #define EAP_EXPORTS __declspec(dllexport)
00062    #else
00063        #define EAP_EXPORTS __declspec(dllimport)
00064    #endif
00065 #else
00066    #define EAP_EXPORTS
00067    #define EAP_IMPORTS
00068 #endif
00069 
00071 typedef ACE_Message_Queue<ACE_MT_SYNCH> EapMessageQueue;
00072 
00074 enum EapCode {
00075   Request = 1,
00076   Response,
00077   Success,
00078   Failure
00079 };
00080 
00082 class EapType
00083 {
00084  public:
00085   EapType() {}
00086 
00088   EapType(ACE_Byte type) : 
00089     type(type), vendorId(0), vendorType(0) {}
00090 
00092   EapType(ACE_UINT16 vid, ACE_UINT16 vty) : 
00093     type(254), vendorId(vid), vendorType(vty) {}
00094 
00097   bool operator==(EapType ty) 
00098     {
00099       if ((ty.type == type) && 
00100           (ty.vendorId == vendorId) && 
00101           (ty.vendorType == vendorType))
00102         return true;
00103       return false;
00104     }
00105 
00108   bool operator!=(EapType ty) 
00109     {
00110       return !(*this == ty);
00111     }
00112 
00115   inline bool IsVSE() { return (type==254 && (*this != EapType(0,0))); }
00116   ACE_Byte  type;
00117   ACE_UINT16 vendorId;
00118   ACE_UINT16 vendorType;
00119 };
00120 
00122 enum EapRole {
00123   Peer,
00124   Authenticator
00125 };
00126 
00128 class EapHeader
00129 {
00130  public:
00131   EapHeader() : code(0), identifier(0), length(0) {}
00132   ACE_Byte code;
00133   ACE_Byte identifier;
00134   ACE_UINT16 length;
00135 };
00136 
00137 const ACE_UINT16 EapMaxPduLength=ACE_UINT16_MAX;
00138 
00141 class EapPayload {};
00142 
00144 class EapRequest : public EapPayload
00145 {
00146 public:
00147   EapRequest() {}
00148   EapRequest(EapType ty) : type(ty) {}
00149   ~EapRequest() {}
00150   inline EapType& GetType() { return type; }
00151   inline void SetType(EapType ty) { type=ty; }
00152   inline bool IsVSE() { return isVSE; }
00153   inline void SetVSE() { isVSE=true; }
00154 protected:
00156   EapType  type;
00157 
00159   bool isVSE;
00160 };
00161 
00163 class EapResponse: public EapRequest 
00164 {
00165  public:
00166   EapResponse() : EapRequest() {}
00167   EapResponse(EapType ty) : EapRequest(ty) {}
00168   ~EapResponse() {}
00169 };
00170 
00172 class EapTypeList : public std::list<EapType>
00173 {
00174 public:
00175 
00178   bool Search(EapType type) 
00179   {
00180     EapTypeList::iterator i;
00181     for (i=begin(); i!=end(); i++)
00182       {
00183         if (*i == type)
00184           return true;
00185       }
00186     return false;
00187   }
00188 
00190   bool IsVSE() 
00191   {
00192     EapTypeList::iterator i;
00193     for (i=begin(); i!=end(); i++)
00194       {
00195         if ((*i).IsVSE())
00196           return true;
00197       }
00198     return false;
00199   }
00200 };
00201 
00203 class EapNak: public EapResponse
00204 {
00205 public:
00206   EapNak() : EapResponse(EapType(3)) {}
00207   EapTypeList& TypeList() { return typeList; }
00208 private:
00209   EapTypeList typeList;
00210 };
00211 
00213 class EapIdentity: public EapRequest
00214 {
00215 public:
00217   EapIdentity() : EapRequest(EapType(1)) {}
00218 
00220   std::string& Identity() { return identity; }
00221 
00222 private:
00232   std::string identity;
00233 };
00234 
00239 class EapNotification: public EapRequest
00240 {
00241 public:
00243   EapNotification() : EapRequest(EapType(2)) {}
00244 
00246   std::string& Notification() { return notification; }
00247 
00248 private:
00251   std::string notification;
00252 };
00253 
00257 class EapMD5Challenge: public EapRequest
00258 {
00259 public:
00261   EapMD5Challenge() : EapRequest(EapType(4)) {}
00262 
00264   std::string& Value() { return value; }
00265 
00267   void Value(std::string& value) { this->value = value; }
00268 
00270   std::string& Name() { return name; }
00271 
00273   void Name(std::string& name) { this->name = name; }
00274 
00275 private:
00278   std::string value;
00279   std::string name;
00280 };
00281 
00282 #endif

Generated on Fri Jun 25 19:16:16 2004 for EAP State Machine by doxygen 1.3.5