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