Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_ProtocolTlv.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_ProtocolTlv.hpp"
00021 
00022 #include "GeneratorError.h"
00023 #include "C_MessageTlv.hpp"
00024 #include "BufferUtils.hpp"
00025 
00026 #include <cstdlib> // for strtoul
00027 #include "GeneratorTrace.hpp"
00028 
00029 #include "ProtocolData.hpp"
00030 
00031 #include "integer_t.hpp"
00032 
00033 unsigned long C_ProtocolTlv::get_header_size() {
00034   GEN_DEBUG(1, "C_ProtocolTlv::get_header_size() m_header_size: " << m_header_size);
00035   return (m_header_size);
00036 }
00037 
00038 unsigned long C_ProtocolTlv::get_nb_field_header () {
00039   GEN_DEBUG(1, "C_ProtocolTlv::get_nb_field_header() m_nb_field_header: " << m_nb_field_header);
00040   return (m_nb_field_header) ;
00041 }
00042 
00043 C_ProtocolTlv::T_pHeaderField 
00044 C_ProtocolTlv::get_header_field_description (int P_id) {
00045 
00046   T_pHeaderField L_result ;
00047 
00048   GEN_DEBUG(1, "C_ProtocolTlv::get_header_field_description() start");
00049   L_result = (P_id < (int)m_nb_field_header) ?
00050     &(m_header_field_table[P_id]) : NULL ;
00051   GEN_DEBUG(1, "C_ProtocolTlv::get_header_field_description() end");
00052 
00053   return (L_result);
00054 }
00055 
00056 C_ProtocolTlv::T_pHeaderField 
00057 C_ProtocolTlv::get_header_field_description (char *P_name) {
00058 
00059   T_pHeaderField         L_result ;
00060   int                    L_id     ;
00061   T_IdMap::iterator      L_it     ;
00062 
00063   GEN_DEBUG(1, "C_ProtocolTlv::get_header_field_description() start");
00064   L_it = m_header_id_map 
00065     -> find (T_IdMap::key_type(P_name)) ;
00066   
00067   if (L_it != m_header_id_map->end()) {
00068     L_id = L_it->second ;
00069     L_result = get_header_field_description(L_id);
00070   } else {
00071     L_result = NULL ;
00072   }
00073   GEN_DEBUG(1, "C_ProtocolTlv::get_header_field_description() end");
00074 
00075   return (L_result) ;
00076 }
00077 
00078 T_pTypeDef
00079 C_ProtocolTlv::get_type_description (int P_id) {
00080 
00081   T_pTypeDef L_result ;
00082 
00083   GEN_DEBUG(1, "C_ProtocolTlv::get_type_description() start");
00084   L_result = (P_id < (int)m_nb_types) ?
00085     &(m_type_def_table[P_id]) : NULL ;
00086   GEN_DEBUG(1, "C_ProtocolTlv::get_type_description() end");
00087 
00088   return (L_result);
00089 }
00090 
00091 T_pTypeDef 
00092 C_ProtocolTlv::get_type_description (char *P_name) {
00093 
00094   T_pTypeDef         L_result ;
00095   int                    L_id     ;
00096   T_IdMap::iterator L_it     ;
00097 
00098   GEN_DEBUG(1, "C_ProtocolTlv::get_type_description() start");
00099   L_it = m_type_id_map 
00100     -> find (T_IdMap::key_type(P_name)) ;
00101   
00102   if (L_it != m_type_id_map->end()) {
00103     L_id = L_it->second ;
00104     L_result = get_type_description(L_id);
00105   } else {
00106     L_result = NULL ;
00107   }
00108   GEN_DEBUG(1, "C_ProtocolTlv::get_type_description() end");
00109 
00110   return (L_result) ;
00111 }
00112 
00113 int C_ProtocolTlv::get_header_type_id () {
00114   return (m_header_type_id) ;
00115 }
00116 
00117 
00118 int C_ProtocolTlv::get_header_type_id_body () {
00119   GEN_DEBUG(1, "C_ProtocolTlv::get_header_type_id_body() = "
00120                 << m_header_type_id_body);
00121   return (m_header_type_id_body) ;
00122 }
00123 
00124 
00125 int C_ProtocolTlv::get_header_length_id () {
00126   GEN_DEBUG(1, "C_ProtocolTlv::get_header_length_id() = "
00127                << m_header_length_id);
00128   return (m_header_length_id) ;
00129 }
00130 
00131 int C_ProtocolTlv::get_header_length_index () {
00132   GEN_DEBUG(1, "C_ProtocolTlv::get_header_length_index() = "
00133                << m_header_length_index);
00134   return (m_header_length_index) ;
00135 }
00136 
00137 void C_ProtocolTlv::set_header_type_id (int P_id) {
00138   GEN_DEBUG(1, "C_ProtocolTlv::set_header_type_id() start: new P_id = "
00139                << P_id);
00140   GEN_DEBUG(1, "C_ProtocolTlv::set_header_type_id() end");
00141   m_header_type_id = P_id ;
00142 }
00143 void C_ProtocolTlv::set_header_length_id (int P_id) {
00144   int L_id ;
00145 
00146   GEN_DEBUG(1, "C_ProtocolTlv::set_header_length_id() start");
00147   m_header_length_id = P_id ;
00148   m_header_length_index = 0 ;
00149   for(L_id = 0; L_id < m_header_length_id; L_id++) {
00150     m_header_length_index += (int) m_header_field_table[L_id].m_size ;
00151   }
00152   GEN_DEBUG(1, "C_ProtocolTlv::set_header_length_id() end");
00153 
00154 }
00155 
00156 int C_ProtocolTlv::add_type (char         *P_name, 
00157                                 T_TypeType    P_type, 
00158                                 unsigned long P_size) {
00159 
00160   int L_id = m_nb_types ;
00161 
00162   GEN_DEBUG(1, "C_ProtocolTlv::add_type() start");
00163 
00164   GEN_DEBUG(1, "C_ProtocolTlv::add_type() type["<<L_id<<"] name:" << P_name);
00165   GEN_DEBUG(1, "C_ProtocolTlv::add_type() type["<<L_id<<"] type:" << P_type);
00166   GEN_DEBUG(1, "C_ProtocolTlv::add_type() type["<<L_id<<"] size:" << P_size);
00167 
00168   m_type_def_table[L_id].m_id = L_id ;
00169   m_type_def_table[L_id].m_name = P_name ;
00170   m_type_def_table[L_id].m_type = P_type ;
00171   m_type_def_table[L_id].m_size = P_size;
00172 
00173   m_nb_types++ ;
00174   GEN_DEBUG(1, "C_ProtocolTlv::add_type() end with id: " << L_id);
00175 
00176   return (L_id) ;
00177 }
00178 
00179 int C_ProtocolTlv::add_header_field (char           *P_name, 
00180                                      unsigned long   P_size,
00181                                      unsigned long  *P_nb_field,
00182                                      unsigned long  *P_header_size,
00183                                      T_pHeaderField  P_field_table,
00184                                      T_pIdMap        P_map,
00185                                      int             P_counter_id,
00186                                      T_pCondPresence P_condPresence,
00187                                      long            P_type_id) {
00188 
00189 
00190   int L_id = (*P_nb_field) ;
00191 
00192   GEN_DEBUG(1, "C_ProtocolTlv::add_header_field() start (nb field: "
00193                   << (*P_nb_field) << ")");
00194   P_field_table[L_id].m_id = L_id ;
00195   P_field_table[L_id].m_name = P_name ;
00196   P_field_table[L_id].m_size = P_size ;
00197   P_field_table[L_id].m_cond_presence = P_condPresence ;
00198   GEN_DEBUG(1, "C_ProtocolTlv::add_header_field() [" 
00199                   << L_id << "] m_cond_presence: " <<
00200                   ((P_condPresence == NULL) ? (unsigned long)0 : P_condPresence ));
00201   P_field_table[L_id].m_type_id = P_type_id ;
00202   P_field_table[L_id].m_counter_id = P_counter_id ;
00203 
00204   
00205   // Set flag to true only for complex type i.e. type_id != -1
00206   if (P_type_id > -1) {
00207     m_header_complex_type_presence = true;
00208   }
00209 
00210   if (P_condPresence == NULL) { // mandatory
00211     (*P_header_size) += P_size ;
00212     (*P_nb_field)++ ;
00213   } else { // optional
00214     if (m_header_body_start_optional_id == -1) {
00215       m_header_body_start_optional_id = L_id ;
00216     }
00217   }
00218 
00219   P_map->insert(T_IdMap::value_type(P_name, L_id));
00220 
00221   GEN_DEBUG(1, "C_ProtocolTlv::add_header_field() end (nb field: " 
00222                   << (*P_nb_field) << ")");
00223   return (L_id) ;
00224 }
00225 
00226 int C_ProtocolTlv::get_header_from_xml (C_XmlData *P_def) {
00227 
00228   C_XmlData                *L_data ;
00229   T_XmlData_List::iterator  L_listIt ;
00230   T_pXmlData_List           L_subList ;
00231   char                     *L_value, *L_value_size, *L_value_unit,  *L_value_type;
00232   char                     *L_value_field_length, *L_value_field_type ;
00233   int                       L_ret = 0 ;
00234   unsigned long             L_size    ;
00235   int                       L_id  = -1 ;
00236   
00237   int                       L_fieldDefCpt      ;
00238   T_IdMap::iterator         L_IdMapIt   ;
00239   int                       L_typeId ;
00240 
00241   char                     *L_transport_field       ;
00242   char                     *L_value_mask            ;
00243   unsigned long             L_mask                  ;
00244   T_pCondPresence           L_presence_mask = NULL  ;
00245   bool                      L_mask_present  = false ; 
00246 
00247 
00248   char                                   *L_value_fielddef              ;
00249   int                                     L_id_length          = 0      ;
00250   int                                     L_header_length_id   = -1     ;
00251 
00252   T_pProtocolCounterDataList              L_header_length_list = NULL   ;
00253   T_ProtocolCounterData                   L_header_length               ;  
00254   T_ProtocolCounterDataList::iterator     L_it                          ;
00255   int                                     L_counter_id = -1             ;
00256   int                                     L_i                           ;
00257   
00258   bool                                    L_last_length_present = false ;
00259   int                                     L_first_counter_id = -1       ;
00260     
00261 
00262   GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() start");
00263 
00264   // Search the type field definition
00265   L_value_field_type   = P_def->find_value((char*)"type");
00266   if (L_value_field_type ==  NULL) {
00267     GEN_ERROR(E_GEN_FATAL_ERROR,"type definition value is mandatory");
00268     L_ret = -1 ;
00269   } else {
00270     m_header_type_name = L_value_field_type ;
00271     GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() m_header_type_name is " << m_header_type_name );
00272   }
00273 
00274   // Search the length field definition
00275   L_value_field_length = P_def->find_value((char*)"length");
00276   if (L_value_field_length == NULL) {
00277     GEN_ERROR(E_GEN_FATAL_ERROR,"length definition value is mandatory");
00278     L_ret = -1 ;
00279   }
00280 
00281   GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() m_header_length_name is " 
00282             << L_value_field_length );
00283 
00284   // Search the Name of protocol exchange element
00285   m_header_name = P_def->find_value((char*)"name");
00286   if (m_header_name == NULL) {
00287     GEN_ERROR(E_GEN_FATAL_ERROR,"header name value is mandatory");
00288     L_ret = -1 ;
00289   }
00290   GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() m_header_name is " << m_header_name );
00291 
00292 
00293   L_transport_field = P_def->find_value((char*)"transport-driven");
00294   if (L_transport_field != NULL) {
00295     if (strcmp(L_transport_field,(char*)"yes") == 0) {
00296       m_transport_type = 1 ;
00297     } else {
00298       GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown transport type [" 
00299                 << L_transport_field << "]");
00300       L_ret = -1 ;
00301     }
00302   }
00303 
00304   L_subList = P_def->get_sub_data() ;
00305   L_fieldDefCpt = 0;
00306 
00307   L_first_counter_id  = add_length ((char*)"length-default");
00308   if (L_first_counter_id == -1 ) {
00309     return (-1);
00310   }
00311 
00312   for(L_listIt  = L_subList->begin() ;
00313       L_listIt != L_subList->end() ;
00314       L_listIt++) {
00315     L_data = *L_listIt ;
00316     L_value = L_data->get_name() ;
00317     
00318     if (strcmp(L_value, (char*)"length") == 0) {
00319       L_value = L_data->find_value((char*)"name") ;
00320       if (L_value == NULL) {
00321         GEN_ERROR(E_GEN_FATAL_ERROR, "length name value is mandatory");
00322         return (-1);
00323       } else {
00324         L_id_length = add_length (L_value);
00325         if (L_id_length == -1 ) {
00326           return (-1);
00327         }
00328         m_counter_id_last_length = L_id_length ;
00329       }
00330     }
00331   }
00332 
00333   if (m_length_max > 0) {
00334     NEW_VAR (L_header_length_list, T_ProtocolCounterDataList()) ;
00335     m_nb_header_length = m_length_max + 1 ;
00336     m_nb_protocol_ctxt_values = m_nb_header_length ;
00337     L_header_length.m_id        = L_first_counter_id ;
00338     L_header_length.m_start_id  =  0                 ;
00339     L_header_length.m_stop_id   = -1                 ;
00340     L_header_length_list->push_back(L_header_length) ;
00341   }
00342   
00343   for(L_listIt  = L_subList->begin() ;
00344       L_listIt != L_subList->end() ;
00345       L_listIt++, L_fieldDefCpt++) {
00346 
00347     L_data = *L_listIt ;
00348     L_value = L_data->get_name() ;
00349 
00350     L_mask_present  = false ;
00351     L_counter_id    = -1    ;
00352 
00353     if (strcmp(L_value, (char*)"fielddef") == 0) {
00354       char *L_endstr ;
00355       
00356       GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() fielddef definition:" );
00357       
00358       L_value = L_data->find_value((char*)"name") ;
00359       if (L_value == NULL) {
00360         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef [" << L_fieldDefCpt << "] name value is mandatory");
00361         L_ret = -1 ;
00362         break ;
00363       }
00364       GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() field name ["
00365                 << L_fieldDefCpt <<"] is " << L_value );
00366 
00367 
00368       L_value_fielddef = L_data->find_value((char*)"value") ;
00369       if (L_value_fielddef != NULL) {
00370         L_counter_id = add_counter_id (L_value_fielddef, true) ;
00371         if (L_counter_id == -1) {
00372           L_ret = -1 ;
00373           break ;
00374         }
00375       }
00376       L_value_unit = L_data->find_value((char*)"unit") ;
00377       if (L_value_unit != NULL) {
00378         GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() field unit ["
00379                   << L_fieldDefCpt <<"] is " << L_value_unit );
00380         
00381         // temporary
00382         if (strcmp(L_value_unit, (char*)"octet") != 0) {
00383           GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported unit ["
00384                     << L_value_unit << "] value on fielddef [" << L_fieldDefCpt << "] defintion");
00385           L_ret = -1 ;
00386           break;
00387         }
00388 
00389         L_value_size = L_data->find_value((char*)"size") ;
00390         if (L_value_size == NULL) {
00391           GEN_ERROR(E_GEN_FATAL_ERROR, 
00392                 "fielddef [" << L_fieldDefCpt << "] size value is mandatory ["
00393                     << L_value << "]");
00394           L_ret = -1 ;
00395           break ;
00396         }
00397         L_size = strtoul_f (L_value_size, &L_endstr,10) ;
00398         GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() field length ["
00399                   << L_fieldDefCpt <<"] is " << L_size );
00400 
00401         if (L_endstr[0] != '\0') {
00402           L_size = strtoul_f (L_value_size, &L_endstr,16) ;
00403           if (L_endstr[0] != '\0') {
00404             GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
00405                       << L_value_size << "] bad format  on fielddef [" << L_fieldDefCpt << "] defintion");
00406             L_ret = -1 ;
00407             break ;
00408           }
00409         }
00410         if ( L_size > sizeof(unsigned long)) {
00411           GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef [" << L_fieldDefCpt 
00412                     << "] max size value ["  << sizeof(unsigned long) << "]");
00413           L_ret = -1 ;
00414           break ;
00415         }
00416 
00417         if (m_msg_length_start_detected == false) {
00418           m_msg_length_start += L_size ;
00419         }
00420 
00421         // Set default unset type
00422         L_typeId = -1;
00423 
00424         L_value_mask = L_data->find_value((char*)"mask") ;
00425         if (L_value_mask != NULL) {
00426           L_mask =  strtoul_f (L_value_mask, &L_endstr,10) ;
00427           if (L_endstr[0] != '\0') {
00428             L_mask = strtoul_f (L_value_mask, &L_endstr,16) ;
00429             if (L_endstr[0] != '\0') {
00430               GEN_ERROR(E_GEN_FATAL_ERROR, "typedef mask value ["
00431                         << L_value_mask 
00432                         << "] bad format  on fielddef [" 
00433                         << L_fieldDefCpt << "] defintion");
00434               L_ret = -1 ;
00435               break ;
00436             }
00437           }
00438           if (L_ret != -1) {
00439             L_mask_present  = true ; 
00440           }
00441         }
00442 
00443       } else {
00444         L_value_type = L_data->find_value((char*)"type") ;
00445         if (L_value_type == NULL) {
00446           GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef [" << L_fieldDefCpt 
00447                     << "] unit or type definition is mandatory");
00448           L_ret = -1 ;
00449           break ;
00450         }
00451         GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() field type ["
00452                   << L_fieldDefCpt <<"] is " << L_value_type );
00453 
00454         // retrieve size of type
00455         L_IdMapIt =
00456           m_type_id_map->find(T_IdMap::key_type(L_value_type));
00457         if (L_IdMapIt != m_type_id_map->end()) {
00458           L_typeId = L_IdMapIt->second ;
00459         } else {
00460           GEN_ERROR(E_GEN_FATAL_ERROR,
00461                 "Type ["
00462                 << L_value_type << "] not defined on fielddef [" << L_fieldDefCpt << "] definition");
00463           L_ret = -1 ;
00464           break;
00465         }
00466         L_size = m_type_def_table[L_typeId].m_size;
00467         GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() field length ["
00468                   << L_fieldDefCpt <<"] is " << L_size );
00469       }
00470 
00471       if (L_ret != -1) {
00472         L_id = add_header_field (L_value, 
00473                                  L_size,
00474                                  &m_nb_field_header,
00475                                  &m_header_size,
00476                                  m_header_field_table,
00477                                  m_header_id_map,
00478                                  L_counter_id,
00479                                  NULL,
00480                                  L_typeId);
00481 
00482 
00483         L_last_length_present = false ;
00484 
00485         if (strcmp(L_value, L_value_field_type) == 0) {
00486           set_header_type_id(L_id) ;
00487         }
00488         
00489         if (strcmp(L_value, L_value_field_length) == 0) {
00490           set_header_length_id(L_id) ;
00491         }
00492         
00493 
00494         if (L_mask_present) {
00495           ALLOC_VAR(L_presence_mask, T_pCondPresence, sizeof(T_CondPresence)) ;
00496           L_presence_mask->m_mask = L_mask ;
00497           L_presence_mask->m_f_id = L_id ;
00498           m_header_field_table[L_id].m_cond_presence = L_presence_mask ;
00499         }
00500 
00501       }
00502     } //     if (strcmp(L_value, (char*)"fielddef") == 0) 
00503 
00504     if (strcmp(L_value, (char*)"start-length") == 0) {
00505       m_msg_length_start_detected = true ;
00506     }
00507     
00508     if (strcmp(L_value, (char*)"length") == 0 ) {
00509       L_value = L_data->find_value((char*)"name") ;
00510       L_header_length_id = ctrl_length(L_value, true) ;
00511       if (L_header_length_id != -1) {
00512         L_header_length.m_id        = L_header_length_id ;
00513         L_header_length.m_start_id  =  L_id + 1 ;
00514         L_header_length.m_stop_id   = -1 ;
00515         L_header_length_list->push_back(L_header_length)      ;
00516         L_last_length_present = true;
00517       } else {
00518         L_ret = -1 ;
00519         break;
00520       }
00521     }
00522 
00523     if (strcmp(L_value, (char*)"end-length") == 0 ) {
00524       L_value = L_data->find_value((char*)"name") ;
00525       L_header_length_id = ctrl_length(L_value, true) ;
00526       if (L_header_length_id != -1 ) {
00527         L_ret = update_field_length(L_header_length_id, 
00528                                     L_id,
00529                                     L_header_length_list, 
00530                                     true);
00531         if (L_ret == -1) break ;
00532       } else {
00533         L_ret = -1 ;
00534         break;
00535       }
00536     }
00537   } // for
00538 
00539   if (m_msg_length_start_detected == false) {
00540     m_msg_length_start = 0 ;
00541   }
00542 
00543   if (m_nb_header_length > 0 ) {
00544     if (!L_header_length_list->empty()) {
00545       if (L_last_length_present == false) {
00546         m_counter_id_last_length = -1 ;
00547       }
00548       m_counter_id_last_length = L_id_length ;
00549       m_nb_header_length_table = L_header_length_list->size() ;
00550       ALLOC_TABLE(m_header_length_table,
00551                   T_pProtocolCounterData,
00552                   sizeof(T_ProtocolCounterData),
00553                   m_nb_header_length_table);
00554       L_id = 0 ;
00555       for (L_it  = L_header_length_list->begin();
00556            L_it != L_header_length_list->end()  ;
00557            L_it++) {
00558 
00559         L_header_length   = *L_it ;
00560         m_header_length_table [L_id] = *L_it  ;
00561         L_id ++ ;
00562       }
00563       L_header_length_list->erase(L_header_length_list->begin(),
00564                                   L_header_length_list->end());
00565 
00566       ALLOC_TABLE(m_header_ctxt_v_table,
00567                   T_pUpdateCtxtValue,
00568                   sizeof(T_UpdateCtxtValue),
00569                   m_nb_field_header);
00570 
00571       
00572       for (L_i = 0; L_i < (int)m_nb_field_header; L_i++) {
00573         m_header_ctxt_v_table[L_i].m_nb_ctxt_id = 0 ;
00574         m_header_ctxt_v_table[L_i].m_ctxt_id_setted = NULL ;
00575       }
00576       
00577       L_ret = update_ctxt_v_field (m_header_ctxt_v_table,
00578                                    (int)m_nb_field_header,
00579                                    m_header_length_table,
00580                                    m_nb_header_length,
00581                                    NULL, -1);
00582 
00583       ALLOC_TABLE(m_header_ctxt_p_table,
00584                   T_pUpdateCtxtPosition,
00585                   sizeof(T_UpdateCtxtPosition),
00586                   m_nb_field_header);
00587       
00588       for (L_i = 0; L_i < (int)m_nb_field_header; L_i++) {
00589         if (m_header_field_table[L_i].m_counter_id != -1) {
00590           m_header_ctxt_p_table[L_i].m_nb_ctxt_pos = 1    ;
00591           m_header_ctxt_p_table[L_i].m_ctxt_id_pos = m_header_field_table[L_i].m_counter_id ;
00592         } else {
00593           m_header_ctxt_p_table[L_i].m_nb_ctxt_pos = 0    ;
00594           m_header_ctxt_p_table[L_i].m_ctxt_id_pos = -1   ;
00595         }
00596       }
00597     } // if (!L_header_length_list->empty()) 
00598   }
00599   
00600   if (m_header_length_id == -1) {
00601     GEN_WARNING("length field name not defined in protocol");
00602   }
00603 
00604   GEN_DEBUG(1, "C_ProtocolTlv::get_header_from_xml() end");
00605 
00606   return (L_ret);
00607 }
00608 
00609 int C_ProtocolTlv::analyze_types_from_xml (C_XmlData *P_def) {
00610 
00611   int                       L_ret = 0 ;
00612   C_XmlData                *L_data    ;
00613 
00614   GEN_DEBUG(1, "C_ProtocolTlv::analyze_types_from_xml() start");
00615 
00616   L_data = P_def ;
00617 
00618   m_max_nb_types = (L_data->get_sub_data())->size() ;
00619   ALLOC_TABLE(m_type_def_table,
00620               T_pTypeDef, sizeof(T_TypeDef),
00621               m_max_nb_types);
00622   L_ret = get_types_from_xml(L_data);
00623 
00624   GEN_DEBUG(1, "C_ProtocolTlv::analyze_types_from_xml() end");
00625   return (L_ret) ;
00626 }
00627 
00628 int C_ProtocolTlv::analyze_header_from_xml (C_XmlData *P_def) {
00629 
00630   int                       L_ret = 0 ;
00631   C_XmlData                *L_data    ;
00632   
00633   GEN_DEBUG(1, "C_ProtocolTlv::analyze_header_from_xml() start");
00634 
00635   L_data = P_def ;
00636 
00637   m_max_nb_field_header = (L_data->get_sub_data())->size() ;
00638 
00639   m_nb_field_header = 0 ;
00640   ALLOC_TABLE(m_header_field_table, 
00641               T_pHeaderField, sizeof(T_HeaderField), 
00642               m_max_nb_field_header) ;
00643   L_ret = get_header_from_xml(L_data);
00644 
00645   GEN_DEBUG(1, "C_ProtocolTlv::analyze_header_from_xml() end");
00646   return (L_ret) ;
00647 }
00648 
00649 
00650 int C_ProtocolTlv::analyze_body_from_xml (C_XmlData *P_def) {
00651   int                       L_ret = 0                       ;
00652   C_XmlData                *L_data                          ;
00653   
00654   T_pXmlData_List           L_subListHeader, L_subListValue ;
00655   T_XmlData_List::iterator  L_listItHeader, L_listItValue   ; 
00656   
00657   int                       L_nb_optional_field = 0         ; 
00658   bool                      L_headerBodyFound = false       ;
00659 
00660   
00661   GEN_DEBUG(1, "C_ProtocolTlv::analyze_body_from_xml() start");
00662   
00663   L_subListHeader = P_def->get_sub_data();
00664   
00665   if (L_subListHeader != NULL) {
00666     
00667     for (L_listItHeader = L_subListHeader->begin() ;
00668          L_listItHeader != L_subListHeader->end() ;
00669          L_listItHeader++) {
00670       L_data = *L_listItHeader ;
00671 
00672       if ((L_data->get_name() != NULL ) && (strcmp(L_data->get_name(), (char*)"header") == 0)) {
00673         
00674         if (L_data->get_sub_data() != NULL) {
00675           
00676           // header definition for body values
00677           m_max_nb_field_header_body = (L_data->get_sub_data())->size() ;
00678 
00679           L_subListValue = L_data->get_sub_data () ;
00680           for (L_listItValue = L_subListValue->begin();
00681                L_listItValue != L_subListValue->end();
00682                L_listItValue ++) {
00683 
00684             if ( (strcmp((*L_listItValue)->get_name(), (char*)"length" ) == 0) ||
00685                  (strcmp((*L_listItValue)->get_name(), (char*)"end-length" ) == 0)) { 
00686               m_max_nb_field_header_body -- ;
00687             }
00688 
00689             if ( strcmp((*L_listItValue)->get_name(), 
00690                         (char*) "optional" ) == 0) { 
00691               if (L_nb_optional_field == 0) {
00692                 m_max_nb_field_header_body -- ;
00693                 if ((*L_listItValue)->get_sub_data() != NULL) {
00694                   L_nb_optional_field
00695                     = ((*L_listItValue)->get_sub_data())->size() ;
00696                 }
00697               } else {
00698                 GEN_ERROR(E_GEN_FATAL_ERROR, 
00699                           "Only one section optional is allowed");
00700                 L_ret = -1 ;
00701                 break ;
00702               }
00703             } else {
00704               if (L_nb_optional_field != 0) {
00705                 GEN_ERROR(E_GEN_FATAL_ERROR, 
00706                           "The section optional must be"
00707                           << " at the end of header");
00708                 L_ret = -1 ;
00709                 break ;
00710               }
00711             }
00712           }
00713 
00714           if (L_ret == -1) break ;
00715           m_max_nb_field_header_body += L_nb_optional_field ;
00716           m_nb_field_header_body = 0 ;
00717           L_headerBodyFound = true ;
00718           ALLOC_TABLE(m_header_body_field_table, 
00719                       T_pHeaderField, sizeof(T_HeaderField), 
00720                       m_max_nb_field_header_body) ;
00721           L_ret = get_header_body_from_xml (L_data);
00722           if (L_ret == -1) break ;
00723         } // get_sub_data != NULL
00724       } // if ((L_data->get_name() != NULL )
00725     }   // for (L_listItHeader = L_subListHeader->begin()
00726     
00727     if (L_headerBodyFound == false)  {
00728       L_ret = -1 ;
00729       GEN_ERROR(E_GEN_FATAL_ERROR, "No body definition found for protocol");
00730     }
00731     
00732   } // if (L_subListHeader != NULL) 
00733   
00734   GEN_DEBUG(1, "C_ProtocolTlv::analyze_body_from_xml() end");
00735   return (L_ret);
00736 }
00737 
00738 int C_ProtocolTlv::analyze_dictionnary_from_xml (C_XmlData *P_def) {
00739 
00740   int                       L_ret = 0                      ;
00741   C_XmlData                *L_data                         ;
00742   T_pXmlData_List           L_subListDico                  ;  
00743   T_XmlData_List::iterator  L_listItDico                   ; 
00744   bool                      L_headerValueFound = false     ;
00745   bool                      L_headerBodyValueFound = false ;  
00746   int                       L_i                            ;
00747 
00748   GEN_DEBUG(1, "C_ProtocolTlv::analyze_dictionnary_from_xml() start");
00749 
00750   L_subListDico = P_def->get_sub_data();
00751   if (L_subListDico != NULL) {
00752 
00753     for (L_listItDico = L_subListDico->begin() ;
00754          L_listItDico != L_subListDico->end() ;
00755          L_listItDico++) {
00756       L_data = *L_listItDico ;
00757       
00758       GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() L_data->get_name is \"" 
00759                 << L_data->get_name() << "\"");
00760       GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() m_header_name is \"" 
00761                 << m_header_name << "\" and m_header_body_name is \"" << 
00762                 m_header_body_name << "\"" ); 
00763       
00764       if ((L_data->get_name() != NULL ) 
00765           && (strcmp(L_data->get_name(), m_header_name) == 0)) {
00766         // "Message" defintion
00767  
00768         L_ret = analyze_sessions_id_from_xml(L_data);
00769         if (L_ret == -1) break;
00770         // header values dictionnary definitions
00771 
00772         if (L_data->get_sub_data() != NULL) {
00773           L_headerValueFound = true ;
00774           
00775           m_nb_header_values = (L_data->get_sub_data())->size() ;
00776           
00777           ALLOC_TABLE(m_header_value_table,
00778                       T_pHeaderValue,
00779                       sizeof(T_HeaderValue),
00780                       m_nb_header_values);
00781           
00782           ALLOC_TABLE(m_body_value_table,
00783                       T_pBodyValueDef,
00784                       sizeof(T_BodyValueDef),
00785                       m_nb_header_values);
00786           for (L_i = 0; L_i < (int)m_nb_header_values; L_i++) {
00787             m_body_value_table[L_i].m_nb_values = 0 ;
00788             m_body_value_table[L_i].m_value_table = NULL ;
00789           }
00790           L_ret = get_header_values_from_xml (L_data);
00791           if (L_ret == -1) break ;
00792         }
00793       }
00794       
00795       if ((L_data->get_name() != NULL ) 
00796           && (strcmp(L_data->get_name(), m_header_body_name) == 0)) {
00797         // body values dictionnary definitions
00798         if (L_data->get_sub_data() != NULL) {
00799           L_headerBodyValueFound = true ;
00800           m_nb_header_body_values = (L_data->get_sub_data())->size() ;
00801           
00802           GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() m_nb_header_body_values is " << 
00803                     m_nb_header_body_values);
00804           L_ret = get_header_body_values_from_xml (L_data);
00805           if (L_ret == -1) break ;
00806         }
00807       }
00808 
00809     } // for (L_listItDico = L_subListDico->begin()
00810   } // L_subListDico
00811 
00812   if (L_ret != -1) {
00813     if (L_headerValueFound == false) {
00814       char *L_name = (m_header_name == NULL) ? 
00815         (char*)"no" : m_header_name ;
00816       GEN_WARNING("No section [" << L_name << "] found");
00817     } 
00818   }
00819   
00820 #ifdef DEBUG_MODE
00821   {
00822     char *L_name = (m_header_name == NULL) ? (char*)"no" : m_header_name ;
00823     GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() "
00824               << "header_name = ["
00825               << L_name << "]");
00826   }
00827 #endif
00828 
00829   if (L_ret != -1) {
00830     if (L_headerBodyValueFound == false) {
00831       char* L_name = (m_header_body_name == NULL) ? 
00832         (char*)"no" : m_header_body_name ;
00833       GEN_WARNING("No section [" << L_name << "] found");
00834     }
00835   }
00836   
00837 #ifdef DEBUG_MODE
00838   {
00839     char* L_name = (m_header_body_name == NULL) ? 
00840       (char*)"no" : m_header_body_name ;
00841     GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() "
00842               << "header_body_name = ["
00843               <<  L_name
00844               << "]");
00845   }
00846 #endif
00847  
00848   
00849   GEN_DEBUG(1, "C_ProtocolTlv::analyze_dictionnary_from_xml() end");
00850   return (L_ret);
00851 }
00852 
00853 
00854 int C_ProtocolTlv::xml_interpretor(C_XmlData *P_def) {
00855 
00856   C_XmlData                *L_data                           ;
00857   T_pXmlData_List           L_subList                        ; 
00858   T_XmlData_List::iterator  L_listIt                         ;
00859   char                     *L_value                          ;
00860   int                       L_ret = 0                        ;
00861 
00862   bool                      L_headerFound = false            ;
00863 
00864   GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() start");
00865 
00866 
00867   m_nb_header_values = 0 ;
00868   m_header_value_table = NULL ;
00869   m_body_value_table = NULL ;
00870   NEW_VAR(m_header_value_id_map, T_IdMap());
00871   NEW_VAR(m_header_decode_map, T_DecodeMap());
00872   m_header_value_id_map->clear();
00873   m_header_decode_map->clear();
00874 
00875   m_nb_header_body_values = 0 ;
00876   m_header_body_value_table = NULL ;
00877   NEW_VAR(m_header_body_value_id_map, T_IdMap());
00878   NEW_VAR(m_header_body_decode_map, T_DecodeMap());
00879   m_header_body_value_id_map->clear();
00880   m_header_body_decode_map->clear();
00881 
00882   L_subList = P_def->get_sub_data() ;
00883   if (L_subList == NULL) {
00884     GEN_ERROR(E_GEN_FATAL_ERROR, "No protocol definition");
00885     L_ret = -1 ;
00886   } else {
00887 
00888     for(L_listIt  = L_subList->begin() ;
00889         L_listIt != L_subList->end() ;
00890         L_listIt++) {
00891 
00892       L_data = *L_listIt ;
00893       L_value = L_data->get_name() ;
00894 
00895       // Type definition
00896       if (strcmp(L_value, "types") == 0) {
00897         L_ret = analyze_types_from_xml (L_data) ;
00898         if (L_ret == -1) break ;
00899       }
00900       
00901       // Message Header definition
00902       if (strcmp(L_value, "header") ==0) {
00903         L_headerFound = true ;
00904         L_ret = analyze_header_from_xml (L_data) ;
00905         if (L_ret == -1) break ;
00906       }
00907 
00908       // Message Body definition
00909       if (strcmp(L_value, "body") ==0) {
00910         L_ret = analyze_body_from_xml (L_data);
00911         if (L_ret == -1) break ;
00912       } // body
00913 
00914       // Message dictionary for "fields" and "Message" definition
00915       if (strcmp(L_value, (char*)"dictionary") ==0) {
00916         //        L_ret = analyze_dictionnary_from_xml (L_data, &L_session_id_name, &L_outof_session_id_name);
00917         L_ret = analyze_dictionnary_from_xml (L_data);
00918         if (L_ret == -1) break ;
00919       } // L_value == dico
00920 
00921     } // L_listIt
00922 
00923     if (L_headerFound == false) {
00924       L_ret = -1 ;
00925       GEN_ERROR(E_GEN_FATAL_ERROR, "No header definition found for protocol");
00926     }
00927   } // else 
00928 
00929   GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() end");
00930   return (L_ret) ;
00931 }
00932 
00933 C_ProtocolTlv::C_ProtocolTlv() {
00934 
00935 
00936   GEN_DEBUG(1, "C_ProtocolTlv::C_ProtocolTlv() start");
00937 
00938   m_header_size = (unsigned long) 0 ;
00939   m_header_body_size = (unsigned long) 0;
00940   m_nb_types = 0 ;
00941   m_header_body_start_optional_id = -1 ; // no optional
00942   m_header_type_id = -1 ;
00943   m_header_type_id_body = -1 ; // no optional
00944   m_header_complex_type_presence = false;
00945   m_header_length_excluded = false ;
00946   m_padding_value = 0 ;
00947 
00948   m_header_name = NULL ;
00949   m_header_body_name = NULL ;
00950   m_nb_header_body_values = 0;
00951   m_max_nb_field_header_body = 0;
00952   m_header_body_field_table = NULL;
00953 
00954   m_header_length_id = -1 ;
00955   m_transport_type = 0 ;
00956 
00957   m_header_body_type_id = -1 ;
00958   m_header_body_length_id = -1;
00959   
00960   m_header_body_field_separator = NULL ;
00961 
00962   m_msg_length_start = (unsigned long) 0 ;
00963   m_msg_length_start_detected = false    ;
00964 
00965   NEW_VAR (m_message_name_list, T_NameAndIdList()) ;
00966   NEW_VAR (m_message_comp_name_list, T_NameAndIdList()) ;
00967 
00968   m_session_id_position = -1 ;
00969 
00970   NEW_VAR(m_length_map, T_LengthIdMap()) ;
00971   m_length_map->clear()                  ;
00972   m_length_max = -1                      ;
00973   m_header_length_table = NULL           ;         
00974   m_nb_header_length_table   = 0         ;
00975   m_nb_header_length         = 0         ;
00976   m_header_body_length_table = NULL      ;
00977   m_nb_header_body_length_table  = 0     ;
00978   m_nb_header_body_length        = 0     ;
00979 
00980   m_counter_id_last_length = -1 ;
00981   
00982   m_header_ctxt_v_table = NULL ;
00983   m_header_body_ctxt_v_table = NULL ;
00984 
00985   m_header_ctxt_p_table  = NULL      ;
00986   m_header_body_ctxt_p_table  = NULL ;
00987   m_nb_protocol_ctxt_values = 0 ;
00988   
00989   m_ctxt_id_data_size = -1 ;
00990 
00991   GEN_DEBUG(1, "C_ProtocolTlv::C_ProtocolTlv() end");
00992   
00993 }
00994 
00995 
00996 void C_ProtocolTlv::construction_data(C_XmlData *P_def,
00997                                       char      **P_name,
00998                                       T_pContructorResult P_res) {
00999 
01000   char         *L_string_val ;
01001   char         *L_endstr = NULL ;
01002   unsigned long L_val ;
01003 
01004   T_ConstructorResult L_res = E_CONSTRUCTOR_OK ;
01005 
01006   if (P_def) {
01007     NEW_VAR(m_header_id_map, T_IdMap());
01008     m_header_id_map->clear();
01009 
01010     NEW_VAR(m_messageList, list_t<C_MessageFrame*>);
01011     m_messageList->clear();
01012 
01013     NEW_VAR(m_header_body_id_map, T_IdMap());
01014     m_header_body_id_map->clear();
01015 
01016     NEW_VAR(m_type_id_map, T_IdMap());
01017     m_type_id_map->clear();
01018 
01019     *P_name = P_def->find_value((char*)"name") ;
01020     if (*P_name == NULL) {
01021       GEN_ERROR(E_GEN_FATAL_ERROR, 
01022                 "No name for protocol definition");
01023       L_res = E_CONSTRUCTOR_KO ;
01024     }
01025 
01026     if (L_res == E_CONSTRUCTOR_OK) {
01027       m_name = *P_name ;
01028       
01029       L_string_val = P_def->find_value((char*)"padding");
01030       if (L_string_val != NULL) {
01031         
01032         L_val = strtoul_f (L_string_val, &L_endstr,10) ;
01033         if (L_endstr[0] != '\0') {
01034           GEN_ERROR(E_GEN_FATAL_ERROR, "bad format ["
01035                     << L_string_val << "] number expected for padding");
01036         } else {
01037           m_padding_value = L_val ;
01038         }
01039       }
01040       
01041       L_string_val = P_def->find_value((char*)"length");
01042       if (L_string_val != NULL) {
01043         if (strcmp(L_string_val, (char*)"header-excluded") == 0) {
01044           m_header_length_excluded = true ;
01045         }
01046       }
01047       
01048 
01049       *P_res = (xml_interpretor(P_def) ==0) 
01050         ? E_CONSTRUCTOR_OK : E_CONSTRUCTOR_KO ;
01051     } else {
01052       *P_res = L_res ;
01053     }
01054 
01055   } else {
01056     *P_res = E_CONSTRUCTOR_KO ;
01057     m_header_id_map = NULL ;
01058   }
01059 
01060   GEN_DEBUG(1, "C_ProtocolTlv::C_ProtocolTlv() start");
01061 }
01062 
01063 void C_ProtocolTlv::set_padding(unsigned long P_value) {
01064   m_padding_value = P_value ;
01065 }
01066 
01067 C_ProtocolTlv::~C_ProtocolTlv() {
01068 
01069   int L_i ;
01070 
01071   GEN_DEBUG(1, "C_ProtocolTlv::~C_ProtocolTlv() start");
01072 
01073 
01074   // Add clear the map message 
01075   if (m_messageList != NULL)
01076   {
01077     if (!m_messageList->empty()) {
01078       list_t<C_MessageFrame*>::iterator L_messageIt;
01079       C_MessageTlv                  *L_msg;
01080       for (L_messageIt = m_messageList->begin();
01081            L_messageIt !=  m_messageList->end();
01082            L_messageIt++)
01083       {
01084         L_msg = dynamic_cast<C_MessageTlv*>(*L_messageIt);
01085         DELETE_VAR(L_msg);
01086       }
01087       m_messageList->erase(m_messageList->begin(), m_messageList->end());
01088     }
01089     DELETE_VAR(m_messageList);
01090   }
01091 
01092   m_header_size = (unsigned long) 0 ;
01093 
01094 
01095   for (L_i = 0 ; L_i < (int)m_max_nb_field_header; L_i++) {
01096     FREE_VAR(m_header_field_table[L_i].m_cond_presence);
01097   }
01098   FREE_TABLE(m_header_field_table);
01099 
01100   m_nb_field_header = 0 ;
01101   m_max_nb_field_header = 0 ;
01102   m_header_type_id = -1 ;
01103   m_header_length_id = -1 ;
01104 
01105   m_header_body_length_id = -1;
01106 
01107 
01108   if (m_header_id_map != NULL) {
01109     if (!m_header_id_map->empty()) {
01110       m_header_id_map->erase(m_header_id_map->begin(), m_header_id_map->end());
01111     }
01112   }
01113   DELETE_VAR(m_header_id_map);
01114 
01115   m_header_body_size = (unsigned long) 0 ;
01116   
01117   if (m_header_body_field_table != NULL) {
01118     for (L_i = 0 ; L_i < (int)m_max_nb_field_header_body; L_i++) {
01119       FREE_VAR(m_header_body_field_table[L_i].m_cond_presence);
01120     }
01121     FREE_TABLE(m_header_body_field_table);
01122   }
01123 
01124   FREE_TABLE(m_type_def_table);
01125 
01126   if (m_header_body_id_map != NULL) {
01127     if (!m_header_body_id_map->empty()) {
01128       m_header_body_id_map->erase(m_header_body_id_map->begin(), m_header_body_id_map->end());
01129     }
01130   }
01131   DELETE_VAR(m_header_body_id_map);
01132 
01133   if (m_type_id_map != NULL) {
01134     if (!m_type_id_map->empty()) {
01135       m_type_id_map->erase(m_type_id_map->begin(), m_type_id_map->end());
01136     }
01137   }
01138   DELETE_VAR(m_type_id_map);
01139 
01140 
01141   for (L_i = 0; L_i < (int)m_nb_header_body_values; L_i++) {
01142     FREE_TABLE(m_header_body_value_table[L_i].m_id_value_setted);
01143     FREE_TABLE(m_header_body_value_table[L_i].m_value_setted);
01144     FREE_TABLE(m_header_body_value_table[L_i].m_values);
01145     FREE_TABLE(m_header_body_value_table[L_i].m_size);
01146   }
01147   FREE_TABLE(m_header_body_value_table);
01148 
01149 
01150   for (L_i = 0; L_i < (int)m_nb_header_values; L_i++) {
01151     FREE_TABLE(m_header_value_table[L_i].m_id_value_setted);
01152     FREE_TABLE(m_header_value_table[L_i].m_value_setted);
01153     FREE_TABLE(m_header_value_table[L_i].m_values);
01154   }
01155   FREE_TABLE(m_header_value_table);
01156 
01157   for (L_i = 0; L_i < (int)m_nb_header_values; L_i++) {
01158     FREE_TABLE(m_body_value_table[L_i].m_value_table);
01159   }
01160   FREE_TABLE(m_body_value_table);
01161 
01162   if (m_header_value_id_map != NULL) {
01163     if (!m_header_value_id_map->empty()) {
01164       m_header_value_id_map
01165         ->erase(m_header_value_id_map->begin(), 
01166                 m_header_value_id_map->end());
01167     }
01168   }
01169   DELETE_VAR(m_header_value_id_map);
01170   if (m_header_decode_map != NULL) {
01171     if (!m_header_decode_map->empty()) {
01172       m_header_decode_map->erase(m_header_decode_map->begin(), 
01173                                  m_header_decode_map->end());
01174     }
01175   }
01176   DELETE_VAR(m_header_decode_map);
01177 
01178   if (m_header_body_value_id_map != NULL) {
01179     if (!m_header_body_value_id_map->empty()) {
01180       m_header_body_value_id_map
01181         ->erase(m_header_body_value_id_map->begin(), 
01182                 m_header_body_value_id_map->end());
01183     }
01184   }
01185   DELETE_VAR(m_header_body_value_id_map);
01186   if (m_header_body_decode_map != NULL) {
01187     if (!m_header_body_decode_map->empty()) {
01188       m_header_body_decode_map->erase(m_header_body_decode_map->begin(), 
01189                                  m_header_body_decode_map->end());
01190     }
01191   }
01192   DELETE_VAR(m_header_body_decode_map);
01193 
01194 
01195   DELETE_VAR(m_stats);
01196   if(! m_message_name_list -> empty()) {
01197     T_NameAndIdList::iterator  L_elt_it ;
01198     T_NameAndId                L_elt    ;
01199 
01200     for(L_elt_it=m_message_name_list->begin();
01201         L_elt_it != m_message_name_list->end();
01202         L_elt_it++) {
01203       L_elt = *L_elt_it ;
01204       FREE_TABLE(L_elt.m_name);
01205     }
01206     m_message_name_list -> erase (m_message_name_list->begin(), m_message_name_list->end());
01207   }
01208   DELETE_VAR (m_message_name_list) ;
01209 
01210   if(! m_message_comp_name_list -> empty()) {
01211     T_NameAndIdList::iterator  L_elt_it ;
01212     T_NameAndId                L_elt    ;
01213     
01214     for(L_elt_it=m_message_comp_name_list->begin();
01215         L_elt_it != m_message_comp_name_list->end();
01216         L_elt_it++) {
01217       L_elt = *L_elt_it ;
01218       FREE_TABLE(L_elt.m_name);
01219     }
01220     m_message_comp_name_list -> erase (m_message_comp_name_list->begin(), 
01221                                        m_message_comp_name_list->end());
01222   }
01223   DELETE_VAR (m_message_comp_name_list) ;
01224 
01225   m_header_body_field_separator = NULL ;
01226   m_session_id_position = -1 ;
01227   m_transport_type = 0 ;
01228 
01229   m_length_max = -1 ;
01230   if (!m_length_map->empty()) {
01231     m_length_map->erase(m_length_map->begin(), m_length_map->end());
01232   }
01233   DELETE_VAR(m_length_map);
01234 
01235 
01236   if (m_nb_header_length_table   != 0)  {
01237     FREE_TABLE(m_header_length_table);
01238     m_nb_header_length_table = 0 ;
01239   }
01240   m_nb_header_length         = 0         ;
01241 
01242   if (m_nb_header_body_length_table   != 0)  {
01243     FREE_TABLE(m_header_body_length_table);
01244     m_nb_header_body_length_table = 0 ;
01245   }
01246   m_nb_header_body_length        = 0     ;
01247 
01248 
01249   for (L_i = 0; L_i < (int)m_nb_field_header;L_i++) {
01250     FREE_TABLE(m_header_ctxt_v_table[L_i].m_ctxt_id_setted);
01251     m_header_ctxt_v_table[L_i].m_nb_ctxt_id = 0 ;
01252   }
01253   FREE_TABLE(m_header_ctxt_v_table);
01254 
01255   for (L_i = 0; L_i < (int)m_nb_field_header_body;L_i++) {
01256     FREE_TABLE(m_header_body_ctxt_v_table[L_i].m_ctxt_id_setted);
01257     m_header_body_ctxt_v_table[L_i].m_nb_ctxt_id = 0 ;
01258   }
01259   FREE_TABLE(m_header_body_ctxt_v_table);
01260 
01261   FREE_TABLE(m_header_ctxt_p_table);
01262   FREE_TABLE(m_header_body_ctxt_p_table);
01263   m_nb_protocol_ctxt_values = 0 ;
01264 
01265   m_counter_id_last_length = -1 ;
01266   m_ctxt_id_data_size = -1 ;
01267 
01268   GEN_DEBUG(1, "C_ProtocolTlv::~C_ProtocolTlv() end");
01269 
01270 }
01271 
01272 bool C_ProtocolTlv::get_header_length_excluded () {
01273   return(m_header_length_excluded);
01274 }
01275 
01276 unsigned long C_ProtocolTlv::get_msg_length_start () {
01277   return(m_msg_length_start);
01278 }
01279 
01280 bool C_ProtocolTlv::get_msg_length_start_detected () {
01281   return(m_msg_length_start_detected);
01282 }
01283 
01284 int C_ProtocolTlv::get_types_from_xml (C_XmlData *P_def) {
01285 
01286   C_XmlData                *L_data ;
01287   T_XmlData_List::iterator  L_listIt ;
01288   T_pXmlData_List           L_subList ;
01289   char                     *L_value, 
01290     *L_type_name,
01291     *L_type_type,
01292     *L_type_size, 
01293     *L_type_unit ;
01294   int                       L_ret = 0 ;
01295   unsigned long             L_size    = 0;
01296   T_TypeType                L_type    = E_UNSUPPORTED_TYPE ;
01297   int                       L_i ;
01298 
01299   int                       L_id      ;
01300   
01301   GEN_DEBUG(1, "C_ProtocolTlv::get_types_from_xml() start");
01302   L_subList = P_def->get_sub_data() ;
01303 
01304   for(L_listIt  = L_subList->begin() ;
01305       L_listIt != L_subList->end() ;
01306       L_listIt++) {
01307 
01308     L_data = *L_listIt ;
01309     L_value = L_data->get_name() ;
01310 
01311     if (strcmp(L_value, (char*)"typedef") == 0) {
01312       char *L_endstr = NULL ;
01313 
01314       L_type_name = L_data->find_value((char*)"name") ;
01315       if (L_type_name == NULL) {
01316         GEN_ERROR(E_GEN_FATAL_ERROR, "typedef name value is mandatory");
01317         L_ret = -1 ;
01318         break ;
01319       }
01320       GEN_DEBUG(1, "C_ProtocolTlv::get_types_from_xml() typedef name is " << L_type_name);
01321 
01322       L_type_type = L_data->find_value((char*)"type") ;
01323       if (L_type_type == NULL) {
01324         GEN_ERROR(E_GEN_FATAL_ERROR, "typedef type value is mandatory for " << L_type_name);
01325         L_ret = -1 ;
01326         break ;
01327       }
01328       GEN_DEBUG(1, "C_ProtocolTlv::get_types_from_xml() typedef type is " << L_type_type);
01329 
01330       L_type = E_UNSUPPORTED_TYPE ;
01331       for(L_i=0; L_i < (int) E_UNSUPPORTED_TYPE; L_i++) {
01332         if (strcmp(L_type_type, type_type_table[L_i])==0) {
01333           L_type = (T_TypeType) L_i ;
01334         }
01335       }
01336       if (L_type == E_UNSUPPORTED_TYPE) {
01337         GEN_ERROR(E_GEN_FATAL_ERROR, "typedef type value ["
01338               << L_type_type << "] unsupported for " << L_type_name);
01339         L_ret = -1 ;
01340         break ;
01341       }
01342       
01343 
01344       switch (L_type) {
01345       case E_TYPE_NUMBER:
01346       case E_TYPE_SIGNED:
01347 
01348         L_type_size = L_data->find_value((char*)"size") ;
01349         if (L_type_size == NULL) {
01350           GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value is mandatory for "
01351                       << L_type_name);
01352           L_ret = -1 ;
01353           break ;
01354         }
01355         L_size = strtoul_f (L_type_size, &L_endstr,10) ;
01356         if (L_endstr[0] != '\0') {
01357           L_size = strtoul_f (L_type_size, &L_endstr,16) ;
01358           if (L_endstr[0] != '\0') {
01359             GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
01360                       << L_type_size << "] bad format for "
01361                       << L_type_name);
01362             L_ret = -1 ;
01363             break ;
01364           }
01365         }
01366 
01367 
01368         if ( L_size > sizeof(T_UnsignedInteger32)) {
01369            GEN_ERROR(E_GEN_FATAL_ERROR, "typedef max size value ["  
01370                      << L_size << "] for " << L_type_name << " instead of ["
01371                      << sizeof(T_UnsignedInteger32) << "]" );
01372            L_ret = -1 ;
01373            break ;
01374         }
01375 
01376 
01377         L_type_unit = L_data->find_value((char*)"unit") ;
01378         if (L_type_unit == NULL) {
01379           GEN_ERROR(E_GEN_FATAL_ERROR, "typedef unit value is mandatory for "
01380                     << L_type_name);
01381           L_ret = -1 ;
01382           break ;
01383         }
01384 
01385         // temporary
01386         if (strcmp(L_type_unit, (char*)"octet") != 0) {
01387           GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported unit ["
01388                 << L_type_unit << "] value for "
01389                 << L_type_name);
01390           L_ret = -1 ;
01391           break;
01392         }
01393         break ;
01394 
01395       case E_TYPE_STRUCT:
01396         L_size = 8;
01397         break ;
01398 
01399       case E_TYPE_STRING:
01400 
01401         L_type_size = L_data->find_value((char*)"size") ;
01402         if (L_type_size == NULL) {
01403           // Has before
01404           L_size = 0;
01405         } else {
01406           L_size = strtoul_f (L_type_size, &L_endstr,10) ;
01407           if (L_endstr[0] != '\0') {
01408             L_size = strtoul_f (L_type_size, &L_endstr,16) ;
01409             if (L_endstr[0] != '\0') {
01410               GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
01411                         << L_type_size << "] bad format for "
01412                         << L_type_name);
01413               L_ret = -1 ;
01414               break ;
01415             }
01416           }
01417         }
01418 
01419         L_type_unit = L_data->find_value((char*)"unit") ;
01420         if (L_type_unit == NULL) {
01421           GEN_ERROR(E_GEN_FATAL_ERROR, "typedef unit value is mandatory for "
01422                     << L_type_name);
01423           L_ret = -1 ;
01424           break ;
01425         }
01426         // temporary
01427         if (strcmp(L_type_unit, (char*)"octet") != 0) {
01428           GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported unit ["
01429                 << L_type_unit << "] value for " << L_type_name);
01430           L_ret = -1 ;
01431           break;
01432         }
01433         break ;
01434 
01435       case E_TYPE_NUMBER_64:
01436       case E_TYPE_SIGNED_64:
01437 
01438         L_type_size = L_data->find_value((char*)"size") ;
01439         if (L_type_size == NULL) {
01440           GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value is mandatory for "
01441                     << L_type_name);
01442           L_ret = -1 ;
01443           break ;
01444         }
01445         L_size = strtoull_f (L_type_size, &L_endstr,10) ;
01446         if (L_endstr[0] != '\0') {
01447           L_size = strtoull_f (L_type_size, &L_endstr,16) ;
01448           if (L_endstr[0] != '\0') {
01449             GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
01450                       << L_type_size << "] bad format for "
01451                       << L_type_name);
01452             L_ret = -1 ;
01453             break ;
01454           }
01455         }
01456 
01457         if ( L_size > sizeof(T_UnsignedInteger64)) {
01458            GEN_ERROR(E_GEN_FATAL_ERROR, "typedef max size value ["  
01459                      << L_size << "] for " << L_type_name << " instead of ["
01460                      << sizeof(T_UnsignedInteger64) << "]" );
01461            L_ret = -1 ;
01462            break ;
01463         }
01464 
01465         L_type_unit = L_data->find_value((char*)"unit") ;
01466         if (L_type_unit == NULL) {
01467           GEN_ERROR(E_GEN_FATAL_ERROR, "typedef unit value is mandatory for "
01468                     << L_type_name);
01469           L_ret = -1 ;
01470           break ;
01471         }
01472 
01473         // temporary
01474         if (strcmp(L_type_unit, (char*)"octet") != 0) {
01475           GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported unit ["
01476                 << L_type_unit << "] value for " << L_type_name);
01477           L_ret = -1 ;
01478           break;
01479         }
01480         break ;
01481 
01482       default :
01483         L_size = 0 ;
01484         break ;
01485       }
01486 
01487 
01488       if (L_ret != -1) {
01489 
01490         L_id = add_type(L_type_name, L_type, L_size);
01491         m_type_id_map->insert(T_IdMap::value_type(L_type_name, L_id));
01492         
01493       }
01494     } // if (strcmp(L_value, (char*)"typedef") == 0)
01495   } // for
01496 
01497   GEN_DEBUG(1, "C_ProtocolTlv::get_types_from_xml() end");
01498   return (L_ret);
01499 }
01500 
01501 int C_ProtocolTlv::get_header_body_from_xml (C_XmlData *P_def) {
01502 
01503   C_XmlData                *L_data ;
01504   T_XmlData_List::iterator  L_listIt ;
01505   T_pXmlData_List           L_subList ;
01506   char                     *L_value, *L_value_size, *L_value_unit ;
01507   char                     *L_value_field_length, *L_value_field_type ;
01508   int                       L_ret = 0 ;
01509   unsigned long             L_size    ;
01510   int                       L_id  = -1    ;
01511 
01512   char                                   *L_value_fielddef                   ;
01513   int                                     L_id_length               = 0      ;
01514   int                                     L_header_body_length_id   = -1     ;
01515 
01516   T_pProtocolCounterDataList              L_header_body_length_list = NULL   ;
01517   T_ProtocolCounterData                   L_header_body_length               ;  
01518   T_ProtocolCounterDataList::iterator     L_it                               ;
01519   int                                     L_counter_id = -1                  ;
01520   int                                     L_i                                ;
01521 
01522   
01523   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_from_xml() start");
01524 
01525   m_header_body_name = P_def->find_value((char*)"name");
01526   if (m_header_body_name == NULL) {
01527     GEN_ERROR(E_GEN_FATAL_ERROR,"header name value is mandatory");
01528     L_ret = -1 ;
01529   }
01530 
01531   L_value_field_type = NULL ;
01532   L_value_field_length = NULL ;
01533   m_header_body_field_separator = P_def->find_value((char*)"field-separator");
01534   if (m_header_body_field_separator == NULL) { // no separator defined 
01535                                                // => type and length mandatory
01536     
01537     L_value_field_type   = P_def->find_value((char*)"type");
01538     if (L_value_field_type == NULL) {
01539       GEN_ERROR(E_GEN_FATAL_ERROR,"type definition value is mandatory");
01540       L_ret = -1 ;
01541     }
01542     L_value_field_length = P_def->find_value((char*)"length");
01543     if (L_value_field_length == NULL) {
01544       GEN_ERROR(E_GEN_FATAL_ERROR,"length definition value is mandatory");
01545       L_ret = -1 ;
01546     }
01547   } 
01548 
01549   L_subList = P_def->get_sub_data() ;
01550 
01551 
01552   for(L_listIt  = L_subList->begin() ;
01553       L_listIt != L_subList->end() ;
01554       L_listIt++) {
01555     L_data = *L_listIt ;
01556     L_value = L_data->get_name() ;
01557     
01558     if (strcmp(L_value, (char*)"length") == 0) {
01559       L_value = L_data->find_value((char*)"name") ;
01560       if (L_value == NULL) {
01561         GEN_ERROR(E_GEN_FATAL_ERROR, "length name value is mandatory");
01562         L_ret = -1 ;
01563         break ;
01564       } else {
01565         L_id_length = add_length (L_value);
01566         if (L_id_length == -1 ) {
01567           L_ret = -1 ;
01568           return (L_ret);
01569         }
01570       }
01571     }
01572   }
01573 
01574 
01575   if (m_length_max > 0) {
01576     NEW_VAR (L_header_body_length_list, T_ProtocolCounterDataList()) ;
01577     m_nb_header_body_length = m_length_max - m_nb_header_length + 1;
01578     m_nb_protocol_ctxt_values += m_nb_header_body_length ;
01579   }
01580 
01581   for(L_listIt  = L_subList->begin() ;
01582       L_listIt != L_subList->end() ;
01583       L_listIt++) {
01584 
01585     L_counter_id = -1  ;
01586 
01587     L_data = *L_listIt ;
01588     L_value = L_data->get_name() ;
01589 
01590     if (strcmp(L_value, (char*)"fielddef") == 0) {
01591 
01592       char *L_endstr ;
01593 
01594       L_value = L_data->find_value((char*)"name") ;
01595       if (L_value == NULL) {
01596         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef name value is mandatory");
01597         L_ret = -1 ;
01598         break ;
01599       }
01600 
01601       L_value_size = L_data->find_value((char*)"size") ;
01602       if (L_value_size == NULL) {
01603         GEN_ERROR(E_GEN_FATAL_ERROR, 
01604               "fielddef size value is mandatory ["
01605               << L_value << "]");
01606         L_ret = -1 ;
01607         break ;
01608       }
01609 
01610       L_size = strtoul_f (L_value_size, &L_endstr,10) ;
01611       if (L_endstr[0] != '\0') {
01612          L_size = strtoul_f (L_value_size, &L_endstr,16) ;
01613          if (L_endstr[0] != '\0') {
01614             GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef size value ["
01615                       << L_value_size << "] bad format");
01616             L_ret = -1 ;
01617             break ;
01618          }
01619       }
01620 
01621       L_value_unit = L_data->find_value((char*)"unit") ;
01622       if (L_value_unit == NULL) {
01623         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef unit value is mandatory");
01624         L_ret = -1 ;
01625         break ;
01626       }
01627 
01628       if ( L_size > sizeof(unsigned long)) {
01629            GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef max size value ["  << sizeof(unsigned long) << "]");
01630            L_ret = -1 ;
01631            break ;
01632       }
01633 
01634       // temporary
01635       if (strcmp(L_value_unit, (char*)"octet") != 0) {
01636         GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported unit ["
01637               << L_value_unit << "] value");
01638         L_ret = -1 ;
01639         break;
01640       }
01641 
01642       L_value_fielddef = L_data->find_value((char*)"value") ;
01643       if (L_value_fielddef != NULL) {
01644         L_counter_id = add_counter_id(L_value_fielddef, false);
01645         if (L_counter_id == -1) {
01646           L_ret = -1 ;
01647           break ;
01648         }
01649       }
01650 
01651       if (L_ret != -1) {
01652 
01653         L_id = add_header_field (L_value, 
01654                                  L_size,
01655                                  &m_nb_field_header_body,
01656                                  &m_header_body_size,
01657                                  m_header_body_field_table,
01658                                  m_header_body_id_map,
01659                                  L_counter_id) ;
01660 
01661         if (L_value_field_type) {
01662           if (strcmp(L_value, L_value_field_type) == 0) {
01663             set_header_body_type_id(L_id) ;
01664           }
01665         }
01666         if (L_value_field_length) {
01667           if (strcmp(L_value, L_value_field_length) == 0) {
01668             set_header_body_length_id(L_id) ;
01669           }
01670         }
01671 
01672       }
01673     } else if (strcmp(L_value, (char*)"length") == 0 ) {
01674       L_value = L_data->find_value((char*)"name") ;
01675       L_header_body_length_id = ctrl_length(L_value, true) ;
01676       if (L_header_body_length_id != -1) {
01677         L_header_body_length.m_id        = L_header_body_length_id ;
01678         L_header_body_length.m_start_id  =  L_id + 1 ;
01679         L_header_body_length.m_stop_id   = -1 ;
01680         L_header_body_length_list->push_back(L_header_body_length)      ;
01681       } else {
01682         L_ret = -1 ;
01683         break;
01684       }
01685     } else if (strcmp(L_value, (char*)"end-length") == 0 ) {
01686       L_value = L_data->find_value((char*)"name") ;
01687       L_header_body_length_id = ctrl_length(L_value, true) ;
01688       if (L_header_body_length_id != -1) {
01689         L_ret = update_field_length(L_header_body_length_id, 
01690                                     L_id,
01691                                     L_header_body_length_list, 
01692                                     true);
01693         if (L_ret == -1)  break ;
01694       } else {
01695         L_ret = -1 ;
01696         break;
01697       }
01698     } else if ( strcmp(L_value, (char *)"optional") == 0 ) {
01699       // option field section
01700       if (L_data -> get_sub_data() != NULL) {
01701         L_ret = get_header_body_optional_from_xml(L_data);
01702         if (L_ret == -1) break ;
01703       }
01704     } else {
01705       GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported section ["
01706                 << L_value << "]");
01707       L_ret = -1 ;
01708       break;
01709     }
01710 
01711   } // for
01712 
01713   if (L_ret != -1) {
01714     if (m_header_body_length_id == -1) {
01715       GEN_ERROR(E_GEN_FATAL_ERROR, "length field name of body is mandatory in protocol");
01716       L_ret = -1 ;
01717     } else {
01718       if (m_header_body_field_table[m_header_body_length_id].m_counter_id == -1) {
01719         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef unit value is mandatory for ["
01720                   << m_header_body_field_table[m_header_body_length_id].m_name << "]");
01721         L_ret = -1 ;
01722       } else {
01723         m_ctxt_id_data_size = 
01724           m_header_body_field_table[m_header_body_length_id].m_counter_id ;
01725       }
01726     }
01727   }
01728 
01729   if (L_ret != -1) {
01730     if (m_nb_header_body_length > 0 ) {
01731       if (!L_header_body_length_list->empty()) {
01732         m_nb_header_body_length_table = L_header_body_length_list->size() ;
01733         ALLOC_TABLE(m_header_body_length_table,
01734                     T_pProtocolCounterData,
01735                     sizeof(T_ProtocolCounterData),
01736                     m_nb_header_body_length_table);
01737         L_id = 0 ;
01738         for (L_it  = L_header_body_length_list->begin();
01739              L_it != L_header_body_length_list->end()  ;
01740              L_it++) {
01741           L_header_body_length   = *L_it ;
01742           m_header_body_length_table [L_id] = *L_it  ;
01743           L_id ++ ;
01744         }
01745 
01746         L_header_body_length_list->erase(L_header_body_length_list->begin(),
01747                                          L_header_body_length_list->end());
01748         
01749         ALLOC_TABLE(m_header_body_ctxt_v_table,
01750                     T_pUpdateCtxtValue,
01751                     sizeof(T_UpdateCtxtValue),
01752                     m_nb_field_header_body);
01753         
01754         for (L_i = 0; L_i < (int)m_nb_field_header_body; L_i++) {
01755           m_header_body_ctxt_v_table[L_i].m_nb_ctxt_id = 0 ;
01756           m_header_body_ctxt_v_table[L_i].m_ctxt_id_setted = NULL ;
01757         }
01758         
01759         L_ret = update_ctxt_v_field (m_header_body_ctxt_v_table,
01760                                      (int)m_nb_field_header_body,
01761                                      m_header_body_length_table,
01762                                      m_nb_header_body_length,
01763                                      &m_header_ctxt_v_table[m_nb_field_header-1],
01764                                      m_counter_id_last_length);
01765         
01766         ALLOC_TABLE(m_header_body_ctxt_p_table,
01767                     T_pUpdateCtxtPosition,
01768                     sizeof(T_UpdateCtxtPosition),
01769                     m_nb_field_header_body);
01770         
01771         for (L_i = 0; L_i < (int)m_nb_field_header_body; L_i++) {
01772           if (m_header_body_field_table[L_i].m_counter_id != -1) {
01773             m_header_body_ctxt_p_table[L_i].m_nb_ctxt_pos = 1    ;
01774             
01775             m_header_body_ctxt_p_table[L_i].m_ctxt_id_pos = 
01776               m_header_body_field_table[L_i].m_counter_id ;
01777           } else {
01778             m_header_body_ctxt_p_table[L_i].m_nb_ctxt_pos = 0    ;
01779             m_header_body_ctxt_p_table[L_i].m_ctxt_id_pos = -1   ;
01780           }
01781         }
01782       }
01783     }
01784   }
01785 
01786   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_from_xml() end");
01787 
01788   return (L_ret);
01789 }
01790 
01791 
01792 int C_ProtocolTlv::get_header_body_optional_from_xml (C_XmlData *P_def) {
01793 
01794   C_XmlData                *L_data ;
01795   T_XmlData_List::iterator  L_listIt ;
01796   T_pXmlData_List           L_subList ;
01797   char                     *L_value, *L_value_size, *L_value_unit ;
01798   char                     *L_value_cond, *L_value_field, *L_value_mask ;
01799   int                       L_ret = 0 ;
01800   unsigned long             L_size    ;
01801   unsigned long             L_mask ;
01802   int                       L_field_id ;
01803   T_pCondPresence           L_condPresence = NULL ;
01804   
01805   
01806   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_optional_from_xml() start");
01807 
01808   L_subList = P_def->get_sub_data() ;
01809 
01810   for(L_listIt  = L_subList->begin() ;
01811       L_listIt != L_subList->end() ;
01812       L_listIt++) {
01813 
01814     L_data = *L_listIt ;
01815     L_value = L_data->get_name() ;
01816 
01817     if (strcmp(L_value, (char*)"fielddef") == 0) {
01818 
01819       char *L_endstr ;
01820 
01821       L_value = L_data->find_value((char*)"name") ;
01822       if (L_value == NULL) {
01823         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef name value is mandatory");
01824         L_ret = -1 ;
01825         break ;
01826       }
01827 
01828       L_value_size = L_data->find_value((char*)"size") ;
01829       if (L_value_size == NULL) {
01830         GEN_ERROR(E_GEN_FATAL_ERROR, 
01831               "fielddef size value is mandatory ["
01832               << L_value << "]");
01833         L_ret = -1 ;
01834         break ;
01835       }
01836 
01837       L_size = strtoul_f (L_value_size, &L_endstr,10) ;
01838       if (L_endstr[0] != '\0') {
01839          L_size = strtoul_f (L_value_size, &L_endstr,16) ;
01840          if (L_endstr[0] != '\0') {
01841             GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef size value ["
01842                       << L_value_size << "] bad format");
01843             L_ret = -1 ;
01844             break ;
01845          }
01846       }
01847       if ( L_size > sizeof(unsigned long)) {
01848            GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef max size value ["  << sizeof(unsigned long) << "]");
01849            L_ret = -1 ;
01850            break ;
01851       }
01852       L_value_unit = L_data->find_value((char*)"unit") ;
01853       if (L_value_unit == NULL) {
01854         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef unit value is mandatory");
01855         L_ret = -1 ;
01856         break ;
01857       }
01858 
01859       // temporary
01860       if (strcmp(L_value_unit, (char*)"octet") != 0) {
01861         GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported unit ["
01862               << L_value_unit << "] value");
01863         L_ret = -1 ;
01864         break;
01865       }
01866 
01867       L_value_cond = L_data->find_value ((char*)"condition") ;
01868       if (L_value_cond == NULL) {
01869         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef condition value is mandatory");
01870         L_ret = -1 ;
01871         break ;
01872       }
01873       if (strcmp(L_value_cond, (char*)"mask") != 0) {
01874         GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported fielddef condition value ["
01875               << L_value_cond << "]");
01876         L_ret = -1 ;
01877         break ;
01878       }
01879       L_value_field = L_data->find_value ((char*)"field") ;
01880       if (L_value_field == NULL) {
01881         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef condition value is mandatory");
01882         L_ret = -1 ;
01883         break ;
01884       } else {
01885         // find id of the field 
01886         T_IdMap::iterator L_bodyFieldIt ;
01887         L_bodyFieldIt = 
01888           m_header_body_id_map->find(T_IdMap::key_type(L_value_field));
01889         if (L_bodyFieldIt != m_header_body_id_map->end()) {
01890           L_field_id = L_bodyFieldIt->second ;
01891         } else {
01892           GEN_ERROR(E_GEN_FATAL_ERROR, "no definition found for field ["
01893                 << L_value_field << "]");
01894           L_ret = -1 ;
01895           break ;
01896         }
01897       }
01898       L_value_mask = L_data->find_value (L_value_cond) ;
01899       if (L_value_mask == NULL) {
01900         GEN_ERROR(E_GEN_FATAL_ERROR, "fielddef " 
01901               << L_value_cond << " value is mandatory");
01902         L_ret = -1 ;
01903         break ;
01904       } else {
01905         L_mask = strtoul_f (L_value_mask, &L_endstr,10) ;
01906         if (L_endstr[0] != '\0') {
01907           GEN_ERROR(E_GEN_FATAL_ERROR, "bad mask format for ["
01908                 << L_value_mask << "]");
01909           L_ret = -1 ;
01910           break ;
01911         }
01912       }
01913 
01914       if (L_ret != -1) {
01915 
01916         ALLOC_VAR(L_condPresence, T_pCondPresence, sizeof(T_CondPresence)) ;
01917         L_condPresence->m_mask = L_mask ;
01918         L_condPresence->m_f_id = L_field_id ;
01919         (void) add_header_field (L_value, 
01920                                  L_size,
01921                                  &m_nb_field_header_body,
01922                                  &m_header_body_size,
01923                                  m_header_body_field_table,
01924                                  m_header_body_id_map,
01925                                  -1,
01926                                  L_condPresence) ;
01927 
01928       }
01929 
01930     } else {
01931 
01932       GEN_ERROR(E_GEN_FATAL_ERROR, "Unsupported section ["
01933             << L_value << "]");
01934       L_ret = -1 ;
01935       break;
01936       
01937     }
01938   }
01939   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_optional_from_xml() end");
01940 
01941   return (L_ret);
01942 }
01943 
01944 
01945 
01946 void C_ProtocolTlv::set_header_body_type_id (int P_id) {
01947   GEN_DEBUG(1, "C_ProtocolTlv::set_header_body_type_id() start");
01948   GEN_DEBUG(1, "C_ProtocolTlv::set_header_body_type_id() end");
01949   m_header_body_type_id = P_id ;
01950 }
01951 void C_ProtocolTlv::set_header_body_length_id (int P_id) {
01952 
01953   int L_id ;
01954 
01955   GEN_DEBUG(1, "C_ProtocolTlv::set_header_body_length_id() start");
01956   m_header_body_length_id = P_id ;
01957   m_header_body_length_index = 0 ;
01958   for(L_id = 0; L_id < m_header_body_length_id; L_id++) {
01959     m_header_body_length_index 
01960       += (int) m_header_body_field_table[L_id].m_size ;
01961   }
01962   GEN_DEBUG(1, "C_ProtocolTlv::set_header_body_length_id() end");
01963 
01964 }
01965 
01966 unsigned long C_ProtocolTlv::get_header_body_size() {
01967   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_size() start");
01968   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_size() end");
01969   return (m_header_body_size);
01970 }
01971 
01972 unsigned long C_ProtocolTlv::get_nb_field_header_body () {
01973   GEN_DEBUG(1, "C_ProtocolTlv::get_nb_field_header_body() start");
01974   GEN_DEBUG(1, "C_ProtocolTlv::get_nb_field_header_body() end");
01975   return (m_nb_field_header_body) ;
01976 }
01977 
01978 C_ProtocolTlv::T_pHeaderField 
01979 C_ProtocolTlv::get_header_body_field_description (int P_id) {
01980 
01981   T_pHeaderField L_result ;
01982 
01983   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_field_description() start");
01984   L_result = (P_id < (int)m_max_nb_field_header_body) ?
01985     &(m_header_body_field_table[P_id]) : NULL ;
01986   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_field_description() end");
01987 
01988   return (L_result);
01989 }
01990 
01991 C_ProtocolTlv::T_pHeaderField 
01992 C_ProtocolTlv::get_header_body_field_description (char *P_name) {
01993 
01994   T_pHeaderField         L_result ;
01995   int                    L_id     ;
01996   T_IdMap::iterator L_it     ;
01997 
01998   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_field_description() start");
01999   L_it = m_header_body_id_map 
02000     -> find (T_IdMap::key_type(P_name)) ;
02001   
02002   if (L_it != m_header_body_id_map->end()) {
02003     L_id = L_it->second ;
02004     L_result = get_header_body_field_description(L_id);
02005   } else {
02006     L_result = NULL ;
02007   }
02008   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_field_description() end");
02009 
02010   return (L_result) ;
02011 }
02012 
02013 int C_ProtocolTlv::get_header_body_type_id () {
02014   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_type_id() start");
02015   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_type_id() end");
02016   return (m_header_body_type_id) ;
02017 }
02018 
02019 int C_ProtocolTlv::get_header_body_length_id () {
02020   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_length_id() start");
02021   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_length_id() end");
02022   return (m_header_body_length_id) ;
02023 }
02024 
02025 int C_ProtocolTlv::get_header_body_length_index () {
02026   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_length_index() start");
02027   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_length_index() end");
02028   return (m_header_body_length_index) ;
02029 }
02030 
02031 int C_ProtocolTlv::get_header_values_from_xml (C_XmlData *P_def) {
02032 
02033   int                       L_ret = 0 ;
02034   C_XmlData                *L_data    ;
02035   char                     *L_value, *L_name, *L_endstr ;
02036   char                     *L_fieldName, *L_fieldValue ;
02037   T_XmlData_List::iterator  L_listIt, L_listFieldIt  ;
02038   T_pXmlData_List           L_subListDefine, L_subListSetField ;
02039   int                       L_id ;
02040 
02041   T_IdMap::iterator         L_IdMapIt   ;
02042   int                       L_fieldId, L_fieldIdx  ;
02043   T_UnsignedInteger32       L_fieldValueUl;
02044   // unsigned long             L_fieldValueUl, L_fieldCode;
02045   unsigned long             L_fieldCode = 0 ; 
02046   bool                      L_codeFound ;
02047   unsigned long             L_i ;
02048 
02049   unsigned long             L_nb_setfield, L_nb_bodyval ;
02050   char                     *L_body_name, *L_body_value ;
02051   int                       L_valueIdx, L_valueId ;
02052 
02053   GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() start");
02054 
02055   L_id = 0 ;
02056   L_subListDefine = P_def->get_sub_data() ;
02057 
02058   for(L_listIt  = L_subListDefine->begin() ;
02059       L_listIt != L_subListDefine->end() ;
02060       L_listIt++) {
02061 
02062     L_data = *L_listIt ;
02063     L_value = L_data->get_name() ;
02064 
02065     GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  " 
02066               << "L_data->get_name() " << 
02067               L_data->get_name() );
02068 
02069     if (strcmp(L_value, (char*)"define") == 0) {
02070 
02071       m_header_value_table[L_id].m_id = L_id ; 
02072 
02073       L_name = L_data->find_value((char*)"name") ;
02074       if (L_name == NULL) {
02075         GEN_ERROR(E_GEN_FATAL_ERROR, "define name value is mandatory");
02076         L_ret = -1 ;
02077         break ;
02078       }
02079       m_header_value_table[L_id].m_name = L_name ;
02080 
02081       if (L_ret != -1) {
02082 
02083         L_subListSetField = L_data->get_sub_data() ;
02084 
02085         if (L_subListSetField != NULL) {
02086           GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  " 
02087                     << "L_subListSetField " << 
02088                     L_subListSetField );
02089 
02090 
02091           // setfield and header_body_name section 
02092           L_nb_setfield = 0 ;
02093           L_nb_bodyval = 0 ;
02094 
02095           for (L_listFieldIt = L_subListSetField->begin();
02096                L_listFieldIt != L_subListSetField->end();
02097                L_listFieldIt++) {
02098             L_data = *L_listFieldIt ;
02099             
02100             if (strcmp(L_data->get_name(), (char*)"setfield") == 0) {
02101               L_nb_setfield++ ;
02102             } else if (strcmp(L_data->get_name(), (char*)m_header_body_name) == 0) {
02103               L_nb_bodyval++;
02104             } else {
02105               GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown ["
02106                         << L_data->get_name() << "] section.[setfield] or ["
02107                         << m_header_body_name << "] section is mandatory");
02108               L_ret = -1 ;
02109               break ;
02110             }
02111           }
02112 
02113           if (L_ret == -1) break ;
02114           
02115           m_header_value_table[L_id].m_nb_set 
02116             = L_nb_setfield ;
02117           
02118 
02119           GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  " 
02120                     << "m_header_value_table [" << 
02121                     L_id << "].m_nb_set " 
02122                     << m_header_value_table[L_id].m_nb_set );
02123 
02124           ALLOC_TABLE(m_header_value_table[L_id].m_values,
02125                       T_pValueData,
02126                       sizeof(T_ValueData),
02127                       m_header_value_table[L_id].m_nb_set);
02128 
02129           ALLOC_TABLE(m_header_value_table[L_id].m_value_setted,
02130                       bool*,
02131                       sizeof(bool),
02132                       m_nb_field_header);
02133 
02134           ALLOC_TABLE(m_header_value_table[L_id].m_id_value_setted,
02135                       int*,
02136                       sizeof(int),
02137                       m_nb_field_header);
02138 
02139           for(L_i = 0; L_i < m_nb_field_header; L_i++) {
02140             m_header_value_table[L_id].m_value_setted[L_i] = false ;
02141             m_header_value_table[L_id].m_id_value_setted[L_i] = -1 ;
02142           }
02143 
02144           L_fieldIdx = 0 ;
02145           L_codeFound = false ;
02146 
02147           m_body_value_table[L_id].m_nb_values 
02148             = L_nb_bodyval ;
02149 
02150           ALLOC_TABLE(m_body_value_table[L_id].m_value_table,
02151                       T_pBodyValue,
02152                       sizeof(T_BodyValue),
02153                       L_nb_bodyval);
02154           L_valueIdx = 0 ;
02155 
02156           GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  " 
02157                     << "m_body_value_table [ " << 
02158                     L_id << "].m_nb_values " 
02159                     << m_body_value_table[L_id].m_nb_values);
02160 
02161                       
02162           for (L_listFieldIt = L_subListSetField->begin();
02163                L_listFieldIt != L_subListSetField->end();
02164                L_listFieldIt++) {
02165             L_data = *L_listFieldIt ;
02166 
02167             GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  " << 
02168                       "L_data->get_name() is " << 
02169                       L_data->get_name() );
02170 
02171             if (strcmp(L_data->get_name(), (char*)"setfield") == 0) {
02172               L_fieldName = L_data->find_value((char*)"name") ;
02173               if (L_fieldName == NULL) {
02174                 GEN_ERROR(E_GEN_FATAL_ERROR, "setfield name value is mandatory");
02175                 L_ret = -1 ;
02176                 break ;
02177               }
02178 
02179               L_IdMapIt = 
02180                 m_header_id_map->find(T_IdMap::key_type(L_fieldName));
02181 
02182               if (L_IdMapIt != m_header_id_map->end()) {
02183                 L_fieldId = L_IdMapIt->second ;
02184                 GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  L_fieldName is " << 
02185                               L_fieldName );
02186               } else {
02187                 GEN_ERROR(E_GEN_FATAL_ERROR, 
02188                       "Field ["
02189                       << L_fieldName << "] not defined");
02190                 L_ret = -1 ;
02191                 break;
02192               }
02193 
02194               L_fieldValue = L_data->find_value((char*)"value") ;
02195               if (L_fieldValue == NULL) {
02196                 GEN_ERROR(E_GEN_FATAL_ERROR, "setfield value is mandatory");
02197                 L_ret = -1 ;
02198                 break ;
02199               }
02200               GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() L_fieldValue is " << 
02201                             L_fieldValue );
02202 
02203 
02204               L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,10) ;
02205 
02206 
02207               if (L_endstr[0] != '\0') {
02208                 L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,16) ;
02209                   GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() typedef size value ["
02210                             << L_fieldValueUl << "] format");
02211                 if (L_endstr[0] != '\0') {
02212                   GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
02213                             << L_fieldValue << "] bad format");
02214                   L_ret = -1 ;
02215                   break ;
02216                 }
02217               }
02218 
02219               if (L_ret != -1) {
02220                        
02221                   GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  "
02222                             << "L_fieldValueUl is " << 
02223                             L_fieldValueUl );
02224 
02225                   GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() " 
02226                             << "L_fieldId is " << 
02227                             L_fieldId << " and m_header_type_id " 
02228                             << m_header_type_id) ;
02229 
02230                 if (L_fieldId == m_header_type_id) {
02231                   L_fieldCode = L_fieldValueUl ;
02232                   L_codeFound = true ;
02233                 }
02234 
02235                 GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() " 
02236                           << "L_id = " << L_id );
02237                 GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() " 
02238                           << "L_fieldId =  " << L_fieldId );
02239                 GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() " 
02240                           << "L_fieldIdx = " << L_fieldIdx );
02241 
02242                 m_header_value_table[L_id]
02243                   .m_value_setted[L_fieldId] = true ;
02244                 m_header_value_table[L_id]
02245                   .m_id_value_setted[L_fieldId] = L_fieldIdx ;
02246 
02247                 (m_header_value_table[L_id].m_values)[L_fieldIdx].m_id
02248                   = L_fieldId ;
02249                 (m_header_value_table[L_id].m_values)[L_fieldIdx].m_type
02250                   = E_TYPE_NUMBER ;
02251                 (m_header_value_table[L_id].m_values)[L_fieldIdx]
02252                   .m_value.m_val_number
02253                   = L_fieldValueUl ;
02254                 L_fieldIdx++;
02255               }
02256 
02257             } else if (strcmp(L_data->get_name(), (char*)m_header_body_name) == 0) {
02258 
02259               L_body_name = L_data->find_value((char*)"name") ;
02260               if (L_body_name == NULL) {
02261                 GEN_ERROR(E_GEN_FATAL_ERROR, 
02262                           "the name of [" << m_header_body_name <<
02263                           "] is mandatory");
02264                 L_ret = -1 ;
02265                 break ;
02266               }
02267               GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  "
02268                         << "L_body_name [" << L_body_name << "]");
02269 
02270               L_valueId 
02271                 = get_header_body_value_id(L_body_name);
02272               if (L_valueId == -1) {
02273                 GEN_ERROR(E_GEN_FATAL_ERROR,
02274                           "No definition found for ["
02275                           << L_body_name << "]");
02276                 L_ret = -1 ;
02277                 break ;
02278               } 
02279               if (get_body_value_type (L_valueId) 
02280                   == E_TYPE_GROUPED) {
02281                 GEN_ERROR(E_GEN_FATAL_ERROR,
02282                           "Grouped type not supported for body value");
02283                 L_ret = -1 ;
02284                 break ;
02285               }
02286 
02287               L_body_value = L_data->find_value((char*)"value") ;
02288               if (L_body_value == NULL) {
02289                 GEN_ERROR(E_GEN_FATAL_ERROR, 
02290                           "the value of [" << m_header_body_name <<
02291                           "] is mandatory");
02292                 L_ret = -1 ;
02293                 break ;
02294               }
02295               GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml()  "
02296                         << "L_body_value [" << L_body_value << "]");
02297 
02298               if (set_body_value(L_valueId,
02299                                  L_body_value,
02300                                  1,
02301                                  &(m_body_value_table[L_id].m_value_table[L_valueIdx])) == 0) {
02302 
02303                 if ((m_header_type_id == -1) && (L_valueId == m_header_type_id_body)) {
02304                   if (m_header_body_field_separator == NULL ) {
02305                     L_fieldCode = 
02306                       m_body_value_table[L_id].m_value_table[L_valueIdx].m_value.m_val_number ;
02307                   } else {
02308                     L_fieldCode = 
02309                       convert_char_to_ul((char*)m_body_value_table[L_id].m_value_table[L_valueIdx].m_value.m_val_binary.m_value);
02310                   }
02311                   L_codeFound = true ;
02312 
02313                 }
02314 
02315 
02316               } else {
02317                 GEN_ERROR(E_GEN_FATAL_ERROR,
02318                           "Bad format for ["
02319                           << L_body_value << "]");
02320                 L_ret = -1 ;
02321                 break ;
02322               }
02323               L_valueIdx ++ ;
02324             }
02325             if (L_ret == -1) break ;
02326           } // for
02327           if (L_ret == -1) break ;
02328         } else {
02329           GEN_ERROR(E_GEN_FATAL_ERROR, 
02330                 "setfield for ["
02331                     << m_header_name << "] or [" << m_header_body_name << "] code is mandatory");
02332           L_ret = -1 ;
02333           break ;
02334         }
02335         if (L_ret == -1) break ;
02336         if ((L_codeFound == false) && (m_header_type_id != -1) ) {
02337           GEN_ERROR(E_GEN_FATAL_ERROR,
02338                 "No value found for the field ["
02339                 << m_header_field_table[m_header_type_id].m_name
02340                 << "]");
02341           L_ret = -1 ;
02342           break ;
02343         }
02344         GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() L_name = " << 
02345                       L_name << " L_fieldCode = " << L_fieldCode << 
02346                       " and L_id = " << L_id) ;
02347 
02348         m_header_value_id_map
02349           ->insert(T_IdMap::value_type(L_name, L_id));
02350         m_header_decode_map
02351           ->insert(T_DecodeMap::value_type(L_fieldCode, L_id));
02352         L_id ++ ;
02353       }
02354     }
02355 
02356     if (L_ret == -1) break ;
02357   }
02358   GEN_DEBUG(1, "C_ProtocolTlv::get_header_values_from_xml() end");
02359 
02360   return (L_ret);
02361 }
02362 
02363 int C_ProtocolTlv::get_header_body_values_from_xml (C_XmlData *P_def) {
02364 
02365   int                       L_ret = 0 ;
02366   C_XmlData                *L_data    ;
02367   char                     *L_value, *L_name, *L_type, *L_endstr ;
02368   char                     *L_fieldName, *L_fieldValue ;
02369   T_XmlData_List::iterator  L_listIt, L_listFieldIt  ;
02370   T_pXmlData_List           L_subListDefine, L_subListSetField ;
02371   int                       L_id ;
02372 
02373   T_IdMap::iterator         L_IdMapIt   ;
02374   int                       L_typeId ;
02375   int                       L_fieldId, L_fieldIdx  ;
02376   unsigned long             L_fieldValueUl, L_fieldCode;
02377   bool                      L_codeFound ;
02378 
02379   int                       L_i ;
02380 
02381   int                       L_nb_setfield = 0 ;
02382 
02383   int                       L_nb_setsize  = 0 ;
02384   int                       L_nb_notpresent  = 0 ;
02385   bool                      L_setsizeFound = false ;
02386 
02387 
02388   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_values_from_xml() start");
02389 
02390 
02391   ALLOC_TABLE(m_header_body_value_table,
02392               T_pHeaderBodyValue,
02393               sizeof(T_HeaderBodyValue),
02394               m_nb_header_body_values);
02395   
02396   L_id = 0 ;
02397   L_subListDefine = P_def->get_sub_data() ;
02398 
02399   for(L_listIt  = L_subListDefine->begin() ;
02400       L_listIt != L_subListDefine->end() ;
02401       L_listIt++) {
02402 
02403     L_data = *L_listIt ;
02404     L_value = L_data->get_name() ;
02405 
02406     if (strcmp(L_value, (char*)"define") == 0) {
02407 
02408       L_name = L_data->find_value((char*)"name") ;
02409       if (L_name == NULL) {
02410         GEN_ERROR(E_GEN_FATAL_ERROR, "define name value is mandatory");
02411         L_ret = -1 ;
02412         break ;
02413       } 
02414 
02415       L_type = L_data->find_value((char*)"type") ;
02416       if (L_type == NULL) {
02417         GEN_ERROR(E_GEN_FATAL_ERROR, "define type value is mandatory");
02418         L_ret = -1 ;
02419         break ;
02420       }
02421       L_IdMapIt = 
02422         m_type_id_map->find(T_IdMap::key_type(L_type));
02423       
02424       if (L_IdMapIt != m_type_id_map->end()) {
02425         L_typeId = L_IdMapIt->second ;
02426       } else {
02427         GEN_ERROR(E_GEN_FATAL_ERROR, 
02428               "Type ["
02429               << L_type << "] not defined");
02430         L_ret = -1 ;
02431         break;
02432       }
02433 
02434 
02435       m_header_body_value_table[L_id].m_id = L_id ;
02436       m_header_body_value_table[L_id].m_name = L_name ;
02437       m_header_body_value_table[L_id].m_type_id = L_typeId ;
02438 
02439       if ((L_ret != -1) && (get_header_type_id() == -1)) {
02440         if (strcmp(L_name, m_header_type_name) == 0) {
02441           m_header_type_id_body = L_id ;
02442         }
02443       } 
02444 
02445       if ((L_ret != -1) && (m_header_body_field_separator == NULL)) {
02446 
02447         GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_values_from_xml() " <<
02448                   "L_id = " << L_id);
02449         GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_values_from_xml() " << 
02450                   "L_name = " << L_name);
02451         GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_values_from_xml() " << 
02452                   "m_header_type_name = " << 
02453                   m_header_type_name);
02454 
02455 
02456         L_subListSetField = L_data->get_sub_data() ;
02457 
02458         if (L_subListSetField != NULL) {
02459           // setfield and header_body_name section 
02460 
02461           for (L_listFieldIt = L_subListSetField->begin();
02462                L_listFieldIt != L_subListSetField->end();
02463                L_listFieldIt++) {
02464             L_data = *L_listFieldIt ;
02465             
02466             if (strcmp(L_data->get_name(), (char*)"setfield") == 0) {
02467               L_nb_setfield++ ;
02468             } else if (strcmp(L_data->get_name(), (char*)"setsize") == 0) {
02469               L_nb_setsize++;
02470             } else if (strcmp(L_data->get_name(), (char*)"not-present") == 0) {
02471               L_nb_notpresent++;   
02472             }
02473           }
02474         }
02475 
02476 
02477         if (L_subListSetField != NULL) {
02478           m_header_body_value_table[L_id].m_nb_set 
02479             = L_nb_setfield ; 
02480         } else {
02481           m_header_body_value_table[L_id].m_nb_set=0;
02482         }
02483 
02484         if (m_header_body_value_table[L_id].m_nb_set != 0) {
02485 
02486           ALLOC_TABLE(m_header_body_value_table[L_id].m_values,
02487                       T_pValueData,
02488                       sizeof(T_ValueData),
02489                       m_header_body_value_table[L_id].m_nb_set);
02490           
02491           ALLOC_TABLE(m_header_body_value_table[L_id].m_value_setted,
02492                       bool*,
02493                       sizeof(bool),
02494                       m_max_nb_field_header_body);
02495           
02496           ALLOC_TABLE(m_header_body_value_table[L_id].m_id_value_setted,
02497                       int*,
02498                       sizeof(int),
02499                       m_max_nb_field_header_body);
02500 
02501           ALLOC_TABLE(m_header_body_value_table[L_id].m_size,
02502                       unsigned long *,
02503                       sizeof(unsigned long),
02504                       m_max_nb_field_header_body);
02505 
02506           ALLOC_TABLE(m_header_body_value_table[L_id].m_present,
02507                       bool*,
02508                       sizeof(bool),
02509                       m_max_nb_field_header_body);
02510           
02511           
02512           
02513           for(L_i = 0; L_i < (int)m_max_nb_field_header_body; L_i++) {
02514             m_header_body_value_table[L_id].m_value_setted[L_i] = false ;
02515             m_header_body_value_table[L_id].m_id_value_setted[L_i] = -1 ;
02516             m_header_body_value_table[L_id].m_size[L_i] =  
02517               m_header_body_field_table[L_i].m_size ;
02518             m_header_body_value_table[L_id].m_present[L_i] =  true ;
02519           }
02520           
02521 
02522           L_fieldIdx = 0 ;
02523           L_codeFound = false ;
02524           L_setsizeFound = false ;
02525 
02526           
02527           for (L_listFieldIt = L_subListSetField->begin();
02528                L_listFieldIt != L_subListSetField->end();
02529                L_listFieldIt++) {
02530             
02531             L_data = *L_listFieldIt ;
02532 
02533             if (strcmp(L_data->get_name(), (char*)"setsize") == 0) {
02534               
02535               L_fieldName = L_data->find_value((char*)"name") ;
02536               if (L_fieldName == NULL) {
02537                 GEN_ERROR(E_GEN_FATAL_ERROR, "setsize name value is mandatory");
02538                 L_ret = -1 ;
02539                 break ;
02540               }
02541               
02542               L_IdMapIt = 
02543                 m_header_body_id_map->find(T_IdMap::key_type(L_fieldName));
02544               
02545               if (L_IdMapIt != m_header_id_map->end()) {
02546                 L_fieldId = L_IdMapIt->second ;
02547               } else {
02548                 GEN_ERROR(E_GEN_FATAL_ERROR, 
02549                           "Field ["
02550                           << L_fieldName << "] not defined");
02551                 L_ret = -1 ;
02552                 break;
02553               }
02554               
02555               L_fieldValue = L_data->find_value((char*)"value") ;
02556               if (L_fieldValue == NULL) {
02557                 GEN_ERROR(E_GEN_FATAL_ERROR, "setsize value is mandatory");
02558                 L_ret = -1 ;
02559                 break ;
02560               }
02561               L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,10) ;
02562               if (L_endstr[0] != '\0') {
02563                 L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,16) ;
02564                 if (L_endstr[0] != '\0') {
02565                   GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
02566                             << L_fieldValue << "] bad format");
02567                   L_ret = -1 ;
02568                   break ;
02569                 }
02570               }
02571               if (L_ret == -1) break ;
02572               m_header_body_value_table[L_id].m_size[L_fieldId] =  L_fieldValueUl ;
02573               if (L_fieldId < m_header_body_type_id) {
02574                 
02575                 GEN_ERROR(E_GEN_FATAL_ERROR, 
02576                           "setsize for ["
02577                           << m_header_body_name 
02578                           << "] is not possible."
02579                           << "setsize defined after type"); 
02580                 L_ret = -1 ;
02581                 break; 
02582                      
02583               } 
02584               if (L_fieldId == m_header_body_length_id) {
02585                 L_setsizeFound = true;
02586               }
02587 
02588             } // if (strcmp(L_data->get_name(), (char*)"setsize") == 0)  
02589 
02590             if (L_ret == -1) break ;
02591 
02592             if (strcmp(L_data->get_name(), (char*)"not-present") == 0) {
02593               L_fieldName = L_data->find_value((char*)"name") ;
02594               if (L_fieldName == NULL) {
02595                 GEN_ERROR(E_GEN_FATAL_ERROR, "not-present name value is mandatory");
02596                 L_ret = -1 ;
02597                 break ;
02598               }
02599               
02600               L_IdMapIt = 
02601                 m_header_body_id_map->find(T_IdMap::key_type(L_fieldName));
02602               
02603               if (L_IdMapIt != m_header_id_map->end()) {
02604                 L_fieldId = L_IdMapIt->second ;
02605               } else {
02606                 GEN_ERROR(E_GEN_FATAL_ERROR, 
02607                           "Field ["
02608                           << L_fieldName << "] not defined");
02609                 L_ret = -1 ;
02610                 break;
02611               }
02612               
02613               if (L_ret == -1) break ;
02614               m_header_body_value_table[L_id].m_present[L_fieldId] = false ;
02615             } // if (strcmp(L_data->get_name(), (char*)"not-present") == 0)  
02616 
02617             if (strcmp(L_data->get_name(), (char*)"setfield") == 0) {
02618               
02619               L_fieldName = L_data->find_value((char*)"name") ;
02620               if (L_fieldName == NULL) {
02621                 GEN_ERROR(E_GEN_FATAL_ERROR, "setfield name value is mandatory");
02622                 L_ret = -1 ;
02623                 break ;
02624               }
02625               GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_values_from_xml() " 
02626                         << "L_fieldName " << 
02627                         L_fieldName );
02628               
02629               
02630               L_IdMapIt = 
02631                 m_header_body_id_map->find(T_IdMap::key_type(L_fieldName));
02632               
02633               if (L_IdMapIt != m_header_id_map->end()) {
02634                 L_fieldId = L_IdMapIt->second ;
02635               } else {
02636                 GEN_ERROR(E_GEN_FATAL_ERROR, 
02637                           "Field ["
02638                           << L_fieldName << "] not defined");
02639                 L_ret = -1 ;
02640                 break;
02641               }
02642               
02643               L_fieldValue = L_data->find_value((char*)"value") ;
02644               if (L_fieldValue == NULL) {
02645                 GEN_ERROR(E_GEN_FATAL_ERROR, "setfield value is mandatory");
02646                 L_ret = -1 ;
02647                 break ;
02648               }
02649               L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,10) ;
02650               if (L_endstr[0] != '\0') {
02651                 L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,16) ;
02652                 if (L_endstr[0] != '\0') {
02653                   GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
02654                             << L_fieldValue << "] bad format");
02655                   L_ret = -1 ;
02656                   break ;
02657                 }
02658               }
02659               
02660               if (L_ret != -1) {
02661                 GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_values_from_xml() L_fieldId = " << 
02662                           L_fieldId << " m_header_body_type_id = " << 
02663                           m_header_body_type_id << " and L_fieldValueUl = " << 
02664                           L_fieldValueUl) ;
02665                 
02666                 if (L_fieldId == m_header_body_type_id) {
02667                   L_fieldCode = L_fieldValueUl ;
02668                   L_codeFound = true ;
02669                 }
02670 
02671                 m_header_body_value_table[L_id]
02672                   .m_value_setted[L_fieldId] = true ;
02673                 m_header_body_value_table[L_id]
02674                   .m_id_value_setted[L_fieldId] = L_fieldIdx ;
02675                 
02676                 (m_header_body_value_table[L_id].m_values)[L_fieldIdx].m_id
02677                   = L_fieldId ;
02678                 (m_header_body_value_table[L_id].m_values)[L_fieldIdx].m_type
02679                   = E_TYPE_NUMBER ;
02680                 (m_header_body_value_table[L_id].m_values)[L_fieldIdx]
02681                   .m_value.m_val_number
02682                   = L_fieldValueUl ;
02683 
02684                 L_fieldIdx++ ;
02685               }
02686             } // if (strcmp(L_data->get_name(), (char*)"setfield") == 0) 
02687             if (L_ret == -1) break ;
02688           } // for (L_listFieldIt = L_subListSetField->begin();
02689 
02690           if ((m_header_body_field_table[m_header_body_length_id].m_size == 0) && 
02691               (L_setsizeFound == false)) {
02692             GEN_ERROR(E_GEN_FATAL_ERROR, 
02693                       "setsize for ["
02694                       << m_header_body_name << "] code is mandatory");
02695             L_ret = -1 ;
02696             break ;
02697           }
02698         } else { // if (m_header_body_value_table[L_id].m_nb_set == 0) 
02699           GEN_ERROR(E_GEN_FATAL_ERROR, 
02700                     "setfield for ["
02701                     << m_header_body_name << "] code is mandatory");
02702           L_ret = -1 ;
02703           break ;
02704         }
02705         if (L_ret == -1) break ;
02706         if (L_codeFound == false) {
02707           if (m_header_body_field_table) {
02708             GEN_ERROR(E_GEN_FATAL_ERROR,
02709                       "No value found for the field ["
02710                       << m_header_body_field_table[m_header_body_type_id].m_name
02711                       << "]");
02712           } else {
02713             GEN_ERROR(E_GEN_FATAL_ERROR,
02714                       "No value found in the header of body");
02715           }
02716           L_ret = -1 ;
02717           break ;
02718         }
02719         m_header_body_decode_map
02720           ->insert(T_DecodeMap::value_type(L_fieldCode, L_id));
02721       } // if (L_ret != -1) && (m_header_body_field_separator == NULL)
02722     }
02723     if (L_ret == -1) break ;
02724     m_header_body_value_id_map
02725       ->insert(T_IdMap::value_type(L_name, L_id));
02726     L_id ++ ;
02727   } // L_listIt
02728   GEN_DEBUG(1, "C_ProtocolTlv::get_header_body_values_from_xml() end");
02729   
02730   return (L_ret);
02731 }
02732 
02733 char* C_ProtocolTlv::get_header_name() {
02734   return (m_header_name);
02735 }
02736 
02737 char* C_ProtocolTlv::get_header_body_name () {
02738   return (m_header_body_name);
02739 }
02740 
02741 int   C_ProtocolTlv::get_header_value_id (char* P_name) {
02742   T_IdMap::iterator L_IdMapIt ;
02743   int               L_Id      ;
02744 
02745   L_IdMapIt = m_header_value_id_map
02746     ->find(T_IdMap::key_type(P_name));
02747 
02748   L_Id = (L_IdMapIt != m_header_value_id_map->end()) 
02749     ? L_IdMapIt->second : -1 ;
02750 
02751   return (L_Id);
02752 }
02753 
02754 int   C_ProtocolTlv::get_header_body_value_id (char* P_name) {
02755   T_IdMap::iterator L_IdMapIt ;
02756   int               L_Id      ;
02757 
02758   L_IdMapIt = m_header_body_value_id_map
02759     ->find(T_IdMap::key_type(P_name));
02760 
02761   L_Id = (L_IdMapIt != m_header_body_value_id_map->end()) 
02762     ? L_IdMapIt->second : -1 ;
02763 
02764   return (L_Id);
02765 }
02766 
02767 int  C_ProtocolTlv::set_body_value(int          P_id, 
02768                                 char*        P_value, 
02769                                 int          P_nb,
02770                                 T_pBodyValue P_res,
02771                                 bool        *P_del) {
02772 
02773   int   L_ret = 0 ;
02774   int   L_type_id ;
02775   char *L_endstr  ;
02776 
02777   GEN_DEBUG(1, "C_ProtocolTlv::set_body_value() start");
02778   GEN_DEBUG(1, " P_id = " << P_id );
02779   if (P_value != NULL)
02780   GEN_DEBUG(1, " P_value = " << P_value);
02781   else
02782   GEN_DEBUG(1, " P_value = " << "empty");
02783   GEN_DEBUG(1, " P_nb = " << P_nb );
02784   GEN_DEBUG(1, " P_res = " << P_res);
02785 
02786   if (P_del != NULL) {
02787     *P_del = false;
02788   }
02789 
02790   P_res->m_id = P_id ;
02791   P_res->m_sub_val = NULL ;
02792 
02793 
02794   // retrieve type definition of the field
02795   L_type_id = m_header_body_value_table[P_id].m_type_id ;
02796 
02797   GEN_DEBUG(1, " L_type_id = " << L_type_id);
02798 
02799   switch (m_type_def_table[L_type_id].m_type) {
02800 
02801   case E_TYPE_NUMBER :
02802     if ((strlen(P_value)>2) && (P_value[0] == '0') && (P_value[1] == 'x')) { // hexa buffer value
02803       P_res->m_value.m_val_number = strtoul_f(P_value, &L_endstr, 16) ;
02804     } else {
02805       P_res->m_value.m_val_number = strtoul_f(P_value, &L_endstr, 10) ;
02806     }
02807     if (L_endstr[0] != '\0') {
02808       GEN_ERROR(E_GEN_FATAL_ERROR, 
02809             "Incorrect value format for ["
02810             << P_value << "] - Unsigned Integer expected");
02811       L_ret = -1 ;
02812     } 
02813     break;
02814   case E_TYPE_SIGNED : {
02815     if ((strlen(P_value)>2) && (P_value[0] == '0') && (P_value[1] == 'x')) { // hexa buffer value
02816       P_res->m_value.m_val_signed = strtol_f(P_value, &L_endstr, 16) ;
02817     } else {
02818       P_res->m_value.m_val_signed = strtol_f(P_value, &L_endstr, 10) ;
02819     }
02820 
02821     if (L_endstr[0] != '\0') {
02822       GEN_ERROR(E_GEN_FATAL_ERROR, 
02823             "Incorrect value format for ["
02824             << P_value << "] - Integer expected");
02825       L_ret = -1 ;
02826     } 
02827   }
02828     break;
02829 
02830   case E_TYPE_STRING : {
02831 
02832     if ((strlen(P_value)>2) && (P_value[0] == '0') && (P_value[1] == 'x')) { // hexa buffer value
02833 
02834       char  *L_ptr = P_value+2 ;
02835       size_t L_res_size ;
02836 
02837       P_res->m_value.m_val_binary.m_value
02838         = convert_hexa_char_to_bin(L_ptr, &L_res_size);
02839 
02840       if (P_res->m_value.m_val_binary.m_value == NULL) {
02841         GEN_ERROR(E_GEN_FATAL_ERROR, 
02842               "Bad buffer size for hexadecimal buffer ["
02843               << P_value << "]");
02844         L_ret = -1 ;
02845       } else {
02846         GEN_DEBUG(1, " P_res->m_value.m_val_binary.m_value = " 
02847                   << (void*)(P_res->m_value.m_val_binary.m_value));
02848 
02849         if (P_del != NULL) {
02850         *P_del = true;
02851          }
02852 
02853         // *P_del = true;
02854         P_res->m_value.m_val_binary.m_size= L_res_size ;
02855       }
02856       
02857     } else { // direct string value
02858 
02859       P_res->m_value.m_val_binary.m_value=(unsigned char*)P_value;
02860       P_res->m_value.m_val_binary.m_size=strlen(P_value);
02861 
02862     }
02863   }
02864     break;
02865 
02866   case E_TYPE_GROUPED:
02867     GEN_DEBUG(1, " E_TYPE_GROUPED");
02868     if (P_nb == 0) {
02869       P_res->m_value.m_val_number = 0 ;
02870       P_res->m_sub_val = NULL ;
02871     } else {
02872       P_res->m_value.m_val_number = P_nb ;
02873       ALLOC_TABLE(P_res->m_sub_val, 
02874                   T_pBodyValue,
02875                   sizeof(T_BodyValue),
02876                   P_nb);
02877       
02878     }
02879     break ;
02880 
02881   case E_TYPE_STRUCT : {
02882    
02883     int   L_i = 0 ;
02884     int   L_size = (P_value == NULL ) ? 0 : strlen(P_value) ;
02885     char *L_value1, *L_value2, *L_value3 ;
02886 
02887     L_value1 = NULL ;
02888     L_value2 = NULL ;
02889     L_value3 = NULL ;
02890 
02891 
02892     while (L_i< L_size) {
02893        if ( P_value[L_i]== ';')  {
02894             P_value[L_i] = 0 ;
02895             L_value3= &P_value[L_i];
02896             L_value1= P_value ;
02897             if (L_i+1 < L_size ) {
02898                    L_value2 = &P_value[L_i+1]; 
02899             }
02900        }
02901        L_i ++;
02902     }
02903 
02904     if ( L_value1 != NULL ) {
02905        if ((strlen(L_value1)>2) && (L_value1[0] == '0') && (L_value1[1] == 'x')) { // hexa buffer value
02906           P_res->m_value.m_val_struct.m_id_1 = strtoul_f(L_value1, &L_endstr, 16) ;
02907        } else {
02908           P_res->m_value.m_val_struct.m_id_1 = strtoul_f(L_value1, &L_endstr, 10) ;
02909        }
02910       if (L_endstr[0] != '\0') {
02911         GEN_ERROR(E_GEN_FATAL_ERROR, 
02912             "Incorrect value format for ["
02913             << L_value1 << "] - Unsigned Integer expected");
02914         L_ret = -1 ;
02915       } 
02916 
02917       if ( (L_value2 != NULL)  && (L_ret != -1 )) {
02918         if ((strlen(L_value2)>2) && (L_value2[0] == '0') && (L_value2[1] == 'x')) { // hexa buffer value
02919           P_res->m_value.m_val_struct.m_id_2 = strtoul_f(L_value2, &L_endstr, 16) ;
02920         } else {
02921           P_res->m_value.m_val_struct.m_id_2 = strtoul_f(L_value2, &L_endstr, 10) ;
02922         }
02923        if (L_endstr[0] != '\0') {
02924         GEN_ERROR(E_GEN_FATAL_ERROR, 
02925             "Incorrect value format for ["
02926             << L_value2 << "] - Unsigned Integer expected");
02927         L_ret = -1 ;
02928         } 
02929 
02930       }
02931       if (L_ret != -1) *L_value3 = ';' ;
02932 
02933             
02934     } else {
02935       char * L_value = (P_value == NULL) ? (char *)"not set" : P_value ;
02936       GEN_ERROR(E_GEN_FATAL_ERROR, 
02937             "Incorrect value format for ["
02938             << L_value << "] - struct expected");
02939       L_ret = -1 ;
02940     }
02941 
02942     }
02943     break;
02944 
02945   case E_TYPE_NUMBER_64 :
02946     if ((strlen(P_value)>2) && (P_value[0] == '0') && (P_value[1] == 'x')) { // hexa buffer value
02947       P_res->m_value.m_val_number_64 = strtoull_f(P_value, &L_endstr, 16) ;
02948     } else {
02949       P_res->m_value.m_val_number_64 = strtoull_f(P_value, &L_endstr, 10) ;
02950     }
02951     if (L_endstr[0] != '\0') {
02952       GEN_ERROR(E_GEN_FATAL_ERROR, 
02953             "Incorrect value format for ["
02954             << P_value << "] - Unsigned Integer64 expected");
02955       L_ret = -1 ;
02956     } 
02957     break;
02958   case E_TYPE_SIGNED_64 : {
02959     if ((strlen(P_value)>2) && (P_value[0] == '0') && (P_value[1] == 'x')) { // hexa buffer value
02960       P_res->m_value.m_val_signed_64 = strtoll_f(P_value, &L_endstr, 16) ;
02961     } else {
02962       P_res->m_value.m_val_signed_64 = strtoll_f(P_value, &L_endstr, 10) ;
02963     }
02964 
02965     if (L_endstr[0] != '\0') {
02966       GEN_ERROR(E_GEN_FATAL_ERROR, 
02967             "Incorrect value format for ["
02968             << P_value << "] - Integer64 expected");
02969       L_ret = -1 ;
02970     } 
02971   }
02972     break;
02973 
02974   default:
02975     GEN_ERROR(E_GEN_FATAL_ERROR, "Type not implemented");
02976     L_ret = -1 ;
02977     break ;
02978   }
02979 
02980   GEN_DEBUG(1, "C_ProtocolTlv::set_body_value() end return: " <<L_ret);
02981 
02982   return (L_ret);
02983 
02984 }
02985 
02986 
02987 int  C_ProtocolTlv::set_body_sub_value(int          P_index,
02988                                     int          P_id,
02989                                     char*        P_value, 
02990                                     T_pBodyValue P_res) {
02991 
02992   int   L_ret = 0 ;
02993   T_pBodyValue L_res ;
02994 
02995   GEN_DEBUG(1, "C_ProtocolTlv::set_body_sub_value() start");
02996   GEN_DEBUG(1, " P_index: " << P_index);
02997   GEN_DEBUG(1, " P_id:    " << P_id);
02998 
02999 
03000   L_res = &(P_res -> m_sub_val[P_index]) ;
03001   L_ret = set_body_value(P_id, P_value, 0, L_res) ;
03002 
03003   GEN_DEBUG(1, "C_ProtocolTlv::set_body_sub_value() end return: " <<L_ret);
03004 
03005   return (L_ret);
03006 
03007 }
03008 
03009 
03010 
03011 void C_ProtocolTlv::set_body_value(T_pBodyValue P_res, T_pBodyValue P_val) {
03012 
03013   int   L_type_id = 0 ;
03014   unsigned long L_i ;
03015 
03016   GEN_DEBUG(1, "C_ProtocolTlv::set_body_value() T_pBodyValue - T_pBodyValue start");
03017   GEN_DEBUG(1, "P_res = " << P_res << " P_val = " << P_val);
03018 
03019   (P_res->m_id) = (P_val-> m_id) ;
03020 
03021   // retrieve type definition of the field
03022   L_type_id = m_header_body_value_table[P_res->m_id].m_type_id ;
03023 
03024   switch (m_type_def_table[L_type_id].m_type) {
03025   case E_TYPE_NUMBER :
03026     P_res->m_value.m_val_number = P_val->m_value.m_val_number;
03027     break;
03028   case E_TYPE_SIGNED :
03029     P_res->m_value.m_val_signed = P_val->m_value.m_val_signed;
03030     break;
03031   case E_TYPE_STRING :
03032     ALLOC_TABLE(P_res->m_value.m_val_binary.m_value,
03033                 unsigned char *,
03034                 sizeof(unsigned char),
03035                 P_val ->m_value.m_val_binary.m_size);
03036     memcpy(P_res->m_value.m_val_binary.m_value,
03037            P_val->m_value.m_val_binary.m_value,
03038            P_val ->m_value.m_val_binary.m_size);
03039     P_res->m_value.m_val_binary.m_size=P_val ->m_value.m_val_binary.m_size;
03040     break;
03041   case E_TYPE_STRUCT :
03042     P_res->m_value.m_val_struct = P_val->m_value.m_val_struct;
03043     break;
03044   case E_TYPE_GROUPED:
03045     P_res->m_value.m_val_number = P_val->m_value.m_val_number ;
03046     if (P_res->m_value.m_val_number != 0 ) {
03047     ALLOC_TABLE(P_res->m_sub_val,
03048                 T_pBodyValue,
03049                 sizeof(T_BodyValue),
03050                 P_res->m_value.m_val_number);
03051     for (L_i = 0 ; L_i < P_res->m_value.m_val_number; L_i++) {
03052       set_body_value(&(P_res->m_sub_val[L_i]), &(P_val->m_sub_val[L_i]));
03053     }
03054     } else {
03055       P_res->m_sub_val = NULL ;
03056     }
03057     break ;
03058   case E_TYPE_NUMBER_64 :
03059     P_res->m_value.m_val_number_64 = P_val->m_value.m_val_number_64;
03060     break;
03061   case E_TYPE_SIGNED_64 :
03062     P_res->m_value.m_val_signed_64 = P_val->m_value.m_val_signed_64;
03063     break;
03064   default:
03065     GEN_FATAL(E_GEN_FATAL_ERROR, "Value type not implemented");
03066     break ;
03067   }
03068   GEN_DEBUG(1, "C_ProtocolTlv::set_body_value() end");
03069 }
03070 
03071 void C_ProtocolTlv::delete_body_value(T_pBodyValue P_res) {
03072 
03073   int   L_type_id = 0 ;
03074   int   L_i ;
03075 
03076   GEN_DEBUG(1, "C_ProtocolTlv::delete_body_value() start");
03077   GEN_DEBUG(1, "C_ProtocolTlv::delete_body_value() Value Id: " 
03078                << P_res->m_id);
03079 
03080   // retrieve type definition of the field
03081   L_type_id = m_header_body_value_table[P_res->m_id].m_type_id ;
03082 
03083   GEN_DEBUG(1, "C_ProtocolTlv::delete_body_value() Type: " 
03084                << m_type_def_table[L_type_id].m_type 
03085                << "(" << m_header_body_value_table[P_res->m_id].m_type_id << ")");
03086 
03087   switch (m_type_def_table[L_type_id].m_type) {
03088   case E_TYPE_STRING :
03089     FREE_TABLE(P_res->m_value.m_val_binary.m_value);
03090     P_res->m_value.m_val_binary.m_size = 0 ;
03091     break;
03092   case E_TYPE_GROUPED :
03093     GEN_DEBUG(1, "C_ProtocolTlv::delete_body_value() Grouped nb: " 
03094                  << (int)P_res->m_value.m_val_number);
03095     if (P_res->m_value.m_val_number != 0 ) {
03096 
03097     for (L_i = 0 ; L_i < (int)P_res->m_value.m_val_number; L_i++) {
03098       delete_body_value(&(P_res->m_sub_val[L_i])) ;
03099       GEN_DEBUG(1, "C_ProtocolTlv::delete_body_value() Grouped nb id: " 
03100                     << L_i);
03101     }
03102     FREE_TABLE (P_res->m_sub_val);
03103     P_res->m_value.m_val_number=0 ;
03104     }
03105     break ;
03106   default:
03107     break ;
03108   }
03109   GEN_DEBUG(1, "C_ProtocolTlv::delete_body_value() end");
03110 }
03111 
03112 void C_ProtocolTlv::reset_grouped_body_value(T_pBodyValue P_res) {
03113 
03114   int   L_type_id = 0 ;
03115   int   L_i ;
03116 
03117   GEN_DEBUG(1, "C_ProtocolTlv::reset_grouped_body_value() start");
03118   GEN_DEBUG(1, "C_ProtocolTlv::reset_grouped_body_value() Value Id: " 
03119                << P_res->m_id);
03120 
03121   // retrieve type definition of the field
03122   L_type_id = m_header_body_value_table[P_res->m_id].m_type_id ;
03123 
03124   GEN_DEBUG(1, "C_ProtocolTlv::reset_grouped_body_value() Type: " 
03125                << m_type_def_table[L_type_id].m_type 
03126                << "(" << m_header_body_value_table[P_res->m_id].m_type_id << ")");
03127 
03128   switch (m_type_def_table[L_type_id].m_type) {
03129   case E_TYPE_GROUPED :
03130     GEN_DEBUG(1, "C_ProtocolTlv::reset_grouped_body_value() Grouped nb: " 
03131                  << (int)P_res->m_value.m_val_number);
03132 
03133     if (P_res->m_value.m_val_number != 0 ){
03134 
03135     for (L_i = 0 ; L_i < (int)P_res->m_value.m_val_number; L_i++) {
03136       reset_grouped_body_value(&(P_res->m_sub_val[L_i])) ;
03137       GEN_DEBUG(1, "C_ProtocolTlv::reset_grouped_body_value() Grouped nb id: " 
03138                     << L_i);
03139     }
03140     FREE_TABLE (P_res->m_sub_val);
03141     P_res->m_value.m_val_number=0 ;
03142     }
03143     break ;
03144   default:
03145     break ;
03146   }
03147   GEN_DEBUG(1, "C_ProtocolTlv::reset_grouped_body_value() end");
03148 }
03149 
03150 int  C_ProtocolTlv::decode_header (unsigned char     **P_buf, 
03151                                    size_t              P_size,
03152                                    T_pValueData        P_valDec,
03153                                    int                *P_headerId,
03154                                    C_ProtocolContext  *P_ctxt_protocol) {
03155   
03156   unsigned char        *L_ptr = (*P_buf)  ;
03157   unsigned long         L_fieldIdx     ;
03158   T_pHeaderField        L_fieldDescr   ;
03159   unsigned long         L_current_size = 0;
03160   T_UnsignedInteger32   L_current_value = 0;
03161   long                  L_current_type_id;
03162   T_DecodeMap::iterator L_decodeIt ;
03163   int                   L_ret = 0 ;
03164   int                   L_headerId ;
03165   unsigned long         L_size     ;
03166   C_ProtocolContext    *L_ctxt_protocol = P_ctxt_protocol ;
03167 
03168   GEN_DEBUG(1, "C_ProtocolTlv::decode_header() start");
03169 
03170   L_ctxt_protocol->start_ctxt_value(0, 
03171                                     P_size);
03172   
03173 
03174   for(L_fieldIdx=0; L_fieldIdx < m_nb_field_header; L_fieldIdx++) {
03175 
03176     L_fieldDescr      = &m_header_field_table[L_fieldIdx] ;
03177     L_current_size    = L_fieldDescr -> m_size ;
03178     L_current_type_id = L_fieldDescr -> m_type_id ; 
03179 
03180     if (L_current_type_id == -1)
03181     {
03182       P_valDec[L_fieldIdx].m_type = E_TYPE_NUMBER ;
03183 
03184       GEN_DEBUG(1, "C_ProtocolTlv::decode_header() value ["
03185                 << L_fieldDescr->m_name << "] with type [number] "
03186                 << " ("<<L_current_type_id<<")]");
03187     } else {
03188       P_valDec[L_fieldIdx].m_type = m_type_def_table[L_current_type_id].m_type ;
03189 
03190       GEN_DEBUG(1, "C_ProtocolTlv::decode_header() value ["
03191                 << L_fieldDescr->m_name << "] with type ["
03192                 << m_type_def_table[L_current_type_id].m_name
03193                 << " ("<<L_current_type_id<<")]");
03194 
03195     }
03196 
03197     switch (P_valDec[L_fieldIdx].m_type) {
03198         case E_TYPE_NUMBER:
03199           GEN_DEBUG(1, "Number value decoding (" << L_fieldIdx << ")");
03200           P_valDec[L_fieldIdx].m_id = L_fieldDescr->m_id ;
03201           P_valDec[L_fieldIdx].m_value.m_val_number
03202             = convert_bin_network_to_ul(L_ptr, L_current_size) ;
03203 
03204           // Store the current number value for decoding
03205           L_current_value =  P_valDec[L_fieldIdx].m_value.m_val_number;
03206 
03207           if (L_fieldDescr -> m_cond_presence != NULL) {
03208             L_current_value = (L_fieldDescr->m_cond_presence)->m_mask & L_current_value ;
03209             P_valDec[L_fieldIdx].m_value.m_val_number = L_current_value ;
03210           }
03211 
03212           GEN_DEBUG(1, "Number value = " << P_valDec[L_fieldIdx].m_value.m_val_number);
03213           break ;
03214 
03215         case E_TYPE_SIGNED:
03216           GEN_DEBUG(1, "Signed value decoding (" << L_fieldIdx << ")");
03217           P_valDec[L_fieldIdx].m_id = L_fieldDescr->m_id ;
03218           P_valDec[L_fieldIdx].m_value.m_val_signed
03219             = convert_bin_network_to_l(L_ptr, L_current_size) ;
03220 
03221           GEN_DEBUG(1, "Signed value = " << P_valDec[L_fieldIdx].m_value.m_val_signed);
03222           break ;
03223 
03224         case E_TYPE_STRING:
03225           GEN_DEBUG(1, "String value decoding (" << L_fieldIdx << ")");
03226           P_valDec[L_fieldIdx].m_id = L_fieldDescr->m_id ;
03227           P_valDec[L_fieldIdx].m_value.m_val_binary.m_size = L_current_size ;
03228           ALLOC_TABLE(P_valDec[L_fieldIdx].m_value.m_val_binary.m_value,
03229                       unsigned char*,
03230                       sizeof(unsigned char),
03231                       L_current_size);
03232           memcpy(P_valDec[L_fieldIdx].m_value.m_val_binary.m_value,
03233                  L_ptr,
03234                  L_current_size);
03235           GEN_DEBUG(1, "String value size = "
03236                 << P_valDec[L_fieldIdx].m_value.m_val_binary.m_size);
03237           break ;
03238 
03239         case E_TYPE_STRUCT: {
03240           GEN_DEBUG(1, "Number value decoding (" << L_fieldIdx << ")");
03241           size_t   L_sub_size = L_current_size/2 ;
03242           P_valDec[L_fieldIdx].m_id = L_fieldDescr->m_id ;
03243           P_valDec[L_fieldIdx].m_value.m_val_struct.m_id_1
03244             = convert_bin_network_to_ul(L_ptr, L_sub_size) ;
03245 
03246           P_valDec[L_fieldIdx].m_value.m_val_struct.m_id_2
03247             = convert_bin_network_to_ul(L_ptr + L_sub_size, L_sub_size) ;
03248 
03249 
03250           GEN_DEBUG(1, "Number value 1= " 
03251                        << P_valDec[L_fieldIdx].m_value.m_val_struct.m_id_1);
03252           GEN_DEBUG(1, "Number value 2= " 
03253                        << P_valDec[L_fieldIdx].m_value.m_val_struct.m_id_2);
03254           }
03255           break ;
03256 
03257         case E_TYPE_GROUPED:
03258           GEN_DEBUG(1, "Grouped values decoding (" << L_fieldIdx << ")");
03259           P_valDec[L_fieldIdx].m_id = L_fieldDescr->m_id ;
03260 
03261         case E_TYPE_NUMBER_64:
03262           GEN_DEBUG(1, "Number64 value decoding (" << L_fieldIdx << ")");
03263           P_valDec[L_fieldIdx].m_id = L_fieldDescr->m_id ;
03264           P_valDec[L_fieldIdx].m_value.m_val_number_64
03265             = convert_bin_network_to_ull(L_ptr, L_current_size) ;
03266 
03267           GEN_DEBUG(1, "Number64 value = " << P_valDec[L_fieldIdx].m_value.m_val_number_64);
03268           break ;
03269 
03270         case E_TYPE_SIGNED_64:
03271           GEN_DEBUG(1, "Signed64 value decoding (" << L_fieldIdx << ")");
03272           P_valDec[L_fieldIdx].m_id = L_fieldDescr->m_id ;
03273           P_valDec[L_fieldIdx].m_value.m_val_signed_64
03274             = convert_bin_network_to_ll(L_ptr, L_current_size) ;
03275 
03276           GEN_DEBUG(1, "Signed64 value = " << P_valDec[L_fieldIdx].m_value.m_val_signed_64);
03277           break ;
03278 
03279         default:
03280           GEN_ERROR(E_GEN_FATAL_ERROR, "value header type not implemented");
03281           break ;
03282     }
03283 
03284  
03285     if (m_header_ctxt_p_table[L_fieldIdx].m_ctxt_id_pos != -1 ) {
03286       L_ctxt_protocol->start_ctxt_value(m_header_ctxt_p_table[L_fieldIdx].m_ctxt_id_pos,
03287                                         P_valDec[L_fieldIdx].m_value.m_val_number);
03288     }
03289 
03290     L_ret = update_ctxt_values_decode(L_ctxt_protocol, 
03291                                       L_fieldIdx,
03292                                       L_current_size,
03293                                       m_header_ctxt_v_table);
03294     if (L_ret == -1) {
03295       return (1);
03296     }
03297 
03298     L_size = L_ptr + L_current_size - (*P_buf) ; 
03299     if (L_size > P_size ) {
03300       return (2);
03301     }
03302 
03303     L_ptr += L_current_size ;
03304 
03305 
03306     // NOT IMPLEMENTED 
03307     // if values have to be tested => do it here
03308 
03309     GEN_DEBUG(1, "C_ProtocolTlv::decode_header() L_fieldIdx " << 
03310                   L_fieldIdx << " and m_header_type_id  " << m_header_type_id );
03311 
03312     // m_header_type_id_body
03313     if (m_header_type_id != -1) {
03314       if (L_fieldIdx == (unsigned long) m_header_type_id) {
03315 
03316         // retrieve type defined
03317         L_decodeIt = m_header_decode_map
03318           ->find(T_DecodeMap::key_type(L_current_value));
03319         if (L_decodeIt != m_header_decode_map->end()) {
03320           L_headerId = L_decodeIt->second ;
03321 
03322           if (m_stats) {
03323             m_stats->updateStats (E_MESSAGE,
03324                                   E_RECEIVE,
03325                                   L_headerId);
03326           }
03327 
03328           GEN_DEBUG(1, "C_ProtocolTlv::decode_header() L_ret: " << L_ret);
03329         }
03330       }
03331     } 
03332   } // for
03333 
03334   (*P_buf) = L_ptr ;
03335   (*P_headerId) = L_headerId;
03336 
03337 
03338   GEN_DEBUG(1, "C_ProtocolTlv::decode_header() end l_ret: " << L_ret);
03339   return (L_ret) ;
03340 }
03341 
03342 
03343 int C_ProtocolTlv::decode_body(unsigned char     **P_buf, 
03344                                T_pBodyValue        P_valDec,
03345                                int                *P_nbValDec,
03346                                int                *P_headerId,
03347                                C_ProtocolContext  *P_ctxt_protocol) {
03348 
03349   int                   L_max_values = *P_nbValDec ;
03350   unsigned char        *L_ptr = (*P_buf) ;
03351   int                   L_ret = 0 ;
03352 
03353   T_pHeaderField        L_body_fieldDescr   ;
03354   T_pHeaderBodyValue    L_body_fieldValues  ;
03355 
03356   unsigned long         L_body_fieldIdx, L_current_size, L_current_value ;
03357   unsigned long         L_data_size, L_data_type, L_padding ;
03358 
03359   T_DecodeMap::iterator L_decodeIt ;
03360   int                   L_body_value_id ;
03361   int                   L_type_id ;
03362   T_TypeType            L_type ;
03363   int                   L_nbValDec = 0 ;
03364 
03365   unsigned long         L_body_found_val [100] ; // TEMPORARY
03366   T_BodyValue           L_body_val       [50]  ; // TEMPORARY
03367   unsigned long         L_i ;
03368 
03369   unsigned long         L_type_id_val ;
03370 
03371   int                   L_header_type_id = get_header_type_id();
03372 
03373   unsigned long         L_body_fieldIdx2  ;
03374   bool                  L_header_body_type_id_present ;
03375   unsigned long         L_header_body_size ;
03376  
03377   unsigned long         L_total_size     ;
03378 
03379   C_ProtocolContext    *L_ctxt_protocol = P_ctxt_protocol ;
03380   unsigned long         L_size  = P_ctxt_protocol->get_counter_ctxt(0);
03381 
03382 
03383   GEN_DEBUG(1, "\nC_ProtocolTlv::decode_body() start");
03384   GEN_DEBUG(1, "C_ProtocolTlv::decode_body() L_size: " << L_size);
03385   GEN_DEBUG(1, "C_ProtocolTlv::decode_body() P_nbValDec: " << *P_nbValDec);
03386   GEN_DEBUG(1, "C_ProtocolTlv::decode_body() P_headerId: " << *P_headerId);
03387 
03388   *P_nbValDec  = 0 ;
03389   L_total_size = 0 ;
03390 
03391   while (true) {
03392     
03393     GEN_DEBUG(1, "\nField Nb: " << L_nbValDec);
03394     
03395     L_data_size = 0  ;
03396     L_data_type = 0  ;
03397     L_header_body_type_id_present = false ;
03398     L_header_body_size  = 0 ;
03399     
03400     if (L_nbValDec == L_max_values) {
03401       GEN_FATAL(E_GEN_FATAL_ERROR, "Maximum number of values reached ["
03402                 << L_max_values << "]");
03403       break ;
03404     }
03405     
03406     // Decode field header 
03407     for(L_body_fieldIdx=0; 
03408         L_body_fieldIdx < m_nb_field_header_body; 
03409         L_body_fieldIdx++) {
03410       
03411       L_body_fieldDescr = &m_header_body_field_table[L_body_fieldIdx];
03412       L_current_size  = L_body_fieldDescr -> m_size ;
03413       L_header_body_size  += L_current_size ;
03414       
03415       L_current_value = convert_bin_network_to_ul(L_ptr, L_current_size);
03416       L_body_found_val[L_body_fieldIdx] = L_current_value ;
03417       if (L_body_fieldIdx == (unsigned long)m_header_body_type_id) {        
03418         L_decodeIt = 
03419           m_header_body_decode_map->find (T_DecodeMap::key_type(L_current_value));
03420         
03421         if (L_decodeIt != m_header_body_decode_map->end()) {
03422           L_body_value_id = L_decodeIt->second ;
03423           L_body_fieldValues = &m_header_body_value_table[L_body_value_id] ;
03424           L_header_body_type_id_present = true;
03425         } else {
03426           GEN_WARNING("Unknown body value type [" << L_data_type 
03427                       << "] with size ["
03428                       << L_current_value << "]");
03429         }
03430       }
03431 
03432       if (m_header_body_ctxt_p_table[L_body_fieldIdx].m_ctxt_id_pos != -1 ) {
03433         L_ctxt_protocol->start_ctxt_value(m_header_body_ctxt_p_table[L_body_fieldIdx].m_ctxt_id_pos,
03434                                           L_current_value);
03435       }
03436       
03437       L_ret = update_ctxt_values_decode(L_ctxt_protocol, 
03438                                         L_body_fieldIdx,
03439                                         L_current_size,
03440                                         m_header_body_ctxt_v_table);
03441       
03442       
03443       if (L_ret == -1) return 1 ;
03444 
03445       L_total_size +=  L_current_size ;
03446       if (L_total_size >= L_size) return 2 ;
03447 
03448       L_ptr += L_current_size ;
03449 
03450 
03451       if (L_header_body_type_id_present) break;
03452 
03453     }
03454 
03455     for(L_body_fieldIdx2 = L_body_fieldIdx +1 ; 
03456         L_body_fieldIdx2 < m_nb_field_header_body; 
03457         L_body_fieldIdx2++) {
03458       
03459       if (L_body_fieldValues-> m_present[L_body_fieldIdx2]) {
03460       L_current_size  = L_body_fieldValues-> m_size[L_body_fieldIdx2] ;
03461       L_header_body_size  += L_current_size ;
03462       L_current_value = convert_bin_network_to_ul(L_ptr, L_current_size);
03463       L_body_found_val[L_body_fieldIdx2] = L_current_value ;
03464       
03465       if (L_body_fieldIdx2 == (unsigned long)m_header_body_length_id) {
03466         L_data_size = L_current_value ;
03467       }
03468 
03469       if (m_header_body_ctxt_p_table[L_body_fieldIdx2].m_ctxt_id_pos != -1 ) {
03470         L_ctxt_protocol->start_ctxt_value(m_header_body_ctxt_p_table[L_body_fieldIdx2].m_ctxt_id_pos,
03471                                           L_current_value);
03472       }
03473       
03474       L_ret = update_ctxt_values_decode(L_ctxt_protocol, 
03475                                         L_body_fieldIdx2,
03476                                         L_current_size,
03477                                         m_header_body_ctxt_v_table);
03478       
03479       if (L_ret == -1) return 1 ;
03480 
03481       L_total_size += L_current_size ;
03482       if (L_total_size >= L_size) return 2 ;
03483       L_ptr += L_current_size ;
03484       
03485       }
03486     } // for
03487     
03488     // Retrieve optional fields
03489     if (m_header_body_start_optional_id != -1) {
03490       for(L_body_fieldIdx=m_header_body_start_optional_id; 
03491           L_body_fieldIdx < m_max_nb_field_header_body; 
03492           L_body_fieldIdx++) {
03493         L_body_fieldDescr = &m_header_body_field_table[L_body_fieldIdx];
03494         if (check_presence_needed(L_body_fieldDescr->m_cond_presence,
03495                                   L_body_found_val) == true) {
03496           // L_current_size = L_body_fieldDescr -> m_size ;
03497           L_current_size = L_body_fieldValues-> m_size[L_body_fieldIdx] ;
03498           L_header_body_size += L_current_size ;
03499           
03500           L_current_value = convert_bin_network_to_ul(L_ptr, L_current_size);
03501 
03502           if (m_header_body_ctxt_p_table[L_body_fieldIdx].m_ctxt_id_pos != -1 ) {
03503             L_ctxt_protocol->start_ctxt_value(m_header_ctxt_p_table[L_body_fieldIdx2].m_ctxt_id_pos,
03504                                               L_current_value);
03505           }
03506           
03507           L_ret = update_ctxt_values_decode(L_ctxt_protocol, 
03508                                             L_body_fieldIdx,
03509                                             L_current_size,
03510                                             m_header_body_ctxt_v_table);
03511           
03512           
03513           if (L_ret == -1) return 1 ;
03514           
03515           // L_size = L_ptr + L_current_size - (*P_buf) ;
03516           L_total_size += L_current_size ;
03517           if (L_total_size >= L_size) return 2 ;
03518           L_ptr += L_current_size ;
03519         }
03520       }
03521     } // if (m_header_body_start_optional_id != -1)
03522 
03523     L_data_size = L_ctxt_protocol->get_counter_ctxt(m_ctxt_id_data_size);
03524 
03525     // padding ?
03526     if (m_padding_value) {
03527       L_padding = L_data_size % m_padding_value ;
03528       if (L_padding) { L_padding = m_padding_value - L_padding ; }
03529     } else {
03530       L_padding = 0 ;
03531     }
03532 
03533     GEN_DEBUG(1, "body field data size " << L_data_size << " ");
03534 
03535     if ((L_total_size + L_data_size) <= L_size) {
03536 
03537       if (m_stats) {
03538         m_stats->updateStats (E_MESSAGE_COMPONENT,
03539                               E_RECEIVE,
03540                               L_body_value_id);
03541       }
03542       
03543       
03544       // L_body_fieldValues = &m_header_body_value_table[L_body_value_id] ;
03545       L_type_id = L_body_fieldValues->m_type_id ;
03546       L_type = m_type_def_table[L_type_id].m_type ;
03547       
03548       GEN_DEBUG(1, "body value ["
03549                 << L_body_fieldValues->m_name << "] with type [" 
03550                 << m_type_def_table[L_type_id].m_name
03551                 << " ("<<L_type<<")]");
03552       
03553       switch (L_type) {
03554       case E_TYPE_NUMBER:
03555         GEN_DEBUG(1, "  Number value decoding (" << L_nbValDec << ")");
03556         P_valDec[L_nbValDec].m_id = L_body_value_id ;
03557         P_valDec[L_nbValDec].m_value.m_val_number 
03558           = convert_bin_network_to_ul(L_ptr, L_data_size) ;
03559         
03560         GEN_DEBUG(1, "  Number value = " 
03561                   << P_valDec[L_nbValDec].m_value.m_val_number);
03562         L_nbValDec ++ ;
03563         break ;
03564         
03565       case E_TYPE_SIGNED:
03566         GEN_DEBUG(1, "  Signed value decoding (" << L_nbValDec << ")");
03567         // GEN_DEBUG(1, "L_body_value_id " << L_body_value_id << " L_data_size " << L_data_size );
03568         // GEN_DEBUG(1, "Val value = " << L_ptr[0] << " ");
03569         P_valDec[L_nbValDec].m_id = L_body_value_id ;
03570         
03571         P_valDec[L_nbValDec].m_value.m_val_signed 
03572           = convert_bin_network_to_l(L_ptr, L_data_size) ;
03573         
03574         GEN_DEBUG(1, "  Signed value = " 
03575                   << P_valDec[L_nbValDec].m_value.m_val_signed);
03576         L_nbValDec ++ ;
03577         break ;
03578         
03579       case E_TYPE_STRING:
03580         GEN_DEBUG(1, "  String value decoding (" << L_nbValDec << ")");
03581         P_valDec[L_nbValDec].m_id = L_body_value_id ;
03582         P_valDec[L_nbValDec].m_value.m_val_binary.m_size = L_data_size ;
03583         
03584         ALLOC_TABLE(P_valDec[L_nbValDec].m_value.m_val_binary.m_value,
03585                     unsigned char*,
03586                     sizeof(unsigned char),
03587                     L_data_size);
03588         memcpy(P_valDec[L_nbValDec].m_value.m_val_binary.m_value,
03589                L_ptr,
03590                L_data_size);
03591         GEN_DEBUG(1, "  String value size = " 
03592                   << P_valDec[L_nbValDec].m_value.m_val_binary.m_size);
03593         L_nbValDec ++ ;
03594         break ;
03595         
03596       case E_TYPE_STRUCT: {
03597         GEN_DEBUG(1, "  Struct value decoding (" << L_nbValDec << ")");
03598         size_t   L_sub_size = L_data_size/2 ;
03599         P_valDec[L_nbValDec].m_id = L_body_value_id ;
03600         
03601         P_valDec[L_nbValDec].m_value.m_val_struct.m_id_1 
03602           = convert_bin_network_to_ul(L_ptr, L_sub_size) ;
03603         
03604         P_valDec[L_nbValDec].m_value.m_val_struct.m_id_2 
03605           = convert_bin_network_to_ul(L_ptr + L_sub_size, L_sub_size) ;
03606         
03607         
03608         GEN_DEBUG(1, "  Number value 1 = " 
03609                   << P_valDec[L_nbValDec].m_value.m_val_struct.m_id_1);
03610         GEN_DEBUG(1, "  Number value 2 = " 
03611                   << P_valDec[L_nbValDec].m_value.m_val_struct.m_id_2);
03612         L_nbValDec ++ ;
03613       }
03614       break ;
03615       
03616       case E_TYPE_GROUPED:
03617         {
03618           GEN_DEBUG(1, "  Grouped values decoding (" << L_nbValDec << ")");
03619           P_valDec[L_nbValDec].m_id = L_body_value_id ;
03620           // P_valDec[L_nbValDec].m_value.m_val_number = 50 ;
03621           
03622           int L_val_nb = 50;
03623           
03624           L_ret = decode_body(&L_ptr, 
03625                               L_body_val, 
03626                               &L_val_nb,
03627                               P_headerId,
03628                               L_ctxt_protocol) ;
03629           if (L_ret == 0) {
03630             GEN_DEBUG(1, "  allocated nb values: " << L_val_nb 
03631                       << " on grouped value (" << L_nbValDec << ")" );
03632             
03633             (*P_buf) = L_ptr ;
03634 
03635             P_valDec[L_nbValDec].m_value.m_val_number = L_val_nb ;
03636             if (L_val_nb > 0){
03637               ALLOC_TABLE(P_valDec[L_nbValDec].m_sub_val,
03638                           T_pBodyValue,
03639                           sizeof(T_BodyValue),
03640                           L_val_nb);
03641               for (L_i = 0 ; L_i < (unsigned int) L_val_nb; L_i++) {
03642                 set_body_value(&(P_valDec[L_nbValDec].m_sub_val[L_i]), 
03643                                &(L_body_val[L_i]));
03644               }
03645               // Now do not forget to clean L_body_val
03646               reset_body_values(L_val_nb, L_body_val);
03647             } else {
03648               P_valDec[L_nbValDec].m_sub_val = NULL ;
03649             }
03650             
03651             L_nbValDec++;
03652             
03653           } else {
03654             GEN_ERROR (E_GEN_FATAL_ERROR, "Erroneous grouped value");
03655             L_ret = 1 ;
03656           }
03657           
03658         }
03659         break ;
03660         
03661       case E_TYPE_NUMBER_64:
03662         GEN_DEBUG(1, "  Number64 value decoding (" << L_nbValDec << ")");
03663         P_valDec[L_nbValDec].m_id = L_body_value_id ;
03664         P_valDec[L_nbValDec].m_value.m_val_number_64 
03665           = convert_bin_network_to_ull(L_ptr, L_data_size) ;
03666         
03667         GEN_DEBUG(1, "  Number64 value = " 
03668                   << P_valDec[L_nbValDec].m_value.m_val_number_64);
03669         L_nbValDec ++ ;
03670         break ;
03671         
03672       case E_TYPE_SIGNED_64:
03673         GEN_DEBUG(1, "  Signed64 value decoding (" << L_nbValDec << ")");
03674         P_valDec[L_nbValDec].m_id = L_body_value_id ;
03675         P_valDec[L_nbValDec].m_value.m_val_signed_64 
03676           = convert_bin_network_to_ll(L_ptr, L_data_size) ;
03677         
03678         GEN_DEBUG(1, "  Signed64 value = " 
03679                   << P_valDec[L_nbValDec].m_value.m_val_signed_64);
03680         L_nbValDec ++ ;
03681         break ;
03682         
03683       default:
03684         GEN_ERROR(E_GEN_FATAL_ERROR, "value body type not implemented");
03685         break ;
03686       }
03687       
03688       // if (get_header_type_id() == -1) 
03689       // Check if header type exist
03690       if (L_header_type_id == -1) {
03691         
03692         // Now check if the current field is the msg type one
03693         if (L_body_value_id == m_header_type_id_body) {
03694           
03695           L_type_id_val = P_valDec[L_nbValDec-1].m_value.m_val_number ;
03696           
03697           GEN_DEBUG(1, "body value ["
03698                     << L_body_fieldValues->m_name << "] with id [" 
03699                     << L_body_value_id 
03700                     << "] specify the message type: " << L_type_id_val);
03701           
03702           L_decodeIt = m_header_decode_map
03703             ->find(T_DecodeMap::key_type(L_type_id_val));
03704           if (L_decodeIt != m_header_decode_map->end()) {
03705             // header recognized
03706             (*P_headerId) = L_decodeIt->second ;
03707           } else {
03708             GEN_LOG_EVENT_FORCE("not found");
03709           }
03710           
03711         }
03712       }
03713       
03714       L_ptr += L_data_size ;
03715       L_ptr += L_padding ;
03716       L_total_size += L_data_size + L_padding ;
03717      
03718       L_ret = update_ctxt_length_decode (L_ctxt_protocol,
03719                                          L_data_size);
03720 
03721       if (L_ret == -1) return 1 ;
03722 
03723     } else {
03724       GEN_ERROR (E_GEN_FATAL_ERROR, "message size error (body size)");
03725       return 2 ;
03726     }
03727     
03728     if (L_ret != 0) break ;
03729 
03730     if (L_ctxt_protocol->end_counter_ctxt()) break;
03731 
03732     reset_protocol_context(L_ctxt_protocol);
03733 
03734   } // End while
03735   
03736   *P_nbValDec = L_nbValDec ;
03737   (*P_buf) = L_ptr ;
03738 
03739 
03740   GEN_DEBUG(1, "C_ProtocolTlv::decode_body() end nb Val: " << L_nbValDec
03741                 << " ret: " << L_ret << "\n");
03742   return (L_ret) ;
03743 
03744 }
03745 
03746 
03747 void C_ProtocolTlv::encode_header (int P_id, 
03748                                 unsigned char *P_buf, 
03749                                 size_t *P_size) {
03750 
03751   unsigned char *L_ptr = P_buf  ;
03752   unsigned long  L_fieldIdx     ;
03753   int            L_valueIdx     ;
03754   T_pHeaderField L_fieldDescr   ;
03755   T_pHeaderValue L_fieldValues  ;
03756   unsigned long  L_current_size, L_total_size ;
03757   unsigned long  L_current_value ;
03758 
03759   GEN_DEBUG(1, "C_ProtocolTlv::encode_header(" << P_id 
03760         << "," << &P_buf << "," << P_size << ") 2 start");
03761 
03762   L_current_size = 0 ;
03763   L_total_size = 0 ;
03764   L_fieldValues = &m_header_value_table[P_id] ;
03765 
03766   GEN_DEBUG(1, "C_ProtocolTlv::encode_header m_nb_field_header = " 
03767                << m_nb_field_header);
03768 
03769 
03770   for(L_fieldIdx=0; L_fieldIdx < m_nb_field_header; L_fieldIdx++) {
03771 
03772     L_fieldDescr = &m_header_field_table[L_fieldIdx] ;
03773     L_current_size = L_fieldDescr -> m_size ;
03774     L_total_size += L_current_size ;
03775 
03776     GEN_DEBUG(1, "C_ProtocolTlv::encode_header L_fieldIdx = " 
03777                  << L_fieldIdx); 
03778     GEN_DEBUG(1, "C_ProtocolTlv::encode_header L_current_size = " 
03779                  << L_current_size);
03780     GEN_DEBUG(1, "C_ProtocolTlv::encode_header L_total_size = " 
03781                  << L_total_size);
03782 
03783     if (L_fieldValues->m_value_setted[L_fieldIdx] == false) {
03784       L_current_value = (unsigned long) 0 ;
03785     } else {
03786       L_valueIdx = L_fieldValues->m_id_value_setted[L_fieldIdx];
03787       L_current_value = L_fieldValues->m_values[L_valueIdx].m_value.m_val_number ;
03788     }
03789 
03790     GEN_DEBUG(1, "C_ProtocolTlv::encode_header L_current_value " 
03791                  << L_current_value);
03792 
03793     convert_ul_to_bin_network(L_ptr,
03794                               L_current_size,
03795                               L_current_value) ;
03796 
03797     L_ptr += L_current_size ;
03798   }
03799 
03800   *P_size = L_total_size ;
03801 
03802 
03803 
03804   GEN_DEBUG(1, "C_ProtocolTlv::encode_header() 2 end");
03805 
03806 }
03807 
03808 
03809 void C_ProtocolTlv::encode_header (int            P_id,
03810                                    T_pValueData   P_headerVal,
03811                                    unsigned char *P_buf, 
03812                                    size_t             *P_size,
03813                                    C_ProtocolContext  *P_ctxt_protocol,
03814                                    C_ProtocolFrame::T_pMsgError P_error) {
03815 
03816   unsigned char      *L_ptr = P_buf  ;
03817   unsigned long       L_fieldIdx     ;
03818   T_pHeaderField      L_fieldDescr   ;
03819 
03820   unsigned long       L_current_size, L_total_size ;
03821   T_UnsignedInteger32 L_current_value ;
03822   T_UnsignedInteger64 L_current_value_ll ;
03823 
03824   int            L_type_id ;
03825   T_TypeType     L_type ;
03826 
03827   unsigned char        *L_position_ptr = NULL;
03828   C_ProtocolContext    *L_ctxt_protocol = P_ctxt_protocol ;
03829 
03830 
03831 
03832   GEN_DEBUG(1, "C_ProtocolTlv::encode_header(" << P_id 
03833         << "," << &P_buf << "," << P_size << ") 1 start");
03834 
03835   *P_error = C_ProtocolFrame::E_MSG_OK ;
03836 
03837   L_current_size = 0 ;
03838   L_total_size = 0 ;
03839 
03840   GEN_DEBUG(1, "C_ProtocolTlv::encode_header m_nb_field_header = " 
03841                << m_nb_field_header);
03842 
03843   if (m_stats) {
03844     m_stats->updateStats(E_MESSAGE,
03845                          E_SEND,
03846                          P_id);
03847   }
03848 
03849   for(L_fieldIdx=0; L_fieldIdx < m_nb_field_header; L_fieldIdx++) {
03850 
03851     L_fieldDescr = &m_header_field_table[L_fieldIdx] ;
03852     
03853     L_current_size = L_fieldDescr -> m_size ;
03854     L_position_ptr = L_ptr ;
03855     
03856     L_total_size += L_current_size ;
03857 
03858     if (L_total_size > *P_size) {
03859       GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
03860                     "Buffer max size reached [" << *P_size << "]");
03861       *P_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
03862       break ;
03863     }
03864 
03865     L_type_id = L_fieldDescr->m_type_id ;
03866     if (L_type_id == -1) {
03867       L_type = E_TYPE_NUMBER;
03868     } else {
03869       L_type = m_type_def_table[L_type_id].m_type ;
03870     }
03871     
03872     // now add the value of the body
03873     switch (L_type) {
03874 
03875     case E_TYPE_NUMBER:
03876       L_current_value = P_headerVal[L_fieldIdx].m_value.m_val_number ;
03877 
03878       GEN_DEBUG(1, "Number Value set = " << L_current_value);
03879 
03880       convert_ul_to_bin_network(L_ptr,
03881                                 L_current_size,
03882                                 L_current_value);
03883       break ;
03884 
03885     case E_TYPE_SIGNED:
03886       L_current_value = P_headerVal[L_fieldIdx].m_value.m_val_signed ;
03887 
03888       GEN_DEBUG(1, "Signed Value set = " << L_current_value);
03889 
03890       convert_l_to_bin_network(L_ptr,
03891                                L_current_size,
03892                                L_current_value);
03893       break ;
03894 
03895     case E_TYPE_STRING: {
03896       size_t L_padding ;
03897       if (P_headerVal[L_fieldIdx].m_value.m_val_binary.m_size == 0) {
03898         GEN_ERROR(E_GEN_FATAL_ERROR, 
03899                   "The value of the field ["
03900                   << L_fieldDescr -> m_name 
03901                   << "] is not set");
03902         
03903         //        *P_error = C_ProtocolTlvFrame::E_MSG_ERROR_ENCODING ;
03904         *P_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
03905         break;
03906       }
03907 
03908       memcpy(L_ptr, P_headerVal[L_fieldIdx].m_value.m_val_binary.m_value, L_current_size);
03909       if (m_padding_value) {
03910         L_padding = L_current_size % m_padding_value ;
03911         if (L_padding) { L_padding = m_padding_value - L_padding ; }
03912         while (L_padding) {
03913           *(L_ptr+L_current_size) = '\0' ;
03914           L_current_size++ ;
03915           L_padding-- ;
03916         }
03917       } else {
03918         L_padding = 0 ;
03919       }
03920     }
03921         break ;
03922 
03923     case E_TYPE_STRUCT: {
03924       size_t   L_sub_value_size = L_current_size/2 ;
03925 
03926       convert_ul_to_bin_network(L_ptr,
03927                                 L_sub_value_size,
03928                                 P_headerVal[L_fieldIdx].m_value.m_val_struct.m_id_1);
03929 
03930       convert_ul_to_bin_network(L_ptr + L_sub_value_size,
03931                                 L_sub_value_size,
03932                                 P_headerVal[L_fieldIdx].m_value.m_val_struct.m_id_2);
03933       }
03934         break ;
03935 
03936     case E_TYPE_NUMBER_64:
03937       L_current_value_ll = P_headerVal[L_fieldIdx].m_value.m_val_number_64 ;
03938 
03939       GEN_DEBUG(1, "Number64 Value set = " << L_current_value_ll);
03940 
03941       convert_ull_to_bin_network(L_ptr,
03942                                  L_current_size,
03943                                  L_current_value_ll);
03944       break ;
03945 
03946     case E_TYPE_SIGNED_64:
03947       L_current_value_ll = P_headerVal[L_fieldIdx].m_value.m_val_signed_64 ;
03948 
03949       GEN_DEBUG(1, "Signed64 Value set = " << L_current_value_ll);
03950 
03951       convert_ll_to_bin_network(L_ptr,
03952                                 L_current_size,
03953                                 L_current_value_ll);
03954       break ;
03955 
03956     case E_TYPE_GROUPED:
03957     default:
03958       GEN_FATAL(E_GEN_FATAL_ERROR,
03959             "Encoding method not implemented for this value");
03960       break ;
03961     }
03962 
03963     update_ctxt_values (L_ctxt_protocol,
03964                         L_position_ptr,
03965                         L_fieldIdx,
03966                         (int)L_current_size,
03967                         m_header_ctxt_v_table,
03968                         m_header_ctxt_p_table) ;
03969       
03970       
03971     L_ptr += L_current_size ;
03972   } // for
03973 
03974   if (*P_error == C_ProtocolFrame::E_MSG_OK) {
03975     *P_size = L_total_size ;
03976   }
03977 
03978 
03979   GEN_DEBUG(1, "C_ProtocolTlv::encode_header() 1 end");
03980 
03981 }
03982 
03983 
03984 C_ProtocolFrame::T_MsgError C_ProtocolTlv::encode_body (int            P_nbVal, 
03985                                                         T_pBodyValue   P_val,
03986                                                         unsigned char *P_buf, 
03987                                                         size_t        *P_size,
03988                                                         C_ProtocolContext  *P_ctxt_protocol) {
03989 
03990   unsigned char     *L_ptr = P_buf ;
03991   int                L_i, L_body_id ;
03992   int                L_valueIdx     ;
03993   size_t             L_total_size   = 0 ;
03994   size_t             L_current_size = 0 ;
03995   T_pHeaderField     L_body_fieldDescr   ;
03996   T_pHeaderBodyValue L_body_fieldValues  ;
03997   T_pBodyValue       L_body_val ;
03998   unsigned long      L_body_fieldIdx, L_valueSize  ;
03999   int                L_type_id ;
04000   T_TypeType         L_type ;
04001   unsigned long      L_current_value ;
04002 
04003   unsigned long      L_header_body_size ;
04004 
04005   unsigned char *L_save_length_ptr = NULL;
04006   unsigned long  L_save_length = 0;
04007   size_t         L_length_size = 0;
04008 
04009   size_t         L_sub_size ;
04010   C_ProtocolFrame::T_MsgError  L_error = C_ProtocolFrame::E_MSG_OK;
04011 
04012   unsigned char        *L_position_ptr = NULL;
04013   C_ProtocolContext    *L_ctxt_protocol = P_ctxt_protocol ;
04014 
04015 
04016   GEN_DEBUG(1, "C_ProtocolTlv::encode_body() start");
04017 
04018   L_total_size = 0 ;
04019   L_current_size = 0 ;
04020 
04021   for (L_i = 0; L_i < P_nbVal ; L_i ++) {
04022 
04023     L_body_val = &P_val[L_i] ;
04024     L_body_id = L_body_val->m_id  ;
04025 
04026     if (m_stats) {
04027       m_stats->updateStats (E_MESSAGE_COMPONENT,
04028                             E_SEND,
04029                             L_body_id);
04030     }
04031 
04032     L_body_fieldValues = &m_header_body_value_table[L_body_id] ;
04033     L_type_id = L_body_fieldValues->m_type_id ;
04034     L_type = m_type_def_table[L_type_id].m_type ;
04035 
04036     if (L_type == E_TYPE_STRING) {
04037       L_valueSize = 
04038         L_body_val -> m_value.m_val_binary.m_size ;
04039     } else {
04040       L_valueSize = 
04041         m_type_def_table[L_type_id].m_size ;
04042     }
04043 
04044     L_header_body_size = 0 ;
04045     L_save_length_ptr = NULL ;
04046     for(L_body_fieldIdx=0; 
04047         L_body_fieldIdx < m_nb_field_header_body; 
04048         L_body_fieldIdx++) {
04049 
04050       if (L_body_fieldValues->m_present[L_body_fieldIdx]) {
04051       L_current_size = L_body_fieldValues->m_size[L_body_fieldIdx] ;
04052       L_header_body_size += L_current_size ;
04053       L_total_size += L_current_size ;      
04054 
04055       if (L_total_size > *P_size) {
04056         GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
04057                       "Buffer max size reached [" << *P_size << "]");
04058         L_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
04059         break ;
04060       }
04061 
04062       L_position_ptr = L_ptr ;
04063 
04064       update_ctxt_values (L_ctxt_protocol,
04065                           L_position_ptr,
04066                           L_body_fieldIdx,
04067                           (int)L_current_size,
04068                           m_header_body_ctxt_v_table,
04069                           m_header_body_ctxt_p_table) ;
04070       
04071       if (L_body_fieldIdx == (unsigned long)m_header_body_length_id) {
04072         L_save_length = L_valueSize ;
04073         L_length_size = L_current_size ;
04074         L_save_length_ptr = L_ptr ;
04075       } else {
04076         
04077         if (L_body_fieldValues->m_value_setted[L_body_fieldIdx] == false) {
04078           L_current_value = (unsigned long) 0 ;
04079         } else {
04080           L_valueIdx = L_body_fieldValues
04081             ->m_id_value_setted[L_body_fieldIdx];
04082           L_current_value = L_body_fieldValues
04083             ->m_values[L_valueIdx].m_value.m_val_number ;
04084         }
04085         
04086         convert_ul_to_bin_network(L_ptr,
04087                                   L_current_size,
04088                                   L_current_value) ;
04089         
04090       }
04091       L_ptr += L_current_size ;
04092     }
04093     } // for(L_body_fieldIdx...
04094 
04095     if (L_error != C_ProtocolFrame::E_MSG_OK) {
04096       break ;
04097     }
04098 
04099     // optional field value management
04100     if (m_header_body_start_optional_id != -1) { // optional part to be added
04101 
04102       for(L_body_fieldIdx=m_header_body_start_optional_id; 
04103           L_body_fieldIdx < m_max_nb_field_header_body; 
04104           L_body_fieldIdx++) {
04105 
04106         L_body_fieldDescr = &m_header_body_field_table[L_body_fieldIdx];
04107         if (L_body_fieldValues->m_value_setted[L_body_fieldIdx] == true) {
04108 
04109           L_current_size = L_body_fieldValues->m_size[L_body_fieldIdx] ;
04110           L_header_body_size += L_current_size ;
04111       
04112           // L_current_size = L_body_fieldDescr -> m_size ;
04113           L_total_size += L_current_size ;
04114 
04115           if (L_total_size > *P_size) {
04116             GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
04117                           "Buffer max size reached [" << *P_size << "]");
04118             L_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
04119             break ;
04120           }
04121 
04122           L_position_ptr = L_ptr ;
04123           
04124           update_ctxt_values (L_ctxt_protocol,
04125                               L_position_ptr,
04126                               L_body_fieldIdx,
04127                               (int)L_current_size,
04128                               m_header_body_ctxt_v_table,
04129                               m_header_body_ctxt_p_table) ;
04130           L_valueIdx = L_body_fieldValues
04131             ->m_id_value_setted[L_body_fieldIdx];
04132           L_current_value = L_body_fieldValues
04133             ->m_values[L_valueIdx].m_value.m_val_number ;
04134           convert_ul_to_bin_network(L_ptr,
04135                                     L_current_size,
04136                                     L_current_value) ;
04137           L_ptr += L_current_size ;
04138         }
04139       } // for (L_body_fieldIdx...
04140 
04141     } // if (m_header_body_start_optional_id != -1)
04142 
04143     GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  value encoding for = " 
04144                  << L_body_fieldValues->m_name);
04145 
04146 
04147     if (L_error != C_ProtocolFrame::E_MSG_OK) {
04148       break ;
04149     }  
04150 
04151 
04152     if ((L_total_size+L_valueSize) > *P_size) {
04153       GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
04154                     "Buffer max size reached [" << *P_size << "]");
04155       L_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
04156       break ;
04157     }
04158 
04159     // now add the value of the body
04160     switch (L_type) {
04161 
04162     case E_TYPE_NUMBER:
04163       convert_ul_to_bin_network(L_ptr,
04164                                 L_valueSize,
04165                                 L_body_val -> m_value.m_val_number);
04166 
04167       GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  with number value = " 
04168                    << L_body_val->m_value.m_val_number);
04169       break ;
04170 
04171     case E_TYPE_SIGNED:
04172       convert_l_to_bin_network(L_ptr,
04173                                L_valueSize,
04174                                L_body_val -> m_value.m_val_signed);
04175 
04176       GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  with signed value = " 
04177                    << L_body_val->m_value.m_val_signed);
04178       break ;
04179 
04180     case E_TYPE_STRING: {
04181       size_t L_padding ;
04182       memcpy(L_ptr, L_body_val->m_value.m_val_binary.m_value, L_valueSize);
04183       if (m_padding_value) {
04184         L_padding = L_valueSize % m_padding_value ;
04185         if (L_padding) { 
04186           L_padding = m_padding_value - L_padding ; 
04187 
04188           if ((L_total_size+L_valueSize+L_padding) > *P_size) {
04189             GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
04190                           "Buffer max size reached [" << *P_size << "]");
04191             L_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
04192             break ;
04193           }
04194 
04195         }
04196         while (L_padding) {
04197           *(L_ptr+L_valueSize) = '\0' ;
04198           L_valueSize++ ;
04199           L_padding-- ;
04200         }
04201       } else {
04202         L_padding = 0 ;
04203       }
04204 
04205       GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  with string value (size: " 
04206                    << L_valueSize << " and padding: " << L_padding);
04207     }
04208         break ;
04209 
04210     case E_TYPE_STRUCT: {
04211       size_t   L_sub_value_size = L_valueSize/2 ;   
04212 
04213       convert_ul_to_bin_network(L_ptr,
04214                                 L_sub_value_size,
04215                                 L_body_val -> m_value.m_val_struct.m_id_1);
04216       
04217       convert_ul_to_bin_network(L_ptr + L_sub_value_size,
04218                                 L_sub_value_size,
04219                                 L_body_val -> m_value.m_val_struct.m_id_2);
04220 
04221       GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  with struct value = [" 
04222                    << L_body_val -> m_value.m_val_struct.m_id_1 << ";" 
04223                    << L_body_val -> m_value.m_val_struct.m_id_2);
04224       }
04225         break ;
04226 
04227     case E_TYPE_GROUPED:
04228       GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  with grouped value " );
04229 
04230       L_save_length += L_header_body_size ;
04231       L_sub_size = *P_size - L_total_size ;
04232 
04233       L_error =  encode_body(L_body_val->m_value.m_val_number,
04234                              L_body_val->m_sub_val,
04235                              L_ptr,
04236                              &L_sub_size,
04237                              L_ctxt_protocol);
04238       
04239       if (L_error == C_ProtocolFrame::E_MSG_OK) {
04240         L_total_size += L_sub_size ;
04241 
04242         if (L_total_size > *P_size) {
04243           GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
04244                         "Buffer max size reached [" << *P_size << "]");
04245           L_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
04246           break ;
04247         }
04248 
04249         L_save_length += L_sub_size ;
04250         convert_ul_to_bin_network(L_save_length_ptr,
04251                                   L_length_size,
04252                                   L_save_length) ;
04253 
04254         L_ptr += L_sub_size ;
04255       }
04256 
04257       break ;
04258       
04259     case E_TYPE_NUMBER_64:
04260       convert_ull_to_bin_network(L_ptr,
04261                                  L_valueSize,
04262                                  L_body_val -> m_value.m_val_number_64);
04263 
04264       GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  with number64 value = " 
04265                    << L_body_val->m_value.m_val_number_64);
04266       break ;
04267 
04268     case E_TYPE_SIGNED_64:
04269       convert_ll_to_bin_network(L_ptr,
04270                                 L_valueSize,
04271                                 L_body_val -> m_value.m_val_signed_64);
04272 
04273       GEN_DEBUG(1, "C_ProtocolTlv::encode_body()  with signed64 value = " 
04274                    << L_body_val->m_value.m_val_signed_64);
04275       break ;
04276 
04277     default:
04278       GEN_FATAL(E_GEN_FATAL_ERROR, 
04279             "Encoding method not implemented for this value");
04280       break ;
04281     }
04282 
04283 
04284     if (L_error != C_ProtocolFrame::E_MSG_OK) {
04285       break ;
04286     }  
04287 
04288     update_ctxt_length (L_ctxt_protocol,
04289                         L_valueSize);
04290 
04291     propagate_ctxt_local (L_ctxt_protocol,
04292                           m_nb_header_length,
04293                           m_nb_protocol_ctxt_values,
04294                           m_header_body_field_table,
04295                           m_header_body_length_table);
04296     
04297     
04298     reset_protocol_context(L_ctxt_protocol);
04299     
04300     L_total_size += L_valueSize ;
04301     L_ptr += L_valueSize ;
04302  
04303  
04304   } // for (L_i ...
04305 
04306   if (L_error == C_ProtocolFrame::E_MSG_OK) {
04307     *P_size = L_total_size ;
04308   }
04309 
04310 
04311   GEN_DEBUG(1, "C_ProtocolTlv::encode_body() end");
04312 
04313   return (L_error);
04314 }
04315 
04316 
04317 int C_ProtocolTlv::find_header_field_id (char *P_name) {
04318 
04319   int               L_id = -1 ;
04320   T_IdMap::iterator L_it ;
04321 
04322   GEN_DEBUG(1, "C_ProtocolTlv::find_header_field_id() start");
04323   L_it = m_header_id_map 
04324     -> find (T_IdMap::key_type(P_name)) ;
04325   
04326   if (L_it != m_header_id_map->end()) {
04327     L_id = L_it->second ;
04328   } 
04329 
04330   GEN_DEBUG(1, "C_ProtocolTlv::find_header_field_id() end");
04331 
04332   return (L_id) ;
04333 }
04334 
04335 int C_ProtocolTlv::find_header_body_id (char *P_name) {
04336   int               L_id = -1 ;
04337   T_IdMap::iterator L_it ;
04338 
04339   GEN_DEBUG(1, "C_ProtocolTlv::find_header_field_id() start");
04340   L_it = m_header_body_id_map 
04341     -> find (T_IdMap::key_type(P_name)) ;
04342   
04343   if (L_it != m_header_body_id_map->end()) {
04344     L_id = L_it->second ;
04345   } 
04346 
04347   GEN_DEBUG(1, "C_ProtocolTlv::find_header_field_id() end");
04348 
04349   return (L_id) ;
04350 }
04351 
04352 int C_ProtocolTlv::find_body_value_id (char *P_name) {
04353   int               L_id = -1 ;
04354   T_IdMap::iterator L_it ;
04355 
04356   GEN_DEBUG(1, "C_ProtocolTlv::find_header_field_id() start");
04357   L_it = m_header_body_value_id_map 
04358     -> find (T_IdMap::key_type(P_name)) ;
04359   
04360   if (L_it != m_header_body_value_id_map->end()) {
04361     L_id = L_it->second ;
04362   } 
04363 
04364   GEN_DEBUG(1, "C_ProtocolTlv::find_header_field_id() end");
04365 
04366   return (L_id) ;
04367 }
04368 
04369 void  C_ProtocolTlv::get_header_values (int          P_id,
04370                                      T_pValueData P_val) {
04371   
04372   unsigned long         L_fieldIdx     ;
04373   T_pHeaderValue        L_val ;
04374 
04375   L_val = &(m_header_value_table[P_id]);
04376 
04377   for(L_fieldIdx=0; L_fieldIdx < m_nb_field_header; L_fieldIdx++) {
04378 
04379     if (L_val -> m_value_setted[L_fieldIdx] == true) {
04380       P_val[L_fieldIdx] 
04381         = L_val->m_values [L_val->m_id_value_setted[L_fieldIdx]] ;
04382     } else {
04383       P_val[L_fieldIdx].m_type = E_TYPE_NUMBER ;
04384       P_val[L_fieldIdx].m_value.m_val_number = (unsigned long) 0 ;
04385     }
04386 
04387   }
04388 
04389 }
04390 
04391 void C_ProtocolTlv::set_header_values (T_pValueData P_dest, 
04392                                           T_pValueData P_orig) {
04393 
04394   unsigned long         L_fieldIdx     ;
04395 
04396   for(L_fieldIdx=0; L_fieldIdx < m_nb_field_header; L_fieldIdx++) {
04397     P_dest[L_fieldIdx] = P_orig [L_fieldIdx] ;
04398   }
04399 }
04400 
04401 void C_ProtocolTlv::set_header_value (int          P_id, 
04402                                          T_pValueData P_dest, 
04403                                          T_pValueData P_orig) {
04404 
04405   int                L_type_id ;
04406   T_pHeaderField     L_fieldVal  ;
04407   T_TypeType         L_type ;
04408 
04409   L_fieldVal = &(m_header_field_table[P_id]);
04410   L_type_id = L_fieldVal->m_type_id ;
04411   if (L_type_id == - 1) {
04412     L_type = E_TYPE_NUMBER;
04413   } else {
04414     L_type = m_type_def_table[L_type_id].m_type ;
04415   }
04416 
04417   if (L_type == P_orig->m_type) {
04418     switch (L_type) {
04419     case E_TYPE_NUMBER:
04420       P_dest->m_value.m_val_number = P_orig->m_value.m_val_number ;
04421       break ;
04422 
04423     case E_TYPE_SIGNED:
04424       P_dest->m_value.m_val_number = P_orig->m_value.m_val_signed ;
04425       break ;
04426 
04427     case E_TYPE_STRING:
04428       FREE_TABLE(P_dest->m_value.m_val_binary.m_value);
04429       P_dest->m_value.m_val_binary.m_size
04430         = P_orig->m_value.m_val_binary.m_size ;
04431       ALLOC_TABLE(P_dest->m_value.m_val_binary.m_value,
04432                   unsigned char *,
04433                   sizeof(unsigned char),
04434                   P_orig->m_value.m_val_binary.m_size);
04435       memcpy(P_dest->m_value.m_val_binary.m_value,
04436              P_orig->m_value.m_val_binary.m_value,
04437              P_dest->m_value.m_val_binary.m_size);
04438       break ;
04439 
04440     case E_TYPE_STRUCT:
04441       P_dest->m_value.m_val_struct = P_orig->m_value.m_val_struct ;
04442       break ;
04443 
04444     case E_TYPE_NUMBER_64:
04445       P_dest->m_value.m_val_number_64 = P_orig->m_value.m_val_number_64 ;
04446       break ;
04447 
04448     case E_TYPE_SIGNED_64:
04449       P_dest->m_value.m_val_number_64 = P_orig->m_value.m_val_signed_64 ;
04450       break ;
04451 
04452     default:
04453       GEN_FATAL(E_GEN_FATAL_ERROR, "Type value not implemented");
04454       break ;
04455     }
04456   } else {
04457     GEN_FATAL(E_GEN_FATAL_ERROR,
04458           "Type ["
04459           << L_type
04460           << "] and ["
04461           << P_orig->m_type
04462           << "] not compatible for setting for ["
04463           << L_fieldVal->m_name
04464           << "]");
04465   }
04466 
04467 }
04468 
04469 void C_ProtocolTlv::delete_header_value(T_pValueData P_res) {
04470 
04471   int                L_type_id = 0 ;
04472   T_pHeaderField     L_fieldVal  ;
04473   T_TypeType         L_type ;
04474 
04475   GEN_DEBUG(1, "C_ProtocolTlv::delete_header_value() start");
04476   GEN_DEBUG(1, "C_ProtocolTlv::delete_header_value() Value Id: " 
04477                << P_res->m_id);
04478 
04479 
04480   L_fieldVal = &(m_header_field_table[P_res->m_id]);
04481 
04482   // retrieve type definition of the field
04483   L_type_id = L_fieldVal->m_type_id ;
04484   if (L_type_id == - 1) {
04485     L_type = E_TYPE_NUMBER;
04486   } else {
04487     L_type = m_type_def_table[L_type_id].m_type ;
04488   }
04489 
04490   GEN_DEBUG(1, "C_ProtocolTlv::delete_header_value() Type: " 
04491                << L_type);
04492 
04493   switch (L_type) {
04494   case E_TYPE_STRING :
04495     FREE_TABLE(P_res->m_value.m_val_binary.m_value);
04496     P_res->m_value.m_val_binary.m_size = 0 ;
04497     break;
04498   default:
04499     break ;
04500   }
04501   GEN_DEBUG(1, "C_ProtocolTlv::delete_header_value() end");
04502 }
04503 
04504 void C_ProtocolTlv::set_body_values (int P_nb, 
04505                                   T_pBodyValue P_dest, 
04506                                   T_pBodyValue P_orig) {
04507 
04508   int                L_i, L_id, L_type_id ;
04509   T_pHeaderBodyValue L_body_fieldValues  ;
04510   T_TypeType         L_type ;
04511 
04512 
04513   for(L_i = 0; L_i < P_nb ; L_i++) {
04514 
04515     L_id = P_orig[L_i].m_id ;
04516     P_dest[L_i].m_id = L_id ;
04517 
04518     L_body_fieldValues = &m_header_body_value_table[L_id] ;
04519     L_type_id = L_body_fieldValues->m_type_id ;
04520     L_type = m_type_def_table[L_type_id].m_type ;
04521     
04522 
04523     switch (L_type) {
04524     case E_TYPE_NUMBER:
04525     case E_TYPE_SIGNED:
04526     case E_TYPE_NUMBER_64:
04527     case E_TYPE_SIGNED_64:
04528       P_dest[L_i].m_value = P_orig[L_i].m_value ;
04529       break ;
04530     case E_TYPE_STRING:
04531       P_dest[L_i].m_value.m_val_binary.m_size 
04532         = P_orig[L_i].m_value.m_val_binary.m_size ; 
04533       ALLOC_TABLE(P_dest[L_i].m_value.m_val_binary.m_value,
04534                   unsigned char *,
04535                   sizeof(unsigned char),
04536                   P_dest[L_i].m_value.m_val_binary.m_size);
04537       memcpy(P_dest[L_i].m_value.m_val_binary.m_value,
04538              P_orig[L_i].m_value.m_val_binary.m_value,
04539              P_orig[L_i].m_value.m_val_binary.m_size);
04540       break ;
04541     case E_TYPE_STRUCT:
04542       P_dest[L_i].m_value = P_orig[L_i].m_value ;
04543       break ;
04544     case E_TYPE_GROUPED:
04545       P_dest[L_i].m_value.m_val_number = P_orig[L_i].m_value.m_val_number ;
04546       if (P_orig[L_i].m_value.m_val_number > 0) {
04547       ALLOC_TABLE(P_dest[L_i].m_sub_val,
04548                   T_pBodyValue,
04549                   sizeof(T_BodyValue),
04550                   P_dest[L_i].m_value.m_val_number);
04551       set_body_values(P_dest[L_i].m_value.m_val_number,
04552                       P_dest[L_i].m_sub_val,
04553                       P_orig[L_i].m_sub_val);
04554       } else {
04555         P_dest[L_i].m_sub_val = NULL ;
04556       }
04557       break ;
04558     default:
04559       GEN_FATAL(E_GEN_FATAL_ERROR, "Unsupported body type value");
04560       break;
04561     }
04562 
04563   }
04564   
04565 
04566 }
04567 
04568 void C_ProtocolTlv::reset_header_values (int          P_nb, 
04569                                             T_pValueData P_val) {
04570 
04571   int                L_i;
04572 
04573   GEN_DEBUG(1, "C_ProtocolTlv::reset_header_values() start P_nb: " << P_nb);
04574 
04575   for(L_i = 0; L_i < P_nb ; L_i++) {
04576 
04577     GEN_DEBUG(1, "C_ProtocolTlv::reset_header_values() Value Id: " 
04578                  << P_val[L_i].m_id);
04579 
04580     delete_header_value(&(P_val[L_i]));
04581 
04582   }
04583   GEN_DEBUG(1, "C_ProtocolTlv::reset_header_values() end");
04584   
04585 }
04586 
04587 void C_ProtocolTlv::reset_body_values (int          P_nb, 
04588                                           T_pBodyValue P_val) {
04589 
04590   int                L_i;
04591 
04592   GEN_DEBUG(1, "C_ProtocolTlv::reset_body_values() start P_nb: " << P_nb);
04593 
04594   for(L_i = 0; L_i < P_nb ; L_i++) {
04595 
04596 
04597     GEN_DEBUG(1, "C_ProtocolTlv::reset_body_values() Value Id: " 
04598                  << P_val[L_i].m_id);
04599 
04600     
04601     delete_body_value(&(P_val[L_i]));
04602 
04603   }
04604   GEN_DEBUG(1, "C_ProtocolTlv::reset_body_values() end");
04605   
04606 }
04607 
04608 void C_ProtocolTlv::get_body_values (int P_id, T_pBodyValue P_val, int *P_nbVal) {
04609   
04610   T_pBodyValueDef L_body_val_def  ;
04611   int             L_nb_val, L_idx ;
04612 
04613   GEN_DEBUG(1, "C_ProtocolTlv::get_body_values() start");
04614   L_body_val_def = &(m_body_value_table[P_id]);
04615   L_nb_val = L_body_val_def->m_nb_values ;
04616   L_idx = 0 ;
04617 
04618   GEN_DEBUG(1, "C_ProtocolTlv::get_body_values() L_nb_val [" << L_nb_val << "]");
04619   while (L_nb_val > 0) {
04620     set_body_value(&(P_val[L_idx]), &(m_body_value_table[P_id].m_value_table[L_idx]));
04621     L_idx++ ;
04622     L_nb_val-- ;
04623     (*P_nbVal)++ ; // to do: check MAX_BODY_VALUES
04624   }
04625   GEN_DEBUG(1, "C_ProtocolTlv::get_body_values() end");
04626 }
04627 
04628 
04629 iostream_output& C_ProtocolTlv::print_header(iostream_output& P_stream,
04630                                           int           P_headerId,
04631                                           T_pValueData  P_val) {
04632 
04633   unsigned long L_fieldIdx     ;
04634   char         *L_name         ;
04635 
04636   T_TypeType    L_type         ;
04637   int           L_type_id      ;
04638 
04639   L_name = (P_headerId == -1) ? 
04640     (char*)"Unknown" : m_header_value_table[P_headerId].m_name ;
04641 
04642   GEN_DEBUG(1, "C_ProtocolTlv::print_header() start header_name:" << L_name 
04643               << " (id:" << P_headerId << ")");
04644 
04645   P_stream << L_name << iostream_endl ;
04646 
04647   for(L_fieldIdx=0; L_fieldIdx < m_nb_field_header; L_fieldIdx++) {
04648 
04649     P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) ;
04650     P_stream << "[" << m_header_field_table[L_fieldIdx].m_name
04651              << "] = [" ;
04652 
04653     L_type_id = m_header_field_table[L_fieldIdx].m_type_id ;
04654 
04655 #ifdef MSG_DETAIL_DUMP
04656     P_stream << " size [" << m_header_field_table[L_fieldIdx].m_size << "]";
04657 #endif
04658 
04659     if (L_type_id == -1)
04660     {
04661       // force the type of header field to number
04662       L_type = E_TYPE_NUMBER;
04663 
04664 #ifdef MSG_DETAIL_DUMP
04665       P_stream << " type [number]";
04666 #endif
04667     } else {
04668       // get the header field type
04669       L_type = m_type_def_table[L_type_id].m_type ;;
04670 
04671 #ifdef MSG_DETAIL_DUMP
04672       P_stream << " type [" << m_type_def_table[L_type_id].m_type << "]";
04673 #endif
04674     }
04675 
04676     P_stream << " ";
04677 
04678 #ifdef MSG_DETAIL_DUMP
04679     P_stream << " value [";
04680 #endif
04681 
04682     switch (L_type) {
04683       case E_TYPE_NUMBER:
04684       case E_TYPE_SIGNED:
04685       case E_TYPE_STRUCT:
04686       case E_TYPE_NUMBER_64:
04687       case E_TYPE_SIGNED_64:
04688         P_stream << P_val[L_fieldIdx] ;
04689         break;
04690       case E_TYPE_STRING: {
04691 
04692         static char L_hexa_buf [50] ;
04693         const  size_t L_cNum = 16 ; 
04694         size_t L_j, L_nb ;
04695         unsigned char*L_cur ;
04696         size_t L_buffer_size = P_val[L_fieldIdx].m_value.m_val_binary.m_size;
04697                         
04698         L_nb = L_buffer_size / L_cNum ;
04699         L_cur = P_val[L_fieldIdx].m_value.m_val_binary.m_value ;
04700         P_stream << " " ;
04701         if (L_cur != NULL)
04702         {
04703           for (L_j = 0 ; L_j < L_nb; L_j++) {
04704             P_stream << iostream_endl ;
04705             P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) ;
04706 
04707             pretty_binary_buffer(L_cur, L_cNum, L_hexa_buf);
04708             P_stream << L_hexa_buf ;
04709             L_cur += L_cNum ;
04710           }
04711 
04712           L_nb = L_buffer_size % L_cNum ;
04713           if (L_nb != 0) {
04714             P_stream << iostream_endl ;
04715             P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) ;
04716 
04717             pretty_binary_buffer(L_cur, L_nb, L_hexa_buf);
04718             P_stream << L_hexa_buf ;
04719           }
04720           P_stream << iostream_endl ;
04721           P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) ;
04722         } else {
04723           P_stream << "NULL(empty)";
04724         }
04725       } 
04726       break ;
04727 
04728       default:
04729         GEN_FATAL(E_GEN_FATAL_ERROR, "type " << L_type << " not implemented");
04730         break ;
04731     }
04732 
04733 #ifdef MSG_DETAIL_DUMP
04734     P_stream << "]";
04735 #endif
04736 
04737     P_stream << "]" << iostream_endl ;
04738   }
04739 
04740   GEN_DEBUG(1, "C_ProtocolTlv::print_header() end:" );
04741 
04742   return (P_stream);
04743 }
04744 
04745 iostream_output& C_ProtocolTlv::print_body  (iostream_output&  P_stream, 
04746                                                 int          P_nb,
04747                                                 T_pBodyValue P_val,
04748                                                 int          P_level) {
04749 
04750   int                L_i, L_id;
04751   T_pHeaderBodyValue L_body_fieldValues  ;
04752   unsigned long      L_fieldIdx     ;
04753   int                L_valueIdx ;
04754 
04755   int                L_type_id ;
04756   T_TypeType         L_type ;
04757   char               L_levelStr[255] = ""; // TEMP
04758 
04759   GEN_DEBUG(1, "C_ProtocolTlv::print_body() start nb: " << P_nb);
04760   GEN_DEBUG(1, "C_ProtocolTlv::print_body() m_nb_field_header_body: " 
04761                   << m_nb_field_header_body);
04762   GEN_DEBUG(1, "C_ProtocolTlv::print_body() Level: " << P_level);
04763 
04764   for (L_i = 0; L_i < P_level; L_i++) {
04765     strcat(L_levelStr," |");
04766   }
04767   for (L_i = 0; L_i < P_nb; L_i++) {
04768     L_id = P_val[L_i].m_id ;
04769     L_body_fieldValues = &m_header_body_value_table[L_id] ;
04770 
04771     GEN_DEBUG(1, "C_ProtocolTlv::print_body() display " <<
04772         L_body_fieldValues->m_name << "(id: " << L_id << ")");
04773 
04774     P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) << L_levelStr 
04775              << " ";
04776     P_stream << "[" << L_body_fieldValues->m_name << iostream_endl ; 
04777 
04778     // print field setted
04779     P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) << L_levelStr
04780              << " " ;
04781 
04782     // Display name
04783     for(L_fieldIdx=0; L_fieldIdx < m_nb_field_header_body; L_fieldIdx++) {
04784       
04785       if (L_body_fieldValues->m_value_setted[L_fieldIdx] == true) {
04786         L_valueIdx = L_body_fieldValues
04787           ->m_id_value_setted[L_fieldIdx];
04788         
04789         P_stream << "(" 
04790                  << m_header_body_field_table[L_fieldIdx].m_name 
04791                  << " = "
04792                  << L_body_fieldValues
04793           ->m_values[L_valueIdx].m_value.m_val_number
04794                  << ")" ;
04795       }
04796     } // for
04797     
04798     
04799     // Display optional part
04800     if (m_header_body_start_optional_id != -1) {
04801       for(L_fieldIdx=m_header_body_start_optional_id; 
04802           L_fieldIdx < m_max_nb_field_header_body; L_fieldIdx++) {
04803         
04804         if (L_body_fieldValues->m_value_setted[L_fieldIdx] == true) {
04805           
04806           L_valueIdx = L_body_fieldValues
04807             ->m_id_value_setted[L_fieldIdx];
04808           P_stream << "(" 
04809                    << m_header_body_field_table[L_fieldIdx].m_name 
04810                    << " = "
04811                    << L_body_fieldValues
04812             ->m_values[L_valueIdx].m_value.m_val_number
04813                    << ")" ;
04814         }
04815       } // for
04816       
04817     }
04818   
04819     P_stream << "] = [" ;
04820 
04821     L_type_id = L_body_fieldValues->m_type_id ;
04822 
04823     GEN_DEBUG(1, "C_ProtocolTlv::print_body() display type " <<
04824         m_type_def_table[L_type_id].m_name << "(id: " << L_type_id << ")");
04825 
04826     L_type = m_type_def_table[L_type_id].m_type ;
04827 
04828     switch (L_type) {
04829       case E_TYPE_NUMBER:
04830 #ifdef MSG_DETAIL_DUMP
04831         P_stream << " size [" << sizeof(T_UnsignedInteger32) << "]";
04832         P_stream << " type [" << m_type_def_table[L_type_id].m_name << "]";
04833         P_stream << " value [";
04834 #endif
04835         P_stream << P_val[L_i].m_value.m_val_number ;
04836         break;
04837       case E_TYPE_SIGNED:
04838 #ifdef MSG_DETAIL_DUMP
04839         P_stream << " size [" << sizeof(T_Integer32) << "]";
04840         P_stream << " type [" << m_type_def_table[L_type_id].m_name << "]";
04841         P_stream << " value [";
04842 #endif
04843         P_stream << P_val[L_i].m_value.m_val_signed ;
04844         break;
04845       case E_TYPE_STRING: {
04846         static char L_hexa_buf [50] ;
04847         const size_t L_cNum = 16 ;
04848         size_t L_i2, L_nb, L_buffer_size ;
04849         unsigned char*L_cur ;
04850 
04851 #ifdef MSG_DETAIL_DUMP
04852         P_stream << " size [" 
04853                  << P_val[L_i].m_value.m_val_binary.m_size
04854                  << "]";
04855         P_stream << " type [" << m_type_def_table[L_type_id].m_name << "]";
04856         P_stream << " value [";
04857 #endif
04858         L_buffer_size = P_val[L_i].m_value.m_val_binary.m_size ;
04859 
04860         L_nb = L_buffer_size / L_cNum ;
04861         L_cur = P_val[L_i].m_value.m_val_binary.m_value ;
04862         if (L_cur != NULL)
04863         {
04864           for (L_i2 = 0 ; L_i2 < L_nb; L_i2++) {
04865             P_stream << iostream_endl ;
04866             P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) 
04867                      << L_levelStr << " ";
04868 
04869             pretty_binary_buffer(L_cur, L_cNum, L_hexa_buf);
04870             P_stream << L_hexa_buf ;
04871             L_cur += L_cNum ;
04872           }
04873           L_nb = L_buffer_size % L_cNum ;
04874           if (L_nb != 0) {
04875             P_stream << iostream_endl ;
04876             P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) 
04877                      << L_levelStr << " ";
04878 
04879             pretty_binary_buffer(L_cur, L_nb, L_hexa_buf);
04880             P_stream << L_hexa_buf ;
04881           }
04882           P_stream << iostream_endl ;
04883           P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) 
04884                    << L_levelStr << " ";
04885         } else {
04886           P_stream << "NULL(empty)";
04887         }
04888         }
04889         break;
04890       case E_TYPE_STRUCT:
04891 #ifdef MSG_DETAIL_DUMP
04892         P_stream << " size [" << (2*sizeof(T_Integer32)) << "]";
04893         P_stream << " type [" << m_type_def_table[L_type_id].m_name << "]";
04894         P_stream << " value [";
04895 #endif
04896         P_stream  << P_val[L_i].m_value.m_val_struct.m_id_1 << ";" 
04897               << P_val[L_i].m_value.m_val_struct.m_id_2 ;
04898         break;
04899       case E_TYPE_GROUPED:
04900 #ifdef MSG_DETAIL_DUMP
04901         P_stream << " grouped";
04902         P_stream << " type [" << m_type_def_table[L_type_id].m_name << "]";
04903         P_stream << " value [";
04904 #endif
04905         P_stream << iostream_endl ;
04906         print_body(P_stream, P_val[L_i].m_value.m_val_number, 
04907                    P_val[L_i].m_sub_val, P_level+1);
04908         P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) 
04909                  << L_levelStr << " ";
04910         break;
04911       case E_TYPE_NUMBER_64:
04912 #ifdef MSG_DETAIL_DUMP
04913         P_stream << " size [" << sizeof(T_UnsignedInteger64) << "]";
04914         P_stream << " type [" << m_type_def_table[L_type_id].m_name << "]";
04915         P_stream << " value [";
04916 #endif
04917         P_stream << P_val[L_i].m_value.m_val_number_64 ;
04918         break;
04919       case E_TYPE_SIGNED_64:
04920 #ifdef MSG_DETAIL_DUMP
04921         P_stream << " size [" << sizeof(T_UnsignedInteger64) << "]";
04922         P_stream << " type [" << m_type_def_table[L_type_id].m_name << "]";
04923         P_stream << " value [";
04924 #endif
04925         P_stream << P_val[L_i].m_value.m_val_signed_64 ;
04926         break;
04927       default:
04928         GEN_FATAL(E_GEN_FATAL_ERROR, "type " << L_type << " not implemented");
04929         break ;
04930     }
04931 
04932 #ifdef MSG_DETAIL_DUMP
04933     P_stream << "]" << iostream_endl ;
04934     P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) 
04935              << L_levelStr << " ";
04936 #endif
04937 
04938     P_stream << "]" << iostream_endl ;
04939 
04940   }
04941 
04942   GEN_DEBUG(1, "C_ProtocolTlv::print_body() end");
04943 
04944   return (P_stream) ;
04945 
04946 }
04947 
04948 void C_ProtocolTlv::get_body_value (T_pValueData P_dest, T_pBodyValue P_orig) {
04949   
04950   int L_id, L_type_id ;
04951   T_pHeaderBodyValue L_body_fieldValues  ;
04952   T_TypeType         L_type ;
04953 
04954   GEN_DEBUG(1, "C_ProtocolTlv::get_body_value() ValData BodyVal start");
04955 
04956   L_id = P_orig -> m_id ;
04957   L_body_fieldValues = &m_header_body_value_table[L_id] ;
04958   L_type_id = L_body_fieldValues->m_type_id ;
04959   L_type = m_type_def_table[L_type_id].m_type ;
04960 
04961   P_dest->m_id = L_id ;
04962   P_dest->m_type = L_type ;
04963 
04964   switch (L_type) {
04965   case E_TYPE_NUMBER:
04966     P_dest->m_value.m_val_number = P_orig->m_value.m_val_number ;
04967     break ;
04968   case E_TYPE_SIGNED:
04969     P_dest->m_value.m_val_number = P_orig->m_value.m_val_signed ;
04970     break ;
04971   case E_TYPE_STRING:
04972     P_dest->m_value.m_val_binary.m_size = P_orig->m_value.m_val_binary.m_size ;
04973     ALLOC_TABLE(P_dest->m_value.m_val_binary.m_value,
04974                 unsigned char *,
04975                 sizeof(unsigned char),
04976                 P_dest->m_value.m_val_binary.m_size);
04977     memcpy(P_dest->m_value.m_val_binary.m_value,
04978            P_orig->m_value.m_val_binary.m_value,
04979            P_dest->m_value.m_val_binary.m_size);
04980     break ;
04981 
04982   case E_TYPE_STRUCT:
04983     P_dest->m_value.m_val_struct = P_orig->m_value.m_val_struct ;
04984     break ;
04985 
04986   case E_TYPE_NUMBER_64:
04987     P_dest->m_value.m_val_number_64 = P_orig->m_value.m_val_number_64 ;
04988     break ;
04989   case E_TYPE_SIGNED_64:
04990     P_dest->m_value.m_val_number_64 = P_orig->m_value.m_val_signed_64 ;
04991     break ;
04992 
04993   default:
04994     GEN_FATAL(E_GEN_FATAL_ERROR, "Type value not implemented");
04995     break ;
04996   }
04997 
04998   GEN_DEBUG(1, "C_ProtocolTlv::get_body_value() ValData BodyVal end");
04999 }
05000 
05001 void C_ProtocolTlv::set_body_value (T_pBodyValue P_dest, T_pValueData P_orig) {
05002 
05003   int L_id, L_type_id ;
05004   T_pHeaderBodyValue L_body_fieldValues  ;
05005   T_TypeType         L_type ;
05006 
05007   L_id = P_dest -> m_id ;
05008   L_body_fieldValues = &m_header_body_value_table[L_id] ;
05009   L_type_id = L_body_fieldValues->m_type_id ;
05010   L_type = m_type_def_table[L_type_id].m_type ;
05011 
05012   if (L_type == P_orig->m_type) {
05013     switch (L_type) {
05014     case E_TYPE_NUMBER:
05015       P_dest->m_value.m_val_number = P_orig->m_value.m_val_number ;
05016       break ;
05017 
05018     case E_TYPE_SIGNED:
05019       P_dest->m_value.m_val_number = P_orig->m_value.m_val_signed ;
05020       break ;
05021 
05022     case E_TYPE_STRING:
05023       FREE_TABLE(P_dest->m_value.m_val_binary.m_value);
05024       P_dest->m_value.m_val_binary.m_size 
05025         = P_orig->m_value.m_val_binary.m_size ;
05026       ALLOC_TABLE(P_dest->m_value.m_val_binary.m_value,
05027                   unsigned char *,
05028                   sizeof(unsigned char),
05029                   P_orig->m_value.m_val_binary.m_size);
05030       memcpy(P_dest->m_value.m_val_binary.m_value,
05031              P_orig->m_value.m_val_binary.m_value,
05032              P_dest->m_value.m_val_binary.m_size);
05033       break ;
05034 
05035     case E_TYPE_STRUCT:
05036       P_dest->m_value.m_val_struct = P_orig->m_value.m_val_struct ;
05037       break ;
05038 
05039     case E_TYPE_NUMBER_64:
05040       P_dest->m_value.m_val_number_64 = P_orig->m_value.m_val_number_64 ;
05041       break ;
05042 
05043     case E_TYPE_SIGNED_64:
05044       P_dest->m_value.m_val_number_64 = P_orig->m_value.m_val_signed_64 ;
05045       break ;
05046 
05047     default:
05048       GEN_FATAL(E_GEN_FATAL_ERROR, "Type value not implemented");
05049       break ;
05050     }
05051   } else {
05052     GEN_FATAL(E_GEN_FATAL_ERROR, 
05053           "Type ["
05054           << L_type
05055           << "] and ["
05056           << P_orig->m_type
05057           << "] not compatible for setting for ["
05058           << L_body_fieldValues->m_name
05059           << "]");
05060   }
05061   
05062 }
05063 
05064 bool C_ProtocolTlv::check_presence_needed (T_pCondPresence P_condition,
05065                                            unsigned long  *P_values) {
05066   bool L_ret ;
05067 
05068   L_ret = (P_values[P_condition->m_f_id] & (P_condition->m_mask)) ;
05069 
05070   return (L_ret);
05071 }
05072 
05073 T_TypeType C_ProtocolTlv::get_header_value_type (int P_id) {
05074 
05075   T_TypeType L_ret = E_TYPE_NUMBER ;
05076   int                L_type_id ;
05077 
05078   T_pHeaderField        L_fieldDescr   ;
05079 
05080   L_fieldDescr = &m_header_field_table[P_id] ;
05081 
05082   GEN_DEBUG(1, "C_ProtocolTlv::get_header_value_type() "
05083                           << "Name \"" << L_fieldDescr->m_name
05084                           << "\" (P_id:" << P_id << ")");
05085   
05086   L_type_id = L_fieldDescr->m_type_id ;
05087 
05088 
05089   if (L_type_id != -1)
05090   {
05091     L_ret = m_type_def_table[L_type_id].m_type ;
05092   }
05093 
05094   GEN_DEBUG(1, "C_ProtocolTlv::get_header_value_type() "
05095                           << "Type is \"" << L_ret
05096                           << "\" (Type Id:" << L_type_id << ")" );
05097 
05098   return (L_ret);
05099 }
05100 
05101 
05102 T_TypeType C_ProtocolTlv::get_body_value_type (int P_id) {
05103 
05104   T_TypeType L_ret = E_UNSUPPORTED_TYPE ;
05105   T_pHeaderBodyValue L_headerBodyValue ;
05106   int                L_type_id ;
05107 
05108   GEN_DEBUG(1, "C_ProtocolTlv::get_body_value_type() "
05109                 << "Name \"" << m_header_body_value_table[P_id].m_name //m_header_body_field_table[P_id].m_name
05110                 << "\" (P_id: " << P_id << ")");
05111 
05112   L_headerBodyValue = &m_header_body_value_table[P_id];
05113   L_type_id = L_headerBodyValue->m_type_id ;
05114   L_ret = m_type_def_table[L_type_id].m_type ;
05115   
05116   GEN_DEBUG(1, "C_ProtocolTlv::get_body_value_type() "
05117                           << "Type is \"" << L_ret
05118                           << "\" (Type Id is " << L_type_id << ")");
05119 
05120   return (L_ret);
05121 }
05122 
05123 C_ProtocolTlv::T_MsgIdType C_ProtocolTlv::get_msg_id_type () {
05124   return(m_msg_id_type) ;
05125 }
05126 
05127 T_TypeType C_ProtocolTlv::get_msg_id_value_type () {
05128   return(m_msg_id_value_type) ;
05129 }
05130 
05131 int C_ProtocolTlv::get_msg_id () {
05132   return(m_msg_id_id);
05133 }
05134 
05135 C_ProtocolTlv::T_MsgIdType C_ProtocolTlv::get_out_of_session_id_type () {
05136   return(m_type_id_out_of_session) ;
05137 }
05138 
05139 int C_ProtocolTlv::get_out_of_session_id () {
05140   return(m_id_out_of_session);
05141 }
05142 
05143 void C_ProtocolTlv::reset_value_data (T_pValueData P_val) {
05144 
05145   switch (P_val->m_type) {
05146   case E_TYPE_STRING:
05147     if (P_val->m_value.m_val_binary.m_size) {
05148       FREE_TABLE(P_val->m_value.m_val_binary.m_value);
05149     }
05150     break ;
05151   case E_TYPE_GROUPED:
05152     GEN_FATAL(E_GEN_FATAL_ERROR, "reset grouped value not implemented");
05153     break ;
05154   default:
05155     break;
05156   }
05157   P_val-> m_type = E_TYPE_NUMBER ;
05158   P_val-> m_value.m_val_number = 0 ;
05159 }
05160 
05161 
05162 void C_ProtocolTlv::convert_to_string (T_pValueData P_res, 
05163                                     T_pValueData P_val) {
05164 
05165   char   L_tmp_val[50] ;
05166 
05167   L_tmp_val[0] = '\0' ;
05168 
05169   switch (P_val->m_type) {
05170   case E_TYPE_NUMBER:
05171     sprintf(L_tmp_val, "%ld", P_val->m_value.m_val_number);
05172     P_res->m_type = E_TYPE_STRING ;
05173     P_res->m_value.m_val_binary.m_size = strlen (L_tmp_val) ;
05174     ALLOC_TABLE(P_res->m_value.m_val_binary.m_value,
05175                 unsigned char*,
05176                 sizeof(unsigned char),
05177                 P_res->m_value.m_val_binary.m_size);
05178     memcpy(P_res->m_value.m_val_binary.m_value,
05179            L_tmp_val,
05180            P_res->m_value.m_val_binary.m_size);
05181     break ;
05182   default:
05183     GEN_FATAL(E_GEN_FATAL_ERROR, 
05184           "convert to string not implemented for this type");
05185     break;
05186   }
05187   P_val-> m_type = E_TYPE_NUMBER ;
05188   P_val-> m_value.m_val_number = 0 ;
05189 }
05190 
05191 C_ProtocolTlv::T_pHeaderBodyValue 
05192 C_ProtocolTlv::get_header_body_value_description (int P_id) {
05193   C_ProtocolTlv::T_pHeaderBodyValue L_value ;
05194   L_value = (P_id <(int) m_nb_header_body_values) ?
05195     &m_header_body_value_table[P_id] : NULL ;
05196   return (L_value) ;
05197 }
05198 
05199 C_ProtocolTlv::T_pHeaderValue 
05200 C_ProtocolTlv::get_header_value_description (int P_id) {
05201   C_ProtocolTlv::T_pHeaderValue L_result ;
05202 
05203   L_result = (P_id < (int)m_nb_field_header_body) ?
05204     &m_header_value_table[P_id] : NULL ;
05205 
05206   return (L_result);
05207 }
05208 
05209 // C_ProtocolTlvFrame::T_pMsgError
05210 C_MessageFrame* C_ProtocolTlv::decode_message(unsigned char *P_buffer, 
05211                                                  size_t        *P_size, 
05212                                                  C_ProtocolFrame::T_pMsgError P_error) {
05213   C_MessageTlv *L_msg ;
05214 
05215   size_t           L_size = *P_size ;
05216 
05217   //  NEW_VAR(L_msg, C_MessageTlv(this));
05218   L_msg=(C_MessageTlv*)create_new_message(NULL);
05219 
05220   (*P_size) = L_msg -> decode(P_buffer, L_size, P_error);
05221   // C_ProtocolBinaryFrame::E_MSG_OK:
05222 
05223   switch (*P_error) {
05224   case C_ProtocolFrame::E_MSG_OK:
05225     // GEN_LOG_EVENT(LOG_LEVEL_MSG, 
05226     //    "Received [" << *L_msg << "]");
05227     break ;
05228   case C_ProtocolFrame::E_MSG_ERROR_DECODING_SIZE_LESS:
05229     DELETE_VAR(L_msg);
05230     break ;
05231   default:
05232     GEN_ERROR(E_GEN_FATAL_ERROR, 
05233               "Unrecognized message received") ;
05234     DELETE_VAR(L_msg);
05235     break ;
05236   }
05237 
05238   return (L_msg);
05239 }
05240 
05241 C_ProtocolFrame::T_MsgError 
05242 C_ProtocolTlv::encode_message(C_MessageFrame *P_msg,
05243                                  unsigned char  *P_buffer,
05244                                  size_t         *P_buffer_size) {
05245 
05246   C_ProtocolFrame::T_MsgError  L_error =  C_ProtocolFrame::E_MSG_OK;
05247   C_MessageTlv             *L_msg   = (C_MessageTlv*) P_msg ;
05248 
05249 
05250   L_msg -> encode (P_buffer, P_buffer_size, &L_error) ;
05251 
05252   if (L_error == C_ProtocolFrame::E_MSG_OK) {
05253     GEN_LOG_EVENT(LOG_LEVEL_MSG, 
05254                   "Send [" << *L_msg << "]");
05255   } else {
05256     GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
05257                   "Error while sending [" << *L_msg << "]");
05258   }
05259 
05260   return (L_error);
05261 }
05262 
05263 C_MessageFrame* C_ProtocolTlv::create_new_message(C_MessageFrame *P_msg) {
05264 
05265   C_MessageTlv *L_msg ;
05266 
05267   GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() start: msg pt");
05268   NEW_VAR(L_msg, C_MessageTlv(this));
05269   if (P_msg != NULL) {
05270     (*L_msg) = *((C_MessageTlv*)P_msg) ;
05271   }
05272   GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() end: msg pt");
05273   return (L_msg);
05274 }
05275 
05276 C_MessageFrame* C_ProtocolTlv::create_new_message(void                *P_xml, 
05277                                                      T_pInstanceDataList  P_list,
05278                                                      int                 *P_nb_value) {
05279 
05280 
05281   C_XmlData *L_Xml = (C_XmlData*) P_xml ;
05282 
05283   bool                            L_msgOk = true ;
05284 
05285   C_MessageTlv                 *L_msg ;
05286   char                            *L_currentName ;
05287   
05288   //   C_ProtocolBinaryFrame::T_MsgError L_decode_result ;
05289   C_ProtocolFrame::T_MsgError L_decode_result ;
05290   
05291   unsigned char            *L_buf ;
05292   size_t                    L_size ;
05293   
05294   int                       L_header_val_id ;
05295   int                       L_body_val_id   ;
05296   
05297   GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() start: xml");
05298   
05299   // Allocate a new message
05300   NEW_VAR(L_msg, C_MessageTlv(this));
05301 
05302   // two cases: direct buffer to be decoded or
05303   //            direct message definition
05304 
05305   // Get the message name from XML definition
05306   L_currentName = L_Xml -> get_name () ;
05307 
05308   GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() msg xml name is "
05309             << L_currentName );
05310       
05311   if (strcmp(L_currentName, (char*)"CDATA") == 0) {
05312         
05313     // direct buffer data definition
05314     // unsigned long L_ret_decode ;
05315     L_currentName = L_Xml->find_value((char*)"value");
05316     
05317     L_buf = convert_hexa_char_to_bin(L_currentName, &L_size);
05318     (void) L_msg -> decode(L_buf, L_size, &L_decode_result);
05319     
05320     //    if (L_decode_result != C_ProtocolBinaryFrame::E_MSG_OK) 
05321     if (L_decode_result != C_ProtocolFrame::E_MSG_OK) {
05322       GEN_ERROR(E_GEN_FATAL_ERROR, 
05323                 "Error while decoding direct data buffer ["
05324                 << L_currentName << "]");
05325       L_msgOk = false ;
05326     }
05327         
05328   } else if (strcmp(L_currentName, get_header_name()) == 0) {
05329         
05330     // message decoding
05331     L_currentName = L_Xml -> find_value ((char*) "name") ;
05332     if (L_currentName == NULL) {
05333       GEN_ERROR(E_GEN_FATAL_ERROR, 
05334                 "name value is mandatory for ["
05335                 << get_header_name()
05336                 << "]");
05337       L_msgOk = false ;
05338     } else {
05339       GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() " 
05340                 << "the name of this message is " << L_currentName );
05341 
05342       L_header_val_id = get_header_value_id(L_currentName) ;
05343 
05344       GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() " 
05345                 << "L_header_val_id = " << L_header_val_id );
05346 
05347       if (L_header_val_id == -1) {
05348         GEN_ERROR(E_GEN_FATAL_ERROR,
05349                   "unknown name ["
05350                   << L_currentName << "] for [" << get_header_name() << "]");
05351         L_msgOk = false ;
05352 
05353       } else { 
05354 
05355         // now search for body values
05356         T_pXmlData_List           L_listBodyVal ;
05357         T_XmlData_List::iterator  L_bodyValIt ;
05358         C_XmlData                *L_bodyData ;
05359         // int                       L_nbBodyVal ;
05360         char                     *L_bodyName, *L_bodyValue ;
05361         C_ProtocolTlv::T_BodyValue   L_bodyVal ;
05362         T_TypeType                L_type ; 
05363 
05364         L_msg->set_header_id_value(L_header_val_id);
05365         
05366         L_listBodyVal = L_Xml -> get_sub_data() ;
05367         if (L_listBodyVal != NULL) {
05368           // L_nbBodyVal = L_listBodyVal->size() ;
05369           for (L_bodyValIt  = L_listBodyVal->begin() ;
05370                L_bodyValIt != L_listBodyVal->end() ;
05371                L_bodyValIt++) {
05372             L_bodyData = *L_bodyValIt ;
05373             
05374             // GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() " << 
05375                       // "L_bodyData name is [" << L_bodyData->get_name() << "]");
05376             // GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() " << 
05377                       // "get_header_body_name() is [" 
05378                       // << get_header_body_name() << "]");
05379               
05380             if (strcmp(L_bodyData->get_name(), 
05381                        get_header_body_name())==0) {
05382               
05383               L_bodyName = L_bodyData->find_value((char*)"name");
05384               if (L_bodyName == NULL) {
05385                 GEN_ERROR(E_GEN_FATAL_ERROR,
05386                           "name value is mandatory for ["
05387                           << get_header_body_name()
05388                           << "] definition");
05389                 L_msgOk = false ;
05390               }
05391                 
05392               GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() "
05393                         << "L_bodyName is    [" << L_bodyName << "]");
05394 
05395               L_body_val_id = get_header_body_value_id(L_bodyName) ;
05396               if (L_body_val_id == -1) {
05397                 GEN_ERROR(E_GEN_FATAL_ERROR,
05398                           "No definition found for ["
05399                           << L_bodyName << "]");
05400                 L_msgOk = false ;
05401                 break ;
05402               } 
05403                 
05404               GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() " 
05405                         << "L_body_val_id is " 
05406                         << L_body_val_id );
05407               
05408               L_type = get_body_value_type (L_body_val_id) ;
05409               if (L_type 
05410                   == E_TYPE_GROUPED) {
05411 
05412                 GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() " 
05413                              << L_bodyName << " is  grouped element" );
05414 
05415 
05416                 if (process_grouped_type(L_bodyData, L_body_val_id, 
05417                                          &L_bodyVal) != 0) {
05418                   GEN_ERROR(E_GEN_FATAL_ERROR,
05419                             "Grouped Type processing Error for "
05420                             << L_bodyName);
05421                   L_msgOk = false ;
05422                   break ;
05423                 }
05424 
05425 
05426                 // Add the grouped value in message
05427                 L_msg->set_body_value(&L_bodyVal);
05428 
05429                 // Now do not forget to clean L_bodyVal
05430                 reset_grouped_body_value(&L_bodyVal);
05431                 FREE_TABLE(L_bodyVal.m_sub_val);
05432               } else { 
05433                 bool L_toBeDelete = false;
05434 
05435                 // not grouped value
05436                 L_bodyValue = L_bodyData->find_value((char*)"value");
05437                 if (L_bodyValue == NULL) {
05438                   GEN_ERROR(E_GEN_FATAL_ERROR,
05439                             "value is mandatory for ["
05440                             << get_header_body_name()
05441                             << "] definition");
05442                   L_msgOk = false ;
05443                   break ;
05444                 }
05445                 
05446                 GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() " 
05447                           << "L_bodyValue is \"" << L_bodyValue << "\"" );
05448                 
05449                 if (set_body_value(L_body_val_id, 
05450                                    L_bodyValue,
05451                                    1,
05452                                    &L_bodyVal,
05453                                    &L_toBeDelete) == 0) {
05454 
05455                   if (m_header_body_field_separator == NULL) {
05456                     L_msg->set_body_value(&L_bodyVal);
05457                   } else {
05458                     T_ValueData L_tmp_value ;
05459                     bool        L_exist     ;
05460                     L_tmp_value.m_value = L_bodyVal.m_value ;
05461                     L_tmp_value.m_id = L_bodyVal.m_id ;
05462                     L_tmp_value.m_type = L_type;
05463                     L_exist = L_msg->set_body_value(L_body_val_id,&L_tmp_value);
05464                     if (L_exist == false) {
05465                       L_msg->set_body_value(&L_bodyVal);
05466                     }
05467                   }
05468 
05469                   if (L_toBeDelete) {
05470                     // Now do not forget to clean L_bodyVal
05471                    delete_body_value(&L_bodyVal);
05472                   }
05473 
05474                 } else {
05475                   GEN_ERROR(E_GEN_FATAL_ERROR,
05476                             "Bad format for ["
05477                             << L_bodyValue << "]");
05478                   L_msgOk = false ;
05479                   break ;
05480                 }
05481               } // end to else not grouped
05482             } else if (strcmp(L_bodyData->get_name(),
05483                               (char*)"setfield")==0) {
05484               unsigned long   L_val_setfield = 0 ;
05485               int             L_id_setfield   = 0 ;
05486               L_msgOk = (analyze_setfield(L_bodyData, &L_id_setfield ,&L_val_setfield) == -1) 
05487                 ? false : true  ;
05488               if (L_msgOk) {
05489                 L_msg->set_header_value(L_id_setfield, L_val_setfield);
05490               }
05491               
05492             } else {
05493               GEN_ERROR(E_GEN_FATAL_ERROR, 
05494                         "Unkown section ["
05495                         << L_bodyData->get_name()
05496                         << "]");
05497               L_msgOk = false;
05498               break ;
05499             }
05500             if (L_msgOk == false) break ;
05501           } // for (L_bodyValIt
05502         } // if (L_listBodyVal != NULL)
05503       }
05504     }
05505   }
05506 
05507   // TO-REMOVE
05508   if (L_msgOk == false) {
05509     DELETE_VAR(L_msg);
05510   } else {
05511     // Store the description message in list
05512     m_messageList->push_back(L_msg);
05513   }
05514 
05515   GEN_DEBUG(1, "C_ProtocolTlv::create_new_message() end: xml");
05516 
05517   return (L_msg);
05518 }
05519 
05520 void C_ProtocolTlv::log_buffer(char* P_header, 
05521                                   unsigned char *P_buffer, 
05522                                   size_t P_buffer_size) {
05523   if (genTraceLevel & gen_mask_table[LOG_LEVEL_BUF]) {
05524     static char L_hexa_buf [50] ;
05525     const  size_t L_cNum = 16 ;
05526     size_t L_i, L_nb ;
05527     unsigned char*L_cur ;
05528     size_t L_buffer_size = P_buffer_size ;
05529     
05530     GEN_LOG_EVENT(LOG_LEVEL_BUF,
05531                   "Buffer " << P_header << " size ["
05532                   << L_buffer_size
05533                   << "]");
05534     L_nb = L_buffer_size / L_cNum ;
05535     L_cur = P_buffer ;
05536     for (L_i = 0 ; L_i < L_nb; L_i++) {
05537       pretty_binary_buffer(L_cur, L_cNum, L_hexa_buf);
05538       GEN_LOG_EVENT_NO_DATE(LOG_LEVEL_BUF, 
05539                             L_hexa_buf) ;
05540       L_cur += L_cNum ;
05541     }
05542     L_nb = L_buffer_size % L_cNum ;
05543     if (L_nb != 0) {
05544       pretty_binary_buffer(L_cur, L_nb, L_hexa_buf);
05545       GEN_LOG_EVENT_NO_DATE(LOG_LEVEL_BUF, 
05546                                 L_hexa_buf) ;
05547     }
05548   }
05549 }
05550 
05551 
05552 char* C_ProtocolTlv::message_name() {
05553   return (get_header_name());
05554 }
05555 
05556 char* C_ProtocolTlv::message_component_name() {
05557   return (get_header_body_name ());
05558 }
05559 
05560 T_pNameAndIdList C_ProtocolTlv::message_name_list     () {
05561 
05562   T_NameAndId                  L_elt                     ;
05563   size_t                          L_i                       ;
05564 
05565   for (L_i = 0 ; L_i < m_nb_header_values ; L_i ++) {
05566     
05567     ALLOC_TABLE(L_elt.m_name,
05568                 char*, sizeof(char),
05569                 (strlen(m_header_value_table[L_i].m_name)+1));
05570 
05571     strcpy(L_elt.m_name,m_header_value_table[L_i].m_name) ;
05572     L_elt.m_id = m_header_value_table[L_i].m_id ;
05573 
05574     m_message_name_list->push_back(L_elt);    
05575 
05576   }
05577 
05578   return (m_message_name_list);
05579   
05580 }
05581 
05582 T_pNameAndIdList C_ProtocolTlv::message_component_name_list    () {
05583 
05584   T_NameAndId                  L_elt                     ;
05585   size_t                          L_i                       ;
05586 
05587   for (L_i = 0 ; L_i < m_nb_header_body_values ; L_i ++) {
05588     
05589     ALLOC_TABLE(L_elt.m_name,
05590                 char*, sizeof(char),
05591                 (strlen(m_header_body_value_table[L_i].m_name)+1));
05592     
05593     strcpy(L_elt.m_name,m_header_body_value_table[L_i].m_name) ;
05594     L_elt.m_id = m_header_body_value_table[L_i].m_id ;
05595     
05596     m_message_comp_name_list->push_back(L_elt);
05597     
05598   }
05599   
05600   return (m_message_comp_name_list) ;
05601   
05602   
05603 }
05604 
05605 
05606 char* C_ProtocolTlv::message_name(int P_headerId) {
05607   if (P_headerId == -1) {
05608     return (get_header_name());
05609   } else {
05610     return (m_header_value_table[P_headerId].m_name);
05611   }
05612 }
05613 
05614 // field management
05615 int C_ProtocolTlv::find_field(char *P_name) {
05616   int L_id ;
05617 
05618   L_id = find_header_field_id (P_name);
05619   if (L_id == -1) {
05620     L_id = find_body_value_id(P_name);
05621     if (L_id != -1) {
05622       L_id += m_max_nb_field_header ;
05623     }
05624   }
05625   return (L_id);
05626 }
05627 
05628 T_TypeType C_ProtocolTlv::get_field_type (int P_id,
05629                                              int P_sub_id) {
05630   int        L_id = P_id ;
05631   T_TypeType L_type = E_TYPE_NUMBER ;
05632   
05633   GEN_DEBUG(1, "C_ProtocolTlv::get_field_type() "
05634                           << "P_id is " << P_id 
05635                           << " (max header is " << m_max_nb_field_header
05636                           << ") P_sub_id is " << P_sub_id );
05637 
05638   if (L_id >= (int)m_max_nb_field_header) {
05639     L_id -= m_max_nb_field_header ;
05640     L_type = get_body_value_type(L_id);
05641   } else {
05642     L_type = get_header_value_type(L_id);
05643   }
05644   return (L_type);
05645 }
05646 
05647 int C_ProtocolTlv::retrieve_field_id(int P_id, T_pMsgIdType P_type) {
05648   int L_id = P_id ;
05649   if (L_id < (int)m_max_nb_field_header) {
05650     *P_type = E_MSG_ID_HEADER ;
05651   } else {
05652     L_id -= m_max_nb_field_header ;
05653 
05654     *P_type = E_MSG_ID_BODY ;
05655   }
05656   return (L_id);
05657 }
05658 
05659 bool C_ProtocolTlv::check_sub_entity_needed (int P_id) {
05660   return (false);
05661 }
05662 
05663 unsigned long  C_ProtocolTlv::get_m_max_nb_field_header () {
05664   return (m_max_nb_field_header);
05665 }
05666 
05667 int C_ProtocolTlv::process_grouped_type(C_XmlData *P_bodyData,
05668                                            int P_body_grouped_val_id,
05669                                            T_pBodyValue P_pBodyVal) {
05670   int L_nRet = 0;
05671 
05672   T_pXmlData_List           L_listGroupedVal ;
05673   T_XmlData_List::iterator  L_groupedValIt ;
05674   C_XmlData                *L_groupedVal ;
05675   int                       L_nb_groupedVal ;
05676   char                     *L_groupedValName, *L_groupedValValue ;
05677   int                       L_groupedValId, L_groupedValIndex;
05678                   
05679   GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() start");
05680   GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() Body Value id: " 
05681                              << P_body_grouped_val_id );
05682 //  GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() Body Value pt  : " 
05683 //                           << P_pBodyVal );
05684 
05685 
05686 
05687   // Retrieve the grouped value list
05688   L_listGroupedVal = P_bodyData -> get_sub_data() ;
05689 
05690   if (L_listGroupedVal != NULL) {
05691     L_nb_groupedVal = L_listGroupedVal->size() ;
05692                   
05693     GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() " 
05694                         << "Number of element in grouped type is " 
05695                         << L_nb_groupedVal );
05696 
05697     // Add the grouped type in the body value structure
05698     L_nRet = set_body_value(P_body_grouped_val_id,
05699                    NULL,
05700                    L_nb_groupedVal,
05701                    P_pBodyVal);
05702                   
05703     if (L_nRet == 0)
05704     {
05705       L_groupedValIndex = 0 ;
05706 
05707       for (L_groupedValIt = L_listGroupedVal->begin() ;
05708            L_groupedValIt != L_listGroupedVal->end() ;
05709            L_groupedValIt++) {
05710 
05711         // Get the sub value description
05712         L_groupedVal = *L_groupedValIt ;
05713                     
05714         // GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() " 
05715                      // << "Grouped Value [" << L_groupedValIndex 
05716                      // << "] get header field name [" << L_groupedVal->get_name()
05717                      // << "] to be compare with ["<< get_header_body_name() << "]");
05718               
05719         // Check component header tag
05720         if (strcmp(L_groupedVal->get_name(), 
05721                    get_header_body_name())==0) {
05722                       
05723           // retrieve the name, the id and value
05724           // of the field
05725           L_groupedValName = 
05726                   L_groupedVal -> find_value ((char*)"name");
05727 
05728           L_groupedValValue = 
05729                   L_groupedVal -> find_value ((char*)"value");
05730 
05731           if (L_groupedValName == NULL) {
05732             GEN_ERROR(E_GEN_FATAL_ERROR, 
05733                                   "name value mandatory for header field "
05734                                   << L_groupedVal->get_name());
05735             L_nRet = 3 ;
05736             break ;
05737           }
05738 
05739           L_groupedValId = 
05740                   get_header_body_value_id(L_groupedValName) ;
05741 
05742           if (L_groupedValId == -1) {
05743             GEN_ERROR(E_GEN_FATAL_ERROR,
05744                     "No definition found for field "
05745                     << L_groupedValName);
05746             L_nRet = 4 ;
05747             break ;
05748           } ;
05749 
05750           GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() " 
05751                      << "Grouped Value [" << L_groupedValIndex 
05752                      << "] " << L_groupedVal->get_name() 
05753                      << " name [" << L_groupedValName 
05754                      << "] with id: "<< L_groupedValId);
05755 
05756                         
05757           // Special grouped type case
05758           if (get_body_value_type (L_groupedValId) 
05759                  == E_TYPE_GROUPED) {
05760 
05761             GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() " 
05762                      << "L_groupedVal [" << L_groupedValIndex 
05763                      << "] name " << L_groupedValName 
05764                      << " is a grouped type");
05765 
05766             // Now try to recursive call
05767             if (process_grouped_type(L_groupedVal, L_groupedValId, 
05768                                      &(P_pBodyVal -> m_sub_val[L_groupedValIndex])) != 0) {
05769                 GEN_ERROR(E_GEN_FATAL_ERROR, 
05770                       "Recursive Grouped error");
05771                 GEN_ERROR(E_GEN_FATAL_ERROR,
05772                         "Grouped Type processing Error for "
05773                          << L_groupedValName);
05774                L_nRet = 99 ;
05775                 break ;
05776             }
05777           } else {
05778 
05779             // Single value processing case
05780             // then a value must be found in message definition
05781             if (L_groupedValValue == NULL) {
05782               GEN_ERROR(E_GEN_FATAL_ERROR, 
05783                         "value mandatory for field "
05784                         << L_groupedValName);
05785               L_nRet = 5 ;
05786               break ;
05787             }
05788 
05789             // Now add the sub value
05790             if (set_body_sub_value(L_groupedValIndex,
05791                                    L_groupedValId,
05792                                    L_groupedValValue,
05793                                    P_pBodyVal) != 0) {
05794               GEN_ERROR(E_GEN_FATAL_ERROR,
05795                         "Bad format for ["
05796                         << L_groupedValValue << "] for field "
05797                         << L_groupedValName);
05798               L_nRet = 6 ;
05799               break ;
05800             }
05801 
05802           }
05803         } else {
05804           GEN_ERROR(E_GEN_FATAL_ERROR, 
05805                      "Unknown header field section [" 
05806                      << L_groupedVal->get_name()
05807                      << "]" );
05808                     L_nRet = 2 ;
05809                     break ;
05810         }
05811         L_groupedValIndex++ ;
05812       }
05813     }
05814   } else {
05815     GEN_ERROR(E_GEN_FATAL_ERROR,
05816               "Grouped value with no value");
05817     L_nRet = 1 ;
05818   }
05819 
05820   GEN_DEBUG(1, "C_ProtocolTlv::process_grouped_type() end return: " 
05821                              << L_nRet );
05822   return L_nRet;
05823 }
05824 
05825 bool C_ProtocolTlv::get_complex_header_presence() {
05826   return m_header_complex_type_presence;
05827 }
05828 
05829 
05830 void C_ProtocolTlv::update_stats (T_ProtocolStatDataType   P_type,
05831                                        T_ProtocolStatDataAction P_action,
05832                                        int                      P_id) {
05833 }
05834 
05835 int C_ProtocolTlv::analyze_sessions_id_from_xml (C_XmlData *P_def) {
05836 
05837 
05838   int                       L_ret = 0                      ;
05839   char                     *L_session_id_name = NULL       ;
05840   char                     *L_outof_session_id_name = NULL ;
05841   C_XmlData                *L_data                         ;
05842 
05843   char                     *L_session_id_position_name = NULL ;
05844   char                     *L_endstr           ;
05845 
05846 
05847   L_data = P_def ;
05848   // header values dictionnary definitions
05849   L_session_id_name = L_data->find_value ((char*)"session-id") ;
05850   
05851   GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() L_session_id_name is " << 
05852             L_session_id_name);
05853   
05854   if (L_session_id_name == NULL) {
05855     GEN_ERROR(E_GEN_FATAL_ERROR,
05856               "session-id value is mandatory for ["
05857               << m_header_name << "] section");
05858     L_ret = -1 ;
05859   } 
05860 
05861   if (L_ret != -1) {
05862     L_outof_session_id_name 
05863       = L_data->find_value ((char*)"out-of-session-id") ;
05864     if (L_outof_session_id_name == NULL) {
05865       GEN_ERROR(E_GEN_FATAL_ERROR,
05866                 "out-of-session-id value is mandatory for ["
05867                 << m_header_name << "] section");
05868       L_ret = -1 ;
05869     } 
05870   }
05871 
05872   if (L_ret != -1) {
05873     L_session_id_position_name 
05874       = L_data->find_value ((char*)"session-id-position") ;
05875     if (L_session_id_position_name != NULL) {
05876       m_session_id_position = (int)strtoul_f (L_session_id_position_name, &L_endstr, 10);
05877       if (L_endstr[0] != '\0') {
05878         GEN_ERROR(E_GEN_FATAL_ERROR, "bad format, ["
05879                   << m_session_id_position << "] not a number");
05880         L_ret = -1 ;
05881       }
05882     }
05883   }
05884   
05885   if (L_ret != -1) {
05886     GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05887               << "Session Id name is " << L_session_id_name );
05888 
05889     // retrieve informations for session_id
05890     if (L_session_id_name) {
05891       m_msg_id_id = find_header_field_id (L_session_id_name) ;
05892       
05893       GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05894                 << "m_msg_id_id is " << m_msg_id_id );
05895       
05896       if (m_msg_id_id != -1) {
05897         GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05898                   << "m_msg_id_id is an header one it type is number");
05899         m_msg_id_type = E_MSG_ID_HEADER ;
05900         m_msg_id_value_type = E_TYPE_NUMBER ;
05901       } else {
05902         GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05903                   << "m_msg_id_id is an body one ");
05904         m_msg_id_id = find_body_value_id (L_session_id_name) ;
05905 
05906         GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05907                   << "m_msg_id_id is " << m_msg_id_id );
05908         if (m_msg_id_id != -1) {
05909           m_msg_id_type = E_MSG_ID_BODY ;
05910           m_msg_id_value_type = get_body_value_type (m_msg_id_id);
05911 
05912           GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05913                     << "m_msg_id_id is " << m_msg_id_id << " its type is " 
05914                     << m_msg_id_value_type);
05915         } else {
05916           GEN_ERROR(E_GEN_FATAL_ERROR,
05917                     "No definition found for session-id ["
05918                     << L_session_id_name << "]");
05919           L_ret = -1 ;
05920         }
05921       }
05922     }
05923 
05924     if (L_ret != -1) {
05925       if (L_outof_session_id_name) {
05926         GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05927                   << "Out Of Session Id name is " 
05928                   << L_outof_session_id_name );
05929         
05930         m_id_out_of_session = find_header_field_id (L_outof_session_id_name) ;
05931         
05932         GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05933                   << "m_id_out_of_session is " 
05934                   << m_id_out_of_session );
05935         
05936         if (m_id_out_of_session != -1) {
05937           m_type_id_out_of_session = E_MSG_ID_HEADER ;
05938           GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05939                     << "m_type_id_out_of_session is " 
05940                     << m_type_id_out_of_session);
05941         } else {
05942           m_id_out_of_session = find_body_value_id (L_outof_session_id_name) ;
05943           if (m_id_out_of_session != -1) {
05944             m_type_id_out_of_session = E_MSG_ID_BODY ;
05945             GEN_DEBUG(1, "C_ProtocolTlv::xml_interpretor() " 
05946                       << "m_type_id_out_of_session is  " 
05947                       << m_type_id_out_of_session);
05948           } else {
05949             GEN_ERROR(E_GEN_FATAL_ERROR,
05950                       "No definition found for out-of-session-id ["
05951                       << L_session_id_name << "]");
05952             L_ret = -1 ;
05953           }
05954         }
05955       } // if (L_outof_session_id_name)
05956     }
05957   }
05958 
05959   return (L_ret) ;
05960 }
05961 
05962 C_ProtocolTlv::T_pManagementSessionId 
05963 C_ProtocolTlv::get_manage_session_elt(int P_id) {
05964   return (NULL) ;
05965 }
05966 
05967 
05968 int C_ProtocolTlv::get_nb_management_session () {
05969   return (0);
05970 }
05971 
05972 bool C_ProtocolTlv::check_present_session (int P_msg_id,int P_id) {
05973   return (true);
05974 }
05975 
05976 bool C_ProtocolTlv::find_present_session (int P_msg_id,int P_id) {
05977   return (true);
05978 }
05979 
05980 char* C_ProtocolTlv::get_header_body_field_separator() {
05981   return (m_header_body_field_separator);
05982 }
05983 
05984 int C_ProtocolTlv::analyze_setfield(C_XmlData          *P_data, 
05985                                        int                *P_fieldId,
05986                                        unsigned long      *P_fieldValueUl) {
05987 
05988   int                       L_ret = 0       ;
05989   C_XmlData                *L_data          ;
05990   char                     *L_fieldName     ;
05991   char                     *L_fieldValue    ;
05992   T_IdMap::iterator         L_IdMapIt       ;
05993   char                     *L_endstr        ;
05994 
05995   unsigned long             L_fieldValueUl  ;  
05996   int                       L_fieldId       ;
05997 
05998 
05999   L_data = P_data ;
06000 
06001   
06002   L_fieldName = L_data->find_value((char*)"name") ;
06003   if (L_fieldName == NULL) {
06004     GEN_ERROR(E_GEN_FATAL_ERROR, "setfield name value is mandatory");
06005     L_ret = -1 ;
06006   }
06007   
06008   L_IdMapIt = 
06009     m_header_id_map->find(T_IdMap::key_type(L_fieldName));
06010   
06011   if (L_IdMapIt != m_header_id_map->end()) {
06012     L_fieldId = L_IdMapIt->second ;
06013     (*P_fieldId) = L_fieldId ;
06014   } else {
06015     GEN_ERROR(E_GEN_FATAL_ERROR, 
06016               "Field ["
06017               << L_fieldName << "] not defined");
06018     L_ret = -1 ;
06019   }
06020   
06021   L_fieldValue = L_data->find_value((char*)"value") ;
06022   if (L_fieldValue == NULL) {
06023     GEN_ERROR(E_GEN_FATAL_ERROR, "setfield value is mandatory");
06024     L_ret = -1 ;
06025   }
06026   
06027   L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,10) ;
06028   
06029   if (L_endstr[0] != '\0') {
06030     L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,16) ;
06031     if (L_endstr[0] != '\0') {
06032       GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value ["
06033                 << L_fieldValue << "] bad format");
06034       L_ret = -1 ;
06035     } else {
06036       (*P_fieldValueUl) = L_fieldValueUl ;
06037     }
06038   }
06039 
06040   return (L_ret) ;
06041 }
06042 
06043 
06044 
06045 int C_ProtocolTlv::ctrl_length  (char *P_length_name, bool P_header) {
06046   char *L_value = P_length_name ; 
06047   int   L_length_id = -1 ;
06048 
06049   if (L_value == NULL) {
06050     GEN_ERROR(E_GEN_FATAL_ERROR, "name value is mandatory");
06051     return (L_length_id);
06052   } 
06053   
06054   L_length_id = check_length(L_value) ;
06055   if ( L_length_id == -1) { 
06056     GEN_ERROR(E_GEN_FATAL_ERROR,
06057               "Unable to find definition for ["
06058               << L_value << "]");
06059     return (L_length_id);
06060   }
06061 
06062 
06063   if (P_header) {
06064     if ( L_length_id > m_nb_header_length) {
06065       GEN_ERROR(E_GEN_FATAL_ERROR,
06066                 "Unable to find definition for ["
06067                 << L_value << "] in header part");
06068       
06069       L_length_id = -1 ;  
06070       return (L_length_id);
06071     }
06072   } else {
06073     if (( L_length_id < m_nb_header_length ) ||
06074         ( L_length_id > m_length_max)) {
06075       GEN_ERROR(E_GEN_FATAL_ERROR,
06076                 "Unable to find definition for ["
06077                 << L_value << "] in header body part");
06078       
06079       L_length_id = -1 ;  
06080       return (L_length_id);
06081     }
06082   }
06083   return (L_length_id);
06084 }
06085 
06086 
06087 int C_ProtocolTlv::update_field_length (int                        P_length_id,
06088                                         int                        P_field_id, 
06089                                         T_pProtocolCounterDataList P_length_list,
06090                                         bool                       P_header) {
06091 
06092   int                                     L_ret   = -1            ;
06093   T_ProtocolCounterData                   L_field_length          ;  
06094   T_ProtocolCounterDataList::iterator     L_it                    ;
06095   bool                                    L_found         = false ;
06096 
06097 
06098   if (!P_length_list->empty()) {
06099     for (L_it = P_length_list->begin();
06100          L_it != P_length_list->end();
06101          L_it++) {
06102       L_field_length = *L_it;
06103       if (L_field_length.m_id == P_length_id) {
06104         P_length_list->erase(L_it);
06105         L_found = true ;
06106         break;
06107       }
06108     }
06109   }
06110   
06111   if (L_found == true) {
06112     L_field_length.m_stop_id = P_field_id ;
06113     P_length_list->push_back(L_field_length);
06114     L_ret = 0 ;
06115   }
06116   return (L_ret);
06117 }
06118 
06119 int C_ProtocolTlv::check_length (char *P_length_name) {
06120   int L_length_id = -1 ;
06121   T_LengthIdMap::iterator
06122     L_it = m_length_map->find (T_LengthIdMap::key_type(P_length_name)) ;
06123   if (L_it != m_length_map->end()) {
06124     L_length_id = L_it->second ;
06125   }
06126   return (L_length_id) ;
06127 }
06128 
06129 int C_ProtocolTlv::add_length (char *P_length_name) {
06130   int L_length_id = check_length (P_length_name) ;
06131   if (L_length_id == -1) {
06132     m_length_max++;
06133     L_length_id = m_length_max ;
06134     m_length_map->insert(T_LengthIdMap::value_type(P_length_name, L_length_id));
06135   } else {
06136     GEN_ERROR(E_GEN_FATAL_ERROR, "field [" << P_length_name << "] already defined");
06137     L_length_id = -1 ;
06138   }
06139   return (L_length_id) ;
06140 }
06141 
06142 
06143 int C_ProtocolTlv::add_counter_id (char *P_value_string, bool P_header) {
06144   char *L_variable = NULL ;
06145   char *L_value_string = P_value_string;
06146   int   L_length_id    = -1 ;
06147   if ((L_variable = is_variable(L_value_string)) != NULL) {
06148     L_length_id = ctrl_length  (L_variable, P_header) ;
06149     if (L_length_id == -1) {
06150       GEN_ERROR(E_GEN_FATAL_ERROR, "Unable to find [" 
06151                 << L_variable 
06152                 << "] in list of length defined in dictionnary");
06153     } 
06154     FREE_TABLE(L_variable);
06155   }
06156   return (L_length_id);
06157 } 
06158 
06159 char* C_ProtocolTlv::is_variable(char* P_varibleString) {
06160   
06161   char *L_ptr     = P_varibleString ;
06162   char *L_value   = NULL            ;
06163   char *L_search  = NULL            ;
06164   char *L_ptr_end = NULL            ;
06165 
06166   int   L_value_size                ;
06167 
06168   if ((L_ptr == NULL) ||
06169       ((strlen(L_ptr)) <= 2)) {
06170     return (L_value) ;
06171   } 
06172 
06173   if (!((L_ptr[0] == '$') && (L_ptr[1] == '('))) {
06174     return (L_value) ;
06175   } else {
06176     L_search = L_ptr + 2 ;
06177     L_ptr_end = strchr(L_search, ')') ;
06178     if (L_ptr_end == NULL) {
06179       return (L_value) ;
06180     } else {
06181       L_value_size =  L_ptr_end - L_search ; 
06182       ALLOC_TABLE(L_value,
06183                   char*, 
06184                   sizeof(char),
06185                   L_value_size+1);
06186       memcpy(L_value, L_search, L_value_size);
06187       L_value[L_value_size] = 0 ;
06188     }    
06189   }
06190   return (L_value);
06191 }
06192 
06193 C_ProtocolContext* C_ProtocolTlv::create_protocol_context() {
06194               
06195   C_ProtocolContext   *L_protocol_context = NULL ;
06196   
06197   NEW_VAR(L_protocol_context,
06198           C_ProtocolContext(m_nb_protocol_ctxt_values));
06199   return (L_protocol_context) ;
06200 }
06201 
06202 
06203 void  C_ProtocolTlv::delete_protocol_context(C_ProtocolContext** P_protocol_ctxt) {
06204   DELETE_VAR(*P_protocol_ctxt);
06205 }
06206 
06207 void  C_ProtocolTlv::reset_protocol_context(C_ProtocolContext* P_protocol_context) {
06208   P_protocol_context->reset_ctxt_values(m_nb_header_length);
06209 }
06210 
06211 
06212 void  C_ProtocolTlv::update_ctxt_values (C_ProtocolContext     *P_protocol_context,
06213                                          unsigned char         *P_buf_pos,
06214                                          int                    P_field_id,
06215                                          int                    P_size,
06216                                          T_pUpdateCtxtValue     P_ctxt_id_v_table,
06217                                          T_pUpdateCtxtPosition  P_ctxt_p_table) {
06218 
06219 
06220   C_ProtocolContext::T_PositionValue L_position_value    ;
06221 
06222   int L_field_id = P_field_id ;
06223   
06224   L_position_value.m_id_field     = -1       ;
06225   L_position_value.m_position_ptr = NULL     ;
06226   
06227   if (P_ctxt_id_v_table[L_field_id].m_nb_ctxt_id != 0 ){
06228     P_protocol_context->update_ctxt_values(P_ctxt_id_v_table[L_field_id].m_nb_ctxt_id,
06229                                            P_ctxt_id_v_table[L_field_id].m_ctxt_id_setted,
06230                                            P_size);
06231   }
06232 
06233   if (P_ctxt_p_table[L_field_id].m_nb_ctxt_pos == 1 ){
06234     L_position_value.m_id_field     = P_field_id    ;
06235     L_position_value.m_position_ptr = P_buf_pos     ;
06236     P_protocol_context->update_ctxt_position(P_ctxt_p_table[L_field_id].m_ctxt_id_pos,
06237                                              &L_position_value);
06238   }
06239   
06240 }
06241 
06242 
06243 int  C_ProtocolTlv::update_ctxt_v_field (T_pUpdateCtxtValue      P_ctxt_id_v_table, 
06244                                          int                     P_nb_field,
06245                                          T_pProtocolCounterData  P_ctxt_table,
06246                                          int                     P_nb_ctxt_table,
06247                                          T_pUpdateCtxtValue      P_ctxt_global_v_table,
06248                                          int                     P_counter_last_id) {
06249 
06250   int                    L_ret  = 0     ;
06251   int                    L_i            ;
06252   int                    L_j            ;
06253   int                    L_id           ;
06254   T_IdCtxtList           L_id_ctxt_list ;
06255   T_IdCtxtList::iterator L_it           ;
06256   int                    L_nb_ctxt = 0  ;
06257   
06258   for (L_i = 0; L_i < P_nb_field ;L_i++) {
06259     for (L_j = 0; L_j <  P_nb_ctxt_table; L_j++) {
06260       if (((L_i >= P_ctxt_table[L_j].m_start_id) && (P_ctxt_table[L_j].m_stop_id == -1)) ||
06261           ((L_i >= P_ctxt_table[L_j].m_start_id) && (L_i <= P_ctxt_table[L_j].m_stop_id))) {
06262         L_id_ctxt_list.push_back(P_ctxt_table[L_j].m_id) ;
06263       }
06264     }
06265 
06266     if (P_ctxt_global_v_table != NULL) {
06267       for (L_j = 0; L_j <   P_ctxt_global_v_table->m_nb_ctxt_id ; L_j++) {
06268           L_id_ctxt_list.push_back(P_ctxt_global_v_table->m_ctxt_id_setted[L_j]) ;
06269       }
06270     }
06271 
06272     if (P_counter_last_id != -1) {
06273         L_id_ctxt_list.push_back(P_counter_last_id);
06274     }
06275 
06276     if (!L_id_ctxt_list.empty()) {
06277       L_nb_ctxt = L_id_ctxt_list.size() ;
06278 
06279       P_ctxt_id_v_table[L_i].m_nb_ctxt_id = L_nb_ctxt ;
06280       ALLOC_TABLE(P_ctxt_id_v_table[L_i].m_ctxt_id_setted,
06281                   int*,
06282                   sizeof(int),
06283                   L_nb_ctxt);
06284       
06285       L_id = 0 ;
06286       for (L_it  = L_id_ctxt_list.begin();
06287            L_it != L_id_ctxt_list.end()  ;
06288            L_it++) {
06289         P_ctxt_id_v_table[L_i].m_ctxt_id_setted[L_id] = *L_it;
06290         L_id++;
06291       }
06292       L_id_ctxt_list.erase(L_id_ctxt_list.begin(),
06293                            L_id_ctxt_list.end());
06294     }
06295   }
06296   return (L_ret);
06297 }
06298 
06299 
06300 void  C_ProtocolTlv::propagate_ctxt_global (C_ProtocolContext         *P_protocol_context) {
06301   propagate_ctxt_local (P_protocol_context,
06302                         1,
06303                         m_nb_header_length,
06304                         m_header_field_table,
06305                         m_header_length_table);
06306 }
06307 
06308 
06309 void  C_ProtocolTlv::propagate_ctxt_local(C_ProtocolContext         *P_protocol_context,
06310                                           int                        P_id_begin,
06311                                           int                        P_id_end,
06312                                           T_pHeaderField             P_field_table,
06313                                           T_pProtocolCounterData     P_ctxt_table) {
06314   int              L_i               ;
06315   unsigned long   *L_size_to_update  ;
06316   unsigned char   *L_position = NULL ;
06317   int              L_field_id        ;
06318 
06319   C_ProtocolContext *L_protocol_context = P_protocol_context ;
06320  
06321   for (L_i = P_id_begin ; L_i < P_id_end ; L_i++) {
06322     L_size_to_update = 
06323       &(L_protocol_context->m_ctxt_val_table[L_i].m_ctxt_value.m_value.m_val_number) ;
06324     L_position = 
06325       L_protocol_context->m_ctxt_val_table[L_i].m_ctxt_position.m_position_ptr ;
06326     L_field_id = 
06327       L_protocol_context->m_ctxt_val_table[L_i].m_ctxt_position.m_id_field ;
06328 
06329     //  To do  if (!m_transport_type) 
06330     if (L_position) {
06331       convert_ul_to_bin_network(L_position,
06332                                 P_field_table[L_field_id].m_size,
06333                                 (unsigned long)(*L_size_to_update));
06334     }
06335   }
06336 }
06337 
06338 
06339 void  C_ProtocolTlv::update_ctxt_length (C_ProtocolContext  *P_protocol_context,
06340                                           unsigned long       P_valueSize) {
06341   
06342   int L_i ;
06343   for (L_i = 0 ; L_i < m_nb_protocol_ctxt_values ; L_i++) {
06344     P_protocol_context->m_ctxt_val_table[L_i].m_ctxt_value.m_value.m_val_number += P_valueSize ;
06345   }
06346 }
06347 
06348 
06349 int  C_ProtocolTlv::update_ctxt_length_decode (C_ProtocolContext *P_protocol_context,
06350                                                unsigned long      P_data_size) {
06351   int L_i ;
06352   int L_ret = 0 ;
06353   for (L_i = 0 ; L_i < m_nb_protocol_ctxt_values ; L_i++) {
06354     P_protocol_context->m_ctxt_val_table[L_i].m_ctxt_value.m_value.m_val_number -= P_data_size ;
06355     if (P_protocol_context->m_ctxt_val_table[L_i].m_ctxt_value.m_value.m_val_number <0 ) {
06356       L_ret = -1;
06357       break;
06358     }
06359   }
06360   return (L_ret);
06361 }
06362 
06363 
06364 int  C_ProtocolTlv::update_ctxt_values_decode (C_ProtocolContext     *P_protocol_context,
06365                                                int                    P_field_id,
06366                                                int                    P_size,
06367                                                T_pUpdateCtxtValue     P_ctxt_id_v_table) {
06368   int L_ret = 0 ;
06369 
06370   if (P_ctxt_id_v_table[P_field_id].m_nb_ctxt_id != 0 ){
06371     L_ret = P_protocol_context->update_ctxt_values_decode(P_ctxt_id_v_table[P_field_id].m_nb_ctxt_id,
06372                                                           P_ctxt_id_v_table[P_field_id].m_ctxt_id_setted,
06373                                                           P_size);
06374   }
06375   return (L_ret);
06376   
06377 }
06378 
06379 
06380 

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