Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_ProtocolBinary.hpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #ifndef _C_PROTOCOLBINARY_
00021 #define _C_PROTOCOLBINARY_
00022 
00023 #include "Utils.hpp"
00024 #include "C_XmlData.hpp"
00025 
00026 #include "iostream_t.hpp"
00027 #include "string_t.hpp"
00028 #include "map_t.hpp"
00029 #include "C_ProtocolStats.hpp"
00030 
00031 #include "C_ProtocolBinaryFrame.hpp"
00032 
00033 class C_ProtocolBinary : public C_ProtocolBinaryFrame {
00034 
00035 public:
00036 
00037   typedef enum _enum_msg_id_type {
00038     E_MSG_ID_HEADER = 0,
00039     E_MSG_ID_BODY
00040   } T_MsgIdType, *T_pMsgIdType ;
00041 
00042   typedef struct _cond_value {
00043     unsigned long m_mask ;
00044     int           m_f_id ;
00045   } T_CondPresence, *T_pCondPresence ;
00046 
00047   typedef map_t<string_t, int> T_IdMap, *T_pIdMap ;
00048   typedef map_t<unsigned long, int> T_DecodeMap, *T_pDecodeMap ;
00049 
00050   typedef struct _struct_header_field {
00051     int             m_id   ;
00052     char           *m_name ;
00053     unsigned long   m_size ;
00054     T_pCondPresence m_cond_presence ;
00055     int             m_type_id;  
00056   } T_HeaderField, *T_pHeaderField ;
00057 
00058   typedef struct _struct_header_value {
00059     int           m_id     ;
00060     char         *m_name   ;
00061     int           m_nb_set ;
00062     bool         *m_value_setted ;
00063     int          *m_id_value_setted ;
00064     T_pValueData  m_values ;
00065   } T_HeaderValue, *T_pHeaderValue ;
00066 
00067   typedef struct _struct_header_body_value {
00068     int            m_id              ;
00069     char          *m_name            ;
00070     int            m_type_id         ;
00071     int            m_nb_set          ;
00072     bool          *m_value_setted    ;
00073     int           *m_id_value_setted ;
00074     T_pValueData   m_values          ;
00075     unsigned long *m_size            ; 
00076     bool          *m_present         ; 
00077   } T_HeaderBodyValue, *T_pHeaderBodyValue ;
00078   
00079   typedef struct _struct_body_value {
00080     int                 m_id      ;
00081     T_Value             m_value   ;
00082     _struct_body_value *m_sub_val ;
00083   } T_BodyValue, *T_pBodyValue ;
00084 
00085 
00086   typedef struct _struct_body_def {
00087     int          m_nb_values   ;
00088     T_pBodyValue m_value_table ;
00089   } T_BodyValueDef, *T_pBodyValueDef ;
00090 
00091 
00092   // protocol msg id management (session-id) and (out-of-session-id)
00093   typedef struct _struct_management_session_id {
00094     int                m_msg_id_id   ;
00095     T_MsgIdType        m_msg_id_type ;
00096     T_TypeType         m_msg_id_value_type ;
00097   } T_ManagementSessionId, *T_pManagementSessionId;
00098 
00099   typedef list_t<T_ManagementSessionId> T_ManagementSessionIdList, *T_pManagementSessionIdList ;
00100 
00101   C_ProtocolBinary() ;
00102   virtual void  construction_data( C_XmlData            *P_def, 
00103                                    char                **P_name,
00104                                    T_pContructorResult   P_res) ;
00105 
00106   ~C_ProtocolBinary() ;
00107 
00108   virtual C_MessageFrame*           decode_message (unsigned char *P_buffer, 
00109                                                     size_t        *P_size, 
00110                                                     C_ProtocolFrame::T_pMsgError    P_error) ;
00111 
00112   C_ProtocolFrame::T_MsgError encode_message (C_MessageFrame *P_msg,
00113                                               unsigned char  *P_buffer,
00114                                               size_t         *P_buffer_size);
00115 
00116   virtual C_MessageFrame*                   create_new_message (C_MessageFrame *P_msg);
00117   virtual C_MessageFrame*                   create_new_message (void                *P_xml,
00118                                                                 T_pInstanceDataList  P_list,
00119                                                                 int                 *P_nb_value);
00120   char*                             message_name();
00121   char*                             message_component_name() ;
00122   T_pNameAndIdList                  message_name_list     () ;
00123   T_pNameAndIdList                  message_component_name_list  () ;
00124 
00125   char*                             message_name(int P_headerId);
00126 
00127   void log_buffer (char *P_header, unsigned char *P_buf, size_t P_size);
00128 
00129 
00130   // field management
00131   int        find_field      (char *P_name);
00132   T_TypeType get_field_type  (int P_id,
00133                               int P_sub_id);
00134   bool           check_sub_entity_needed     (int P_id)      ;
00135 
00136   int        retrieve_field_id(int P_id, T_pMsgIdType P_type);
00137 
00138   void           update_stats (T_ProtocolStatDataType   P_type,
00139                                T_ProtocolStatDataAction P_action,
00140                                int                      P_id) ;
00141   
00142 
00143 
00144 
00145 
00146   T_MsgIdType get_msg_id_type () ;
00147   int         get_msg_id () ;
00148   T_TypeType  get_msg_id_value_type () ;
00149 
00150   T_MsgIdType get_out_of_session_id_type () ;
00151   int         get_out_of_session_id () ;
00152 
00153 
00154   unsigned long      decode_msg_size (unsigned char* P_buffer, 
00155                                       unsigned long  P_size);
00156 
00157   int                get_header_type_id_body () ;
00158 
00159   int                get_header_type_id () ;
00160   int                get_header_length_id () ;
00161   int                get_header_length_index () ;
00162   unsigned long      get_nb_field_header () ;
00163   unsigned long      get_header_size () ;
00164   T_pHeaderField     get_header_field_description (int P_id);
00165   T_pHeaderField     get_header_field_description (char *P_name);
00166 
00167   T_pHeaderValue     get_header_value_description (int P_id) ;
00168 
00169   T_pTypeDef         get_type_description (int P_id);
00170   T_pTypeDef         get_type_description (char *P_name);
00171 
00172   int                get_header_body_type_id () ;
00173   int                get_header_body_length_id () ;
00174   int                get_header_body_length_index () ;
00175   unsigned long      get_nb_field_header_body () ;
00176   unsigned long      get_header_body_size () ;
00177   T_pHeaderField     get_header_body_field_description (int P_id);
00178   T_pHeaderField     get_header_body_field_description (char *P_name);
00179 
00180   T_pHeaderBodyValue get_header_body_value_description (int P_id);
00181 
00182   unsigned long      get_m_max_nb_field_header () ;
00183 
00184 
00185   char*              get_header_name();
00186   char*              get_header_body_name () ;
00187 
00188   int                get_header_value_id (char* P_name);
00189   int                get_header_body_value_id (char* P_name);
00190 
00191   int                set_body_value(int P_id, char* P_value, 
00192                                     int P_nb, T_pBodyValue P_res,
00193                                     bool        *P_del = NULL);
00194 
00195   int                set_body_sub_value(int P_index, 
00196                                         int P_id, 
00197                                         char* P_value, 
00198                                         T_pBodyValue P_res);
00199   void               set_body_value(T_pBodyValue P_res, T_pBodyValue P_val);
00200 
00201   void               delete_header_value(T_pValueData P_res);
00202   void               delete_body_value(T_pBodyValue P_res);
00203   void               reset_grouped_body_value(T_pBodyValue P_res);
00204 
00205 
00206   void               encode_header (int P_id, unsigned char*P_buf, size_t *P_size) ;
00207 
00208   void               encode_header (int P_id, 
00209                                     T_pValueData  P_headerVal, 
00210                                     unsigned char*P_buf, size_t *P_size,
00211                                     C_ProtocolFrame::T_pMsgError P_error); 
00212 
00213   virtual C_ProtocolFrame::T_MsgError       encode_body   (int            P_nbVal, 
00214                                                            T_pBodyValue   P_val, 
00215                                                            unsigned char *P_buf, 
00216                                                            size_t        *P_size) ;
00217 
00218   int                decode_header (unsigned char *P_buf, 
00219                                     size_t         P_size, 
00220                                     T_pValueData   P_valDec);
00221   virtual int        decode_body   (unsigned char *P_buf, 
00222                                     size_t         P_size,
00223                                     T_pBodyValue   P_valDec,
00224                                     int           *P_nbValDec,
00225                                     int           *P_headerId);
00226 
00227 
00228   void               update_length (unsigned char*P_buf, size_t P_size);
00229 
00230   int find_header_field_id (char *P_name) ;
00231   int find_header_body_id (char *P_name) ;
00232   int find_body_value_id (char *P_name) ;
00233 
00234   void get_header_values (int P_id, T_pValueData P_val);
00235   void set_header_values (T_pValueData P_dest, T_pValueData P_orig) ;
00236   void set_header_value (int P_id, T_pValueData P_dest, T_pValueData P_orig) ;
00237   void set_body_values (int P_nb, T_pBodyValue P_dest, T_pBodyValue P_orig);
00238 
00239   void reset_header_values (int P_nb, T_pValueData P_val);
00240   void reset_body_values (int P_nb, T_pBodyValue P_val);
00241 
00242   void get_body_values (int P_id, T_pBodyValue P_val, int *P_nbVal);
00243   virtual void get_body_value (T_pValueData P_dest, T_pBodyValue P_orig);
00244   virtual void set_body_value (T_pBodyValue P_dest, T_pValueData P_orig);
00245 
00246 
00247   virtual T_ManagementSessionId* get_manage_session_elt (int P_id);
00248   virtual int get_nb_management_session () ;
00249 
00250   virtual bool check_present_session (int P_msg_id,int P_id) ;
00251   virtual bool find_present_session (int P_msg_id,int P_id) ;
00252 
00253 
00254   iostream_output& print_header(iostream_output& P_stream, 
00255                                 int           P_headerId,
00256                                 T_pValueData  P_val) ;
00257   virtual iostream_output& print_body  (iostream_output&  P_stream, 
00258                                         int          P_nb,
00259                                         T_pBodyValue P_val,
00260                                         int          P_level = 0) ;
00261 
00262   T_TypeType get_body_value_type (int P_id);
00263   T_TypeType get_header_value_type (int P_id);
00264 
00265   void          reset_value_data (T_pValueData P_val) ;
00266   void          convert_to_string (T_pValueData P_res, 
00267                                    T_pValueData P_val) ;
00268 
00269   void set_padding (unsigned long P_value);
00270   bool get_header_length_excluded ();
00271 
00272   unsigned long get_msg_length_start ();  
00273 
00274   bool get_msg_length_start_detected ();  
00275 
00276   bool get_complex_header_presence ();
00277   char* get_header_body_field_separator();
00278 
00279 
00280   int analyze_setfield(C_XmlData          *P_data,
00281                        int                *P_fieldId,
00282                        unsigned long      *P_fieldValueUl) ;
00283 
00284 
00285 
00286 protected:
00287 
00288   // header definition variables
00289   char          *m_header_name ;
00290   T_pHeaderField m_header_field_table ;
00291   T_pIdMap       m_header_id_map ;
00292 
00293   char          *m_header_type_name ;
00294   int            m_header_type_id_body ;
00295 
00296   int            m_header_type_id;
00297   int            m_header_length_id ;
00298   int            m_header_length_index ;
00299   unsigned long  m_nb_field_header, m_max_nb_field_header ;
00300   unsigned long  m_header_size ;
00301 
00302   int            m_transport_type ;
00303 
00304   unsigned long  m_msg_length_start ;
00305   bool           m_msg_length_start_detected ;
00306 
00307   // body definition variables
00308   char          *m_header_body_name ;
00309   T_pHeaderField m_header_body_field_table ;
00310   T_pIdMap       m_header_body_id_map ;
00311 
00312   int            m_header_body_type_id, m_header_body_length_id ;
00313   int            m_header_body_length_index;
00314   unsigned long  m_nb_field_header_body ;
00315   unsigned long  m_max_nb_field_header_body;
00316   unsigned long  m_header_body_size ;
00317 
00318   int            m_header_body_start_optional_id ;
00319 
00320   bool           m_header_complex_type_presence ;
00321 
00322 
00323   T_pNameAndIdList             m_message_name_list            ;
00324   T_pNameAndIdList             m_message_comp_name_list       ;
00325 
00326 
00327   // separator management
00328   char *m_header_body_field_separator ;
00329   int     m_session_id_position       ;
00330 
00331   // type management variables
00332   T_pTypeDef     m_type_def_table ;
00333   unsigned long  m_nb_types, m_max_nb_types ;
00334   T_pIdMap       m_type_id_map ;
00335 
00336   // header values management
00337   unsigned long      m_nb_header_values ;
00338   T_pHeaderValue     m_header_value_table ;
00339   T_pIdMap           m_header_value_id_map ;
00340   T_pDecodeMap       m_header_decode_map ;
00341 
00342   // body values defined in the header_name section (ie command for diameter)
00343   // header_name section is a sub section of dictionnary
00344 
00345   T_pBodyValueDef    m_body_value_table ;
00346 
00347   // body values management
00348   unsigned long      m_nb_header_body_values ;
00349   T_pHeaderBodyValue m_header_body_value_table ;
00350   T_pIdMap           m_header_body_value_id_map ;
00351   T_pDecodeMap       m_header_body_decode_map ;
00352 
00353   // protocol msg id management (session-id)
00354   T_MsgIdType        m_msg_id_type ;
00355   int                m_msg_id_id   ;
00356   T_TypeType         m_msg_id_value_type ;
00357 
00358   // protocol msg id management (out of session)
00359   T_MsgIdType        m_type_id_out_of_session ;
00360   int                m_id_out_of_session ;
00361 
00362   // padding control
00363   unsigned long      m_padding_value ;
00364   bool               m_header_length_excluded ;
00365 
00366   int  add_counter (char *P_name, unsigned long P_init) ;
00367   
00368   int  add_type(char *P_name, T_TypeType P_type, unsigned long P_size);
00369   
00370   int  add_header_field (char           *P_name, 
00371                          unsigned long   P_size, 
00372                          unsigned long  *P_nb_field,
00373                          unsigned long  *P_header_size,
00374                          T_pHeaderField  P_field_table,
00375                          T_pIdMap        P_map,
00376                          T_pCondPresence P_condPresence = NULL,
00377                          long            P_type_id = -1);
00378 
00379   void set_header_type_id (int P_id);
00380   void set_header_length_id (int P_id);
00381 
00382   void set_header_body_type_id (int P_id);
00383   void set_header_body_length_id (int P_id);
00384   
00385   int get_header_from_xml (C_XmlData *P_def);
00386   int get_types_from_xml (C_XmlData *P_def);
00387 
00388   virtual int xml_interpretor(C_XmlData *P_def);
00389   virtual int analyze_header_from_xml (C_XmlData *P_def);
00390   virtual int analyze_types_from_xml (C_XmlData *P_def);
00391   virtual int analyze_body_from_xml (C_XmlData *P_def);
00392 
00393   int analyze_dictionnary_from_xml (C_XmlData *P_def); 
00394   virtual    int analyze_sessions_id_from_xml (C_XmlData *P_def) ;
00395 
00396   
00397   virtual int get_header_body_values_from_xml (C_XmlData *P_def);
00398   virtual int get_header_values_from_xml (C_XmlData *P_def);
00399 
00400   int get_header_body_from_xml (C_XmlData *P_def);
00401   int get_header_body_optional_from_xml (C_XmlData *P_def);
00402 
00403 
00404 
00405 
00406   int get_counter_from_xml (C_XmlData *P_def);
00407 
00408   bool check_presence_needed (T_pCondPresence P_condition,
00409                               unsigned long  *P_values);
00410 
00411   int process_grouped_type(C_XmlData *P_bodyData,
00412                            int P_body_grouped_val_id,
00413                            T_pBodyValue P_pBodyVal);
00414                            
00415   list_t<C_MessageFrame*> *m_messageList;
00416 
00417 } ; // class C_ProtocolBinary
00418 
00419 #endif // _C_PROTOCOLBINARY_
00420 
00421 
00422 
00423 
00424 
00425 
00426 
00427 
00428 

Generated on Wed Mar 7 14:44:52 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002