00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "C_MessageText.hpp"
00021 #include "C_ProtocolText.hpp"
00022 #include "ProtocolData.hpp"
00023
00024
00025 #include "GeneratorTrace.hpp"
00026 #include "GeneratorError.h"
00027
00028 #include "C_ContextFrame.hpp"
00029 #include "ReceiveMsgContext.h"
00030 #include "C_CallContext.hpp"
00031
00032 #define m_body_separator_size m_protocol->m_body_separator_size
00033 #define m_body_separator m_protocol->m_body_separator
00034 #define m_message_type_field_id m_protocol->m_message_type_field_id
00035 #define m_session_id_id m_protocol->m_session_id_id
00036 #define m_session_method m_protocol->m_session_method
00037 #define m_field_separator_size m_protocol->m_field_separator_size
00038 #define m_field_separator m_protocol->m_field_separator
00039
00040 #define m_field_body_separator_size m_protocol->m_field_body_separator_size
00041 #define m_field_body_separator m_protocol->m_field_body_separator
00042
00043 #define m_names_fields m_protocol->m_names_fields
00044
00045 #define m_methods m_protocol->m_methods
00046 #define m_nb_methods m_protocol->m_nb_methods
00047
00048
00049 C_ProtocolFrame::T_MsgError C_MessageText::EncodeWithContentLength (int P_index) {
00050
00051 C_ProtocolFrame::T_MsgError L_error = C_ProtocolFrame::E_MSG_OK ;
00052
00053 char L_size_char[10] ;
00054 size_t L_size_body = 0 ;
00055 T_ValueData L_size ;
00056 int L_result = -1 ;
00057 int L_ret = 0 ;
00058
00059 GEN_DEBUG(1, "C_MessageText::EncodeWithContentLength() start");
00060
00061 L_size_body = (m_body == NULL) ? 0 : m_body->m_value.m_val_binary.m_size ;
00062 snprintf(L_size_char, 10, "%d", L_size_body);
00063 L_size = valueFromString(L_size_char, E_TYPE_STRING, L_result);
00064
00065 if (L_result == -1) {
00066 L_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
00067 } else {
00068 L_size.m_type = E_TYPE_STRING ;
00069 L_ret = m_protocol->set_field_value(this, (m_methods[P_index]->m_param_encode).m_id, &L_size) ;
00070 if (L_ret == -1) {
00071 L_error = C_ProtocolFrame::E_MSG_ERROR_ENCODING ;
00072 }
00073 resetMemory(L_size);
00074 }
00075
00076 GEN_DEBUG(1, "C_MessageText::EncodeWithContentLength() end");
00077 return (L_error);
00078 }
00079
00080 C_ProtocolFrame::T_MsgError C_MessageText::NoEncode (int P_index) {
00081
00082 C_ProtocolFrame::T_MsgError L_error = C_ProtocolFrame::E_MSG_OK ;
00083
00084 GEN_DEBUG(1, "C_MessageText::EncodeWithContentLength() start");
00085 GEN_DEBUG(1, "C_MessageText::EncodeWithContentLength() end");
00086
00087 return (L_error);
00088 }
00089
00090
00091 C_ProtocolFrame::T_MsgError C_MessageText::DecodeBodyWithParser (int P_index,
00092 char *P_ptr,
00093 size_t *P_size) {
00094
00095 C_ProtocolFrame::T_MsgError L_error = C_ProtocolFrame::E_MSG_OK ;
00096 size_t L_size_body = *P_size ;
00097
00098
00099
00100
00101 L_error = (*(((m_methods[P_index])->m_param_decode).m_parser))(P_ptr,
00102 P_size,
00103 (char *)m_header->m_value.m_val_binary.m_value,
00104 (size_t)m_header->m_value.m_val_binary.m_size);
00105 if (L_error == C_ProtocolFrame::E_MSG_OK) {
00106 L_size_body -= *P_size ;
00107 ALLOC_VAR(m_body, T_pValueData, sizeof(T_ValueData));
00108 m_body->m_type = E_TYPE_STRING ;
00109 m_body->m_value.m_val_binary.m_size = L_size_body ;
00110 ALLOC_TABLE(m_body->m_value.m_val_binary.m_value,
00111 unsigned char*,
00112 sizeof(unsigned char),
00113 m_body->m_value.m_val_binary.m_size);
00114
00115 memcpy(m_body->m_value.m_val_binary.m_value,
00116 P_ptr,
00117 m_body->m_value.m_val_binary.m_size);
00118 }
00119
00120 return (L_error);
00121 }
00122
00123
00124 C_ProtocolFrame::T_MsgError C_MessageText::DecodeBodyWithContentLength (int P_index,
00125 char *P_ptr,
00126 size_t *P_size) {
00127
00128 char *L_value = NULL ;
00129 size_t L_size_body = 0 ;
00130 C_ProtocolFrame::T_MsgError L_error = C_ProtocolFrame::E_MSG_OK ;
00131
00132 GEN_DEBUG(1, "C_MessageText::DecodeBodyWithContentLength() start");
00133
00134 if (*P_size == 0) {
00135
00136 return (L_error);
00137 }
00138
00139 L_value = m_protocol->get_field_value(this,(m_methods[P_index]->m_param_decode).m_id) ;
00140
00141 if (L_value != NULL) {
00142
00143
00144 L_size_body = atoi(L_value);
00145 if (L_size_body <= (*P_size)) {
00146 ALLOC_VAR(m_body, T_pValueData, sizeof(T_ValueData));
00147 m_body->m_type = E_TYPE_STRING ;
00148 m_body->m_value.m_val_binary.m_size = L_size_body ;
00149 ALLOC_TABLE(m_body->m_value.m_val_binary.m_value,
00150 unsigned char*,
00151 sizeof(unsigned char),
00152 m_body->m_value.m_val_binary.m_size);
00153
00154 memcpy(m_body->m_value.m_val_binary.m_value,
00155 P_ptr,
00156 m_body->m_value.m_val_binary.m_size);
00157 (*P_size) = (*P_size) - L_size_body ;
00158 } else {
00159 L_error = C_ProtocolFrame::E_MSG_ERROR_DECODING_SIZE_LESS ;
00160 }
00161 FREE_TABLE(L_value);
00162 } else {
00163 L_error = C_ProtocolFrame::E_MSG_ERROR_DECODING ;
00164 }
00165
00166 GEN_DEBUG(1, "C_MessageText::DecodeBodyWithContentLength() end");
00167 return (L_error);
00168 }
00169
00170
00171 C_MessageText::C_MessageText(C_ProtocolText *P_protocol) {
00172 m_protocol = P_protocol ;
00173 m_header = NULL ;
00174 m_body = NULL ;
00175 m_id = -1 ;
00176 m_session_id = NULL ;
00177 }
00178
00179 C_MessageText::C_MessageText(C_MessageText &P_val) {
00180
00181 GEN_DEBUG(1, "C_MessageText::C_MessageText() copy message start");
00182 m_protocol = P_val.m_protocol ;
00183 m_id = P_val.m_id ;
00184
00185 ALLOC_VAR(m_header, T_pValueData, sizeof(T_ValueData));
00186 m_header->m_type = E_TYPE_NUMBER ;
00187
00188 copyValue(*m_header, *P_val.m_header, false);
00189
00190 ALLOC_VAR(m_body, T_pValueData, sizeof(T_ValueData));
00191 m_body->m_type = E_TYPE_NUMBER ;
00192
00193 copyValue(*m_body, *P_val.m_body, false);
00194
00195 m_session_id = NULL ;
00196 GEN_DEBUG(1, "C_MessageText::C_MessageText() copy message end");
00197 }
00198
00199 C_MessageText::C_MessageText(C_ProtocolText *P_protocol,
00200 T_pValueData P_header,
00201 T_pValueData P_body,
00202 int *P_id) {
00203
00204 char * L_message_type = NULL ;
00205
00206 GEN_DEBUG(1, "C_MessageText::C_MessageText() start");
00207 m_protocol = P_protocol ;
00208
00209 m_session_id = NULL ;
00210
00211
00212 m_header = P_header ;
00213 m_body = P_body ;
00214
00215 L_message_type
00216 = m_protocol->get_field_value(this, m_message_type_field_id);
00217 if (L_message_type == NULL) {
00218
00219 *P_id = -1 ;
00220 m_id = -1 ;
00221 GEN_ERROR(E_GEN_FATAL_ERROR, "Unknown (not in dictionary) message ["
00222 << this->get_text_value(m_header)
00223 << "]");
00224 } else {
00225
00226
00227 m_id = m_protocol->get_message_id(L_message_type);
00228 *P_id = m_id ;
00229
00230 }
00231 FREE_TABLE(L_message_type);
00232 GEN_DEBUG(1, "C_MessageText::C_MessageText() end");
00233 }
00234
00235
00236 int C_MessageText::set_text_value(bool P_header_body, T_pValueData P_value,
00237 int P_start, int P_end) {
00238
00239 int L_ret = 0 ;
00240
00241 GEN_DEBUG(1, "C_MessageText::set_text_value() start");
00242
00243 T_pValueData L_data = (P_header_body == true) ? m_header : m_body ;
00244
00245 unsigned char *L_new_value = L_data->m_value.m_val_binary.m_value ;
00246 int L_old_data_size = P_end - P_start ;
00247 int L_delta_data_size = 0 ;
00248 int L_new_size = 0 ;
00249
00250
00251
00252 if (L_data) {
00253
00254 if (P_value->m_type == E_TYPE_STRING) {
00255
00256 if (L_old_data_size != (int)P_value->m_value.m_val_binary.m_size) {
00257 L_delta_data_size = P_value->m_value.m_val_binary.m_size - L_old_data_size ;
00258
00259
00260 L_new_size = L_data->m_value.m_val_binary.m_size + L_delta_data_size ;
00261
00262 if (L_new_size > 0) {
00263 ALLOC_TABLE(L_new_value,
00264 unsigned char*,
00265 sizeof(unsigned char),
00266 L_new_size);
00267 memcpy(L_new_value, L_data->m_value.m_val_binary.m_value, P_start);
00268
00269 memcpy((L_new_value+P_start+P_value->m_value.m_val_binary.m_size),
00270 (L_data->m_value.m_val_binary.m_value+P_end),
00271 (L_data->m_value.m_val_binary.m_size-P_end));
00272 FREE_TABLE(L_data->m_value.m_val_binary.m_value);
00273 L_data->m_value.m_val_binary.m_value = L_new_value ;
00274 L_data->m_value.m_val_binary.m_size = L_new_size ;
00275 } else {
00276 L_ret = -1 ;
00277 }
00278 }
00279 if (L_ret == 0) {
00280 memcpy(L_new_value+P_start,
00281 P_value->m_value.m_val_binary.m_value,
00282 P_value->m_value.m_val_binary.m_size);
00283 }
00284 } else {
00285 L_ret = -1 ;
00286 }
00287
00288 } else {
00289 L_ret = -1 ;
00290 }
00291
00292
00293
00294 GEN_DEBUG(1, "C_MessageText::set_text_value() end");
00295 return (L_ret);
00296 }
00297
00298
00299 char* C_MessageText::get_text_value(bool P_header_body) {
00300
00301 T_pValueData L_value ;
00302 char *L_result = NULL ;
00303
00304 GEN_DEBUG(1, "C_MessageText::get_text_value() start");
00305
00306 L_value = (P_header_body == true) ? m_header : m_body ;
00307
00308 if (L_value != NULL) {
00309 ALLOC_TABLE(L_result,
00310 char*,
00311 sizeof(char),
00312 (L_value->m_value.m_val_binary.m_size+1));
00313 memcpy(L_result,
00314 (char*)L_value->m_value.m_val_binary.m_value,
00315 L_value->m_value.m_val_binary.m_size) ;
00316 L_result[L_value->m_value.m_val_binary.m_size] = 0 ;
00317 }
00318 return (L_result) ;
00319 }
00320
00321
00322 T_pValueData C_MessageText::get_data_value(bool P_header_body) {
00323
00324 T_pValueData L_value = NULL ;
00325 GEN_DEBUG(1, "C_MessageText::get_data_value() start");
00326 L_value = (P_header_body == true) ? m_header : m_body ;
00327 return (L_value);
00328
00329 }
00330
00331
00332 C_MessageText::~C_MessageText() {
00333 GEN_DEBUG(1, "C_MessageText::~C_MessageText() start");
00334 if (m_header) resetMemory(*m_header) ;
00335 FREE_VAR(m_header) ;
00336 if (m_body) resetMemory(*m_body) ;
00337 FREE_VAR(m_body) ;
00338 m_protocol = NULL ;
00339 m_id = -1 ;
00340
00341 if (m_session_id != NULL) {
00342 if ((m_session_id->m_type == E_TYPE_STRING)
00343 && (m_session_id->m_value.m_val_binary.m_size> 0)) {
00344 FREE_TABLE(m_session_id->m_value.m_val_binary.m_value);
00345 m_session_id->m_value.m_val_binary.m_size = 0 ;
00346 }
00347 FREE_VAR(m_session_id) ;
00348 }
00349
00350 GEN_DEBUG(1, "C_MessageText::~C_MessageText() end");
00351 }
00352
00353 T_pValueData C_MessageText::getSessionFromOpenId (C_ContextFrame *P_ctxt) {
00354
00355 T_pReceiveMsgContext L_recvCtx = NULL ;
00356 C_CallContext* L_callCtx = NULL ;
00357 GEN_DEBUG(1, "C_MessageText::getSessionFromOpenId() start");
00358
00359 if (m_session_id == NULL) {
00360 if (P_ctxt != NULL) {
00361 if ((L_callCtx = dynamic_cast<C_CallContext*>(P_ctxt)) != NULL) {
00362 ALLOC_VAR(m_session_id, T_pValueData, sizeof(T_ValueData));
00363 m_session_id->m_type = E_TYPE_NUMBER ;
00364 m_session_id->m_value.m_val_number = L_callCtx->m_channel_table[L_callCtx->m_channel_received] ;
00365 m_session_id->m_id = m_session_id_id ;
00366
00367 } else if ((L_recvCtx = dynamic_cast<T_pReceiveMsgContext>(P_ctxt)) != NULL) {
00368 ALLOC_VAR(m_session_id, T_pValueData, sizeof(T_ValueData));
00369 m_session_id->m_type = E_TYPE_NUMBER ;
00370 m_session_id->m_value.m_val_number = L_recvCtx->m_response ;
00371 m_session_id->m_id = m_session_id_id ;
00372 }
00373 }
00374 }
00375
00376 GEN_DEBUG(1, "C_MessageText::getSessionFromOpenId() end");
00377 return (m_session_id);
00378 }
00379
00380 T_pValueData C_MessageText::getSessionFromField (C_ContextFrame *P_ctxt) {
00381
00382
00383 int L_i ;
00384 C_ProtocolText::T_pManagementSessionTextId L_session_elt ;
00385 int L_nb_manag_session ;
00386 char *L_value = NULL ;
00387 int L_result = 0 ;
00388
00389
00390 GEN_DEBUG(1, "C_MessageText::getSessionFromField() start");
00391
00392 if (m_session_id == NULL) {
00393
00394
00395 L_nb_manag_session = m_protocol->get_nb_management_session () ;
00396
00397 for (L_i = 0 ; L_i < L_nb_manag_session ; L_i++) {
00398 L_session_elt = m_protocol->get_manage_session_elt(L_i);
00399 L_value = m_protocol->get_field_value (this , L_session_elt->m_msg_id_id) ;
00400 if (L_value != NULL) {
00401 ALLOC_VAR(m_session_id, T_pValueData, sizeof(T_ValueData));
00402 *m_session_id = valueFromString(L_value, E_TYPE_STRING , L_result);
00403 if (L_result == -1) {
00404 FREE_VAR(m_session_id);
00405 }
00406 }
00407 FREE_TABLE(L_value);
00408
00409 if (m_session_id != NULL) {
00410 break;
00411 }
00412 }
00413 }
00414
00415 GEN_DEBUG(1, "C_MessageText::getSessionFromField() end");
00416
00417 return (m_session_id) ;
00418 }
00419
00420 T_pValueData C_MessageText::get_session_id (C_ContextFrame *P_ctxt) {
00421 return (((this)->*(m_session_method))(P_ctxt)) ;
00422 }
00423
00424
00425 T_pValueData C_MessageText::get_out_of_session_id () {
00426 return (NULL);
00427 }
00428
00429 bool C_MessageText::update_fields (C_MessageFrame* P_msg) {
00430 return (true) ;
00431 }
00432
00433 bool C_MessageText::compare_types (C_MessageFrame* P_msg) {
00434
00435 bool L_result ;
00436 C_MessageText *L_msg ;
00437
00438 GEN_DEBUG(1, "C_MessageText::compare_types() start");
00439
00440 L_msg = dynamic_cast<C_MessageText*>(P_msg) ;
00441
00442 L_result = (L_msg == NULL) ? false : (L_msg->m_id == m_id) ;
00443
00444 GEN_DEBUG(1, "C_MessageText::compare_types() end");
00445
00446
00447 return (L_result);
00448 }
00449
00450
00451 bool C_MessageText::check(C_MessageFrame *P_ref,
00452 unsigned int P_levelMask,
00453 T_CheckBehaviour P_behave) {
00454
00455 bool L_ret = true ;
00456
00457 GEN_DEBUG(1, "C_MessageText::check() start");
00458
00459 GEN_DEBUG(1, "C_MessageText::check() end");
00460
00461 return (L_ret);
00462 }
00463
00464
00465 bool C_MessageText::check_field_presence (int P_id,
00466 T_CheckBehaviour P_behave,
00467 int P_instance,
00468 int P_sub_id) {
00469 bool L_ret = true ;
00470 char *L_value = NULL ;
00471
00472 GEN_DEBUG(1, "C_MessageText::check_field_presence() start");
00473 L_value = m_protocol->get_field_value(this,P_id) ;
00474 if (L_value) {
00475 FREE_TABLE(L_value);
00476 } else {
00477 GEN_LOG_EVENT (_check_behaviour_mask[P_behave],
00478 "check failed in ["
00479 << m_protocol->message_name (m_id)
00480 << "] " << m_protocol->message_name()
00481 << ", the field ["
00482 << m_names_fields[P_id]
00483 << "] is not found");
00484
00485 L_ret = false ;
00486 }
00487 GEN_DEBUG(1, "C_MessageText::check_field_presence() end");
00488
00489 return (L_ret);
00490 }
00491
00492 bool C_MessageText::check_field_value (C_MessageFrame *P_ref,
00493 int P_id,
00494 T_CheckBehaviour P_behave,
00495 int P_instance,
00496 int P_sub_id) {
00497
00498 bool L_ret = true ;
00499 char *L_value = NULL ;
00500 int L_size = -1 ;
00501
00502 C_MessageText *L_ref ;
00503 char *L_value_ref = NULL ;
00504 int L_size_ref = -1 ;
00505
00506
00507 GEN_DEBUG(1, "C_MessageText::check_field_value() start");
00508
00509 L_ref = dynamic_cast<C_MessageText*>(P_ref);
00510
00511 L_value_ref = m_protocol->get_field_value_to_check(L_ref,P_id, &L_size_ref) ;
00512
00513 if (L_value_ref) {
00514 L_value = m_protocol->get_field_value_to_check(this,P_id, &L_size) ;
00515 if (L_value) {
00516 if (L_size != L_size_ref) {
00517 GEN_LOG_EVENT (_check_behaviour_mask[P_behave],
00518 "check failed in ["
00519 << m_protocol->message_name (m_id)
00520 << "] " << m_protocol->message_name()
00521 << ", the value of field ["
00522 << m_names_fields[P_id]
00523 << "] is incorrect");
00524 L_ret = false ;
00525 } else {
00526 if (memcmp(L_value_ref, L_value, L_size) != 0 ){
00527 GEN_LOG_EVENT (_check_behaviour_mask[P_behave],
00528 "check failed in ["
00529 << m_protocol->message_name (m_id)
00530 << "] " << m_protocol->message_name()
00531 << ", the value of field ["
00532 << m_names_fields[P_id]
00533 << "] is incorrect");
00534 L_ret = false ;
00535 }
00536 }
00537 FREE_TABLE(L_value);
00538 } else {
00539 GEN_LOG_EVENT (_check_behaviour_mask[P_behave],
00540 "check failed in ["
00541 << m_protocol->message_name (m_id)
00542 << "] " << m_protocol->message_name()
00543 << " received, the value of field ["
00544 << m_names_fields[P_id]
00545 << "] is incorrect");
00546 L_ret = false ;
00547 }
00548 FREE_TABLE(L_value_ref);
00549 } else {
00550 GEN_LOG_EVENT (_check_behaviour_mask[P_behave],
00551 "check failed in ["
00552 << m_protocol->message_name (m_id)
00553 << "] " << m_protocol->message_name()
00554 << " reference, the value of field ["
00555 << m_names_fields[P_id]
00556 << "] is incorrect");
00557 L_ret = false ;
00558
00559 }
00560 GEN_DEBUG(1, "C_MessageText::check_field_value() end");
00561 return (L_ret);
00562
00563 }
00564
00565
00566 bool C_MessageText::check_field_order (int P_id,
00567 T_CheckBehaviour P_behave,
00568 int P_position) {
00569 bool L_ret = true ;
00570 GEN_DEBUG(1, "C_MessageText::check_field_order() start");
00571
00572 GEN_DEBUG(1, "C_MessageText::check_field_order() end");
00573 return (L_ret);
00574 }
00575
00576 bool C_MessageText::get_field_value(int P_id,
00577 C_RegExp *P_reg,
00578 T_pValueData P_value) {
00579
00580
00581 bool L_found = true ;
00582 T_ValueData L_value ;
00583 char *L_buffer = NULL ;
00584 int L_result = 0 ;
00585
00586
00587 L_buffer = m_protocol->get_field_value(this, P_id, P_reg);
00588
00589 if (L_buffer != NULL) {
00590 L_value = valueFromString(L_buffer, E_TYPE_STRING, L_result);
00591 FREE_TABLE(L_buffer);
00592 if (L_result == -1) {
00593 L_found = false ;
00594 } else {
00595 L_value.m_id = P_id;
00596 (*P_value) = L_value ;
00597 }
00598 } else {
00599 L_found = false ;
00600 }
00601
00602
00603 GEN_DEBUG(1, "C_MessageText::get_field_value() end");
00604
00605 return (L_found);
00606 }
00607
00608 bool C_MessageText::get_field_value(int P_id,
00609 int P_instance,
00610 int P_sub_id,
00611 T_pValueData P_value) {
00612
00613 bool L_found = true ;
00614 T_ValueData L_value ;
00615 char *L_buffer = NULL ;
00616 int L_result = 0 ;
00617
00618 GEN_DEBUG(1, "C_MessageText::get_field_value() start");
00619
00620
00621 L_buffer = m_protocol->get_field_value(this, P_id);
00622
00623 if (L_buffer != NULL) {
00624 L_value = valueFromString(L_buffer, E_TYPE_STRING, L_result);
00625 FREE_TABLE(L_buffer);
00626 if (L_result == -1) {
00627 L_found = false ;
00628 } else {
00629 L_value.m_id = P_id;
00630 (*P_value) = L_value ;
00631 }
00632 } else {
00633 L_found = false ;
00634 }
00635
00636 GEN_DEBUG(1, "C_MessageText::get_field_value() end");
00637
00638 return (L_found);
00639 }
00640
00641
00642 bool C_MessageText::set_field_value(T_pValueData P_value,
00643 int P_id,
00644 int P_instance,
00645 int P_sub_id) {
00646
00647 bool L_found = true ;
00648
00649 GEN_DEBUG(1, "C_MessageText::set_field_value() start");
00650
00651
00652 L_found = (m_protocol->set_field_value(this, P_id, P_value) == 0) ? true : false ;
00653
00654 GEN_DEBUG(1, "C_MessageText::set_field_value() end");
00655
00656 return (L_found);
00657 }
00658
00659 T_TypeType C_MessageText::get_field_type (int P_id,
00660 int P_sub_id) {
00661 return (m_protocol->get_field_type(P_id,P_sub_id));
00662 }
00663
00664
00665 void C_MessageText::dump(iostream_output& P_stream) {
00666 GEN_DEBUG(1, "C_MessageText::dump() start");
00667
00668 P_stream << *this << iostream_endl ;
00669
00670 GEN_DEBUG(1, "C_MessageText::dump() end");
00671 }
00672
00673
00674 iostream_output& operator<< (iostream_output& P_stream,
00675 C_MessageText& P_msg) {
00676
00677 P_stream << "[" ;
00678 if (P_msg.m_header) {
00679 if (P_msg.m_id != -1) {
00680 P_msg.m_protocol->print_header_msg(P_stream,
00681 P_msg.m_id,
00682 P_msg.m_header);
00683 if (P_msg.m_body) {
00684 P_msg.m_protocol->print_data_msg(P_stream,
00685 P_msg.m_body);
00686 }
00687 } else {
00688 P_stream << "Unknown text message" << iostream_endl ;
00689 }
00690 }
00691
00692
00693 P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) << "]" ;
00694
00695 return (P_stream) ;
00696 }
00697
00698 char* C_MessageText::name() {
00699 return( m_protocol->message_name(m_id));
00700 }
00701
00702 int C_MessageText::get_id_message(){
00703 return (m_id) ;
00704 }
00705
00706 void C_MessageText::set_id_message(int P_id){
00707 m_id = P_id ;
00708 }
00709
00710 C_ProtocolFrame::T_MsgError C_MessageText::encode(unsigned char *P_buf,
00711 size_t *P_siz) {
00712
00713 GEN_DEBUG(1, "C_MessageText::encode() start");
00714
00715 C_ProtocolFrame::T_MsgError L_error = C_ProtocolFrame::E_MSG_OK ;
00716 size_t L_pos = 0 ;
00717
00718 unsigned char *L_buf = P_buf ;
00719
00720 int L_index = 0 ;
00721
00722
00723 while (L_index < m_nb_methods) {
00724 L_error = ((this)->*(m_methods[L_index]->m_encode))(L_index);
00725 if (L_error == C_ProtocolFrame::E_MSG_OK) break ;
00726 L_index ++ ;
00727 }
00728
00729
00730 if (L_error != C_ProtocolFrame::E_MSG_OK) return (L_error);
00731
00732 L_pos += m_header->m_value.m_val_binary.m_size ;
00733
00734
00735 if (L_pos <= (*P_siz)) {
00736 memcpy(L_buf,
00737 m_header->m_value.m_val_binary.m_value,
00738 m_header->m_value.m_val_binary.m_size);
00739 L_buf += m_header->m_value.m_val_binary.m_size ;
00740 L_pos += m_body_separator_size ;
00741 if (L_pos <= (*P_siz)) {
00742 memcpy(L_buf,
00743 m_body_separator,
00744 m_body_separator_size);
00745 L_buf += m_body_separator_size ;
00746
00747 if (m_body != NULL) {
00748 L_pos += m_body->m_value.m_val_binary.m_size ;
00749 if (L_pos <= (*P_siz)) {
00750 memcpy(L_buf,
00751 m_body->m_value.m_val_binary.m_value,
00752 m_body->m_value.m_val_binary.m_size);
00753 *P_siz = L_pos ;
00754 } else {
00755 L_error = C_ProtocolTextFrame::E_MSG_ERROR_ENCODING ;
00756 }
00757 } else {
00758 *P_siz = L_pos ;
00759 }
00760 } else {
00761 L_error = C_ProtocolTextFrame::E_MSG_ERROR_ENCODING ;
00762 }
00763 } else {
00764 L_error = C_ProtocolTextFrame::E_MSG_ERROR_ENCODING ;
00765 }
00766
00767 GEN_DEBUG(1, "C_MessageText::encode() end");
00768 return (L_error);
00769
00770 }
00771
00772 unsigned long C_MessageText::decode(unsigned char *P_buf,
00773 size_t P_siz,
00774 C_ProtocolFrame::T_pMsgError P_error) {
00775
00776 GEN_DEBUG(1, "C_MessageText::decode() start");
00777
00778 char *L_ptr = NULL ;
00779 unsigned char *L_buf = NULL ;
00780
00781 unsigned long L_header_size_decoded = 0 ;
00782
00783 char *L_message_type = NULL ;
00784 size_t L_remaining = P_siz ;
00785 char L_char ;
00786 int L_index = 0 ;
00787
00788 unsigned char *L_wbuf = NULL ;
00789
00790 *P_error = C_ProtocolFrame::E_MSG_OK ;
00791
00792 if (memcmp((P_buf + (P_siz - m_body_separator_size)),
00793 m_body_separator,
00794 m_body_separator_size) == 0) {
00795
00796 ALLOC_TABLE(L_buf, unsigned char*, sizeof(unsigned char), P_siz +1);
00797 memcpy(L_buf, P_buf, P_siz);
00798 L_buf[P_siz] = 0 ;
00799 } else {
00800 L_char = P_buf[(P_siz-1)] ;
00801 P_buf[(P_siz-1)] = 0 ;
00802 }
00803
00804
00805 L_wbuf = (L_buf == NULL) ? P_buf : L_buf ;
00806
00807
00808 L_ptr = strstr((char*)L_wbuf, m_field_body_separator);
00809
00810 if (L_ptr != NULL) {
00811
00812 ALLOC_VAR(m_header, T_pValueData, sizeof(T_ValueData));
00813 m_header->m_type = E_TYPE_STRING;
00814 L_header_size_decoded = ((unsigned char*)L_ptr - L_wbuf) ;
00815
00816
00817 L_header_size_decoded += m_field_separator_size ;
00818
00819 m_header->m_value.m_val_binary.m_size = L_header_size_decoded ;
00820 ALLOC_TABLE(m_header->m_value.m_val_binary.m_value,
00821 unsigned char*,
00822 sizeof(unsigned char),
00823 m_header->m_value.m_val_binary.m_size);
00824
00825 memcpy(m_header->m_value.m_val_binary.m_value,
00826 L_wbuf,
00827 m_header->m_value.m_val_binary.m_size);
00828
00829 L_remaining -= L_header_size_decoded ;
00830 L_remaining -= m_body_separator_size ;
00831
00832
00833
00834
00835 L_ptr += m_field_body_separator_size ;
00836
00837 if (!L_buf) { P_buf[(P_siz-1)] = L_char ; }
00838
00839 while (L_index < m_nb_methods) {
00840 (*P_error) = ((this)->*((m_methods[L_index])->m_decode))(L_index, L_ptr, &L_remaining) ;
00841 if ((*P_error) == C_ProtocolFrame::E_MSG_OK) break ;
00842 L_index ++ ;
00843 }
00844
00845 switch (*P_error) {
00846 case C_ProtocolFrame::E_MSG_OK:
00847 L_message_type
00848 = m_protocol->get_field_value(this, m_message_type_field_id);
00849 if (L_message_type == NULL) {
00850
00851 *P_error = C_ProtocolFrame::E_MSG_ERROR_DECODING_SIZE_LESS ;
00852 m_id = -1 ;
00853 } else {
00854
00855 m_id = m_protocol->get_message_id(L_message_type);
00856 }
00857 FREE_TABLE(L_message_type);
00858 break ;
00859 case C_ProtocolFrame::E_MSG_ERROR_DECODING:
00860 break ;
00861 case C_ProtocolFrame::E_MSG_ERROR_DECODING_SIZE_LESS:
00862 L_remaining += L_header_size_decoded ;
00863 L_remaining += m_body_separator_size ;
00864 break ;
00865 default:
00866 break ;
00867 }
00868
00869 } else {
00870 *P_error = C_ProtocolFrame::E_MSG_ERROR_DECODING_SIZE_LESS ;
00871 if (!L_buf) { P_buf[(P_siz-1)] = L_char ; }
00872 }
00873
00874
00875 if (L_buf) {
00876 FREE_TABLE(L_buf);
00877 }
00878
00879 GEN_DEBUG(1, "C_MessageText::decode() with " << L_remaining);
00880
00881 return (L_remaining) ;
00882 }
00883
00884 void C_MessageText::update_message_stats () {
00885 }
00886
00887 int C_MessageText::get_buffer (T_pValueData P_dest ,
00888 T_MessagePartType P_header_body_type) {
00889
00890 int L_ret = 0 ;
00891
00892 switch (P_header_body_type) {
00893 case E_HEADER_TYPE :
00894 copyValue(*P_dest, *m_header, false);
00895 break;
00896 case E_BODY_TYPE :
00897 copyValue(*P_dest, *m_body, false);
00898 break;
00899 case E_ALL_TYPE :
00900 default:
00901 L_ret = -1 ;
00902 break ;
00903 }
00904 return (L_ret) ;
00905 }