Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_ProtocolText.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_PROTOCOL_TEXT_H
00021 #define _C_PROTOCOL_TEXT_H
00022 
00023 #include "C_ProtocolTextFrame.hpp"
00024 #include "C_GeneratorConfig.hpp"
00025 
00026 #include "C_RegExp.hpp"
00027 #include "list_t.hpp"
00028 #include "map_t.hpp"
00029 #include "ExternalMethod.h"
00030 #include "C_ProtocolStats.hpp"
00031 
00032 #include "TextDef.hpp"
00033 
00034 #include "C_ContextFrame.hpp"
00035 #include "ParserFrame.hpp"
00036 #include "FilterFrame.hpp"
00037 #include "ExternalMethodDef.hpp"
00038 
00039 class C_MessageText ;
00040 
00041 class C_ProtocolText : public C_ProtocolTextFrame {
00042 public:
00043 
00044   friend class C_MessageText ;
00045 
00046   typedef struct _struct_management_session_id {
00047     int                m_msg_id_id   ;
00048     T_TypeType         m_msg_id_value_type ;
00049   } T_ManagementSessionTextId, *T_pManagementSessionTextId;
00050 
00051   typedef list_t<T_ManagementSessionTextId> T_ManagementSessionTextIdList, *T_pManagementSessionTextIdList ;
00052 
00053   C_ProtocolText();
00054 
00055   void  analyze_data( C_XmlData            *P_def, 
00056                       char                **P_name,
00057                       T_pConfigValueList    P_config_value_list,
00058                       T_pContructorResult   P_res) ;
00059   ~C_ProtocolText();
00060 
00061   C_MessageFrame*                 decode_message (unsigned char *P_buffer, 
00062                                                   size_t        *P_size, 
00063                                                   C_ProtocolTextFrame::T_pMsgError    P_error) ;
00064   
00065   C_ProtocolTextFrame::T_MsgError encode_message (C_MessageFrame *P_msg,
00066                                                   unsigned char  *P_buffer,
00067                                                   size_t         *P_buffer_size);
00068 
00069   void                            log_buffer (char *P_header, 
00070                                               unsigned char *P_buf, 
00071                                               size_t P_size);
00072 
00073   char*                           message_name();
00074   char*                           message_component_name() ;
00075   T_pNameAndIdList                message_name_list     () ;
00076   T_pNameAndIdList                message_component_name_list  () ;
00077 
00078   char*                           message_name(int P_Id);
00079 
00080   int                             find_field      (char *P_name);
00081   T_TypeType                      get_field_type  (int P_id,
00082                                                    int P_sub_id);
00083 
00084   bool                            check_sub_entity_needed     (int P_id)      ;
00085 
00086 
00087   bool                            find_present_session (int P_msg_id,int P_id) ;
00088 
00089   C_MessageFrame*                   create_new_message (C_MessageFrame *P_msg);
00090   C_MessageFrame*                   create_new_message (void                *P_xml,
00091                                                         T_pInstanceDataList  P_list,
00092                                                         int                 *P_nb_value);
00093   char* get_field_value_to_check(C_MessageText *P_msg, 
00094                                  int  P_id,
00095                                  int *P_size);
00096 
00097   char* get_field_value(C_MessageText *P_msg, int P_id);
00098 
00099   char* get_field_value(C_MessageText *P_msg, int P_id,C_RegExp  *P_regexp_data);
00100 
00101   int   set_field_value(C_MessageText *P_msg, 
00102                         int            P_id, 
00103                         T_pValueData   P_value) ;
00104   
00105   int   get_message_id (char *P_name);
00106 
00107   T_pManagementSessionTextId get_manage_session_elt (int P_id);
00108   int get_nb_management_session () ;
00109 
00110   iostream_output& print_header_msg(iostream_output& P_stream, 
00111                                     int              P_id,
00112                                     T_pValueData     P_header) ;
00113   
00114   
00115   iostream_output& print_data_msg(iostream_output& P_stream, 
00116                                   T_pValueData     P_data) ;
00117 
00118 
00119   C_MessageText* create (C_ProtocolText *P_protocol,
00120                           char           *P_header,
00121                           char           *P_body);
00122 
00123 
00124   int find_field_id (char*P_name) ;
00125 
00126   typedef C_ProtocolFrame::T_MsgError 
00127   (C_MessageText::* T_BodyDecodeMethod)(int  P_index,
00128                                         char *P_ptr, 
00129                                         size_t *P_size);
00130 
00131 
00132   typedef C_ProtocolFrame::T_MsgError 
00133   (C_MessageText::* T_EncodeMethod)(int P_index);
00134 
00135 
00136   typedef T_pValueData (C_MessageText::* T_SessionMethod)(C_ContextFrame *P_void);
00137 
00138 
00139 protected:
00140 private:
00141 
00142   typedef list_t<char*> T_charPlist, *T_pcharPlist ;
00143 
00144   typedef struct _regexp_str_t {
00145     char *m_name ;
00146     char *m_expr ;
00147     int   m_nb_match ; 
00148     int   m_sub_match; 
00149     int   m_line ;     
00150   } T_RegExpStr, *T_pRegExpStr ;
00151   typedef list_t<T_pRegExpStr> T_ExpStrLst, *T_pExpStrLst ;
00152 
00153   
00154   typedef struct _fielddef_t {
00155     char        *m_name      ;
00156     char        *m_format    ;
00157     T_ExpStrLst *m_expr_list ;
00158   } T_FieldDef, *T_pFieldDef ;
00159   typedef list_t<T_pFieldDef> T_FieldDefList, *T_pFieldDefList ;
00160 
00161   typedef list_t<C_RegExp*> T_RegExpLst, *T_pRegExpLst ;
00162 
00163   typedef struct _field_desc_t {
00164     int                                  m_id          ;
00165     bool                                 m_header_body ; // true ==> header
00166     char                                *m_name        ; // to allocate  
00167     T_RegExpLst                         *m_reg_exp_lst ;
00168     
00169     T_pValueData                         m_format      ;
00170     int                                  m_format_value_start ;
00171     int                                  m_format_value_end ;
00172 
00173   } T_FieldDesc, *T_pFieldDesc ;
00174 
00175   typedef map_t<string_t,T_pFieldDesc> T_FieldNameMap, *T_pFieldNameMap ;
00176 
00177 
00178   typedef struct _fielddef_header_t {
00179     char              *m_name                    ; 
00180   } T_FieldHeader, *T_pFieldHeader               ;
00181   typedef list_t<T_FieldHeader> T_FieldHeaderList, *T_pFieldHeaderList ;
00182 
00183   typedef map_t<string_t,C_MessageText*> T_MessageNameMap, *T_pMessageNameMap ;
00184 
00185 
00186   typedef struct _cdata_value_t {
00187     char          *m_value ;
00188   } T_CDATAValue, *T_pCDATAValue ;
00189   typedef list_t<T_CDATAValue> T_CDATAValueList, *T_pCDATAValueList ;
00190 
00191 
00192   typedef struct _defmethod_t {
00193     char               *m_name        ; 
00194     T_BodyMethodType    m_method      ;
00195     char               *m_param       ;
00196     char               *m_default     ;
00197   } T_DefMethod, *T_pDefMethod ;
00198   typedef list_t<T_DefMethod> T_DefMethodList, *T_pDefMethodList ;
00199 
00200 
00201   int xml_interpretor(C_XmlData *P_def,
00202                       char **P_name,
00203                       T_pConfigValueList P_config_value_list) ;
00204 
00205   int set_body_method();
00206 
00207   int analyze_from_xml (C_XmlData *P_def, 
00208                         T_FieldDefList *P_fielddef_list,
00209                         char **P_section_name,
00210                         char **P_type,
00211                         bool P_header_body);
00212 
00213   int analyze_dictionnary_from_xml (C_XmlData *P_def); 
00214   int analyze_sessions_id_from_xml (C_XmlData *P_def) ;
00215 
00216   int analyze_extern_method_from_xml(C_XmlData *P_data, 
00217                                      T_DefMethodExternList *P_def_method_list);
00218 
00219   T_ExternalMethod find_method_extern(char *P_name) ;
00220 
00221 
00222   int analyze_body_method_param (int P_index, char *P_body_method_param);
00223   int set_filter_method (char *P_filter_method) ;
00224 
00225   int analyze_body_method_from_xml (C_XmlData *P_data, 
00226                                     T_DefMethodList *P_def_method_list) ;
00227 
00228 
00229 
00230   T_FieldHeaderList* analyze_header_value(C_XmlData            *P_data, 
00231                                           T_FieldHeaderList    *P_fielddef_header_list,
00232                                           int                  *P_ret);
00233 
00234   int   analyze_message_scen(C_XmlData            *P_data, 
00235                               T_pCDATAValueList     P_cdata_value_list);
00236 
00237   C_MessageText* build_message (char *P_header, 
00238                                 char *P_body);
00239 
00240   T_pFieldDesc check_field(T_pFieldDef P_field_def, bool P_header);
00241 
00242   int new_id () ;
00243 
00244 
00245   char                            *m_header_name              ;
00246   char                            *m_header_type              ;
00247   char                            *m_body_name                ;
00248   char                            *m_body_type                ;
00249 
00250   char                           **m_names_fields             ;
00251 
00252 
00253   T_pFieldDefList                  m_header_fields_list        ;
00254   T_pFieldDefList                  m_body_fields_list          ;
00255   int                              m_nb_body_fields            ;
00256   int                              m_nb_header_fields          ;
00257 
00258   T_pFieldNameMap                  m_fields_name_map           ;
00259   int                              m_id_counter                ;
00260 
00261 
00262   T_pFieldHeaderList               m_header_fields_dico        ;
00263   int                              m_nb_message_names          ;
00264 
00265 
00266   typedef map_t<string_t,int>     T_DecodeMap, *T_pDecodeMap       ;
00267 
00268   char                           **m_message_names_table       ;
00269   T_pDecodeMap                     m_message_decode_map        ;
00270   
00271 
00272   T_pNameAndIdList                 m_message_name_list         ;
00273   
00274 
00275   T_pFieldDesc                    *m_fields_desc_table         ;
00276   int                              m_nb_fields_desc_table      ;
00277   
00278   T_pManagementSessionTextId       m_value_sessions_table      ;
00279   int                              m_value_sessions_table_size ;
00280 
00281   T_pDefMethodList                 m_def_method_list           ;
00282 
00283   T_pDefMethodExternList           m_def_method_extern_list    ;
00284   T_pDefMethodExternal             m_method_external_table     ;
00285   int                              m_nb_method_external_table  ;
00286   
00287 
00288 private:
00289   char                            *m_body_separator            ;
00290   size_t                           m_body_separator_size       ;
00291 
00292   char                            *m_field_separator           ;
00293   size_t                           m_field_separator_size      ;
00294 
00295   char                            *m_field_body_separator      ;
00296   size_t                           m_field_body_separator_size ;
00297 
00298 
00299   int                              m_message_type_field_id     ;
00300   int                              m_session_id_id             ;
00301 
00302   T_SessionMethod                  m_session_method            ;
00303 
00304   T_FilterFunction                 m_filter_function           ;
00305 
00306   typedef union _union_param {
00307     int                 m_id ;
00308     T_ParserFunction    m_parser ;
00309   } T_ParamMethod, *T_pParamMethod ;
00310 
00311   typedef struct _struct_body_decode_data {
00312     T_BodyDecodeMethod m_decode ;
00313     T_EncodeMethod     m_encode ;
00314     T_ParamMethod      m_param_encode  ;
00315     T_ParamMethod      m_param_decode  ;
00316   } T_BodyDecodeData, *T_pBodyDecodeData ;
00317 
00318   T_BodyDecodeData **m_methods ;
00319   int                m_nb_methods ;
00320 
00321 
00322   T_pConfigValueList           m_config_value_list ;
00323   
00324   int xml_configuration_parameters (C_XmlData *P_data,
00325                                     T_ParamDefList *P_paramdef_list) ;
00326   
00327   int  update_config_params(T_ParamDef& P_config_param_dico,
00328                             T_pConfigValueList P_config_value_list);
00329   
00330   char* find_config_value(char* P_variable) ;
00331   char* search_variable(char* P_varibleString) ;
00332   unsigned long  calculate_size(char* P_varibleString) ;
00333   
00334   char* replace_variable_config(char* P_buffer, unsigned long P_size_config) ;
00335   
00336 
00337 
00338   void set_body_separator (char*  P_body_separator) ;
00339   void set_field_separator (char*  P_field_separator) ;
00340   void set_message_type_field_id (int P_id) ;
00341   void set_session_id_id (int  P_id) ;
00342   void use_open_id () ;
00343 
00344   void set_number_methods (int P_nb) ;
00345   void destroy_methods () ;
00346   
00347 
00348   void set_body_decode_method (int                     P_index,
00349                                T_BodyMethodType        P_type,
00350                                T_BodyDecodeMethod      P_method,
00351                                void                   *P_param);
00352 
00353   void set_encode_method (int                 P_index,
00354                           T_BodyMethodType    P_type,
00355                           T_EncodeMethod      P_method,
00356                           void               *P_param);
00357 
00358 
00359   
00360 
00361 } ;
00362 
00363 #endif // _C_PROTOCOL_TEXT_H
00364 
00365 

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