From: <aa...@us...> - 2007-03-20 12:33:26
|
Revision: 213 http://svn.sourceforge.net/gull/?rev=213&view=rev Author: aajjan Date: 2007-03-20 04:59:31 -0700 (Tue, 20 Mar 2007) Log Message: ----------- - Add Seagull multi-channel and correlation features - Extend setfield feature in binary protocol: accept all type of field in dictionary except grouped type Modified Paths: -------------- seagull/trunk/src/protocol-binary/C_MessageBinary.cpp seagull/trunk/src/protocol-binary/C_MessageBinary.hpp seagull/trunk/src/protocol-binary/C_ProtocolBinary.cpp seagull/trunk/src/protocol-binary/C_ProtocolBinary.hpp Modified: seagull/trunk/src/protocol-binary/C_MessageBinary.cpp =================================================================== --- seagull/trunk/src/protocol-binary/C_MessageBinary.cpp 2007-03-20 10:51:48 UTC (rev 212) +++ seagull/trunk/src/protocol-binary/C_MessageBinary.cpp 2007-03-20 11:59:31 UTC (rev 213) @@ -66,7 +66,7 @@ m_header_body_field_separator = m_protocol->get_header_body_field_separator () ; - + m_session_id = NULL ; GEN_DEBUG(1, "C_MessageBinary::C_MessageBinary() end"); } @@ -155,6 +155,15 @@ m_header_body_field_separator = NULL ; m_protocol = NULL ; + if (m_session_id != NULL) { + if ((m_session_id->m_type == E_TYPE_STRING) + && (m_session_id->m_value.m_val_binary.m_size> 0)) { + FREE_TABLE(m_session_id->m_value.m_val_binary.m_value); + m_session_id->m_value.m_val_binary.m_size = 0 ; + } + FREE_VAR(m_session_id) ; + } + GEN_DEBUG(1, "C_MessageBinary::~C_MessageBinary() end"); } @@ -464,18 +473,18 @@ return (*this) ; } + void C_MessageBinary::get_header_value (T_pValueData P_res, - int P_id) { + int P_id) { *P_res = m_header_values[P_id] ; } -void C_MessageBinary::get_body_value (T_pValueData P_res, - int P_id) { - +bool C_MessageBinary::get_body_value (T_pValueData P_res, + int P_id) { + int L_i ; bool L_found = false ; - // Search the body value in the array for (L_i=0 ; L_i < m_nb_body_values ; L_i++) { if (m_body_val[L_i].m_id == P_id) { @@ -486,6 +495,8 @@ if (L_found == true) { m_protocol->get_body_value(P_res, &m_body_val[L_i]) ; } + + return (L_found) ; } bool C_MessageBinary::set_body_value (int P_id, T_pValueData P_val) { @@ -804,8 +815,8 @@ T_ValueData L_value_ref ; T_ValueData L_value ; + bool L_found = true ; - C_ProtocolBinary::T_pHeaderBodyValue L_descr ; C_ProtocolBinary::T_pHeaderField L_headerField ; @@ -816,8 +827,38 @@ if (L_id >= (int) L_max_nb_field_header) { // case body L_id -= L_max_nb_field_header ; - L_ref->get_body_value (&L_value_ref, L_id); - get_body_value (&L_value, L_id); + + L_found = L_ref->get_body_value (&L_value_ref, L_id); + if (L_found == false ) { + L_descr = m_protocol->get_header_body_value_description(L_id); + if (L_descr != NULL) { + GEN_LOG_EVENT (_check_behaviour_mask[P_behave], + "check failed in [" + << m_protocol->message_name(L_ref->m_header_id) + << "] " << m_protocol->message_name() + << ", value of " << m_protocol->message_component_name () + << " [" + << L_descr->m_name + << "] is not present in this in reference message"); + } + return (L_found); + } + L_found = get_body_value (&L_value, L_id); + if (L_found == false ) { + L_descr = m_protocol->get_header_body_value_description(L_id); + if (L_descr != NULL) { + GEN_LOG_EVENT (_check_behaviour_mask[P_behave], + "check failed in [" + << m_protocol->message_name(L_ref->m_header_id) + << "] " << m_protocol->message_name() + << ", value of " << m_protocol->message_component_name () + << " [" + << L_descr->m_name + << "] is not present in message received"); + } + return (L_found); + } + L_check = (L_value_ref == L_value) ; } else { // case header @@ -909,6 +950,26 @@ return (L_found) ; } +T_pValueData C_MessageBinary::get_field_value (int P_id, + int P_instance, + int P_sub_id) { + + if (m_session_id == NULL) { + + ALLOC_VAR(m_session_id, + T_pValueData, + sizeof(T_ValueData)); + + if (get_field_value(P_id, + P_instance, + P_sub_id, + m_session_id) == false ) { + FREE_VAR(m_session_id); + } + } + return (m_session_id); +} + bool C_MessageBinary::get_field_value(int P_id, int P_instance, int P_sub_id, @@ -926,10 +987,10 @@ get_header_value (P_value, L_id); break ; case C_ProtocolBinary::E_MSG_ID_BODY: - get_body_value (P_value, L_id); + L_found = get_body_value (P_value, L_id); break ; } - + GEN_DEBUG(1 , "C_MessageBinary::get_field_value() end ret = " << L_found); return (L_found); } @@ -948,8 +1009,6 @@ } char* C_MessageBinary::name() { -// GEN_DEBUG(1, "C_MessageBinary::name() name:[" -// << m_protocol -> message_name(m_header_id) << "]"); return( m_protocol -> message_name(m_header_id)); } Modified: seagull/trunk/src/protocol-binary/C_MessageBinary.hpp =================================================================== --- seagull/trunk/src/protocol-binary/C_MessageBinary.hpp 2007-03-20 10:51:48 UTC (rev 212) +++ seagull/trunk/src/protocol-binary/C_MessageBinary.hpp 2007-03-20 11:59:31 UTC (rev 213) @@ -100,7 +100,13 @@ void set_body_value (C_ProtocolBinary::T_pBodyValue P_val); void get_header_value (T_pValueData P_res, int P_id); - virtual void get_body_value (T_pValueData P_res, int P_id); + + T_pValueData get_field_value (int P_id, + int P_instance, + int P_sub_id) ; + + // virtual void get_body_value (T_pValueData P_res, int P_id); + virtual bool get_body_value (T_pValueData P_res, int P_id); virtual bool set_body_value (int P_id, T_pValueData P_val); C_MessageBinary& operator= (C_MessageBinary & P_val); @@ -147,6 +153,7 @@ T_pValueData m_header_values ; char *m_header_body_field_separator ; + T_pValueData m_session_id ; // temporary // linked with protocol Modified: seagull/trunk/src/protocol-binary/C_ProtocolBinary.cpp =================================================================== --- seagull/trunk/src/protocol-binary/C_ProtocolBinary.cpp 2007-03-20 10:51:48 UTC (rev 212) +++ seagull/trunk/src/protocol-binary/C_ProtocolBinary.cpp 2007-03-20 11:59:31 UTC (rev 213) @@ -5049,14 +5049,15 @@ } // end to else not grouped } else if (strcmp(L_bodyData->get_name(), (char*)"setfield")==0) { - unsigned long L_val_setfield = 0 ; - int L_id_setfield = 0 ; - L_msgOk = (analyze_setfield(L_bodyData, &L_id_setfield ,&L_val_setfield) == -1) + T_ValueData L_val_setfield ; + L_val_setfield.m_type = E_TYPE_NUMBER ; + + L_msgOk = (analyze_setfield(L_bodyData, &L_val_setfield) == -1) ? false : true ; if (L_msgOk) { - L_msg->set_header_value(L_id_setfield, L_val_setfield); + L_msg->set_header_value((int)L_val_setfield.m_id, &L_val_setfield); + resetMemory(L_val_setfield); } - } else { GEN_ERROR(E_GEN_FATAL_ERROR, "Unkown section [" @@ -5550,8 +5551,7 @@ } int C_ProtocolBinary::analyze_setfield(C_XmlData *P_data, - int *P_fieldId, - unsigned long *P_fieldValueUl) { + T_pValueData P_res) { int L_ret = 0 ; C_XmlData *L_data ; @@ -5559,9 +5559,10 @@ char *L_fieldValue ; T_IdMap::iterator L_IdMapIt ; char *L_endstr ; - - unsigned long L_fieldValueUl ; int L_fieldId ; + int L_type_id ; + T_pHeaderField L_fieldVal ; + T_TypeType L_type ; L_data = P_data ; @@ -5575,34 +5576,201 @@ L_IdMapIt = m_header_id_map->find(T_IdMap::key_type(L_fieldName)); - if (L_IdMapIt != m_header_id_map->end()) { L_fieldId = L_IdMapIt->second ; - (*P_fieldId) = L_fieldId ; } else { GEN_ERROR(E_GEN_FATAL_ERROR, "Field [" << L_fieldName << "] not defined"); L_ret = -1 ; } + + if (L_ret != -1) { + L_fieldVal = &(m_header_field_table[L_fieldId]); + L_type_id = L_fieldVal->m_type_id ; + if (L_type_id == - 1) { + L_type = E_TYPE_NUMBER; + } else { + L_type = m_type_def_table[L_type_id].m_type ; + } - L_fieldValue = L_data->find_value((char*)"value") ; - if (L_fieldValue == NULL) { - GEN_ERROR(E_GEN_FATAL_ERROR, "setfield value is mandatory"); - L_ret = -1 ; - } - - L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,10) ; - - if (L_endstr[0] != '\0') { - L_fieldValueUl = strtoul_f (L_fieldValue, &L_endstr,16) ; - if (L_endstr[0] != '\0') { - GEN_ERROR(E_GEN_FATAL_ERROR, "typedef size value [" - << L_fieldValue << "] bad format"); + L_fieldValue = L_data->find_value((char*)"value") ; + if (L_fieldValue == NULL) { + GEN_ERROR(E_GEN_FATAL_ERROR, "setfield value is mandatory"); L_ret = -1 ; - } else { - (*P_fieldValueUl) = L_fieldValueUl ; } + + if (L_ret != -1) { + P_res->m_id = L_fieldId ; + P_res->m_type = L_type ; + + switch (L_type) { + case E_TYPE_NUMBER: + if ((strlen(L_fieldValue)>2) && + (L_fieldValue[0] == '0') && + (L_fieldValue[1] == 'x')) { // hexa buffer value + P_res->m_value.m_val_number = strtoul_f(L_fieldValue, &L_endstr, 16) ; + } else { + P_res->m_value.m_val_number = strtoul_f(L_fieldValue, &L_endstr, 10) ; + } + if (L_endstr[0] != '\0') { + GEN_ERROR(E_GEN_FATAL_ERROR, + "Incorrect value format for [" + << L_fieldValue << "] - Unsigned Integer expected"); + L_ret = -1 ; + } + break ; + + case E_TYPE_SIGNED: { + if ((strlen(L_fieldValue)>2) && + (L_fieldValue[0] == '0') && + (L_fieldValue[1] == 'x')) { // hexa buffer value + P_res->m_value.m_val_signed = strtol_f(L_fieldValue, &L_endstr, 16) ; + } else { + P_res->m_value.m_val_signed = strtol_f(L_fieldValue, &L_endstr, 10) ; + } + + if (L_endstr[0] != '\0') { + GEN_ERROR(E_GEN_FATAL_ERROR, + "Incorrect value format for [" + << L_fieldValue << "] - Integer expected"); + L_ret = -1 ; + } + } + + break ; + + case E_TYPE_STRING: { + if ((strlen(L_fieldValue)>2) && + (L_fieldValue[0] == '0') && + (L_fieldValue[1] == 'x')) { // hexa buffer value + char *L_ptr = L_fieldValue+2 ; + size_t L_res_size ; + P_res->m_value.m_val_binary.m_value + = convert_hexa_char_to_bin(L_ptr, &L_res_size); + + if (P_res->m_value.m_val_binary.m_value == NULL) { + GEN_ERROR(E_GEN_FATAL_ERROR, + "Bad buffer size for hexadecimal buffer [" + << L_fieldValue << "]"); + L_ret = -1 ; + } else { + P_res->m_value.m_val_binary.m_size= L_res_size ; + } + + } else { // direct string value + P_res->m_value.m_val_binary.m_value=(unsigned char*)L_fieldValue; + P_res->m_value.m_val_binary.m_size=strlen(L_fieldValue); + } + } + + break ; + + case E_TYPE_STRUCT : { + + int L_i = 0 ; + int L_size = (L_fieldValue == NULL ) ? 0 : strlen(L_fieldValue) ; + char *L_value1, *L_value2, *L_value3 ; + L_value1 = NULL ; + L_value2 = NULL ; + L_value3 = NULL ; + while (L_i< L_size) { + if ( L_fieldValue[L_i]== ';') { + L_fieldValue[L_i] = 0 ; + L_value3= &L_fieldValue[L_i]; + L_value1= L_fieldValue ; + if (L_i+1 < L_size ) { + L_value2 = &L_fieldValue[L_i+1]; + } + } + L_i ++; + } + + if ( L_value1 != NULL ) { + if ((strlen(L_value1)>2) && + (L_value1[0] == '0') && + (L_value1[1] == 'x')) { // hexa buffer value + P_res->m_value.m_val_struct.m_id_1 = strtoul_f(L_value1, &L_endstr, 16) ; + } else { + P_res->m_value.m_val_struct.m_id_1 = strtoul_f(L_value1, &L_endstr, 10) ; + } + if (L_endstr[0] != '\0') { + GEN_ERROR(E_GEN_FATAL_ERROR, + "Incorrect value format for [" + << L_value1 << "] - Unsigned Integer expected"); + L_ret = -1 ; + } + + if ( (L_value2 != NULL) && + (L_ret != -1 )) { + if ((strlen(L_value2)>2) && + (L_value2[0] == '0') && + (L_value2[1] == 'x')) { // hexa buffer value + P_res->m_value.m_val_struct.m_id_2 = strtoul_f(L_value2, &L_endstr, 16) ; + } else { + P_res->m_value.m_val_struct.m_id_2 = strtoul_f(L_value2, &L_endstr, 10) ; + } + if (L_endstr[0] != '\0') { + GEN_ERROR(E_GEN_FATAL_ERROR, + "Incorrect value format for [" + << L_value2 << "] - Unsigned Integer expected"); + L_ret = -1 ; + } + + } + if (L_ret != -1) *L_value3 = ';' ; + } else { + char * L_value = (L_fieldValue == NULL) ? (char *)"not set" : L_fieldValue ; + GEN_ERROR(E_GEN_FATAL_ERROR, + "Incorrect value format for [" + << L_value << "] - struct expected"); + L_ret = -1 ; + } + } + + break ; + + case E_TYPE_NUMBER_64: { + if ((strlen(L_fieldValue)>2) && + (L_fieldValue[0] == '0') && + (L_fieldValue[1] == 'x')) { // hexa buffer value + P_res->m_value.m_val_number_64 = strtoull_f(L_fieldValue, &L_endstr, 16) ; + } else { + P_res->m_value.m_val_number_64 = strtoull_f(L_fieldValue, &L_endstr, 10) ; + } + if (L_endstr[0] != '\0') { + GEN_ERROR(E_GEN_FATAL_ERROR, + "Incorrect value format for [" + << L_fieldValue << "] - Unsigned Integer64 expected"); + L_ret = -1 ; + } + } + break ; + + case E_TYPE_SIGNED_64: { + if ((strlen(L_fieldValue)>2) && + (L_fieldValue[0] == '0') && + (L_fieldValue[1] == 'x')) { // hexa buffer value + P_res->m_value.m_val_signed_64 = strtoll_f(L_fieldValue, &L_endstr, 16) ; + } else { + P_res->m_value.m_val_signed_64 = strtoll_f(L_fieldValue, &L_endstr, 10) ; + } + + if (L_endstr[0] != '\0') { + GEN_ERROR(E_GEN_FATAL_ERROR, + "Incorrect value format for [" + << L_fieldValue << "] - Integer64 expected"); + L_ret = -1 ; + } + } + break ; + + default: + GEN_FATAL(E_GEN_FATAL_ERROR, "Type value not implemented"); + L_ret = -1 ; + break ; + } // switch + } } return (L_ret) ; Modified: seagull/trunk/src/protocol-binary/C_ProtocolBinary.hpp =================================================================== --- seagull/trunk/src/protocol-binary/C_ProtocolBinary.hpp 2007-03-20 10:51:48 UTC (rev 212) +++ seagull/trunk/src/protocol-binary/C_ProtocolBinary.hpp 2007-03-20 11:59:31 UTC (rev 213) @@ -277,12 +277,11 @@ char* get_header_body_field_separator(); + int analyze_setfield(C_XmlData *P_data, - int *P_fieldId, - unsigned long *P_fieldValueUl) ; + T_pValueData P_value_field); - protected: // header definition variables This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |