hsms_config.h

00001 /*   
00002  *   (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net)
00003  *
00004  *   This file is part of FREESECS.
00005  *
00006  *   FREESECS is free software: you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation, either version 3 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   FREESECS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with FREESECS, see COPYING.
00018  *   If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 #ifndef _HSMS_CONFIG_H
00021 #define _HSMS_CONFIG_H
00022 
00023 #include <unistd.h>
00024 #include <string>
00025 #include <vector>
00026 #include <expat.h>
00027 
00028 namespace freesecs
00029 {
00034     class hsms_config_t
00035     {
00036     public:
00037         enum
00038         {
00039             NO_ERROR = 0,
00040             INVALID_TOKEN,
00041             INVALID_VALUE,
00042             NUM_OF_ERRORS
00043         };
00044         static char *str_err[NUM_OF_ERRORS];
00045         typedef enum
00046         {
00047             PASSIVE = 0,
00048             ACTIVE,
00049             UNDEFINED
00050         } type_t;
00051 
00052         std::string     name;
00053         type_t          type;
00054         uint32_t        port;
00055         uint16_t        t6;
00056         uint16_t        t8;
00057         uint16_t        linktest;
00058         uint16_t        session_id;
00059 
00060     public:
00061         hsms_config_t(const char *name);
00062         hsms_config_t(const hsms_config_t&);
00063         hsms_config_t& operator = (const hsms_config_t&);
00064 
00065         virtual         ~hsms_config_t();
00066 
00067         virtual bool    is_valid()const;
00068 
00069         virtual int     set_attr(const char *name, const char *value);
00070 
00071         void            complete();
00072 
00073     protected:
00074         enum
00075         {
00076             NAME        = 1 << 0,
00077             TYPE        = 1 << 1,
00078             IP          = 1 << 2,
00079             PORT        = 1 << 3,
00080             T5          = 1 << 5,
00081             T6          = 1 << 6,
00082             T7          = 1 << 7,
00083             T8          = 1 << 8,
00084             LINKTEST    = 1 << 9,
00085             SESSION_ID  = 1 << 10,
00086             UNEXPECTED  = 1 << 11,
00087             COMPLETED   = 1 << 12
00088         };
00089         uint32_t parse_flags;
00090 
00091     private:
00092         hsms_config_t();
00093     };
00094 
00098     class hsms_passive_config_t : public hsms_config_t
00099     {
00100     public:
00101         uint16_t        t7;
00102 
00103     public:
00104         hsms_passive_config_t(const char *name);
00105         hsms_passive_config_t(const hsms_passive_config_t &);
00106         hsms_passive_config_t & operator = (const hsms_passive_config_t &);
00107 
00108         virtual bool    is_valid()const;
00109         virtual int     set_attr(const char *name, const char *value);
00110 
00111     };
00112 
00116     class hsms_active_config_t : public hsms_config_t
00117     {
00118     public:
00119         uint16_t        t5;
00120         std::string     ip;
00121 
00122     public:
00123         hsms_active_config_t(const char *name);
00124         hsms_active_config_t(const hsms_active_config_t&);
00125         hsms_active_config_t & operator = (const hsms_active_config_t&);
00126 
00127         virtual bool    is_valid()const;
00128         virtual int     set_attr(const char *name, const char *value);
00129 
00130     };
00131 
00140     class hsms_config_parser_t
00141     {
00142     public:
00143         hsms_config_parser_t();
00144         ~hsms_config_parser_t();
00145         int parse(const char *s, int len, int is_final);
00146 
00147     public:
00148         std::vector<hsms_active_config_t>   active_configs;
00149         std::vector<hsms_passive_config_t>  passive_configs;
00150         std::vector<std::string>            errors;
00151     private:
00152         XML_Parser p;
00153         hsms_config_t *curr_cnx;
00154         bool process;
00155     private:
00156         static void
00157         start_handler(void *data, const char *el, const char **attr);
00158         static void
00159         end_handler(void *data, const char *el);
00160         static void
00161         char_handler(void *data, const char *txt, int txtlen);
00162 
00163     };
00164 }//namespace
00165 #endif /*_HSMS_CONFIG_H*/

Generated on Fri Oct 3 15:30:01 2008 for FREESECS hsms by  doxygen 1.5.1