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_COOKIE_H__ 00035 #define __PANA_COOKIE_H__ 00036 00037 #include "ace/Synch.h" 00038 #include "ace/Singleton.h" 00039 #include <string> 00040 00041 class PANA_Cookie 00042 { 00043 public: 00044 typedef enum { 00045 default_table_size_ = 5, 00046 }; 00047 00048 public: 00052 PANA_Cookie(); 00053 00057 virtual ~PANA_Cookie() { } 00058 00065 bool Generate(std::string &id, std::string &digest); 00066 00073 bool Verify(std::string &id, std::string &digest); 00074 00078 void Cycle(); 00079 00080 protected: 00088 bool Generate(ACE_UINT32 ndx, std::string &id, std::string &digest); 00089 00090 private: 00091 00092 ACE_UINT32 s_index_; 00094 std::string s_table_[default_table_size_]; 00095 }; 00096 00100 typedef ACE_Singleton<PANA_Cookie, ACE_Null_Mutex> PANA_Cookie_S; 00101 00105 #define PANA_COOKIE_GENERATE(x, y) PANA_Cookie_S::instance()->Generate((x), (y)) 00106 #define PANA_COOKIE_VERIFY(x, y) PANA_Cookie_S::instance()->Verify((x), (y)) 00107 #define PANA_COOKIE_CYCLE() PANA_Cookie_S::instance()->Cycle() 00108 00109 #endif // __PANA_COOKIE_H__ 00110