Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_ProtocolExternal.cpp

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 #include "C_ProtocolExternal.hpp"
00021 #include "C_MessageExternal.hpp"
00022 
00023 #include "GeneratorTrace.hpp"
00024 #include "GeneratorError.h"
00025 
00026 #include "dlfcn_t.hpp"
00027 #include "Utils.hpp"
00028 #include "ProtocolData.hpp"
00029 
00030 #include "set_t.hpp"
00031 
00032 
00033 C_ProtocolExternal::C_ProtocolExternal
00034 (C_TransportControl   *P_transport_control,
00035  C_XmlData            *P_def,
00036  char                **P_name,
00037  T_pConfigValueList    P_config_value_list,
00038  T_ConstructorResult  *P_res) : C_ProtocolExternalFrame() {
00039 
00040   T_ConstructorResult  L_res = E_CONSTRUCTOR_KO ;
00041   char                *L_library_name = NULL ;
00042   char                *L_use_transport_name = NULL ;
00043   int                  L_transport_id ;
00044   C_TransportControl::T_pTransportContext L_transport_ctxt ;
00045 
00046 
00047   m_factory_info.m_create = NULL ;
00048   m_factory_info.m_delete = NULL ;
00049   m_factory = NULL ;
00050 
00051   m_library_handle = NULL ;
00052 
00053   m_field_body_name_map = NULL;
00054   m_field_name_map = NULL ;
00055   m_body_value_name_map = NULL ;
00056   m_body_decode_map = NULL ;
00057 
00058 
00059   m_id_counter = -1 ;
00060   m_start_body_index = -1 ;
00061   m_end_header_index = -1 ;
00062   
00063   m_header_defaults = NULL ;
00064   m_body_defaults = NULL ;
00065 
00066   m_nb_body_values = 0 ;
00067 
00068   m_session_id       = -1 ;
00069   m_outof_session_id = -1 ;
00070 
00071   m_message_map = NULL ;
00072   
00073 
00074   m_header_field_desc_table = NULL    ;
00075   m_body_field_desc_table   = NULL    ;
00076   m_body_value_table        = NULL    ;
00077   m_names_table             = NULL    ;
00078   m_message_names_table     = NULL    ;
00079   m_nb_names                = 0       ;
00080   m_nb_message_names        = 0       ;
00081   m_message_decode_map       = NULL   ;
00082 
00083 
00084   m_body_not_present_table = NULL ;
00085   m_header_not_present_table = NULL ;
00086 
00087   m_from_string_table = NULL ;
00088   m_to_string_table = NULL ;
00089   m_nb_from_string = 0 ;
00090 
00091 
00092   m_from_string_field_body_table = NULL ;
00093   m_to_string_field_body_table   = NULL ;
00094   m_nb_from_string_field_body    = 0    ;
00095 
00096 
00097   m_config_value_list = P_config_value_list ;
00098 
00099 
00100   NEW_VAR (m_message_name_list, T_NameAndIdList()) ;
00101   NEW_VAR (m_message_comp_name_list, T_NameAndIdList()) ;
00102 
00103 
00104   if (P_def != NULL) {
00105 
00106     *P_name = P_def->find_value((char *)"name");
00107     if (*P_name == NULL) {
00108       GEN_ERROR(E_GEN_FATAL_ERROR, "No name for external protocol definition");
00109     } else {
00110       m_name = *P_name ;
00111       L_library_name = P_def->find_value((char *)"library");
00112       L_use_transport_name = P_def->find_value((char*)"use-transport-library");
00113 
00114       if ((L_library_name == NULL) && (L_use_transport_name == NULL)) {
00115         GEN_ERROR(E_GEN_FATAL_ERROR, "Definition of protocol ["
00116                   << *P_name << "] with no library or use-transport-library field" );
00117       } else {
00118 
00119         if (L_use_transport_name != NULL) {
00120           // library already loaded from transport lib
00121           L_transport_id = P_transport_control->get_transport_id (L_use_transport_name);
00122           if (L_transport_id != ERROR_TRANSPORT_UNKNOWN) {
00123             L_transport_ctxt = P_transport_control->get_transport_context(L_transport_id);
00124             m_library_handle = L_transport_ctxt->m_lib_handle ;
00125           } else {
00126             GEN_ERROR(E_GEN_FATAL_ERROR, "External protocol ["
00127                       << *P_name << "] defined with library transport ["
00128                       << L_use_transport_name << "] unknown");
00129           }
00130 
00131         } else {
00132           // direct library loading
00133           m_library_handle = dlopen(L_library_name, RTLD_LAZY);
00134           if (m_library_handle == NULL) {
00135             GEN_ERROR(E_GEN_FATAL_ERROR, 
00136                       "Unable to open library file [" 
00137                       << L_library_name
00138                       << "] error [" << dlerror() << "]");
00139           }
00140         }
00141 
00142         if (m_library_handle != NULL) {
00143           if (xml_analysis(P_def, P_name,P_config_value_list) == 0) {
00144             L_res = E_CONSTRUCTOR_OK ;
00145           }
00146         }
00147       }
00148     }
00149       
00150   } else {
00151 
00152     GEN_ERROR(E_GEN_FATAL_ERROR, "C_ProtocolExternal() called with NULL Xml definition");
00153     
00154   }
00155 
00156   *P_res = L_res ;
00157 
00158 }
00159 
00160 C_ProtocolExternal::~C_ProtocolExternal() {
00161 
00162   int  L_i ;
00163 
00164   if (m_factory != NULL) {
00165     if (m_factory_context != NULL) {
00166       m_factory->delete_context(&m_factory_context);
00167     }
00168     if (m_factory_info.m_delete != NULL) {
00169       (*m_factory_info.m_delete)(&m_factory);
00170     }
00171   }
00172 
00173 
00174   // reset m_config_field ??
00175   if (m_header_field_desc_table != NULL) {
00176     for (L_i = 0; L_i < m_nb_header_fields ; L_i++) {
00177       if ((m_header_field_desc_table[L_i])->m_config_field_name != NULL) {
00178         (m_header_field_desc_table[L_i])->m_config_field_name = NULL ;
00179       }
00180     }
00181     FREE_TABLE(m_header_field_desc_table) ;
00182   }
00183 
00184   FREE_TABLE(m_body_field_desc_table)   ;
00185   FREE_TABLE(m_body_value_table)   ;
00186 
00187 
00188   if ((m_names_table != NULL) && (m_nb_names > 0)) {
00189     for(L_i = 0; L_i < m_nb_names; L_i++) {
00190       FREE_TABLE(m_names_table[L_i]);
00191     }
00192     FREE_TABLE(m_names_table);
00193   }
00194 
00195 
00196   if (m_message_names_table != NULL) {
00197     for(L_i = 0; L_i < m_nb_message_names; L_i++) {
00198       FREE_TABLE(m_message_names_table[L_i]);
00199     }
00200     FREE_TABLE(m_message_names_table);
00201   }
00202 
00203 
00204   // delete m_message_decode_map 
00205   if (m_message_decode_map != NULL) {
00206     if (!m_message_decode_map->empty()) {
00207       m_message_decode_map->erase(m_message_decode_map->begin(),
00208                               m_message_decode_map->end());
00209     }
00210   }
00211 
00212   DELETE_VAR(m_message_decode_map);
00213 
00214   // delete m_field_name_map 
00215   if (m_field_name_map != NULL) {
00216     if (!m_field_name_map->empty()) {
00217       m_field_name_map->erase(m_field_name_map->begin(),
00218                               m_field_name_map->end());
00219     }
00220     DELETE_VAR(m_field_name_map);
00221   }
00222 
00223   // delete m_body_value_name_map
00224   if (m_body_value_name_map != NULL) {
00225     if (!m_body_value_name_map->empty()) {
00226       m_body_value_name_map->erase(m_body_value_name_map->begin(),
00227                                    m_body_value_name_map->end());
00228     }
00229     DELETE_VAR(m_body_value_name_map);
00230   }
00231     
00232   // delete m_field_body_name_map
00233   if (m_field_body_name_map != NULL) {
00234     if (!m_field_body_name_map->empty()) {
00235       m_field_body_name_map->erase(m_field_body_name_map->begin(),
00236                                    m_field_body_name_map->end());
00237     }
00238     DELETE_VAR(m_field_body_name_map);
00239   }
00240 
00241 
00242   // delete m_field_body_name_map
00243   if (m_body_decode_map != NULL) {
00244     if (!m_body_decode_map->empty()) {
00245       m_body_decode_map->erase(m_body_decode_map->begin(),
00246                                    m_body_decode_map->end());
00247     }
00248   }
00249 
00250   DELETE_VAR(m_body_decode_map);
00251 
00252 
00253   // delete m_message_map
00254   if (m_message_map != NULL) {
00255     if (!m_message_map->empty()) {
00256       m_message_map->erase(m_message_map->begin(),
00257                            m_message_map->end());
00258     }
00259   }
00260 
00261   DELETE_VAR(m_message_map);
00262 
00263   if (m_body_not_present_table != NULL ) {
00264     for (L_i = 0; L_i <m_nb_body_values ; L_i++) {
00265       FREE_TABLE (m_body_not_present_table[L_i]);
00266     }
00267     FREE_TABLE (m_body_not_present_table) ;
00268   }
00269 
00270   if (m_header_not_present_table != NULL ) {
00271     for (L_i = 0; L_i <m_nb_header_fields ; L_i++) {
00272       FREE_TABLE (m_header_not_present_table[L_i]);
00273     }
00274     FREE_TABLE (m_header_not_present_table) ;
00275   }
00276 
00277   FREE_TABLE(m_from_string_table);
00278   FREE_TABLE(m_to_string_table);
00279   m_nb_from_string = 0 ;
00280 
00281 
00282   DELETE_VAR(m_stats);
00283 
00284 
00285   FREE_TABLE(m_from_string_field_body_table);
00286   FREE_TABLE(m_to_string_field_body_table);
00287   m_nb_from_string_field_body = 0 ;
00288 
00289 
00290   if(! m_message_name_list -> empty()) {
00291     T_NameAndIdList::iterator  L_elt_it ;
00292     T_NameAndId                L_elt    ;
00293 
00294     for(L_elt_it=m_message_name_list->begin();
00295         L_elt_it != m_message_name_list->end();
00296         L_elt_it++) {
00297       L_elt = *L_elt_it ;
00298       FREE_TABLE(L_elt.m_name);
00299     }
00300     m_message_name_list -> erase (m_message_name_list->begin(), m_message_name_list->end());
00301   }
00302   DELETE_VAR (m_message_name_list) ;
00303 
00304   if(! m_message_comp_name_list -> empty()) {
00305     T_NameAndIdList::iterator  L_elt_it ;
00306     T_NameAndId                L_elt    ;
00307     
00308     for(L_elt_it=m_message_comp_name_list->begin();
00309         L_elt_it != m_message_comp_name_list->end();
00310         L_elt_it++) {
00311       L_elt = *L_elt_it ;
00312       FREE_TABLE(L_elt.m_name);
00313     }
00314     m_message_comp_name_list -> erase (m_message_comp_name_list->begin(), 
00315                                        m_message_comp_name_list->end());
00316   }
00317   DELETE_VAR (m_message_comp_name_list) ;
00318 
00319 
00320   m_config_value_list = NULL ;
00321   
00322 }
00323 
00324 
00325 C_MessageFrame* C_ProtocolExternal::create_new_message (C_MessageFrame *P_msg) {
00326   C_MessageExternal *L_dest = NULL ;
00327   C_MessageExternal *L_source = dynamic_cast<C_MessageExternal *>(P_msg) ;
00328   
00329   if (L_source != NULL) {
00330     // L_source->dump(std::cerr);
00331     //    NEW_VAR(L_dest, C_MessageExternal());
00332     //    *L_dest = *L_source ;
00333     NEW_VAR(L_dest, C_MessageExternal(*L_source));
00334   }
00335   return (L_dest);
00336 }
00337 
00338 C_MessageFrame* C_ProtocolExternal::create_new_message (void                *P_xml, 
00339                                                         T_pInstanceDataList  P_list,
00340                                                         int                 *P_nb_value) {
00341   // xml message analysis 
00342   C_XmlData         *P_data = (C_XmlData *)P_xml ;
00343   T_FieldHeaderList *L_field_list = NULL ;
00344   int                L_ret = 0 ;
00345   C_MessageExternal *L_msg = NULL ;
00346   T_MessageNameMap::iterator L_it ;
00347 
00348   if (P_data != NULL) {
00349     L_field_list = analyze_header_value(P_data, L_field_list, false, &L_ret);
00350   }
00351   
00352   if (L_ret != -1) {
00353     if (L_field_list != NULL) {
00354       if (!L_field_list->empty()) {
00355         L_it = m_message_map->find(T_MessageNameMap::key_type((*(L_field_list->begin())).m_name));
00356         if (L_it == m_message_map->end()) {
00357           GEN_ERROR(E_GEN_FATAL_ERROR,
00358                     "Unknown message [" << (*(L_field_list->begin())).m_name << "] in dictionnary");
00359         } else {
00360           L_msg = build_message(L_it->second, *(L_field_list->begin()), P_list, P_nb_value);
00361           if (L_msg != NULL) {
00362             L_msg -> m_id = L_it->second->m_id ;
00363 
00364             // L_msg->dump(std::cerr);
00365 
00366           } 
00367         }
00368       }
00369     }
00370   }
00371   
00372   return (L_msg);
00373 }
00374 
00375 char*           C_ProtocolExternal::message_name       () {
00376   return (m_message_name);
00377 }
00378 
00379 
00380 char*           C_ProtocolExternal::message_component_name () {
00381   return (m_body_name);
00382 }
00383 
00384 T_pNameAndIdList C_ProtocolExternal::message_name_list     () {
00385   T_MessageNameMap::iterator   L_it_message              ;
00386   T_NameAndId                  L_elt                     ;
00387   int                          L_id                      ;
00388 
00389   L_id = 0 ;
00390   for (L_it_message = m_message_map->begin();
00391        L_it_message != m_message_map->end();
00392        L_it_message++) {
00393 
00394     
00395     ALLOC_TABLE(L_elt.m_name,
00396                 char*, sizeof(char),
00397                 ((L_it_message->first).length())+1);
00398     
00399     strcpy(L_elt.m_name,(L_it_message->first).c_str()) ;
00400     L_elt.m_id = L_id ;
00401     m_message_name_list->push_back(L_elt);
00402     L_id ++ ;      
00403   }
00404 
00405   return (m_message_name_list);
00406 }
00407 
00408 T_pNameAndIdList C_ProtocolExternal::message_component_name_list    () {
00409   T_FieldBodyNameMap::iterator L_it_body                 ;
00410   T_NameAndId                  L_elt                     ;
00411 
00412   for (L_it_body = m_body_value_name_map->begin();
00413        L_it_body != m_body_value_name_map->end();
00414        L_it_body++) {
00415 
00416     ALLOC_TABLE(L_elt.m_name,
00417                char*, sizeof(char),
00418                 strlen((L_it_body->second)->m_name)+1);
00419     
00420     strcpy(L_elt.m_name,(L_it_body->second)->m_name) ;
00421     
00422     L_elt.m_id = (L_it_body->second)->m_id - m_end_header_index -1 ;
00423     
00424     m_message_comp_name_list->push_back(L_elt);
00425 
00426   }
00427 
00428 
00429   return (m_message_comp_name_list);
00430 
00431 }
00432 
00433 
00434 int             C_ProtocolExternal::find_field         (char *P_name) {
00435   int L_id ;
00436 
00437   for(L_id = 0 ; L_id < m_nb_names; L_id++) {
00438 
00439     if (strcmp(m_names_table[L_id], P_name)==0) {
00440       return (L_id);
00441     }
00442   }
00443   return (-1);
00444 }
00445 
00446 T_TypeType      C_ProtocolExternal::get_field_type     (int P_id,
00447                                                         int P_sub_id) {
00448 
00449   //  std::cerr << "P_id = " << P_id << " P_sub_id = " << P_sub_id << " val= " << P_id - m_start_body_index << std::endl ;
00450   if (P_id < m_nb_header_fields) {
00451     return(m_header_field_desc_table[P_id]->m_type) ;
00452   } else {
00453       return (m_body_field_desc_table[P_sub_id - m_start_body_index]->m_type);
00454   }
00455 
00456 }
00457 
00458 C_ProtocolFrame::T_MsgError C_ProtocolExternal::from_external 
00459 (C_MsgBuildContext* P_build,T_pReceiveMsgContext P_recvMsgCtx) {
00460 
00461 
00462   C_ProtocolFrame::T_MsgError L_error = C_ProtocolFrame::E_MSG_EXTERNAL_ERROR;
00463   
00464   int                              L_i               ;
00465   T_pValueData                     L_header          ;
00466 
00467   int                             *L_body_instance   ;
00468   T_pValueData                     L_a_body          ;
00469   T_ValueDataList                  L_body            ;
00470   list_t<int>                      L_body_id         ;
00471 
00472   T_BodyDecodeMap::iterator        L_it              ;
00473 
00474   int                              L_id              ;
00475   int                              L_msg_id          ;
00476 
00477 
00478   T_MessageDecodeMap::iterator     L_msg_it          ;
00479   C_MessageExternal               *L_msg             ;
00480 
00481   P_build->init_from_external();
00482 
00483   ALLOC_TABLE(L_header, T_pValueData, sizeof(T_ValueData), m_nb_header_fields);
00484   ALLOC_TABLE(L_body_instance, int*, sizeof(int), 
00485               m_nb_body_values);
00486   for (L_i = 0 ; L_i < m_nb_body_values; L_i ++) {
00487     L_body_instance[L_i] = 0 ;
00488   }
00489 
00490   L_header[m_type_id].m_id = m_type_id ;
00491   L_header[m_type_id].m_type 
00492     = m_header_field_desc_table[m_type_id]->m_type ;
00493   
00494   ((P_build)->*(m_header_field_desc_table[m_type_id]->m_get))
00495     (&L_header[m_type_id]);
00496   
00497   // To be improved: the type of the message can be in the header or the body
00498   L_msg_it = m_message_decode_map
00499     ->find(T_MessageDecodeMap::key_type(L_header[m_type_id]));
00500 
00501   if (L_msg_it != m_message_decode_map->end()) {
00502 
00503     L_msg_id = (L_msg_it->second)->m_id ;
00504 
00505     if (m_stats) {
00506       m_stats->updateStats (E_MESSAGE,
00507                             E_RECEIVE,
00508                             L_msg_id);
00509     }
00510 
00511     for(L_i = 0; L_i < m_nb_header_fields; L_i++) {
00512       
00513       if (m_header_not_present_table[L_msg_id][L_i] == true) {
00514         
00515         L_header[L_i].m_id = L_i ;
00516         L_header[L_i].m_type = m_header_field_desc_table[L_i]->m_type ;
00517         
00518         
00519         if (m_header_field_desc_table[L_i]->m_check_get 
00520             != (C_MsgBuildContext::T_ContextFunction)NULL) {
00521           if ( ((P_build)->*(m_header_field_desc_table[L_i]->m_check_get))
00522                (&(L_header[L_i])) == true ) {
00523             ((P_build)->*(m_header_field_desc_table[L_i]->m_get))(&(L_header[L_i]));
00524           }
00525         } else {
00526           ((P_build)->*(m_header_field_desc_table[L_i]->m_get))(&(L_header[L_i]));
00527         }
00528       }
00529     }
00530     
00531     while ((((P_build)->*(m_get_body))(NULL)) == true) {
00532       
00533       ALLOC_TABLE(L_a_body, T_pValueData, 
00534                   sizeof(T_ValueData), m_nb_body_fields);
00535       L_body.push_back(L_a_body);
00536       
00537       // decode first body type
00538       L_a_body[m_body_type_id-m_start_body_index].m_id = m_body_type_id ;
00539       L_a_body[m_body_type_id-m_start_body_index].m_type 
00540         = m_body_field_desc_table[m_body_type_id-m_start_body_index]->m_type ;
00541       
00542       ((P_build)->*(m_body_field_desc_table[m_body_type_id-m_start_body_index]->m_get))
00543         (&L_a_body[m_body_type_id-m_start_body_index]);
00544       
00545       L_it = m_body_decode_map
00546         ->find(T_BodyDecodeMap::key_type(L_a_body[m_body_type_id-m_start_body_index]));
00547 
00548       if (L_it != m_body_decode_map->end()) {
00549         L_id = L_it->second - m_end_header_index - 1 ;
00550 
00551         if (m_stats) {
00552           m_stats->updateStats (E_MESSAGE_COMPONENT,
00553                                 E_RECEIVE,
00554                                 L_id);
00555         }
00556 
00557         L_body_instance[L_id] ++ ;
00558         L_body_id.push_back(L_id);
00559       } else {
00560         // error on decoding body
00561         // L_error = ?
00562         break ;
00563       }
00564       
00565       
00566       // now decode all the other fields
00567       for (L_i = 0; L_i < m_nb_body_fields; L_i++) {
00568         if (L_i != (m_body_type_id-m_start_body_index)) {
00569           if (m_body_not_present_table[L_id][L_i] == true) {
00570             L_a_body[L_i].m_id = L_i + m_start_body_index ;
00571             L_a_body[L_i].m_type = m_body_field_desc_table[L_i]->m_type ;
00572             ((P_build)->*(m_body_field_desc_table[L_i]->m_get))(&L_a_body[L_i]);
00573           } else {
00574             L_a_body[L_i].m_type = E_TYPE_NUMBER ;
00575             // temporary TO DO m_id = -1
00576             L_a_body[L_i].m_id = 0 ;
00577           }
00578         }
00579       }
00580     
00581     } // while 
00582 
00583     NEW_VAR(L_msg, 
00584             C_MessageExternal(this, L_header, &L_body, &L_body_id, L_body_instance));
00585     
00586     L_msg->m_id =(L_msg_it->second)->m_id ;
00587     // TODO: delete primitive and component ?????
00588     ((P_build)->*(m_delete_body))(NULL) ;
00589     ((P_build)->*(m_delete_header))(NULL) ;
00590     
00591     P_recvMsgCtx->m_msg = L_msg ;
00592     L_error = C_ProtocolFrame::E_MSG_OK ;
00593     
00594   } else {
00595     iostream_error << "message unknown" << iostream_endl ;
00596   }
00597   
00598 
00599   FREE_TABLE(L_body_instance);
00600   if (!L_body.empty()) {
00601     L_body.erase(L_body.begin(), L_body.end());
00602     L_body_id.erase(L_body_id.begin(), L_body_id.end());
00603   }
00604 
00605   return (L_error);
00606 }
00607 
00608 C_ProtocolFrame::T_MsgError C_ProtocolExternal::to_external   (C_MsgBuildContext* P_build, C_MessageFrame* P_msg) {
00609 
00610   int               L_i,  L_j ;
00611   T_pValueData      L_header ;
00612   C_MessageExternal *L_msg =  dynamic_cast<C_MessageExternal*>(P_msg);
00613 
00614   //  T_BodyDecodeMap::iterator L_it ;
00615   int                       L_id ;
00616   int                       L_msg_id ;
00617 
00618 
00619   ((P_build)->*(m_create_header))(NULL) ;
00620 
00621   P_build->init_to_external();
00622 
00623   L_header = L_msg->m_header ;
00624   L_msg_id = L_msg->m_id     ;
00625 
00626   if (m_stats) {
00627     m_stats->updateStats(E_MESSAGE,
00628                          E_SEND,
00629                          L_msg_id);
00630   }
00631 
00632   for(L_i = 0; L_i < m_nb_header_fields; L_i++) {
00633     if (m_header_not_present_table[L_msg_id][L_i] == true) {
00634       L_header[L_i].m_id = L_i ;
00635       L_header[L_i].m_type = m_header_field_desc_table[L_i]->m_type ;
00636 
00637       if (m_header_field_desc_table[L_i]->m_check_set 
00638           != (C_MsgBuildContext::T_ContextFunction)NULL) {
00639         if ( ((P_build)->*(m_header_field_desc_table[L_i]->m_check_set))
00640              (&(L_header[L_i])) == true ) {
00641           ((P_build)->*(m_header_field_desc_table[L_i]->m_set))(&(L_header[L_i]));
00642         }
00643       } else {
00644         ((P_build)->*(m_header_field_desc_table[L_i]->m_set))(&(L_header[L_i]));
00645       }
00646 
00647       //   ((P_build)->*(m_header_field_desc_table[L_i]->m_set))(&(L_header[L_i]));
00648     }
00649   }
00650   
00651   for (L_i = m_nb_header_fields ; L_i < L_msg->m_nb_values ; L_i++ ) {
00652     ((P_build)->*(m_create_body))(NULL) ;
00653 
00654     L_id = L_msg->m_ids[L_i] ;
00655 
00656     if (m_stats) {
00657       m_stats->updateStats (E_MESSAGE_COMPONENT,
00658                             E_SEND,
00659                             L_id);
00660     }
00661     
00662     for (L_j = 0; L_j < m_nb_body_fields ; L_j++) {
00663       if (m_body_not_present_table[L_id][L_j] == true) {
00664         L_msg->m_all_values[L_i][L_j].m_type 
00665           = m_body_field_desc_table[L_j]->m_type ;
00666         ((P_build)->*(m_body_field_desc_table[L_j]->m_set))
00667           (&(L_msg->m_all_values[L_i][L_j]));
00668         }
00669       }
00670     ((P_build)->*(m_add_body))(NULL) ;
00671   }
00672 
00673   return (C_ProtocolFrame::E_MSG_OK);
00674 }
00675 
00676 // Private methods
00677 
00678 int C_ProtocolExternal::xml_analysis (C_XmlData *P_data, char **P_name,
00679                                       T_pConfigValueList P_config_value_list) {
00680 
00681   int                      L_ret = 0 ;
00682   char                    *L_factory_create_symbol = NULL ;
00683   char                    *L_factory_delete_symbol = NULL ;
00684   T_pXmlData_List          L_data = NULL ;
00685   T_pXmlData_List          L_data_dico = NULL ;
00686   T_XmlData_List::iterator L_it ;
00687   bool                     L_found = false ;
00688 
00689   T_pFieldDefList          L_header_fields = NULL ;
00690   T_pFieldDefList          L_body_fields = NULL ;
00691 
00692   char                    *L_header_type = NULL ;
00693   char                    *L_body_type = NULL ;
00694   char                    *L_header_create_function = NULL ;
00695   char                    *L_body_create_function = NULL ;
00696 
00697   char                    *L_header_delete_function = NULL ;
00698   char                    *L_body_delete_function = NULL ;
00699 
00700   char                    *L_body_add_function = NULL ;
00701   char                    *L_body_get_function = NULL ;
00702   char                    *L_value_field = NULL ;
00703 
00704   C_XmlData                    *L_dataDico = NULL ;
00705   char                         *L_session_id_name = NULL ;
00706   char                         *L_outof_session_id_name = NULL ;
00707 
00708   T_pFieldHeaderList            L_header_fields_dico = NULL ;
00709   T_pFieldBodyList              L_body_fields_dico = NULL ;
00710   
00711   T_pParamDefList               L_config_params_dico = NULL ;
00712   T_ParamDefList::iterator      L_config_params_dico_it     ;
00713   
00714 
00715   L_factory_create_symbol = P_data->find_value((char *)"context-factory-constructor");
00716   L_factory_delete_symbol = P_data->find_value((char *)"context-factory-destructor");
00717 
00718   if (L_factory_create_symbol == NULL) {
00719     GEN_ERROR(E_GEN_FATAL_ERROR, "Field [context-factory-constructor] not found");
00720     L_ret = -1 ;
00721   }
00722 
00723   if (L_factory_delete_symbol == NULL) {
00724     GEN_ERROR(E_GEN_FATAL_ERROR, "Field [context-factory-destructor] not found");
00725     L_ret = -1 ;
00726   }
00727 
00728   if (L_ret != -1) {
00729     m_factory_info.m_create =
00730       (T_CreateContextFactory) dlsym(m_library_handle, L_factory_create_symbol);
00731     if (m_factory_info.m_create == NULL) {
00732       GEN_ERROR(E_GEN_FATAL_ERROR, "Symbol [" << dlerror() << "]");
00733       L_ret = -1 ;
00734     }
00735   }
00736 
00737   if (L_ret != -1) {
00738     m_factory_info.m_delete =
00739       (T_DeleteContextFactory) dlsym(m_library_handle, L_factory_delete_symbol);
00740     if (m_factory_info.m_delete == NULL) {
00741       GEN_ERROR(E_GEN_FATAL_ERROR, "Symbol [" << dlerror() << "]");
00742       L_ret = -1 ;
00743     }
00744   }
00745 
00746   if (L_ret != -1) {
00747     m_factory = (*m_factory_info.m_create)() ;
00748     if (m_factory == NULL) {
00749       L_ret = -1;
00750     } else {
00751       m_factory_context = m_factory->create_context() ;
00752     }
00753   }
00754 
00755   // xml dictionnary analysis
00756   if (L_ret != -1) {
00757     L_data = P_data->get_sub_data();
00758     if (L_data == NULL){
00759       L_ret = -1 ;
00760     } 
00761   }
00762    
00763   // types analysis => to be done later / check compatibility
00764   // with other protocols
00765 
00766   // analyze presence of configuration-parameters in dico
00767   if (L_ret != -1) {
00768     for (L_it = L_data->begin();
00769          L_it != L_data->end();
00770          L_it++) {
00771       if (strcmp((*L_it)->get_name(), "configuration-parameters") == 0) {
00772         L_found = true ;
00773         NEW_VAR(L_config_params_dico, T_ParamDefList());
00774         L_ret = xml_configuration_parameters (*L_it, L_config_params_dico);
00775         break ;
00776       }
00777     }
00778 
00779 
00780     if (L_ret != -1) {
00781       if (L_found == true) {
00782         L_found = false ;
00783         if ((L_config_params_dico != NULL ) && (!L_config_params_dico->empty())) {
00784           m_nb_config_params = L_config_params_dico->size();
00785           if (m_nb_config_params != 0) {
00786             // ctrl between parameters from config and dico
00787             for (L_config_params_dico_it = L_config_params_dico->begin();
00788                  L_config_params_dico_it != L_config_params_dico->end();
00789                  L_config_params_dico_it++) {
00790               L_ret = update_config_params (*L_config_params_dico_it, P_config_value_list) ;
00791               if (L_ret == -1) { break;}
00792             }
00793 
00794           }
00795         
00796         } else {
00797           GEN_ERROR(E_GEN_FATAL_ERROR, "Error in  configuration parameters definition for protocol ["
00798                     << *P_name << "]");
00799           L_ret = -1 ;
00800         }
00801       
00802       } else {
00803         GEN_ERROR(E_GEN_FATAL_ERROR, "No configuration parameters definition found for protocol ["
00804                   << *P_name << "]");
00805         L_ret = -1 ;
00806       }
00807     } else {
00808       GEN_ERROR(E_GEN_FATAL_ERROR, "Error in configuration parameters definition found for protocol ["
00809                   << *P_name << "]");
00810         L_ret = -1 ;
00811     }
00812   }
00813 
00814   // header analysis
00815   if (L_ret != -1) {
00816     for (L_it = L_data->begin();
00817          L_it != L_data->end();
00818          L_it++) {
00819       if (strcmp((*L_it)->get_name(), "header") == 0) {
00820         L_found = true ;
00821         NEW_VAR(L_header_fields, T_FieldDefList());
00822         L_ret = xml_fields (*L_it, L_header_fields, 
00823                             &m_message_name,
00824                             &L_header_type,
00825                             &L_header_create_function,
00826                             &L_header_delete_function,
00827                             NULL,
00828                             NULL,
00829                             NULL,
00830                             false) ;
00831         break ;
00832       }
00833     }
00834   }
00835 
00836   if (L_found == true) {
00837     L_found = false ;
00838   } else {
00839     GEN_ERROR(E_GEN_FATAL_ERROR, "No header definition found for protocol ["
00840               << *P_name << "]");
00841     L_ret = -1 ;
00842   }
00843 
00844   // body analysis
00845   if (L_ret != -1) {
00846     for (L_it = L_data->begin();
00847          L_it != L_data->end();
00848          L_it++) {
00849       if (strcmp((*L_it)->get_name(), "body") == 0) {
00850         L_found = true ;
00851         NEW_VAR(L_body_fields, T_FieldDefList());
00852         L_ret = xml_fields (*L_it, L_body_fields, 
00853                             &m_body_name,
00854                             &L_body_type,
00855                             &L_body_create_function,
00856                             &L_body_delete_function,
00857                             &L_body_add_function,
00858                             &L_body_get_function,
00859                             &L_value_field,
00860                             true) ;
00861         break ;
00862       }
00863     }
00864   }
00865 
00866   if (L_found == true) {
00867     L_found = false ;
00868   } else {
00869     GEN_ERROR(E_GEN_FATAL_ERROR, "No body definition found for protocol ["
00870               << *P_name << "]");
00871     L_ret = -1 ;
00872   }
00873   
00874   // dico analysis
00875   if (L_ret != -1) {
00876     for (L_it = L_data->begin();
00877          L_it != L_data->end();
00878          L_it++) {
00879       
00880       if (strcmp((*L_it)->get_name(), "dictionary") == 0) {
00881         L_found = true ;
00882         
00883         L_dataDico = *L_it ;
00884         if (L_dataDico != NULL) {
00885           L_data_dico = L_dataDico->get_sub_data();
00886         }
00887         GEN_DEBUG(1, "dictionnary [" << L_dataDico->get_name() << "]");
00888         
00889         L_session_id_name = L_dataDico->find_value((char *)"session-id");
00890         if (L_session_id_name == NULL) {
00891           GEN_ERROR(E_GEN_FATAL_ERROR,
00892                     "session-id value is mandatory for ["
00893                     << m_message_name  << "] section");
00894           L_ret = -1 ;
00895           break ;
00896         }
00897 
00898         GEN_DEBUG(1, "session-id [" << L_session_id_name << "]");
00899         
00900         L_outof_session_id_name 
00901           = L_dataDico->find_value ((char *)"out-of-session-id") ;
00902         if (L_outof_session_id_name == NULL) {
00903           GEN_ERROR(E_GEN_FATAL_ERROR,
00904                     "out-of-session-id value is mandatory for ["
00905                     <<  m_message_name << "] section");
00906           L_ret = -1 ;
00907           break ;
00908         }
00909 
00910         GEN_DEBUG(1, "out-of-session-id [" << L_outof_session_id_name << "]");
00911         GEN_DEBUG(1, "m_message_name [" << m_message_name << "]");
00912         GEN_DEBUG(1, "m_body_name [" << m_body_name << "]");
00913         break ;
00914         
00915       } // if (strcmp((*L_it)->get_name(), "dictionary") == 0)
00916     } // for (L_it = ...)
00917   } // if L_ret != -1
00918 
00919   if (L_dataDico == NULL) {
00920     GEN_ERROR(E_GEN_FATAL_ERROR, "No dictionnary found (or no value) in protocol ["
00921               << *P_name << "]");
00922     L_ret = -1 ;
00923   }
00924 
00925   // header values analysis => don t forget optionnal
00926   if (L_ret != -1) {
00927     for (L_it = L_data_dico->begin();
00928          L_it != L_data_dico->end();
00929          L_it++) {
00930       if (strcmp((*L_it)->get_name(), m_body_name) == 0) {
00931         L_body_fields_dico = analyze_body_value(*L_it, L_body_fields_dico, true, &L_ret);
00932         if (L_ret == -1) break ;
00933       }
00934     }
00935   }
00936 
00937 
00938   // body values analysis => probably none
00939   // header values analysis => don t forget optionnal
00940   if (L_ret != -1) {
00941     for (L_it = L_data_dico->begin();
00942          L_it != L_data_dico->end();
00943          L_it++) {
00944       if (strcmp((*L_it)->get_name(), m_message_name) == 0) {
00945         L_header_fields_dico = analyze_header_value(*L_it, L_header_fields_dico, true, &L_ret);
00946         if (L_ret == -1) break ;
00947       }
00948     }
00949   }
00950 
00951   if (L_value_field == NULL) {
00952     GEN_ERROR(E_GEN_FATAL_ERROR, "No field data defined");
00953     L_ret = -1 ;
00954   } else {
00955     m_data_field_name = L_value_field ;
00956   }
00957 
00958 
00959 
00960   if (L_ret != -1) {
00961     if (L_header_create_function == NULL) {
00962       GEN_ERROR(E_GEN_FATAL_ERROR, "No create-function defined in header");
00963       L_ret = -1 ;
00964     } else {
00965       m_create_header = m_factory->get_function(L_header_create_function) ;
00966     }
00967   }
00968 
00969   if (L_ret != -1) {
00970     if (L_header_delete_function == NULL) {
00971       GEN_ERROR(E_GEN_FATAL_ERROR, "No delete-function defined in header");
00972       L_ret = -1 ;
00973     } else {
00974       m_delete_header = m_factory->get_function(L_header_delete_function) ;
00975     }
00976   }
00977 
00978   if (L_ret != -1) {
00979     if (L_body_create_function == NULL) {
00980       GEN_ERROR(E_GEN_FATAL_ERROR, "No create-function defined in body");
00981       L_ret = -1 ;
00982     } else {
00983       m_create_body = m_factory->get_function(L_body_create_function) ;
00984     }
00985   }
00986 
00987   if (L_ret != -1) {
00988     if (L_body_delete_function == NULL) {
00989       GEN_ERROR(E_GEN_FATAL_ERROR, "No delete-function defined in body");
00990       L_ret = -1 ;
00991     } else {
00992       m_delete_body = m_factory->get_function(L_body_delete_function) ;
00993     }
00994   }
00995 
00996 
00997   // ctrl add_body and get_body
00998   if (L_ret != -1) {
00999     if (L_body_add_function == NULL) {
01000       GEN_ERROR(E_GEN_FATAL_ERROR, "No add-function defined in body");
01001       L_ret = -1 ;
01002     } else {
01003       m_add_body = m_factory->get_function(L_body_add_function) ;
01004     }
01005   }
01006 
01007   if (L_ret != -1) {
01008     if (L_body_get_function == NULL) {
01009       GEN_ERROR(E_GEN_FATAL_ERROR, "No get-function defined in body");
01010       L_ret = -1 ;
01011     } else {
01012       m_get_body = m_factory->get_function(L_body_get_function) ;
01013     }
01014   }
01015 
01016   if (L_ret != -1) {
01017 
01018 
01019     L_ret = analyze_dictionnary(L_header_fields,
01020                                 L_body_fields,
01021                                 L_value_field,
01022                                 L_session_id_name,
01023                                 L_outof_session_id_name,
01024                                 L_body_fields_dico,
01025                                 L_header_fields_dico,
01026                                 L_header_type,
01027                                 P_config_value_list,
01028                                 L_body_type);
01029 
01030   }
01031 
01032   // delete list
01033   if (L_header_fields != NULL) {
01034     if (!L_header_fields->empty()) {
01035       L_header_fields->erase(L_header_fields->begin(),
01036                              L_header_fields->end());
01037     }
01038     DELETE_VAR(L_header_fields);
01039   }
01040 
01041   if (L_body_fields != NULL ) {
01042     if (!L_body_fields->empty()) {
01043       L_body_fields->erase(L_body_fields->begin(),
01044                            L_body_fields->end());
01045     }
01046     DELETE_VAR(L_body_fields);
01047   }
01048 
01049   if (L_body_fields_dico != NULL) {
01050     if (!L_body_fields_dico->empty()) {
01051       L_body_fields_dico->erase(L_body_fields_dico->begin(),
01052                                 L_body_fields_dico->end());
01053     }
01054     DELETE_VAR(L_body_fields_dico);
01055   }
01056 
01057   if (L_header_fields_dico != NULL ) {
01058     if (!L_header_fields_dico->empty()) {
01059       L_header_fields_dico->erase(L_header_fields_dico->begin(),
01060                                   L_header_fields_dico->end());
01061     }
01062     DELETE_VAR(L_header_fields_dico);
01063   }
01064 
01065   if (L_config_params_dico != NULL) {
01066     if (!L_config_params_dico->empty()) {
01067       L_config_params_dico->erase(L_config_params_dico->begin(),
01068                              L_config_params_dico->end());
01069     }
01070     DELETE_VAR(L_config_params_dico);
01071   }
01072 
01073 
01074   return (L_ret);
01075 }
01076 
01077 int C_ProtocolExternal::xml_fields(C_XmlData *P_data, 
01078                                    T_FieldDefList *P_fielddef_list,
01079                                    char **P_section_name,
01080                                    char **P_type,
01081                                    char **P_create,
01082                                    char **P_delete,
01083                                    char **P_add,
01084                                    char **P_get,
01085                                    char **P_value_field,
01086                                    bool   P_ctrl_body) {
01087 
01088   int                       L_ret = 0 ;
01089 
01090   T_pXmlData_List           L_fielddef_xml_list = NULL ;
01091   C_XmlData                *L_fielddef = NULL          ;
01092   T_XmlData_List::iterator  L_fielddef_it              ;
01093 
01094   T_FieldDef                L_fielddef_data            ;
01095 
01096   GEN_DEBUG(1, "C_ProtocolExternal::xml_fields() start");
01097 
01098   *P_section_name = P_data->find_value((char *)"name");
01099   if (*P_section_name == NULL) {
01100     GEN_ERROR(E_GEN_FATAL_ERROR,
01101               "name definition value is mandatory for header section");
01102     L_ret = -1 ;
01103   }
01104 
01105   *P_type   = P_data->find_value((char *)"type");
01106   if (*P_type == NULL) {
01107     GEN_ERROR(E_GEN_FATAL_ERROR,
01108               "type definition value is mandatory for header section");
01109     L_ret = -1 ;
01110   }
01111 
01112   *P_create = P_data->find_value((char *)"create-function");
01113   if (*P_create == NULL) {
01114     GEN_ERROR(E_GEN_FATAL_ERROR,
01115               "create-function definition value is mandatory for header section");
01116     L_ret = -1 ;
01117   }
01118 
01119   *P_delete = P_data->find_value((char *)"delete-function");
01120   if (*P_delete == NULL) {
01121     GEN_ERROR(E_GEN_FATAL_ERROR,
01122               "delete-function definition value is mandatory for header section");
01123     L_ret = -1 ;
01124   }
01125 
01126 
01127 
01128   if (P_ctrl_body == true) {
01129 
01130     *P_value_field = P_data->find_value((char *)"value-field");
01131     if (*P_value_field == NULL) {
01132       GEN_ERROR(E_GEN_FATAL_ERROR,
01133                 "value-field definition value is mandatory for header section");
01134       L_ret = -1 ;
01135     }
01136 
01137     *P_add = P_data->find_value((char *)"add-function");
01138     if (*P_add == NULL) {
01139       GEN_ERROR(E_GEN_FATAL_ERROR,
01140                 "add-function definition value is mandatory for header section");
01141       L_ret = -1 ;
01142     }
01143     
01144     *P_get = P_data->find_value((char *)"get-function");
01145     if (*P_get == NULL) {
01146       GEN_ERROR(E_GEN_FATAL_ERROR,
01147                 "get-function definition value is mandatory for header section");
01148       L_ret = -1 ;
01149     }
01150   }
01151 
01152   L_fielddef_xml_list = P_data->get_sub_data() ;
01153 
01154   for(L_fielddef_it  = L_fielddef_xml_list->begin() ;
01155       L_fielddef_it != L_fielddef_xml_list->end() ;
01156       L_fielddef_it++) {
01157 
01158     L_fielddef = *L_fielddef_it ;
01159 
01160     if (strcmp(L_fielddef->get_name(), (char*)"fielddef") == 0) {
01161 
01162       L_fielddef_data.m_name = L_fielddef->find_value((char*)"name") ;
01163       if (L_fielddef_data.m_name == NULL) {
01164         GEN_ERROR(E_GEN_FATAL_ERROR, 
01165                   "fielddef name value is mandatory");
01166         L_ret = -1 ;
01167       }
01168       L_fielddef_data.m_type = L_fielddef->find_value((char*)"type") ;
01169       if (L_fielddef_data.m_type == NULL) {
01170         GEN_ERROR(E_GEN_FATAL_ERROR, 
01171                   "fielddef type value is mandatory");
01172         L_ret = -1 ;
01173       }
01174       L_fielddef_data.m_set = L_fielddef->find_value((char*)"set-function") ;
01175       if (L_fielddef_data.m_set == NULL) {
01176         GEN_ERROR(E_GEN_FATAL_ERROR, 
01177                   "fielddef set-function value is mandatory");
01178         L_ret = -1 ;
01179       }
01180       L_fielddef_data.m_get = L_fielddef->find_value((char*)"get-function") ;
01181       if (L_fielddef_data.m_get == NULL) {
01182         GEN_ERROR(E_GEN_FATAL_ERROR, 
01183                   "fielddef get-function value is mandatory");
01184         L_ret = -1 ;
01185       }
01186       L_fielddef_data.m_check_set = L_fielddef->find_value((char*)"check-set") ;
01187       L_fielddef_data.m_check_get = L_fielddef->find_value((char*)"check-get") ;
01188 
01189       L_fielddef_data.m_default = L_fielddef->find_value((char*)"default") ;
01190 
01191       L_fielddef_data.m_from_string = L_fielddef->find_value((char*)"from-string") ;
01192       L_fielddef_data.m_to_string = L_fielddef->find_value((char*)"to-string") ;
01193 
01194 
01195       L_fielddef_data.m_config_field_name = L_fielddef->find_value((char*)"config-field") ;
01196 
01197 
01198       if (L_ret == -1) { 
01199         break ; 
01200       } else {
01201         P_fielddef_list->push_back(L_fielddef_data);
01202       }
01203 
01204     }
01205   }
01206 
01207   GEN_DEBUG(1, "C_ProtocolExternal::xml_fields() end");
01208   return (L_ret);
01209 }
01210 
01211 
01212 int C_ProtocolExternal::xml_configuration_parameters(C_XmlData *P_data, 
01213                                                      T_ParamDefList *P_paramdef_list) { 
01214 
01215 
01216 
01217   int                       L_ret = 0 ;
01218 
01219   T_pXmlData_List           L_paramdef_xml_list = NULL ;
01220   C_XmlData                *L_paramdef = NULL          ;
01221   T_XmlData_List::iterator  L_paramdef_it              ;
01222 
01223   T_ParamDef                L_paramdef_data            ;
01224   bool                      L_found_default = false    ;
01225 
01226   GEN_DEBUG(1, "C_ProtocolExternal::xml_configuration_parameters() start");
01227 
01228   L_paramdef_xml_list = P_data->get_sub_data() ;
01229 
01230   for(L_paramdef_it  = L_paramdef_xml_list->begin() ;
01231       L_paramdef_it != L_paramdef_xml_list->end() ;
01232       L_paramdef_it++) {
01233 
01234     L_paramdef = *L_paramdef_it ;
01235 
01236     if (strcmp(L_paramdef->get_name(), (char*)"paramdef") == 0) {
01237 
01238       L_found_default = false ;
01239       L_paramdef_data.m_name = L_paramdef->find_value((char*)"name") ;
01240       if (L_paramdef_data.m_name == NULL) {
01241         GEN_ERROR(E_GEN_FATAL_ERROR, 
01242                   "paramdef name value is mandatory");
01243         L_ret = -1 ;
01244         break ;
01245       }
01246 
01247       L_paramdef_data.m_default = L_paramdef->find_value((char*)"default") ;
01248       if (L_paramdef_data.m_default != NULL) {
01249         L_found_default = true ;
01250       } 
01251 
01252       L_paramdef_data.m_mandatory = L_paramdef->find_value((char*)"mandatory") ;
01253 
01254       if ((L_paramdef_data.m_mandatory == NULL) ||
01255           (strcmp(L_paramdef_data.m_mandatory,"false") == 0 )) {
01256         
01257         if (L_found_default == false ) {
01258           GEN_ERROR(E_GEN_FATAL_ERROR, 
01259                     "paramdef mandatory or default value is mandatory");
01260           L_ret = -1 ;
01261         }
01262       }
01263 
01264       if (L_ret == -1) { 
01265         break ; 
01266       } else {
01267         P_paramdef_list->push_back(L_paramdef_data);
01268       }
01269 
01270     } // strcmp paradef
01271   }
01272 
01273   GEN_DEBUG(1, "C_ProtocolExternal::xml_configuration_parameters() end");
01274   return (L_ret);
01275 }
01276 
01277 
01278 C_ProtocolExternal::T_FieldBodyList* 
01279 C_ProtocolExternal::analyze_body_value (C_XmlData          *P_data, 
01280                                         T_FieldBodyList    *P_fielddef_body_list,
01281                                         bool                P_body_only,
01282                                         int                *P_ret) { 
01283 
01284   C_XmlData::T_pXmlField_List  L_fields_list      ;
01285   C_XmlData::T_XmlField_List::iterator L_fieldIt  ;
01286 
01287   char                     *L_value               ;
01288   T_FieldBody               L_fielddef_body       ;
01289 
01290   T_pXmlData_List           L_subListSetField     ;
01291   C_XmlData                *L_data                ;  
01292   T_XmlData_List::iterator L_listFieldIt          ;
01293 
01294   GEN_DEBUG(1, "C_ProtocolExternal::analyze_body_value() start");
01295 
01296   (*P_ret) = 0  ;
01297   
01298   // ctrl fields 
01299   L_value = P_data->find_value((char *)"name");
01300   GEN_DEBUG(1, "C_ProtocolExternal::analyze_body_value() "
01301             << "[" << m_body_name << "] [" << L_value << "]");
01302 
01303   if (L_value == NULL) {
01304     GEN_ERROR(E_GEN_FATAL_ERROR,
01305               "name definition value is mandatory for this section");
01306     *P_ret = -1 ;
01307   } else {
01308     L_fielddef_body.m_name = L_value ;
01309     L_fielddef_body.m_instance = NULL ;
01310     // Add not-present option 
01311     L_fielddef_body.m_list_not_present = NULL ;
01312   }
01313   
01314  
01315   // get fields
01316   L_fields_list = P_data->get_fields();
01317   if (!L_fields_list->empty()) {
01318     
01319     NEW_VAR(L_fielddef_body.m_list_value, T_FieldValueList());
01320     for(L_fieldIt  = L_fields_list->begin() ;
01321         L_fieldIt != L_fields_list->end() ;
01322         L_fieldIt++) {
01323       
01324       T_FieldValue L_field_val ;
01325       if(strcmp((*L_fieldIt)->get_name() , (char *)"instance") == 0) {
01326         L_fielddef_body.m_instance = (*L_fieldIt)->get_value() ;
01327 
01328         GEN_DEBUG(1, "C_ProtocolExternal::analyze_body_value() "
01329                   << "instance [" << (*L_fieldIt)->get_value()  << "]");
01330   
01331       } else if (strcmp((*L_fieldIt)->get_name() , (char *)"name") != 0) {
01332         L_field_val.m_name = (*L_fieldIt)->get_name();
01333         L_field_val.m_value = (*L_fieldIt)->get_value();
01334         GEN_DEBUG(1, "C_ProtocolExternal::analyze_body_value() "
01335                   << "[" << L_field_val.m_name << "] = [" 
01336                   << L_field_val.m_value << "]");
01337         
01338         
01339         L_fielddef_body.m_list_value->push_back(L_field_val);
01340       }
01341       // name case
01342     }
01343   } else {
01344     L_fielddef_body.m_list_value = NULL;
01345   }
01346 
01347   if (*P_ret != -1){
01348     // get setfield
01349     L_subListSetField = P_data->get_sub_data() ;
01350     if (L_subListSetField != NULL) {
01351       for (L_listFieldIt = L_subListSetField->begin();
01352            L_listFieldIt != L_subListSetField->end();
01353            L_listFieldIt++) {
01354         
01355         L_data = *L_listFieldIt ;
01356         if (strcmp(L_data->get_name(), "setfield") == 0) {
01357           L_fielddef_body.m_list_value 
01358             = analyze_setfield(L_data, L_fielddef_body.m_list_value, P_ret);
01359           if (*P_ret == -1) break ;
01360         } // if (strcmp(L_data->get_name(), (char*)"setfield") == 0)
01361 
01362         // Add not-present option
01363         // attention only component !!!!
01364         if (P_body_only == true) {
01365           if (strcmp(L_data->get_name(), "not-present") == 0) {
01366             L_fielddef_body.m_list_not_present 
01367               = analyze_not_present(L_data, L_fielddef_body.m_list_not_present, P_ret);
01368             if (*P_ret == -1) break ;
01369           } // if (strcmp(L_data->get_name(), (char*)"not-present") == 0)
01370         }
01371         
01372 
01373       } // for (L_listFieldIt ... )
01374       
01375     }
01376   }
01377   
01378   if (*P_ret != -1){
01379     if (P_fielddef_body_list == NULL) {
01380       NEW_VAR(P_fielddef_body_list, T_FieldBodyList());
01381     }
01382     P_fielddef_body_list->push_back(L_fielddef_body);
01383   } 
01384   GEN_DEBUG(1, "C_ProtocolExternal::xml_fields_body() end");
01385 
01386   return (P_fielddef_body_list);
01387 }
01388 
01389 C_ProtocolExternal::T_FieldHeaderList* 
01390 C_ProtocolExternal::analyze_header_value (C_XmlData          *P_data, 
01391                                           T_FieldHeaderList  *P_fielddef_header_list,
01392                                           bool                P_header_only,
01393                                           int                *P_ret) {
01394 
01395   C_XmlData::T_pXmlField_List  L_fields_list     ;
01396   C_XmlData::T_XmlField_List::iterator L_fieldIt ;
01397  
01398   char                     *L_value              ;
01399   T_FieldHeader             L_fielddef_header    ;
01400 
01401   T_pXmlData_List           L_subListSetField    ;
01402   C_XmlData                *L_data               ;  
01403   T_XmlData_List::iterator  L_listFieldIt        ;
01404 
01405   *P_ret = 0 ;
01406   
01407   GEN_DEBUG(1, "C_ProtocolExternal::analyze_header_value() start");
01408 
01409   // ctrl fields 
01410   L_value = P_data->find_value((char *)"name");
01411 
01412   GEN_DEBUG(1, "C_ProtocolExternal::analyze_header_value() "
01413             << "[" << m_message_name << "] = [" << L_value << "]");
01414 
01415   if (L_value == NULL) {
01416     GEN_ERROR(E_GEN_FATAL_ERROR,
01417               "name definition value is mandatory for this section");
01418     *P_ret = -1 ;
01419   } else {
01420     L_fielddef_header.m_name = L_value ;
01421     L_fielddef_header.m_list_header_not_present = NULL;
01422   }
01423 
01424   // get fields
01425   L_fields_list = P_data->get_fields();
01426   if (!L_fields_list->empty()) {
01427         
01428     NEW_VAR(L_fielddef_header.m_list_value, T_FieldValueList());
01429     for(L_fieldIt  = L_fields_list->begin() ;
01430         L_fieldIt != L_fields_list->end() ;
01431         L_fieldIt++) {
01432       T_FieldValue L_field_val ;
01433       if(strcmp((*L_fieldIt)->get_name() , (char *)"name") != 0) {
01434         L_field_val.m_name = (*L_fieldIt)->get_name();
01435         L_field_val.m_value = (*L_fieldIt)->get_value();
01436 
01437         GEN_DEBUG(1, "C_ProtocolExternal::analyze_header_value() "
01438                   << "[" << L_field_val.m_name << "] = [" 
01439                   << L_field_val.m_value << "]");
01440 
01441 
01442         L_fielddef_header.m_list_value->push_back(L_field_val);
01443       }
01444     }
01445   } else {
01446     L_fielddef_header.m_list_value = NULL;
01447   }
01448 
01449 
01450 
01451   // get setfield
01452 
01453   if (*P_ret != -1) {
01454 
01455     L_subListSetField = P_data->get_sub_data() ;
01456     if (L_subListSetField != NULL) {
01457       L_fielddef_header.m_list_body = NULL ;
01458       for (L_listFieldIt = L_subListSetField->begin();
01459            L_listFieldIt != L_subListSetField->end();
01460            L_listFieldIt++) {
01461         
01462         L_data = *L_listFieldIt ;
01463         if (strcmp(L_data->get_name(), "setfield") == 0) {
01464           L_fielddef_header.m_list_value 
01465             = analyze_setfield(L_data, L_fielddef_header.m_list_value, P_ret);
01466           if (*P_ret == -1) break ;
01467         } // if (strcmp(L_data->get_name(), (char*)"setfield") == 0)
01468 
01469         if (P_header_only == true) {
01470           if (strcmp(L_data->get_name(), "not-present") == 0) {
01471             L_fielddef_header.m_list_header_not_present 
01472               = analyze_not_present(L_data, L_fielddef_header.m_list_header_not_present, P_ret);
01473             if (*P_ret == -1) break ;
01474           } // if (strcmp(L_data->get_name(), (char*)"not-present") == 0)
01475         }
01476         
01477 
01478         if (strcmp(L_data->get_name(), m_body_name) == 0) {
01479 
01480           L_fielddef_header.m_list_body
01481             = analyze_body_value(L_data, L_fielddef_header.m_list_body, false, P_ret); 
01482           if (*P_ret == -1) break ;
01483         }
01484       } // for (L_listFieldIt ... )
01485     }
01486   }
01487   
01488   if (*P_ret != -1) {
01489     if (P_fielddef_header_list == NULL) {
01490       NEW_VAR(P_fielddef_header_list, T_FieldHeaderList());
01491     }
01492     P_fielddef_header_list->push_back(L_fielddef_header);
01493   }
01494   
01495 
01496   return (P_fielddef_header_list);
01497 }
01498 
01499 
01500 C_ProtocolExternal::T_FieldValueList* 
01501 C_ProtocolExternal::analyze_setfield (C_XmlData          *P_data,
01502                                       T_FieldValueList   *P_field_value_list,
01503                                       int                *P_ret) {
01504 
01505   C_XmlData                *L_data                ;  
01506   char                     *L_fieldName, *L_fieldValue ;
01507   
01508   GEN_DEBUG(1, "C_ProtocolExternal::analyze_setfield() start");
01509   
01510   (*P_ret) = 0  ;
01511   
01512   L_data = P_data ;
01513 
01514   L_fieldName = L_data->find_value((char*)"name") ;
01515   if (L_fieldName == NULL) {
01516     GEN_ERROR(E_GEN_FATAL_ERROR, "setfield name is mandatory");
01517     (*P_ret) = -1 ;
01518   }
01519         
01520   L_fieldValue = L_data->find_value((char*)"value") ;
01521   if (L_fieldValue == NULL) {
01522     GEN_ERROR(E_GEN_FATAL_ERROR, "setfield value is mandatory for ["
01523               << L_fieldName << "]");
01524     (*P_ret) = -1 ;
01525   }
01526         
01527   if ((*P_ret) != -1) {
01528     T_FieldValue L_field_val ;
01529     if (P_field_value_list == NULL) {
01530       NEW_VAR(P_field_value_list, T_FieldValueList());
01531     }
01532     L_field_val.m_name = L_fieldName;
01533     L_field_val.m_value = L_fieldValue;
01534     GEN_DEBUG(1, "C_ProtocolExternal::analyze_setfield() "
01535               << "[" << L_field_val.m_name << "] = [" 
01536               << L_field_val.m_value << "]");
01537 
01538     P_field_value_list->push_back(L_field_val);
01539   } // if (*P_ret != -1)
01540         
01541   GEN_DEBUG(1, "C_ProtocolExternal::analyze_setfield() end");
01542   return (P_field_value_list);
01543 }
01544 
01545 C_ProtocolExternal::T_CharList* 
01546 C_ProtocolExternal::analyze_not_present (C_XmlData          *P_data,
01547                                          T_CharList         *P_field_not_present_list,
01548                                          int                *P_ret) {
01549 
01550   C_XmlData                *L_data            ;  
01551   char                     *L_fieldName       ;
01552   
01553   GEN_DEBUG(1, "C_ProtocolExternal::analyze_not_present() start");
01554   
01555   (*P_ret) = 0  ;
01556   
01557   L_data = P_data ;
01558 
01559   L_fieldName = L_data->find_value((char*)"name") ;
01560   if (L_fieldName == NULL) {
01561     GEN_ERROR(E_GEN_FATAL_ERROR, "not-present name is mandatory");
01562     (*P_ret) = -1 ;
01563   }
01564 
01565   if ((*P_ret) != -1) {
01566     if (P_field_not_present_list == NULL) {
01567       NEW_VAR(P_field_not_present_list, T_CharList());
01568     }
01569     
01570     GEN_DEBUG(1, "C_ProtocolExternal::analyze_not_present() "
01571               << "[" << L_fieldName << "]"); 
01572     
01573     P_field_not_present_list->push_back(L_fieldName);
01574   } // if (*P_ret != -1)
01575   
01576   GEN_DEBUG(1, "C_ProtocolExternal::analyze_not_present() end");
01577   return (P_field_not_present_list);
01578 }
01579 
01580 
01581 int C_ProtocolExternal::analyze_dictionnary (T_FieldDefList *P_header_fields, // fields
01582                                              T_FieldDefList *P_body_fields,   // sub fields
01583                                              char *P_body_value_name,
01584                                              char *P_session_id_name,
01585                                              char *P_outof_session_id_name,
01586                                              T_FieldBodyList *P_body_values,  // fields
01587                                              T_FieldHeaderList *P_header_values, // message
01588                                              char *P_header_type,
01589                                              T_pConfigValueList P_config_value_list,
01590                                              char *P_body_type) {
01591 
01592   int                          L_ret              = 0    ;
01593   T_FieldDefList::iterator     L_fielddef_it             ;
01594   T_pFieldDesc                 L_field_desc       = NULL ;
01595   char                        *L_data_type_name   = NULL ;
01596   char                        *L_body_type        = NULL ;
01597   char                        *L_header_type      = NULL ;
01598 
01599   T_FieldBodyList::iterator    L_body_fielddef_it        ;
01600   T_pFieldBodyDesc             L_body_desc = NULL        ;
01601 
01602   T_FieldNameMap::iterator     L_it                      ;
01603 
01604   T_FieldHeaderList::iterator  L_header_fielddef_it      ;
01605   int                          L_result           = -1   ;
01606   int                          L_i, L_j                  ;
01607   T_FieldBodyNameMap::iterator L_it_body                 ;
01608   T_MessageNameMap::iterator   L_it_message              ;
01609   int                          L_id ;
01610 
01611   GEN_DEBUG(1, "C_ProtocolExternal::analyze_dictionnary() start");
01612 
01613 
01614   NEW_VAR(m_field_body_name_map, T_FieldNameMap());
01615   NEW_VAR(m_field_name_map, T_FieldNameMap());
01616   NEW_VAR(m_body_value_name_map, T_FieldBodyNameMap());
01617 
01618 
01619   m_field_name_map->clear();
01620   m_field_body_name_map->clear();
01621   m_body_value_name_map->clear();
01622 
01623 
01624   if (!P_body_fields->empty()) {
01625     m_nb_body_fields = P_body_fields->size()  ;
01626 
01627     if (m_nb_body_fields > 0) {
01628       m_nb_names += m_nb_body_fields ;
01629       for (L_fielddef_it = P_body_fields->begin();
01630            L_fielddef_it != P_body_fields->end();
01631            L_fielddef_it++) {
01632         L_field_desc = check_field ((*L_fielddef_it), P_body_value_name, 
01633                                     &L_data_type_name, 
01634                                     P_body_type, &L_body_type, NULL, false);
01635         if (L_field_desc == NULL) { L_ret = -1 ; break ; }
01636       }
01637     } 
01638   } else {
01639     GEN_ERROR(E_GEN_FATAL_ERROR, "ERROR TO DEFINE");
01640     L_ret = -1 ;
01641   }
01642 
01643   if (L_ret != -1) {
01644     if (L_body_type == NULL) {
01645       GEN_ERROR(E_GEN_FATAL_ERROR, "Unable to find field [" << P_body_type << "]");
01646       L_ret = -1 ;
01647     }
01648   }
01649 
01650   if (L_ret != -1) {
01651     if (!P_header_fields->empty()) {
01652       m_nb_header_fields = P_header_fields->size();
01653       if (m_nb_header_fields != 0) {
01654         m_nb_names += m_nb_header_fields ;
01655         for (L_fielddef_it = P_header_fields->begin();
01656              L_fielddef_it != P_header_fields->end();
01657              L_fielddef_it++) {
01658           L_field_desc = check_field ((*L_fielddef_it), NULL, NULL, 
01659                                       P_header_type, &L_header_type, 
01660                                       P_config_value_list,
01661                                       true);
01662           if (L_field_desc == NULL) { L_ret = -1 ; break ; }
01663         }
01664       } 
01665     } else {
01666       GEN_ERROR(E_GEN_FATAL_ERROR, "ERROR TO DEFINE");
01667       L_ret = -1 ;
01668     }
01669   }
01670 
01671   if (L_ret != -1) {
01672     if (L_data_type_name == NULL) {
01673       GEN_ERROR(E_GEN_FATAL_ERROR, "Unable to find field [" << P_body_value_name << "]");
01674       L_ret = -1 ;
01675     }
01676   }
01677 
01678   if (L_ret != -1) {
01679     if (!P_body_values->empty()) {
01680       m_nb_body_values = P_body_values->size();
01681       m_nb_names += m_nb_body_values ;
01682       for (L_body_fielddef_it = P_body_values->begin();
01683            L_body_fielddef_it != P_body_values->end();
01684            L_body_fielddef_it++) {
01685         L_body_desc = check_body ((*L_body_fielddef_it));
01686         if (L_body_desc == NULL) { L_ret = -1 ; break ; }
01687       }
01688     }
01689   }
01690 
01691   if (L_ret != -1) {
01692     if (L_header_type == NULL) {
01693       // check the field header 
01694       // ctrl the body contains in the map of body
01695       L_it_body = m_body_value_name_map->find(T_FieldBodyNameMap::key_type(P_header_type));
01696       if (L_it_body == m_body_value_name_map->end()) {
01697         GEN_ERROR(E_GEN_FATAL_ERROR, "Unable to find field [" << P_header_type << "]");
01698         L_ret = -1 ;
01699       }
01700     }
01701   }
01702 
01703 
01704   // remove the data body value from map
01705   if (L_ret != -1) {
01706       set_body_field_id() ;
01707   }
01708 
01709   if (L_ret != -1) {
01710     // check not-present field for each body
01711     // phase init 
01712     ALLOC_TABLE(m_body_not_present_table,
01713                 bool**,
01714                 sizeof(bool*),
01715                 m_nb_body_values);
01716     
01717     for (L_i = 0; L_i <m_nb_body_values ; L_i++) {
01718       ALLOC_TABLE (m_body_not_present_table[L_i], bool*, sizeof(bool), m_nb_body_fields);
01719       for (L_j = 0; L_j < m_nb_body_fields ; L_j++) {
01720         m_body_not_present_table[L_i][L_j] = true ;
01721       }
01722     }
01723 
01724     // phase anlyze for not-present     
01725     for (L_body_fielddef_it = P_body_values->begin();
01726          L_body_fielddef_it != P_body_values->end();
01727          L_body_fielddef_it++) {
01728       
01729       L_ret = check_not_present ((*L_body_fielddef_it));
01730       if (L_ret == -1 ) { break ; }
01731     }
01732 
01733     // delete m_list_not_present TO DO
01734 
01735   }
01736 
01737   
01738   if (L_ret != -1) { 
01739     T_FieldNameMap::iterator L_it_f_b ;
01740     T_pFieldDesc             L_desc_f_b ;
01741     int                      L_i_f_b  ;
01742 
01743     if (!m_field_body_name_map->empty()) {
01744       m_nb_from_string_field_body = m_field_body_name_map->size();
01745       ALLOC_TABLE(m_from_string_field_body_table,
01746                   C_MsgBuildContext::T_ContextStringFunction*,
01747                   sizeof(C_MsgBuildContext::T_ContextStringFunction),
01748                   m_nb_from_string_field_body);
01749       ALLOC_TABLE(m_to_string_field_body_table,
01750                   C_MsgBuildContext::T_ContextStringFunction*,
01751                   sizeof(C_MsgBuildContext::T_ContextStringFunction),
01752                   m_nb_from_string_field_body);
01753       for (L_i_f_b = 0 ; L_i_f_b < m_nb_from_string_field_body; L_i_f_b++) {
01754         m_from_string_field_body_table[L_i_f_b] = (C_MsgBuildContext::T_ContextStringFunction)NULL;
01755         m_to_string_field_body_table[L_i_f_b] = (C_MsgBuildContext::T_ContextStringFunction)NULL;
01756       }
01757       for (L_it_f_b = m_field_body_name_map->begin() ;
01758            L_it_f_b != m_field_body_name_map->end() ;
01759            L_it_f_b ++) {
01760         L_desc_f_b = L_it_f_b->second ;
01761         m_from_string_field_body_table[L_desc_f_b->m_id-m_start_body_index] = L_desc_f_b->m_from_string ;
01762         m_to_string_field_body_table[L_desc_f_b->m_id-m_start_body_index] = L_desc_f_b->m_to_string ;
01763       }
01764     } 
01765   }
01766 
01767   if (L_ret != -1) {
01768     bool L_convert ;
01769     if (m_nb_body_fields != 0) {
01770       ALLOC_TABLE(m_body_defaults, T_pValueData, sizeof(T_ValueData), m_nb_body_fields);
01771       for (L_fielddef_it = P_body_fields->begin();
01772            L_fielddef_it != P_body_fields->end();
01773            L_fielddef_it++) {
01774 
01775         L_convert = false ;
01776         L_result = -1 ;
01777         L_it = m_field_body_name_map->find(T_FieldNameMap::key_type(L_fielddef_it->m_name)) ;
01778         
01779         if (L_fielddef_it->m_default != NULL) {
01780           if (m_from_string_field_body_table[((L_it->second)->m_id)-m_start_body_index] 
01781               != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
01782             L_convert = 
01783               ((m_factory_context)->*(m_from_string_field_body_table[((L_it->second)->m_id)-m_start_body_index]))
01784               (&(L_fielddef_it->m_default), &m_body_defaults[((L_it->second)->m_id)-m_start_body_index]) ;
01785             if (L_convert == true) { L_result = 0 ; }
01786           }
01787         }
01788         if (L_convert == false) {
01789           m_body_defaults[((L_it->second)->m_id)-m_start_body_index] 
01790             = valueFromString ((L_fielddef_it->m_default == NULL) 
01791                                ? (char*)defaultStringValue((L_it->second)->m_type) 
01792                                : L_fielddef_it->m_default,
01793                                (L_it->second)->m_type,
01794                                L_result);
01795         }
01796         if (L_result == -1) { L_ret = -1 ; break ; }
01797         m_body_defaults[((L_it->second)->m_id)-m_start_body_index].m_id
01798           = (L_it->second)->m_id ;
01799       }
01800     } 
01801   }
01802   
01803 
01804   
01805   if (L_ret != -1) {
01806     for (L_body_fielddef_it = P_body_values->begin();
01807            L_body_fielddef_it != P_body_values->end();
01808            L_body_fielddef_it++) {
01809         L_body_desc = check_body_value ((*L_body_fielddef_it));
01810         if (L_body_desc == NULL) { L_ret = -1 ; break ; }
01811     }
01812   }
01813   
01814   if (L_ret != -1) {
01815     // retrieve id and type of session id
01816     m_type_id = find_field_id(P_header_type) ;
01817     if (m_type_id == -1) {
01818       char *L_name = (P_header_type == NULL) ?
01819         (char*)"" : P_header_type ; 
01820       GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << L_name 
01821                 << "] not found for message type");
01822       L_ret = -1 ;
01823     } 
01824   }
01825 
01826   if (L_ret != -1) {
01827     // retrieve m_body_type_id
01828     m_body_type_id = -1 ;
01829     L_it = m_field_body_name_map->
01830       find(T_FieldNameMap::key_type(P_body_type));
01831     if (L_it != m_field_body_name_map->end()) {
01832       m_body_type_id = (L_it->second)->m_id ;
01833     } 
01834 
01835     if (m_body_type_id == -1) {
01836       char *L_name = (P_body_type == NULL) ?
01837         (char*)"" : P_body_type ;
01838       GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << L_name
01839                 << "] not found for body type");
01840       L_ret = -1 ;
01841     }
01842     GEN_DEBUG(1, "C_ProtocolExternal::analyze_dictionnary() "
01843               << "m_body_type_id [" << m_body_type_id << "]"); 
01844   }
01845 
01846   if (L_ret != -1) {
01847     // retrieve id of session 
01848     m_session_id = find_field_id(P_session_id_name) ;
01849     if (m_session_id == -1) {
01850       char *L_name = (P_session_id_name == NULL) ?
01851         (char*)"" : P_session_id_name ; 
01852       GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << L_name 
01853                 << "] not found for message session");
01854       L_ret = -1 ;
01855     } 
01856   }
01857   
01858   if (L_ret != -1) {
01859     // retrieve id of outof-session 
01860     m_outof_session_id = find_field_id(P_outof_session_id_name) ;
01861     if (m_outof_session_id == -1) {
01862       char *L_name = (P_outof_session_id_name == NULL) ?
01863         (char*)"" : P_outof_session_id_name ; 
01864       GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << L_name 
01865                 << "] not found for message out-of session");
01866       L_ret = -1 ;
01867     } 
01868   }
01869   
01870 
01871   if (L_ret != -1) {
01872     // build a table for all names  
01873     if (m_nb_names > 0) {
01874 
01875       ALLOC_TABLE(m_names_table, char**, sizeof(char*),m_nb_names);
01876       for (L_i = 0; L_i < m_nb_names ; L_i++) {
01877         m_names_table[L_i] = NULL ;
01878       } 
01879     } else {
01880       GEN_ERROR(E_GEN_FATAL_ERROR, 
01881                 "header field, body and header body not found"); 
01882       L_ret = -1 ;
01883     }
01884   }
01885 
01886   if (L_ret != -1) {
01887     if (!P_header_values->empty()) {
01888       m_nb_message_names =  P_header_values->size();
01889       
01890       // build a table for all message names  
01891       if (m_nb_message_names > 0) {
01892         ALLOC_TABLE(m_message_names_table, char**, sizeof(char*),m_nb_message_names);
01893         for (L_i = 0; L_i < m_nb_message_names ; L_i++) {
01894           m_message_names_table[L_i] = NULL ;
01895         } 
01896       } else {
01897         GEN_ERROR(E_GEN_FATAL_ERROR, 
01898                   "messages not found in dictionnary"); 
01899         L_ret = -1 ;
01900       }
01901     } else {
01902       L_ret = -1 ;
01903     }
01904   }
01905   
01906 
01907   if (L_ret != -1) {
01908     // check not-present field for each header
01909     // phase init 
01910     ALLOC_TABLE(m_header_not_present_table,
01911                 bool**,
01912                 sizeof(bool*),
01913                 m_nb_message_names);
01914     for (L_i = 0; L_i <m_nb_message_names ; L_i++) {
01915       ALLOC_TABLE (m_header_not_present_table[L_i], bool*, sizeof(bool), m_nb_header_fields);
01916       for (L_j = 0; L_j < m_nb_header_fields ; L_j++) {
01917         m_header_not_present_table[L_i][L_j] = true ;
01918       }
01919     }
01920 
01921   }
01922 
01923 
01924   if (L_ret != -1) { 
01925     T_FieldNameMap::iterator L_it_h ;
01926     T_pFieldDesc             L_desc_h ;
01927     int                      L_i_h  ;
01928 
01929     if (!m_field_name_map->empty()) {
01930       m_nb_from_string = m_field_name_map->size();
01931       ALLOC_TABLE(m_from_string_table,
01932                   C_MsgBuildContext::T_ContextStringFunction*,
01933                   sizeof(C_MsgBuildContext::T_ContextStringFunction),
01934                   m_nb_from_string);
01935       ALLOC_TABLE(m_to_string_table,
01936                   C_MsgBuildContext::T_ContextStringFunction*,
01937                   sizeof(C_MsgBuildContext::T_ContextStringFunction),
01938                   m_nb_from_string);
01939       for (L_i_h = 0 ; L_i_h < m_nb_from_string; L_i_h++) {
01940         m_from_string_table[L_i_h] = (C_MsgBuildContext::T_ContextStringFunction)NULL;
01941         m_to_string_table[L_i_h] = (C_MsgBuildContext::T_ContextStringFunction)NULL;
01942       }
01943       for (L_it_h = m_field_name_map->begin() ;
01944            L_it_h != m_field_name_map->end() ;
01945            L_it_h ++) {
01946         L_desc_h = L_it_h->second ;
01947         m_from_string_table[L_desc_h->m_id] = L_desc_h->m_from_string ;
01948         m_to_string_table[L_desc_h->m_id] = L_desc_h->m_to_string ;
01949       }
01950       
01951     } 
01952   }
01953 
01954   // default value management
01955   if (L_ret != -1) {
01956     bool L_convert ;
01957     if (m_nb_header_fields != 0) {
01958       ALLOC_TABLE(m_header_defaults, T_pValueData, sizeof(T_ValueData), m_nb_header_fields);
01959       for (L_fielddef_it = P_header_fields->begin();
01960            L_fielddef_it != P_header_fields->end();
01961            L_fielddef_it++) {
01962 
01963         L_convert = false ;
01964         L_result = -1 ;
01965         L_it = m_field_name_map->find(T_FieldNameMap::key_type(L_fielddef_it->m_name)) ;
01966 
01967         if (L_fielddef_it->m_default != NULL) {
01968           if (m_from_string_table[(L_it->second)->m_id] 
01969               != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
01970             L_convert = ((m_factory_context)->*(m_from_string_table[(L_it->second)->m_id]))
01971               (&(L_fielddef_it->m_default), &m_header_defaults[(L_it->second)->m_id]) ;
01972             if (L_convert == true) { L_result = 0 ; }
01973           }
01974         }
01975         if (L_convert == false) {
01976           m_header_defaults[(L_it->second)->m_id] 
01977             = valueFromString ((L_fielddef_it->m_default == NULL) 
01978                                ? (char*)defaultStringValue((L_it->second)->m_type) 
01979                                : L_fielddef_it->m_default,
01980                                (L_it->second)->m_type,
01981                                L_result);
01982         }
01983         if (L_result == -1) { L_ret = -1 ; break ; }
01984         m_header_defaults[(L_it->second)->m_id].m_id = (L_it->second)->m_id ;
01985       }
01986     } 
01987   }
01988 
01989   if (L_ret != -1) {
01990     C_MessageExternal::set_protocol_data(m_nb_header_fields,
01991                                          m_nb_body_values,
01992                                          m_nb_body_fields,
01993                                          m_session_id,
01994                                          m_outof_session_id,
01995                                          m_type_id,
01996                                          m_names_table,
01997                                          m_message_names_table,
01998                                          m_body_not_present_table,
01999                                          m_header_not_present_table);
02000   }
02001 
02002 
02003   if (L_ret != -1) {
02004     NEW_VAR(m_message_map, T_MessageNameMap());
02005     m_message_map->clear();
02006     C_MessageExternal *L_msg ;
02007     for (L_header_fielddef_it = P_header_values->begin();
02008          L_header_fielddef_it != P_header_values->end();
02009          L_header_fielddef_it++) {
02010       L_msg = build_message (NULL, *L_header_fielddef_it, NULL,NULL);
02011       if (L_msg == NULL) { L_ret = -1 ; break ; }
02012 
02013       m_message_map->insert(T_MessageNameMap::value_type(L_header_fielddef_it->m_name,
02014                                                          L_msg));
02015       
02016     }
02017   }
02018 
02019   if (L_ret != -1) {
02020     // build a table for header field using m_field_name_map 
02021 
02022     ALLOC_TABLE(m_header_field_desc_table,
02023                 T_pFieldDesc*,
02024                 sizeof(T_pFieldDesc),
02025                 m_nb_header_fields);
02026     
02027     for (L_it = m_field_name_map->begin();
02028          L_it != m_field_name_map->end();
02029          L_it++) {
02030       
02031       ALLOC_TABLE(m_names_table[(L_it->second)->m_id],
02032                   char*, sizeof(char),
02033                   strlen((L_it->second)->m_name)+1);
02034       
02035       strcpy(m_names_table[(L_it->second)->m_id],(L_it->second)->m_name) ;
02036 
02037       m_header_field_desc_table[(L_it->second)->m_id] = L_it->second  ;
02038 
02039     }
02040     
02041   }
02042 
02043   if (L_ret != -1) {
02044     NEW_VAR(m_body_decode_map, T_BodyDecodeMap());
02045     m_body_decode_map->clear();
02046 
02047     // build a table for body value using m_body_value_name_map
02048     ALLOC_TABLE(m_body_value_table,
02049                 T_pFieldBodyDesc*,
02050                 sizeof(T_pFieldBodyDesc),
02051                 m_nb_body_values);
02052 
02053     // copy names of body in m_names_table using  m_body_value_name_map 
02054     for (L_it_body = m_body_value_name_map->begin();
02055          L_it_body != m_body_value_name_map->end();
02056          L_it_body++) {
02057       
02058       ALLOC_TABLE(m_names_table[(L_it_body->second)->m_id],
02059                   char*, sizeof(char),
02060                   strlen((L_it_body->second)->m_name)+1);
02061 
02062       strcpy(m_names_table[(L_it_body->second)->m_id],(L_it_body->second)->m_name) ;
02063       
02064       m_body_value_table[(L_it_body->second)->m_id - m_end_header_index -1] 
02065         = (L_it_body->second)  ;
02066 
02067       // build a m_body_decode_map  using m_body_value_name_map       
02068       T_ValueData  L_value_body;
02069 
02070       L_value_body.m_type = E_TYPE_NUMBER ;
02071 
02072       copyValue(L_value_body,
02073                 ((L_it_body->second)->m_header[m_body_type_id-m_start_body_index]),
02074                 false);
02075 
02076       m_body_decode_map->insert(T_BodyDecodeMap::value_type(L_value_body,
02077                                                             (L_it_body->second)->m_id));
02078       // do not reset the value (if string => the string allocated is used by the map)
02079     }
02080   }
02081 
02082   if (L_ret != -1) {
02083     // build a table for body header field using m_field_body_name_map
02084 
02085     ALLOC_TABLE(m_body_field_desc_table,
02086                 T_pFieldDesc*,
02087                 sizeof(T_pFieldDesc),
02088                 m_nb_body_fields);
02089     for (L_it = m_field_body_name_map->begin();
02090          L_it != m_field_body_name_map->end();
02091          L_it++) {
02092       ALLOC_TABLE(m_names_table[(L_it->second)->m_id],
02093                   char*, sizeof(char),
02094                   strlen((L_it->second)->m_name)+1);
02095       strcpy(m_names_table[(L_it->second)->m_id],(L_it->second)->m_name) ;
02096 
02097       GEN_DEBUG(1, "C_ProtocolExternal::analyze_dictionnary() "
02098                 << "(L_it->second)->m_id [" << (L_it->second)->m_id << "]"); 
02099 
02100       m_body_field_desc_table[(L_it->second)->m_id - m_start_body_index] = L_it->second  ;
02101       
02102     }
02103   } 
02104   
02105   
02106 //        if (L_ret != -1) {
02107 //          for (L_i = 0 ; L_i <  m_nb_names ; L_i ++) {
02108 //            std::cerr << "m_names_table[" << L_i << "] = [" 
02109 //              << m_names_table[L_i] << "]"<< std::endl;
02110 //          }
02111 //        }
02112   
02113   if (L_ret != -1) {
02114     NEW_VAR(m_message_decode_map, T_MessageDecodeMap());
02115     m_message_decode_map->clear();
02116     
02117     C_MessageExternal *L_msg ;
02118 
02119     L_id = 0 ;
02120     for (L_it_message = m_message_map->begin();
02121          L_it_message != m_message_map->end();
02122          L_it_message++) {
02123       L_msg = L_it_message->second ;
02124       L_msg->m_id = L_id ;
02125 
02126 
02127       ALLOC_TABLE(m_message_names_table[L_id],
02128                   char*, sizeof(char),
02129                   ((L_it_message->first).length())+1);
02130                   
02131       strcpy(m_message_names_table[L_id],(L_it_message->first).c_str()) ;
02132 
02133       // L_msg->dump(std::cerr);
02134       // std::cerr << " ********** L_id " << L_id << std::endl;
02135       L_id ++ ;      
02136 
02137       GEN_DEBUG(1, "C_ProtocolExternal::analyze_dictionnary() "
02138                 << "L_msg from m_message_map [" << (*L_msg) << "]"); 
02139 
02140       T_ValueData   L_value ;
02141       L_value.m_type = E_TYPE_NUMBER ;
02142       
02143       copyValue(L_value,
02144                 *(L_msg->get_type()),
02145                 false);
02146       
02147       m_message_decode_map->insert(T_MessageDecodeMap::value_type(L_value,
02148                                                                   L_msg));
02149     }
02150     
02151   }
02152   
02153 //    if (L_ret != -1) {
02154 //      for (L_i = 0 ; L_i <  m_nb_message_names ; L_i ++) {
02155 //        std::cerr << "m_message_names_table[" << L_i << "] = [" 
02156 //                      << m_message_names_table[L_i] << "]"<< std::endl;
02157 //      }
02158 //    }
02159   
02160   
02161   if (L_ret != -1) {
02162     // phase anlyze for not-present     
02163     for (L_header_fielddef_it = P_header_values->begin();
02164          L_header_fielddef_it != P_header_values->end();
02165          L_header_fielddef_it++) {
02166 
02167       L_ret = check_header_not_present ((*L_header_fielddef_it));
02168       if (L_ret == -1 ) { break ; }
02169     }
02170 
02171   }
02172 
02173   
02174   
02175   GEN_DEBUG(1, "C_ProtocolExternal::analyze_dictionnary() end");
02176   return (L_ret);
02177 
02178 }
02179 
02180 C_ProtocolExternal::T_pFieldDesc 
02181 C_ProtocolExternal::check_field(T_FieldDef &P_field_def,
02182                                 char *P_field_name,
02183                                 char **P_data_type_name,
02184                                 char *P_field_type,
02185                                 char **P_field_type_found,
02186                                 T_pConfigValueList P_config_value_list,
02187                                 bool P_header) {
02188 
02189   T_pFieldDesc                  L_ret = NULL ;
02190   T_FieldNameMap::iterator      L_it ;
02191   size_t                        L_size = 0 ;
02192 
02193 
02194   GEN_DEBUG(1, "C_ProtocolExternal::check_field() start");
02195 
02196 
02197   
02198   L_it = m_field_body_name_map->find(T_FieldNameMap::key_type(P_field_def.m_name));
02199   if (L_it != m_field_body_name_map->end()) {
02200     GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << P_field_def.m_name << "] already defined");
02201     return (L_ret);
02202   }
02203   L_it = m_field_name_map->find(T_FieldNameMap::key_type(P_field_def.m_name));
02204   if (L_it != m_field_name_map->end()) {
02205     GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << P_field_def.m_name << "] already defined");
02206     return (L_ret);
02207   }
02208   
02209   ALLOC_VAR(L_ret, T_pFieldDesc, sizeof(T_FieldDesc));
02210 
02211   L_ret->m_config_field_name = NULL ;
02212   
02213 
02214   L_ret->m_type = typeFromString (P_field_def.m_type);
02215   if (L_ret->m_type == E_UNSUPPORTED_TYPE) {
02216     GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown type definition for [" << P_field_def.m_type << "]");
02217     FREE_VAR(L_ret);
02218     return (L_ret);
02219   }
02220 
02221   L_size = strlen(P_field_def.m_name) ;
02222   ALLOC_TABLE(L_ret->m_name, char*, sizeof(char), L_size+1);
02223   strcpy(L_ret->m_name, P_field_def.m_name);
02224   
02225   L_ret->m_get = m_factory->get_function(P_field_def.m_get);
02226   if ((L_ret->m_get) == (C_MsgBuildContext::T_ContextFunction)NULL) {
02227     GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown function definition for [" << P_field_def.m_get << "]");
02228     FREE_VAR(L_ret);
02229     return (L_ret);
02230   }
02231 
02232   L_ret->m_set = m_factory->get_function(P_field_def.m_set);
02233   if ((L_ret->m_set) == (C_MsgBuildContext::T_ContextFunction)NULL) {
02234     GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown function definition for [" << P_field_def.m_set << "]");
02235     FREE_VAR(L_ret);
02236     return (L_ret);
02237   }
02238 
02239   if (P_field_def.m_check_get != NULL) {
02240     L_ret->m_check_get = m_factory->get_function(P_field_def.m_check_get);
02241     if ((L_ret->m_check_get) == (C_MsgBuildContext::T_ContextFunction)NULL) {
02242       GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown function definition for [" 
02243                 << P_field_def.m_check_get << "]");
02244       FREE_VAR(L_ret);
02245       return (L_ret);
02246     }
02247   } else {
02248     L_ret->m_check_get = (C_MsgBuildContext::T_ContextFunction)NULL;
02249   }
02250 
02251   if (P_field_def.m_check_set != NULL) {
02252     L_ret->m_check_set = m_factory->get_function(P_field_def.m_check_set);
02253     if ((L_ret->m_check_set) == (C_MsgBuildContext::T_ContextFunction)NULL) {
02254       GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown function definition for [" 
02255                 << P_field_def.m_check_set << "]");
02256       FREE_VAR(L_ret);
02257       return (L_ret);
02258     }
02259   } else {
02260     L_ret->m_check_set = (C_MsgBuildContext::T_ContextFunction)NULL;
02261   }
02262 
02263   if (P_field_def.m_from_string != NULL) {
02264     L_ret->m_from_string = m_factory->get_string_function(P_field_def.m_from_string);
02265     if ((L_ret->m_from_string) == (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02266       GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown function definition for [" 
02267                 << P_field_def.m_from_string << "]");
02268       FREE_VAR(L_ret);
02269       return (L_ret);
02270     }
02271   } else {
02272     L_ret->m_from_string = (C_MsgBuildContext::T_ContextStringFunction)NULL;
02273   }
02274 
02275 
02276   if (P_field_def.m_to_string != NULL) {
02277     L_ret->m_to_string = m_factory->get_string_function(P_field_def.m_to_string);
02278     if ((L_ret->m_to_string) == (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02279       GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown function definition for [" 
02280                 << P_field_def.m_to_string << "]");
02281       FREE_VAR(L_ret);
02282       return (L_ret);
02283     }
02284   } else {
02285     L_ret->m_to_string = (C_MsgBuildContext::T_ContextStringFunction)NULL;
02286   }
02287 
02288   if (P_field_def.m_config_field_name != NULL) {
02289     L_ret->m_config_field_name = P_field_def.m_config_field_name ;
02290   } 
02291   
02292   if (P_header == true) {
02293     L_ret->m_id = new_id();
02294     if (get_id() > m_end_header_index) { m_end_header_index = get_id(); }
02295     m_field_name_map->insert(T_FieldNameMap::value_type(P_field_def.m_name, L_ret));
02296   } else {
02297     m_field_body_name_map->insert(T_FieldNameMap::value_type(P_field_def.m_name, L_ret));
02298     if (strcmp(P_field_name, P_field_def.m_name) == 0) {
02299       *P_data_type_name = P_field_def.m_name ;
02300     }
02301   }
02302 
02303   if (strcmp(P_field_def.m_name, P_field_type) == 0) {
02304     (*P_field_type_found) = P_field_def.m_name ;
02305   } 
02306   
02307   GEN_DEBUG(1, "C_ProtocolExternal::check_field() end ");
02308 
02309   return (L_ret);
02310 }
02311 
02312 int C_ProtocolExternal::update_config_params(T_ParamDef& P_config_param_dico,
02313                                              T_pConfigValueList P_config_value_list) {
02314 
02315 
02316   int                          L_ret            = 0     ;
02317   T_ConfigValueList::iterator  L_configValue_it         ;
02318   bool                         L_found          = false ;
02319   T_ConfigValue               L_configValue             ;
02320 
02321   GEN_DEBUG(1, "C_ProtocolExternal::update_config_params() start");
02322 
02323   if (!P_config_value_list->empty()) {
02324     for (L_configValue_it = P_config_value_list->begin();
02325          L_configValue_it != P_config_value_list->end();
02326          L_configValue_it++) {
02327       if (strcmp(L_configValue_it->m_name, P_config_param_dico.m_name) == 0) {
02328         L_found = true ;
02329         // the config file value is used
02330         break;
02331       }
02332     }
02333   }
02334   
02335   if (L_found == false) {
02336     // ctrl mandatory => error , must be in the config
02337     if ((P_config_param_dico.m_mandatory != NULL) && 
02338         (strcmp(P_config_param_dico.m_mandatory,"true") == 0 )) {
02339       GEN_ERROR(E_GEN_FATAL_ERROR, 
02340                 "paramdef mandatory value is mandatory for ["
02341                 << P_config_param_dico.m_name << "]");
02342       L_ret = -1 ;
02343     } else {
02344       // not mandatory, but a default value is known
02345       // element not found in config list
02346       // Add this element in the P_config_value_list
02347       L_configValue.m_name = P_config_param_dico.m_name ;
02348       L_configValue.m_value = P_config_param_dico.m_default ;
02349       P_config_value_list->push_back(L_configValue);
02350     }
02351   } 
02352  
02353   GEN_DEBUG(1, "C_ProtocolExternal::update_config_params() end");
02354   return (L_ret);
02355 }
02356 
02357 
02358 
02359 C_ProtocolExternal::T_pFieldBodyDesc 
02360 C_ProtocolExternal::check_body(T_FieldBody &P_field_body) {
02361   T_pFieldBodyDesc              L_desc = NULL ;
02362   T_FieldBodyNameMap::iterator  L_it       ;
02363   size_t                        L_size = 0 ;
02364 
02365   GEN_DEBUG(1, "C_ProtocolExternal::check_body() start ");
02366 
02367   L_it = m_body_value_name_map->find(T_FieldBodyNameMap::key_type(P_field_body.m_name));
02368   if (L_it != m_body_value_name_map->end()) {
02369     GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << P_field_body.m_name << "] already defined");
02370     return (L_desc);
02371   }
02372 
02373   ALLOC_VAR(L_desc, T_pFieldBodyDesc, sizeof(T_FieldBodyDesc));
02374   L_desc->m_id = new_id();
02375   L_desc->m_header = NULL ;
02376   
02377   L_size = strlen(P_field_body.m_name) ;
02378   ALLOC_TABLE(L_desc->m_name, char*, sizeof(char), L_size+1);
02379   strcpy(L_desc->m_name,P_field_body.m_name);
02380   
02381   m_body_value_name_map->insert(T_FieldBodyNameMap::value_type(P_field_body.m_name, L_desc));
02382   
02383   GEN_DEBUG(1, "C_ProtocolExternal::check_body() end");
02384 
02385   return (L_desc);
02386 }
02387 
02388 C_ProtocolExternal::T_pFieldBodyDesc 
02389 C_ProtocolExternal::check_body_value(T_FieldBody &P_field_body) {
02390   
02391   T_pFieldBodyDesc L_desc = NULL ;
02392   T_FieldBodyNameMap::iterator L_it ;
02393   T_FieldValueList::iterator L_field_it ;
02394   
02395   T_FieldNameMap::iterator L_field_found ;
02396   int                      L_result = 0 ;
02397   int                      L_i ;
02398   int L_id ;
02399 
02400   T_ValueData              L_value ;
02401   bool                     L_convert ;
02402 
02403   GEN_DEBUG(1, "C_ProtocolExternal::check_body_value() start");  
02404 
02405   L_it = m_body_value_name_map->find(T_FieldBodyNameMap::key_type(P_field_body.m_name));
02406   if (L_it == m_body_value_name_map->end()) {
02407     GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << P_field_body.m_name << "] already defined");
02408     return (L_desc);
02409   }
02410 
02411   L_desc = L_it->second ;
02412 
02413   ALLOC_TABLE(L_desc->m_header, T_pValueData, 
02414               sizeof(T_ValueData), m_nb_body_fields);
02415   for(L_i = 0 ; L_i < m_nb_body_fields; L_i++) {
02416     L_desc->m_header[L_i].m_type = E_TYPE_NUMBER ;
02417     copyValue(L_desc->m_header[L_i], m_body_defaults[L_i], false) ;
02418   }
02419   
02420   for (L_field_it = (P_field_body.m_list_value)->begin();
02421        L_field_it != (P_field_body.m_list_value)->end();
02422        L_field_it++) {
02423     L_field_found = m_field_body_name_map->find(T_FieldNameMap::key_type(L_field_it->m_name));
02424     if (L_field_found == m_field_body_name_map->end()) {
02425       GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << L_field_it->m_name << "] not found");
02426       return (NULL);
02427     } else {
02428 
02429 
02430 
02431       L_convert = false ;
02432       L_result = -1 ;
02433       if (m_from_string_field_body_table[((L_field_found->second)->m_id) - m_start_body_index] 
02434           != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02435         L_convert = 
02436           ((m_factory_context)->*(m_from_string_field_body_table[((L_field_found->second)->m_id)- m_start_body_index]))
02437           (&(L_field_it->m_value), &L_value) ;
02438         if (L_convert == true) { L_result = 0 ; }
02439       }
02440 
02441       if (L_convert == false) {
02442         L_value = valueFromString(L_field_it->m_value, (L_field_found->second)->m_type, L_result);
02443       }
02444 
02445       L_value.m_id = (L_field_found->second)->m_id;
02446       if (L_result == -1) { return(NULL); }
02447       L_id = ((L_field_found->second)->m_id) - m_start_body_index ;
02448       copyValue((L_desc->m_header)[L_id],
02449                 L_value, true);
02450       resetMemory(L_value);
02451       (L_desc->m_header)[L_id].m_id 
02452         = (L_field_found->second)->m_id ;
02453     }
02454   }
02455 
02456   GEN_DEBUG(1, "C_ProtocolExternal::check_body_value() end");    
02457   return (L_desc);
02458 }
02459 
02460 
02461 int C_ProtocolExternal::check_not_present(T_FieldBody &P_field_body) {
02462   
02463   int                          L_ret  = 0    ;
02464   T_CharList::iterator         L_field_it    ;
02465   T_FieldNameMap::iterator     L_field_found ;
02466   T_FieldBodyNameMap::iterator L_it          ;
02467   int                          L_i, L_j      ;
02468 
02469   GEN_DEBUG(1, "C_ProtocolExternal::check_not_present() start");  
02470   
02471 
02472   // find the id of body
02473   L_it = m_body_value_name_map->find(T_FieldBodyNameMap::key_type(P_field_body.m_name));
02474   if (L_it == m_body_value_name_map->end()) {
02475     GEN_ERROR(E_GEN_FATAL_ERROR, "body [" << P_field_body.m_name << "] not found");
02476     L_ret = -1 ;
02477     return (L_ret);
02478   }
02479 
02480   L_i = (L_it->second)->m_id - m_end_header_index - 1 ;
02481 
02482 
02483   // find the field not present for this body corresponding to L_id
02484   if ((P_field_body.m_list_not_present != NULL ) && (!(P_field_body.m_list_not_present)->empty())) {      
02485     for (L_field_it = (P_field_body.m_list_not_present)->begin();
02486          L_field_it != (P_field_body.m_list_not_present)->end();
02487          L_field_it++) {
02488 
02489       L_field_found = m_field_body_name_map->find(T_FieldNameMap::key_type(*L_field_it));
02490       if (L_field_found == m_field_body_name_map->end()) {
02491         GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << *L_field_it << "] not found");
02492         L_ret = -1 ;
02493       } else {
02494         L_j = ((L_field_found->second)->m_id) - m_start_body_index ;
02495         m_body_not_present_table[L_i][L_j] = false ;
02496       }
02497     }
02498   } 
02499 
02500   GEN_DEBUG(1, "C_ProtocolExternal::check_not_present() end");    
02501   return (L_ret);
02502 }
02503 
02504 int C_ProtocolExternal::check_header_not_present(T_FieldHeader &P_field_header) {
02505   
02506   int                          L_ret  = 0    ;
02507   T_CharList::iterator         L_field_it    ;
02508   T_FieldNameMap::iterator     L_field_found ;
02509 
02510   T_MessageNameMap::iterator   L_it          ;
02511   int                          L_j           ;
02512   int                          L_i           ;
02513  
02514   GEN_DEBUG(1, "C_ProtocolExternal::check_header_not_present() start");  
02515   
02516 
02517   // find the id of body
02518   L_it = m_message_map->find(T_MessageNameMap::key_type(P_field_header.m_name));
02519   if (L_it == m_message_map->end()) {
02520     GEN_ERROR(E_GEN_FATAL_ERROR, "body [" << P_field_header.m_name << "] not found");
02521     L_ret = -1 ;
02522     return (L_ret);
02523   }
02524 
02525   L_i = (L_it->second)->m_id ;
02526 
02527 
02528   // find the field not present for this body corresponding to L_id
02529   if ((P_field_header.m_list_header_not_present != NULL ) && 
02530       (!(P_field_header.m_list_header_not_present)->empty())) {   
02531     for (L_field_it = (P_field_header.m_list_header_not_present)->begin();
02532          L_field_it != (P_field_header.m_list_header_not_present)->end();
02533          L_field_it++) {
02534 
02535       L_field_found = m_field_name_map->find(T_FieldNameMap::key_type(*L_field_it));
02536       if (L_field_found == m_field_name_map->end()) {
02537         GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << *L_field_it << "] not found");
02538         L_ret = -1 ;
02539       } else {
02540         L_j = ((L_field_found->second)->m_id) ;
02541         m_header_not_present_table[L_i][L_j] = false ;
02542       }
02543     }
02544   } 
02545 
02546   GEN_DEBUG(1, "C_ProtocolExternal::check_header_not_present() end");    
02547   return (L_ret);
02548 }
02549 
02550 int C_ProtocolExternal::new_id() {
02551   m_id_counter ++ ;
02552   return(m_id_counter);
02553 }
02554 
02555 int C_ProtocolExternal::get_id() {
02556   return(m_id_counter);
02557 }
02558 
02559 
02560 void C_ProtocolExternal::set_body_field_id() {
02561   T_FieldNameMap::iterator L_it ;
02562   if (!m_field_body_name_map->empty()) {
02563     for(L_it = m_field_body_name_map->begin();
02564         L_it != m_field_body_name_map->end();
02565         L_it++) {
02566       ((L_it->second)->m_id) = new_id();
02567       if (m_start_body_index == -1) {
02568         m_start_body_index = get_id();
02569       }
02570     }
02571   }
02572 }
02573 
02574 C_MessageExternal* C_ProtocolExternal::build_message (C_MessageExternal *P_msg,
02575                                                       T_FieldHeader &P_header,
02576                                                       T_pInstanceDataList P_list,
02577                                                       int                *P_nb_value) {
02578 
02579   C_MessageExternal           *L_msg = NULL      ;
02580   int                          L_i               ;
02581   int                          L_id              ;
02582   int                          L_field_id        ;
02583 
02584   T_pValueData                 L_header          ;
02585   T_pValueData                 L_header_init     ;
02586   int                         *L_body_instance   ;
02587 
02588   T_pValueData                 L_a_body ;
02589   T_ValueDataList              L_body   ;
02590   list_t<int>                  L_body_id;
02591   int                          L_instance;
02592 
02593   T_FieldValueList::iterator   L_value_it        ;
02594 
02595   T_FieldBodyList::iterator    L_body_it         ;
02596   T_FieldNameMap::iterator     L_field_it        ;
02597 
02598   T_FieldBodyNameMap::iterator L_it_body         ;
02599 
02600 
02601 
02602   T_ValueData                  L_value           ;
02603   int                          L_result          ;
02604   //  bool                         L_data          = false ;
02605 
02606   set_t<int>                   L_confict_set     ;
02607   bool                         L_convert ;
02608   //  set_t<int>::iterator         L_conf_it         ;
02609   //  int                          L_j, L_k          ;
02610   //  bool                         L_do_copy = false ;
02611 
02612 
02613   ALLOC_TABLE(L_body_instance, int*, sizeof(int), 
02614               m_nb_body_values);
02615   for (L_i = 0 ; L_i < m_nb_body_values; L_i ++) {
02616     L_body_instance[L_i] = 0 ;
02617   }
02618 
02619 
02620 
02621   L_confict_set.clear();
02622 
02623   GEN_DEBUG(1, "C_ProtocolExternal::build_message() start");    
02624 
02625   GEN_DEBUG(1, "C_ProtocolExternal::build_message() "
02626             << "P_header.m_name [" << P_header.m_name << "]");
02627 
02628   L_header_init = (P_msg == NULL) ? m_header_defaults : P_msg->m_header ;
02629 
02630   ALLOC_TABLE(L_header, T_pValueData, sizeof(T_ValueData), m_nb_header_fields);
02631 
02632   for (L_i = 0 ; L_i < m_nb_header_fields; L_i ++) {
02633 
02634     if ((P_msg != NULL) && (m_header_field_desc_table[L_i]->m_config_field_name != NULL)) {
02635       char * L_valueString = NULL ;
02636       L_convert = false ;
02637       L_result = -1 ;
02638       L_valueString = find_config_value(m_header_field_desc_table[L_i]->m_config_field_name);
02639       if (L_valueString != NULL ) {
02640         if (m_from_string_table[m_header_field_desc_table[L_i]->m_id] 
02641             != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02642           L_convert = 
02643             ((m_factory_context)->*(m_from_string_table[m_header_field_desc_table[L_i]->m_id]))
02644             (&(L_valueString), &L_value) ;
02645           if (L_convert == true) { L_result = 0 ; }
02646         }
02647         if (L_convert == false) {
02648           L_value = valueFromString(L_valueString, m_header_field_desc_table[L_i]->m_type, L_result);
02649         }
02650         if (L_result == -1) {
02651           return (NULL);
02652         }
02653 
02654         L_value.m_id = m_header_field_desc_table[L_i]->m_id ;
02655         L_header[L_i].m_type = m_header_field_desc_table[L_i]->m_type ;
02656 
02657         copyValue(L_header[L_i], L_value, true);
02658         resetMemory(L_value);
02659       } else {
02660         GEN_ERROR(E_GEN_FATAL_ERROR, "Unable to find [" 
02661                   << m_header_field_desc_table[L_i]->m_config_field_name 
02662                   << "] in configuration parameters");
02663         return (NULL);
02664       }
02665     } else {
02666       copyValue(L_header[L_i], L_header_init[L_i], false);
02667     }
02668   }
02669 
02670 
02671   //      if (P_msg != NULL) {
02672   // P_msg->dump(std::cerr);
02673   //  }
02674   
02675   
02676   if ((P_header.m_list_value != NULL ) 
02677       && (!(P_header.m_list_value)->empty())) {  
02678     for(L_value_it = (P_header.m_list_value)->begin();
02679         L_value_it != (P_header.m_list_value)->end();
02680         L_value_it++) {
02681       
02682       GEN_DEBUG(1, "C_ProtocolExternal::build_message() "
02683                 << "L_value_it->m_name [" << L_value_it->m_name << "]");
02684 
02685       L_field_it = m_field_name_map->find(T_FieldNameMap::key_type(L_value_it->m_name));
02686       if (L_field_it == m_field_name_map->end()) {
02687         GEN_ERROR(E_GEN_FATAL_ERROR, 
02688                   "C_ProtocolExternal::build_message field header [" 
02689                   << L_value_it->m_name << "] not found");
02690         return (NULL);
02691       }
02692 
02693       L_convert = false ;
02694       L_result = -1 ;
02695 
02696 
02697       if (P_msg != NULL) {
02698         char *L_valueConfig = NULL ;
02699         char *L_variable = NULL ;
02700         char *L_valueString = L_value_it->m_value ;
02701 
02702         if ((L_variable = is_variable(L_valueString)) != NULL) {
02703           L_valueConfig = find_config_value(L_variable);
02704           if (L_valueConfig == NULL) {
02705             // => error variable existe pas
02706             GEN_ERROR(E_GEN_FATAL_ERROR, "Unable to find [" 
02707                       << L_variable 
02708                       << "] in configuration parameters");
02709       
02710             FREE_TABLE(L_variable);
02711             return(NULL);
02712           } else {
02713             L_valueString = L_valueConfig;
02714           }
02715           FREE_TABLE(L_variable);
02716         } 
02717 
02718         if (m_from_string_table[(L_field_it->second)->m_id] 
02719             != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02720           L_convert = ((m_factory_context)->*(m_from_string_table[(L_field_it->second)->m_id]))
02721             (&(L_valueString), &L_value) ;
02722           if (L_convert == true) { L_result = 0 ; }
02723         }
02724         if (L_convert == false) {
02725           L_value = valueFromString(L_valueString, (L_field_it->second)->m_type, L_result);
02726         }
02727         if (L_result == -1) {
02728           return (NULL);
02729         }
02730 
02731       } else {
02732         
02733         if (m_from_string_table[(L_field_it->second)->m_id] 
02734             != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02735           L_convert = ((m_factory_context)->*(m_from_string_table[(L_field_it->second)->m_id]))
02736             (&(L_value_it->m_value), &L_value) ;
02737           if (L_convert == true) { L_result = 0 ; }
02738         }
02739         if (L_convert == false) {
02740           
02741           L_value = valueFromString(L_value_it->m_value, (L_field_it->second)->m_type, L_result);
02742         }
02743         if (L_result == -1) {
02744           return (NULL);
02745         }
02746         
02747       }
02748 
02749       L_value.m_id = (L_field_it->second)->m_id ;
02750 
02751       copyValue(L_header[(L_field_it->second)->m_id], L_value, true);
02752 
02753       resetMemory(L_value);
02754     }
02755   }
02756 
02757   if ((P_header.m_list_body != NULL ) 
02758       && (!((P_header.m_list_body)->empty()))) {  
02759 
02760     // count the body and body field
02761     for(L_body_it = (P_header.m_list_body)->begin();
02762         L_body_it != (P_header.m_list_body)->end();
02763         L_body_it++) {
02764 
02765       // ctrl the body contains in the map of body
02766       L_it_body = m_body_value_name_map->find(T_FieldBodyNameMap::key_type(L_body_it->m_name));
02767       if (L_it_body == m_body_value_name_map->end()) {
02768         GEN_ERROR(E_GEN_FATAL_ERROR, "field body [" << L_body_it->m_name << "] not found");
02769         return (NULL);
02770       }
02771       L_id = ((L_it_body->second)->m_id) - m_end_header_index -1 ;
02772 
02773     } // for(L_body_it ..)
02774     
02775 
02776     for(L_body_it = (P_header.m_list_body)->begin();
02777         L_body_it != (P_header.m_list_body)->end();
02778         L_body_it++) {
02779       
02780       // ctrl the body contains in the map of body
02781       L_it_body = m_body_value_name_map->find(T_FieldBodyNameMap::key_type(L_body_it->m_name));
02782 
02783       L_id = ((L_it_body->second)->m_id) - m_end_header_index - 1 ;
02784 
02785       ALLOC_TABLE(L_a_body, T_pValueData, sizeof(T_ValueData), 
02786                   m_nb_body_fields);
02787       for (L_i = 0 ; L_i < m_nb_body_fields; L_i ++) {
02788         copyValue(L_a_body[L_i], 
02789                   ((L_it_body->second)->m_header)[L_i], false);
02790       }
02791       L_body.push_back(L_a_body);
02792 
02793       L_body_id.push_back(L_id);
02794       L_instance = L_body_instance[L_id] ;
02795       L_body_instance[L_id]++;
02796 
02797       if (L_body_it->m_instance != NULL) {
02798 
02799         T_InstanceData L_data ;
02800         T_InstanceDataList::iterator L_it_data ;
02801         L_data.m_instance_name = L_body_it->m_instance ;
02802 
02803         if (!P_list->empty()) {
02804           for (L_it_data = P_list->begin();
02805                L_it_data != P_list->end();
02806                L_it_data++) {
02807             if (strcmp(L_it_data->m_instance_name, L_body_it->m_instance) == 0) {
02808               GEN_ERROR(E_GEN_FATAL_ERROR,
02809                         "Duplicate instance name [" << L_body_it->m_instance << "]");
02810               return (NULL);
02811             }
02812           }
02813         }
02814         
02815         L_data.m_id = (L_it_body->second)->m_id ;
02816         L_data.m_instance_id = L_instance ;
02817 
02818         P_list->push_back(L_data);
02819       }
02820       
02821       
02822       // build header field for this body
02823       if (L_body_it->m_list_value != NULL)  {  
02824 
02825         GEN_DEBUG(1, "C_ProtocolExternal::build_message() "
02826                   << "L_body_it->m_list_value size [" << (L_body_it->m_list_value)->size() << "]");
02827               
02828         
02829         for(L_value_it = (L_body_it->m_list_value)->begin();
02830             L_value_it != (L_body_it->m_list_value)->end();
02831             L_value_it++) {
02832           
02833           GEN_DEBUG(1, "C_ProtocolExternal::build_message() "
02834                     << "L_value_it->m_name [" << L_value_it->m_name << "]");
02835           
02836      L_field_it = m_field_body_name_map->find(T_FieldNameMap::key_type(L_value_it->m_name));
02837      if (L_field_it == m_field_body_name_map->end()) {
02838        GEN_ERROR(E_GEN_FATAL_ERROR,
02839           "C_ProtocolExternal::build_message field body ["
02840           << L_value_it->m_name << "] not found");
02841        return (NULL);
02842      }
02843 
02844           L_convert = false ;
02845           L_result = -1 ;
02846      if (m_from_string_field_body_table[((L_field_it->second)->m_id) - m_start_body_index] 
02847               != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02848             L_convert = 
02849               ((m_factory_context)->*(m_from_string_field_body_table[((L_field_it->second)->m_id)- m_start_body_index]))
02850               (&(L_value_it->m_value), &L_value) ;
02851             if (L_convert == true) { L_result = 0 ; }
02852           }
02853           if (L_convert == false) {
02854             L_value = valueFromString(L_value_it->m_value, (L_field_it->second)->m_type, L_result);
02855           }
02856 
02857 
02858 
02859           if (L_result == -1) {
02860             return (NULL);
02861           }
02862 
02863           L_field_id = ((L_field_it->second)->m_id) - m_start_body_index ;
02864           L_value.m_id = (L_field_it->second)->m_id ;
02865           copyValue(L_a_body[L_field_id], 
02866                     L_value, 
02867                     true);
02868           resetMemory(L_value);
02869 
02870         } // for(L_value_it =...)
02871       } // if (L_body_it->m_list_value != NULL)
02872     } // for(L_body_it = ...)
02873   } // (P_header.m_list_body != NULL ...)
02874 
02875   // TO DO: add body from dictionnary
02876 
02877   if ((P_nb_value != NULL) && (!L_body.empty())) {
02878     (*P_nb_value) = L_body.size() ;
02879   }
02880   
02881 
02882   NEW_VAR(L_msg, C_MessageExternal(this, L_header, &L_body, &L_body_id, L_body_instance));
02883 
02884   
02885 
02886   FREE_TABLE(L_body_instance);
02887   if (!L_body.empty()) {
02888 
02889     L_body.erase(L_body.begin(), L_body.end());
02890     L_body_id.erase(L_body_id.begin(), L_body_id.end());
02891   }
02892 
02893   GEN_DEBUG(1, "C_ProtocolExternal::build_message() end");    
02894   
02895   if (!L_confict_set.empty()) {
02896     L_confict_set.erase(L_confict_set.begin(), L_confict_set.end());
02897   }
02898 
02899 
02900   return (L_msg);
02901 }
02902 
02903 int C_ProtocolExternal::find_field_id (char*P_name) {
02904 
02905   int L_id = -1 ;
02906   T_FieldNameMap::iterator     L_it                      ;
02907   T_FieldBodyNameMap::iterator L_body_it                 ; 
02908 
02909   // retrieve id and type of session id
02910   if (P_name != NULL ) {
02911     // retrieve session id in header field map (m_field_name_map)
02912     L_it = m_field_name_map->find(T_FieldNameMap::key_type(P_name));
02913     if (L_it != m_field_name_map->end()) {
02914       L_id = (L_it->second)->m_id ;
02915     } else {
02916       // retrieve session id in body map (m_body_value_name_map)
02917       L_body_it = m_body_value_name_map->
02918         find(T_FieldBodyNameMap::key_type(P_name));
02919       if (L_body_it != m_body_value_name_map->end()) {
02920         L_id = (L_body_it->second)->m_id ;
02921       } 
02922       
02923     }
02924   } 
02925   return (L_id);
02926 }
02927 
02928 
02929 C_MsgBuildContextFactory* C_ProtocolExternal::get_factory() {
02930   return (m_factory);
02931 }
02932  
02933 void C_ProtocolExternal::log_message (char *P_header, C_MessageFrame *P_msg) {
02934   //  C_MessageExternal *L_msg = dynamic_cast<C_MessageExternal*>(P_msg);
02935 
02936   if (genTraceLevel & gen_mask_table[LOG_LEVEL_MSG]) {
02937     GEN_LOG_EVENT(LOG_LEVEL_MSG, 
02938                   "Message " << P_header << " [ " << *P_msg <<
02939                   GEN_HEADER_LOG << GEN_HEADER_NO_LEVEL << "]" );
02940 
02941   }
02942 
02943 }
02944 
02945 
02946 bool C_ProtocolExternal::check_sub_entity_needed (int P_id) {
02947   bool L_ret = false;
02948   
02949   if ((P_id > m_end_header_index) && 
02950       (P_id <= (m_end_header_index + m_nb_body_values))) {
02951     L_ret = true ;
02952   }
02953   return (L_ret);
02954 }
02955 
02956 char *C_ProtocolExternal::get_string_value (int P_id, T_pValueData P_data) {
02957  
02958   char *L_string = NULL ;
02959 
02960   if (m_to_string_table[P_id] != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02961     (void)((m_factory_context)->*(m_to_string_table[P_id]))(&L_string, P_data) ;
02962   }
02963   
02964   return (L_string);
02965  
02966 }
02967 
02968 
02969 char *C_ProtocolExternal::get_string_value_field_body (int P_id, T_pValueData P_data) {
02970  
02971   char *L_string = NULL ;
02972 
02973   if (m_to_string_field_body_table[P_id] != (C_MsgBuildContext::T_ContextStringFunction)NULL) {
02974     (void)((m_factory_context)->*(m_to_string_field_body_table[P_id]))(&L_string, P_data) ;
02975   }
02976   
02977   return (L_string);
02978  
02979 }
02980 
02981 char* C_ProtocolExternal::find_config_value(char* P_varible) {
02982   
02983   char* L_value = NULL ;
02984 
02985   T_ConfigValueList::iterator  L_configValue_it         ;
02986   GEN_DEBUG(1, "C_ProtocolExternal::find_config_value() start");    
02987 
02988   if (!m_config_value_list->empty()) {
02989     for (L_configValue_it = m_config_value_list->begin();
02990          L_configValue_it != m_config_value_list->end();
02991          L_configValue_it++) {
02992       if (strcmp(L_configValue_it->m_name, P_varible) == 0) {
02993         L_value = L_configValue_it->m_value ;
02994         break ;
02995       }
02996     }
02997   }
02998     
02999   GEN_DEBUG(1, "C_ProtocolExternal::find_config_value() end");    
03000   return (L_value);
03001 
03002 }
03003 
03004 
03005 char* C_ProtocolExternal::is_variable(char* P_varibleString) {
03006   
03007   char *L_ptr     = P_varibleString ;
03008   char *L_value   = NULL            ;
03009   char *L_search  = NULL            ;
03010   char *L_ptr_end = NULL            ;
03011 
03012   int   L_value_size                ;
03013 
03014   if ((L_ptr == NULL) ||
03015       ((strlen(L_ptr)) <= 2)) {
03016     return (L_value) ;
03017   } 
03018 
03019   if (!((L_ptr[0] == '$') && (L_ptr[1] == '('))) {
03020     return (L_value) ;
03021   } else {
03022     L_search = L_ptr + 2 ;
03023     L_ptr_end = strchr(L_search, ')') ;
03024     if (L_ptr_end == NULL) {
03025       return (L_value) ;
03026     } else {
03027       L_value_size =  L_ptr_end - L_search ; 
03028       ALLOC_TABLE(L_value,
03029                   char*, 
03030                   sizeof(char),
03031                   L_value_size+1);
03032       memcpy(L_value, L_search, L_value_size);
03033       L_value[L_value_size] = 0 ;
03034     }    
03035   }
03036 
03037   GEN_DEBUG(1, "C_ProtocolExternal::retrieve_config_value() end");    
03038   return (L_value);
03039 
03040 }
03041 
03042 bool C_ProtocolExternal::find_present_session (int P_msg_id,int P_id) {
03043   return (true);
03044 }
03045 

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