// This C++ source file was generated by the TTCN-3 compiler // of the TTCN-3 Test Executor version 9.0.0 // The generation of user and time information were disabled by the -D flag. // Copyright (c) 2000-2023 Ericsson Telecom AB // Do not edit this file unless you know what you are doing. /* Including header files */ #include "RSRES.hh" namespace RSRES { /* Literal string constants */ const unsigned char module_checksum[] = { 0xab, 0x82, 0x88, 0xf0, 0x4e, 0x83, 0xf8, 0x8c, 0x26, 0xd2, 0x72, 0xfd, 0xc8, 0xeb, 0xd0, 0xb4 }; /* Global variable definitions */ // No XER for ConnectionState const TTCN_JSONdescriptor_t ConnectionState_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t ConnectionState_descr_ = { "@RSRES.ConnectionState", NULL, NULL, NULL, NULL, &ConnectionState_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING ConnectionState_default_coding("JSON"); const XERdescriptor_t JsBank_peer_xer_ = { {"peer>\n", "peer>\n"}, {6, 6}, 0 |FORM_UNQUALIFIED, WHITESPACE_PRESERVE, NULL, &module_object, -1, 0, NULL, NULL, -1, XSD_NONE }; const TTCN_Typedescriptor_t JsBank_peer_descr_ = { "@RSRES.JsBank.peer", NULL, &CHARSTRING_raw_, &CHARSTRING_text_, &JsBank_peer_xer_, &CHARSTRING_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsBank_peer_default_coding("JSON"); // No XER for JsBank_state const TTCN_Typedescriptor_t JsBank_state_descr_ = { "@RSRES.JsBank.state", NULL, NULL, NULL, NULL, &ConnectionState_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsBank_state_default_coding("JSON"); // No XER for JsBank_component__id const int JsBank_component__id_oer_ext_arr_[0] = {}; const int JsBank_component__id_oer_p_[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; const TTCN_OERdescriptor_t JsBank_component__id_oer_ = { -1, TRUE, -1, TRUE, 9, 0, JsBank_component__id_oer_ext_arr_, 9, JsBank_component__id_oer_p_}; const ASN_PERdescriptor_t JsBank_component__id_per_ = { &JsBank_component__id_per_cons_ }; const TTCN_Typedescriptor_t JsBank_component__id_descr_ = { "@RSRES.JsBank.component_id", &SEQUENCE_ber_, NULL, NULL, NULL, &RSPRO::ComponentIdentity_json_, &JsBank_component__id_oer_, &JsBank_component__id_per_, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsBank_component__id_default_coding(""); // No XER for JsBank_bankId const int JsBank_bankId_oer_ext_arr_[0] = {}; const int JsBank_bankId_oer_p_[0] = {}; const TTCN_OERdescriptor_t JsBank_bankId_oer_ = { 2, FALSE, -1, FALSE, 0, 0, JsBank_bankId_oer_ext_arr_, 0, JsBank_bankId_oer_p_}; static PerIntegerConstraint JsBank_bankId_per_cons_(new INTEGER(0), new INTEGER(1023), FALSE); const ASN_PERdescriptor_t JsBank_bankId_per_ = { &JsBank_bankId_per_cons_ }; const TTCN_Typedescriptor_t JsBank_bankId_descr_ = { "@RSRES.JsBank.bankId", &INTEGER_ber_, NULL, NULL, NULL, &INTEGER_json_, &JsBank_bankId_oer_, &JsBank_bankId_per_, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsBank_bankId_default_coding(""); // No XER for JsBank_numberOfSlots const int JsBank_numberOfSlots_oer_ext_arr_[0] = {}; const int JsBank_numberOfSlots_oer_p_[0] = {}; const TTCN_OERdescriptor_t JsBank_numberOfSlots_oer_ = { 2, FALSE, -1, FALSE, 0, 0, JsBank_numberOfSlots_oer_ext_arr_, 0, JsBank_numberOfSlots_oer_p_}; static PerIntegerConstraint JsBank_numberOfSlots_per_cons_(new INTEGER(0), new INTEGER(1023), FALSE); const ASN_PERdescriptor_t JsBank_numberOfSlots_per_ = { &JsBank_numberOfSlots_per_cons_ }; const TTCN_Typedescriptor_t JsBank_numberOfSlots_descr_ = { "@RSRES.JsBank.numberOfSlots", &INTEGER_ber_, NULL, NULL, NULL, &INTEGER_json_, &JsBank_numberOfSlots_oer_, &JsBank_numberOfSlots_per_, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsBank_numberOfSlots_default_coding(""); // No XER for JsBank const TTCN_JSONdescriptor_t JsBank_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t JsBank_descr_ = { "@RSRES.JsBank", NULL, NULL, NULL, NULL, &JsBank_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsBank_default_coding("JSON"); // No XER for JsBanks const TTCN_JSONdescriptor_t JsBanks_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t JsBanks_descr_ = { "@RSRES.JsBanks", NULL, NULL, NULL, NULL, &JsBanks_json_, NULL, NULL, &JsBanks_0_descr_, TTCN_Typedescriptor_t::DONTCARE }; // No XER for JsBanks_0 const TTCN_Typedescriptor_t JsBanks_0_descr_ = { "@RSRES.JsBanks.", NULL, NULL, NULL, NULL, &JsBank_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsBanks_0_default_coding("JSON"); UNIVERSAL_CHARSTRING JsBanks_default_coding("JSON"); const XERdescriptor_t JsClient_peer_xer_ = { {"peer>\n", "peer>\n"}, {6, 6}, 0 |FORM_UNQUALIFIED, WHITESPACE_PRESERVE, NULL, &module_object, -1, 0, NULL, NULL, -1, XSD_NONE }; const TTCN_Typedescriptor_t JsClient_peer_descr_ = { "@RSRES.JsClient.peer", NULL, &CHARSTRING_raw_, &CHARSTRING_text_, &JsClient_peer_xer_, &CHARSTRING_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsClient_peer_default_coding("JSON"); // No XER for JsClient_state const TTCN_Typedescriptor_t JsClient_state_descr_ = { "@RSRES.JsClient.state", NULL, NULL, NULL, NULL, &ConnectionState_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsClient_state_default_coding("JSON"); // No XER for JsClient_component__id const int JsClient_component__id_oer_ext_arr_[0] = {}; const int JsClient_component__id_oer_p_[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; const TTCN_OERdescriptor_t JsClient_component__id_oer_ = { -1, TRUE, -1, TRUE, 9, 0, JsClient_component__id_oer_ext_arr_, 9, JsClient_component__id_oer_p_}; const ASN_PERdescriptor_t JsClient_component__id_per_ = { &JsClient_component__id_per_cons_ }; const TTCN_Typedescriptor_t JsClient_component__id_descr_ = { "@RSRES.JsClient.component_id", &SEQUENCE_ber_, NULL, NULL, NULL, &RSPRO::ComponentIdentity_json_, &JsClient_component__id_oer_, &JsClient_component__id_per_, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsClient_component__id_default_coding(""); // No XER for JsClient const TTCN_JSONdescriptor_t JsClient_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t JsClient_descr_ = { "@RSRES.JsClient", NULL, NULL, NULL, NULL, &JsClient_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsClient_default_coding("JSON"); // No XER for JsClients const TTCN_JSONdescriptor_t JsClients_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t JsClients_descr_ = { "@RSRES.JsClients", NULL, NULL, NULL, NULL, &JsClients_json_, NULL, NULL, &JsClients_0_descr_, TTCN_Typedescriptor_t::DONTCARE }; // No XER for JsClients_0 const TTCN_Typedescriptor_t JsClients_0_descr_ = { "@RSRES.JsClients.", NULL, NULL, NULL, NULL, &JsClient_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsClients_0_default_coding("JSON"); UNIVERSAL_CHARSTRING JsClients_default_coding("JSON"); // No XER for SlotmapState const TTCN_JSONdescriptor_t SlotmapState_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t SlotmapState_descr_ = { "@RSRES.SlotmapState", NULL, NULL, NULL, NULL, &SlotmapState_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING SlotmapState_default_coding("JSON"); // No XER for JsSlotmap_bank const int JsSlotmap_bank_oer_ext_arr_[0] = {}; const int JsSlotmap_bank_oer_p_[2] = {0, 1}; const TTCN_OERdescriptor_t JsSlotmap_bank_oer_ = { -1, TRUE, -1, TRUE, 2, 0, JsSlotmap_bank_oer_ext_arr_, 2, JsSlotmap_bank_oer_p_}; const ASN_PERdescriptor_t JsSlotmap_bank_per_ = { &JsSlotmap_bank_per_cons_ }; const TTCN_Typedescriptor_t JsSlotmap_bank_descr_ = { "@RSRES.JsSlotmap.bank", &SEQUENCE_ber_, NULL, NULL, NULL, &RSPRO::BankSlot_json_, &JsSlotmap_bank_oer_, &JsSlotmap_bank_per_, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsSlotmap_bank_default_coding(""); // No XER for JsSlotmap_client const int JsSlotmap_client_oer_ext_arr_[0] = {}; const int JsSlotmap_client_oer_p_[2] = {0, 1}; const TTCN_OERdescriptor_t JsSlotmap_client_oer_ = { -1, TRUE, -1, TRUE, 2, 0, JsSlotmap_client_oer_ext_arr_, 2, JsSlotmap_client_oer_p_}; const ASN_PERdescriptor_t JsSlotmap_client_per_ = { &JsSlotmap_client_per_cons_ }; const TTCN_Typedescriptor_t JsSlotmap_client_descr_ = { "@RSRES.JsSlotmap.client", &SEQUENCE_ber_, NULL, NULL, NULL, &RSPRO::ClientSlot_json_, &JsSlotmap_client_oer_, &JsSlotmap_client_per_, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsSlotmap_client_default_coding(""); // No XER for JsSlotmap const TTCN_JSONdescriptor_t JsSlotmap_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t JsSlotmap_descr_ = { "@RSRES.JsSlotmap", NULL, NULL, NULL, NULL, &JsSlotmap_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; // No XER for JsSlotmap_state const TTCN_Typedescriptor_t JsSlotmap_state_descr_ = { "@RSRES.JsSlotmap.state", NULL, NULL, NULL, NULL, &SlotmapState_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsSlotmap_state_default_coding("JSON"); UNIVERSAL_CHARSTRING JsSlotmap_default_coding("JSON"); // No XER for JsSlotmaps const TTCN_JSONdescriptor_t JsSlotmaps_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t JsSlotmaps_descr_ = { "@RSRES.JsSlotmaps", NULL, NULL, NULL, NULL, &JsSlotmaps_json_, NULL, NULL, &JsSlotmaps_0_descr_, TTCN_Typedescriptor_t::DONTCARE }; // No XER for JsSlotmaps_0 const TTCN_Typedescriptor_t JsSlotmaps_0_descr_ = { "@RSRES.JsSlotmaps.", NULL, NULL, NULL, NULL, &JsSlotmap_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsSlotmaps_0_default_coding("JSON"); UNIVERSAL_CHARSTRING JsSlotmaps_default_coding("JSON"); SlotmapState_template template_ts__JsSlotmap_state_defval; const SlotmapState_template& ts__JsSlotmap_state_defval = template_ts__JsSlotmap_state_defval; SlotmapState_template template_tr__JsSlotmap_state_defval; const SlotmapState_template& tr__JsSlotmap_state_defval = template_tr__JsSlotmap_state_defval; // No XER for JsRoot const TTCN_JSONdescriptor_t JsRoot_json_ = { FALSE, NULL, FALSE, { JD_UNSET, NULL, NULL }, FALSE, FALSE, FALSE, 0, NULL, FALSE, ESCAPE_AS_SHORT }; const TTCN_Typedescriptor_t JsRoot_descr_ = { "@RSRES.JsRoot", NULL, NULL, NULL, NULL, &JsRoot_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE }; // No XER for JsRoot_clients const TTCN_Typedescriptor_t JsRoot_clients_descr_ = { "@RSRES.JsRoot.clients", NULL, NULL, NULL, NULL, &JsClients_json_, NULL, NULL, &JsClients_0_descr_, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsRoot_clients_default_coding("JSON"); // No XER for JsRoot_banks const TTCN_Typedescriptor_t JsRoot_banks_descr_ = { "@RSRES.JsRoot.banks", NULL, NULL, NULL, NULL, &JsBanks_json_, NULL, NULL, &JsBanks_0_descr_, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsRoot_banks_default_coding("JSON"); // No XER for JsRoot_slotmaps const TTCN_Typedescriptor_t JsRoot_slotmaps_descr_ = { "@RSRES.JsRoot.slotmaps", NULL, NULL, NULL, NULL, &JsSlotmaps_json_, NULL, NULL, &JsSlotmaps_0_descr_, TTCN_Typedescriptor_t::DONTCARE }; UNIVERSAL_CHARSTRING JsRoot_slotmaps_default_coding("JSON"); UNIVERSAL_CHARSTRING JsRoot_default_coding("JSON"); TTCN_Module module_object("RSRES", __DATE__, __TIME__, module_checksum, pre_init_module, NULL, 0U, 4294967295U, 4294967295U, 4294967295U, NULL, 0LU, 0, post_init_module, NULL, NULL, NULL, NULL, NULL, NULL, NULL); const RuntimeVersionChecker ver_checker( current_runtime_version.requires_major_version_9, current_runtime_version.requires_minor_version_0, current_runtime_version.requires_patch_level_0, current_runtime_version.requires_runtime_1); /* Member functions of C++ classes */ ConnectionState::ConnectionState() { enum_value = UNBOUND_VALUE; } ConnectionState::ConnectionState(int other_value) { if (!is_valid_enum(other_value)) TTCN_error("Initializing a variable of enumerated type @RSRES.ConnectionState with invalid numeric value %d.", other_value); enum_value = (enum_type)other_value; } ConnectionState::ConnectionState(enum_type other_value) { enum_value = other_value; } ConnectionState::ConnectionState(const ConnectionState& other_value) : Base_Type() { if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("Copying an unbound value of enumerated type @RSRES.ConnectionState."); enum_value = other_value.enum_value; } ConnectionState& ConnectionState::operator=(int other_value) { if (!is_valid_enum(other_value)) TTCN_error("Assigning unknown numeric value %d to a variable of enumerated type @RSRES.ConnectionState.", other_value); enum_value = (enum_type)other_value; return *this; } ConnectionState& ConnectionState::operator=(enum_type other_value) { enum_value = other_value; return *this; } ConnectionState& ConnectionState::operator=(const ConnectionState& other_value) { if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("Assignment of an unbound value of enumerated type @RSRES.ConnectionState."); enum_value = other_value.enum_value; return *this; } boolean ConnectionState::operator==(enum_type other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); return enum_value == other_value; } boolean ConnectionState::operator==(const ConnectionState& other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); return enum_value == other_value.enum_value; } boolean ConnectionState::operator<(enum_type other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); return enum_value < other_value; } boolean ConnectionState::operator<(const ConnectionState& other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); return enum_value < other_value.enum_value; } boolean ConnectionState::operator>(enum_type other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); return enum_value > other_value; } boolean ConnectionState::operator>(const ConnectionState& other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @RSRES.ConnectionState."); return enum_value > other_value.enum_value; } const char *ConnectionState::enum_to_str(enum_type enum_par) { switch (enum_par) { case INIT: return "INIT"; case ESTABLISHED: return "ESTABLISHED"; case CONNECTED__CLIENT: return "CONNECTED_CLIENT"; case CONNECTED__BANKD: return "CONNECTED_BANKD"; default: return ""; } } ConnectionState::enum_type ConnectionState::str_to_enum(const char *str_par) { if (!strcmp(str_par, "INIT")) return INIT; else if (!strcmp(str_par, "ESTABLISHED")) return ESTABLISHED; else if (!strcmp(str_par, "CONNECTED_CLIENT")) return CONNECTED__CLIENT; else if (!strcmp(str_par, "CONNECTED_BANKD")) return CONNECTED__BANKD; else return UNKNOWN_VALUE; } boolean ConnectionState::is_valid_enum(int int_par) { switch (int_par) { case 0: case 1: case 2: case 3: return TRUE; default: return FALSE; } } int ConnectionState::enum2int(enum_type enum_par) { if (enum_par==UNBOUND_VALUE || enum_par==UNKNOWN_VALUE) TTCN_error("The argument of function enum2int() is an %s value of enumerated type @RSRES.ConnectionState.", enum_par==UNBOUND_VALUE?"unbound":"invalid"); return enum_par; } int ConnectionState::enum2int(const ConnectionState& enum_par) { if (enum_par.enum_value==UNBOUND_VALUE || enum_par.enum_value==UNKNOWN_VALUE) TTCN_error("The argument of function enum2int() is an %s value of enumerated type @RSRES.ConnectionState.", enum_par==UNBOUND_VALUE?"unbound":"invalid"); return enum_par.enum_value; } void ConnectionState::int2enum(int int_val) { if (!is_valid_enum(int_val)) TTCN_error("Assigning invalid numeric value %d to a variable of enumerated type @RSRES.ConnectionState.", int_val); enum_value = (enum_type)int_val; } ConnectionState::operator ConnectionState::enum_type() const { if (enum_value == UNBOUND_VALUE) TTCN_error("Using the value of an unbound variable of enumerated type @RSRES.ConnectionState."); return enum_value; } void ConnectionState::log() const { if (enum_value != UNBOUND_VALUE) TTCN_Logger::log_event_enum(enum_to_str(enum_value), enum_value); else TTCN_Logger::log_event_unbound(); } void ConnectionState::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_VALUE, "enumerated value"); if (param.get_type()!=Module_Param::MP_Enumerated) param.type_error("enumerated value", "@RSRES.ConnectionState"); enum_value = str_to_enum(param.get_enumerated()); if (!is_valid_enum(enum_value)) { param.error("Invalid enumerated value for type @RSRES.ConnectionState."); } } void ConnectionState::encode_text(Text_Buf& text_buf) const { if (enum_value == UNBOUND_VALUE) TTCN_error("Text encoder: Encoding an unbound value of enumerated type @RSRES.ConnectionState."); text_buf.push_int(enum_value); } void ConnectionState::decode_text(Text_Buf& text_buf) { enum_value = (enum_type)text_buf.pull_int().get_val(); if (!is_valid_enum(enum_value)) TTCN_error("Text decoder: Unknown numeric value %d was received for enumerated type @RSRES.ConnectionState.", enum_value); } void ConnectionState::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) const { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name); unsigned BER_coding=va_arg(pvar, unsigned); BER_encode_chk_coding(BER_coding); ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding); tlv->put_in_buffer(p_buf); ASN_BER_TLV_t::destruct(tlv); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); RAW_enc_tr_pos rp; rp.level=0; rp.pos=NULL; RAW_enc_tree root(TRUE, NULL, &rp, 1, p_td.raw); RAW_encode(p_td, root); root.put_to_buf(p_buf); break;} case TTCN_EncDec::CT_TEXT: { TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); TEXT_encode(p_td,p_buf); break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XER_encode(*(p_td.xer),p_buf, XER_coding, 0, 0, 0); p_buf.put_c('\n'); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok(va_arg(pvar, int) != 0); JSON_encode(p_td, tok, FALSE); p_buf.put_s(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-encoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_encode(p_td, p_buf); break;} default: TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name); } va_end(pvar); } void ConnectionState::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name); unsigned L_form=va_arg(pvar, unsigned); ASN_BER_TLV_t tlv; BER_decode_str2TLV(p_buf, tlv, L_form); BER_decode_TLV(p_td, tlv, L_form); if(tlv.isComplete) p_buf.increase_pos(tlv.get_len()); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); raw_order_t r_order; switch(p_td.raw->top_bit_order) { case TOP_BIT_LEFT: r_order=ORDER_LSB; break; case TOP_BIT_RIGHT: default: r_order=ORDER_MSB; } int rawr = RAW_decode(p_td, p_buf, p_buf.get_len()*8, r_order); if(rawr<0) switch (-rawr) { case TTCN_EncDec::ET_INCOMPL_MSG: case TTCN_EncDec::ET_LEN_ERR: ec.error((TTCN_EncDec::error_type_t)-rawr, "Can not decode type '%s', because incomplete message was received", p_td.name); break; case 1: default: ec.error(TTCN_EncDec::ET_INVAL_MSG, "Can not decode type '%s', because invalid message was received", p_td.name); break; } break;} case TTCN_EncDec::CT_TEXT: { Limit_Token_List limit; TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); const unsigned char *b_data=p_buf.get_data(); int null_added=0; if(b_data[p_buf.get_len()-1]!='\0'){ null_added=1; p_buf.set_pos(p_buf.get_len()); p_buf.put_zero(8,ORDER_LSB); p_buf.rewind(); } if(TEXT_decode(p_td,p_buf,limit)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); if(null_added){ size_t actpos=p_buf.get_pos(); p_buf.set_pos(p_buf.get_len()-1); p_buf.cut_end(); p_buf.set_pos(actpos); } break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XmlReaderWrap reader(p_buf); for (int rd_ok=reader.Read(); rd_ok==1; rd_ok=reader.Read()) { if (reader.NodeType() == XML_READER_TYPE_ELEMENT) break; } XER_decode(*(p_td.xer), reader, XER_coding | XER_TOPLEVEL, XER_NONE, 0); size_t bytes = reader.ByteConsumed(); p_buf.set_pos(bytes); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok((const char*)p_buf.get_data(), p_buf.get_len()); if(JSON_decode(p_td, tok, FALSE, FALSE)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); p_buf.set_pos(tok.get_buf_pos()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-decoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_struct p_oer; OER_decode(p_td, p_buf, p_oer); break;} default: TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name); } va_end(pvar); } int ConnectionState::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean) const { if (enum_value == UNBOUND_VALUE) { TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "Encoding an unbound value of enumerated type @RSRES.ConnectionState."); return -1; } if (p_td.json->use_null) { return p_tok.put_next_token(JSON_TOKEN_LITERAL_NULL); } char* tmp_str; if (p_td.json->as_number) { tmp_str = mprintf("%d", enum_value); } else { boolean text_found = false; for (size_t i = 0; i < p_td.json->nof_enum_texts; ++i) { if (p_td.json->enum_texts[i].index == enum_value) { tmp_str = mprintf("\"%s\"", p_td.json->enum_texts[i].text); text_found = true; break; } } if (!text_found) { tmp_str = mprintf("\"%s\"", enum_to_str(enum_value)); } } int enc_len = p_tok.put_next_token(p_td.json->as_number ? JSON_TOKEN_NUMBER : JSON_TOKEN_STRING, tmp_str); Free(tmp_str); return enc_len; } int ConnectionState::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent, boolean, int) { json_token_t token = JSON_TOKEN_NONE; char* value = 0; size_t value_len = 0; boolean error = FALSE; size_t dec_len = 0; boolean use_default = FALSE; if (p_td.json->default_value.type == JD_STANDARD && 0 == p_tok.get_buffer_length()) { *this = *static_cast(p_td.json->default_value.val); return dec_len; } if (p_td.json->default_value.type == JD_LEGACY && 0 == p_tok.get_buffer_length()) { value = const_cast(p_td.json->default_value.str); value_len = strlen(value); use_default = TRUE; } else { dec_len = p_tok.get_next_token(&token, &value, &value_len); } if (JSON_TOKEN_ERROR == token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } else if (JSON_TOKEN_LITERAL_NULL == token && p_td.json->use_null) { enum_value = INIT; } else if (!p_td.json->use_null && ((JSON_TOKEN_STRING == token && !p_td.json->as_number) || use_default)) { if (use_default || (value_len > 2 && value[0] == '\"' && value[value_len - 1] == '\"')) { if (!use_default) value[value_len - 1] = 0; boolean text_found = false; for (size_t i = 0; i < p_td.json->nof_enum_texts; ++i) { if (strcmp(p_td.json->enum_texts[i].text, value + (use_default ? 0 : 1)) == 0) { enum_value = static_cast(p_td.json->enum_texts[i].index); text_found = true; break; } } if (!text_found) { enum_value = str_to_enum(value + (use_default ? 0 : 1)); } if (!use_default) value[value_len - 1] = '\"'; if (UNKNOWN_VALUE == enum_value) { error = TRUE; } } else { error = TRUE; } } else if (!p_td.json->use_null && JSON_TOKEN_NUMBER == token && p_td.json->as_number) { char* value_str = mcopystrn(value, value_len); int number = atoi(value_str); if (strchr(value_str, '.') != NULL || strchr(value_str, 'e') != NULL || strchr(value_str, 'E') != NULL) { error = TRUE; } else if (is_valid_enum(number)) { enum_value = static_cast(number); } else { error = TRUE; } Free(value_str); } else { enum_value = UNBOUND_VALUE; return JSON_ERROR_INVALID_TOKEN; } if (error) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FORMAT_ERROR, p_td.json->as_number ? "number" : "string", "enumerated"); enum_value = UNBOUND_VALUE; return JSON_ERROR_FATAL; } return (int)dec_len; } void ConnectionState_template::copy_template(const ConnectionState_template& other_value) { set_selection(other_value); switch (template_selection) { case SPECIFIC_VALUE: single_value = other_value.single_value; break; case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = other_value.value_list.n_values; value_list.list_value = new ConnectionState_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]); break; case IMPLICATION_MATCH: implication_.precondition = new ConnectionState_template(*other_value.implication_.precondition); implication_.implied_template = new ConnectionState_template(*other_value.implication_.implied_template); break; case DYNAMIC_MATCH: dyn_match = other_value.dyn_match; dyn_match->ref_count++; break; default: TTCN_error("Copying an uninitialized/unsupported template of enumerated type @RSRES.ConnectionState."); } } ConnectionState_template::ConnectionState_template() { } ConnectionState_template::ConnectionState_template(template_sel other_value) : Base_Template(other_value) { check_single_selection(other_value); } ConnectionState_template::ConnectionState_template(int other_value) : Base_Template(SPECIFIC_VALUE) { if (!ConnectionState::is_valid_enum(other_value)) TTCN_error("Initializing a template of enumerated type @RSRES.ConnectionState with unknown numeric value %d.", other_value); single_value = (ConnectionState::enum_type)other_value; } ConnectionState_template::ConnectionState_template(ConnectionState::enum_type other_value) : Base_Template(SPECIFIC_VALUE) { single_value = other_value; } ConnectionState_template::ConnectionState_template(const ConnectionState& other_value) : Base_Template(SPECIFIC_VALUE) { if (other_value.enum_value == ConnectionState::UNBOUND_VALUE) TTCN_error("Creating a template from an unbound value of enumerated type @RSRES.ConnectionState."); single_value = other_value.enum_value; } ConnectionState_template::ConnectionState_template(const OPTIONAL& other_value) { switch (other_value.get_selection()) { case OPTIONAL_PRESENT: set_selection(SPECIFIC_VALUE); single_value = (ConnectionState::enum_type)(const ConnectionState&)other_value; break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Creating a template of enumerated type @RSRES.ConnectionState from an unbound optional field."); } } ConnectionState_template::ConnectionState_template(ConnectionState_template* p_precondition, ConnectionState_template* p_implied_template) : Base_Template(IMPLICATION_MATCH) { implication_.precondition = p_precondition; implication_.implied_template = p_implied_template; } ConnectionState_template::ConnectionState_template(Dynamic_Match_Interface* p_dyn_match) : Base_Template(DYNAMIC_MATCH) { dyn_match = new dynmatch_struct; dyn_match->ptr = p_dyn_match; dyn_match->ref_count = 1; } ConnectionState_template::ConnectionState_template(const ConnectionState_template& other_value) : Base_Template() { copy_template(other_value); } ConnectionState_template::~ConnectionState_template() { clean_up(); } boolean ConnectionState_template::is_bound() const { if (template_selection == UNINITIALIZED_TEMPLATE && !is_ifpresent) return FALSE; return TRUE; } boolean ConnectionState_template::is_value() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) return FALSE; return single_value != ConnectionState::UNBOUND_VALUE; } void ConnectionState_template::clean_up() { switch (template_selection) { case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: delete [] value_list.list_value; break; case IMPLICATION_MATCH: delete implication_.precondition; delete implication_.implied_template; break; case DYNAMIC_MATCH: dyn_match->ref_count--; if (dyn_match->ref_count == 0) { delete dyn_match->ptr; delete dyn_match; } break; default: break; } template_selection = UNINITIALIZED_TEMPLATE; } ConnectionState_template& ConnectionState_template::operator=(template_sel other_value) { check_single_selection(other_value); clean_up(); set_selection(other_value); return *this; } ConnectionState_template& ConnectionState_template::operator=(int other_value) { if (!ConnectionState::is_valid_enum(other_value)) TTCN_warning("Assigning unknown numeric value %d to a template of enumerated type @RSRES.ConnectionState.", other_value); clean_up(); set_selection(SPECIFIC_VALUE); single_value = (ConnectionState::enum_type)other_value; return *this; } ConnectionState_template& ConnectionState_template::operator=(ConnectionState::enum_type other_value) { clean_up(); set_selection(SPECIFIC_VALUE); single_value = other_value; return *this; } ConnectionState_template& ConnectionState_template::operator=(const ConnectionState& other_value) { if (other_value.enum_value == ConnectionState::UNBOUND_VALUE) TTCN_error("Assignment of an unbound value of enumerated type @RSRES.ConnectionState to a template."); clean_up(); set_selection(SPECIFIC_VALUE); single_value = other_value.enum_value; return *this; } ConnectionState_template& ConnectionState_template::operator=(const OPTIONAL& other_value) { clean_up(); switch (other_value.get_selection()) { case OPTIONAL_PRESENT: set_selection(SPECIFIC_VALUE); single_value = (ConnectionState::enum_type)(const ConnectionState&)other_value; break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Assignment of an unbound optional field to a template of enumerated type @RSRES.ConnectionState."); } return *this; } ConnectionState_template& ConnectionState_template::operator=(const ConnectionState_template& other_value) { if (&other_value != this) { clean_up(); copy_template(other_value); } return *this; } boolean ConnectionState_template::match(ConnectionState::enum_type other_value, boolean) const { switch (template_selection) { case SPECIFIC_VALUE: return single_value == other_value; case OMIT_VALUE: return FALSE; case ANY_VALUE: case ANY_OR_OMIT: return TRUE; case VALUE_LIST: case COMPLEMENTED_LIST: for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) if (value_list.list_value[list_count].match(other_value)) return template_selection == VALUE_LIST; return template_selection == COMPLEMENTED_LIST; case CONJUNCTION_MATCH: for (unsigned int i = 0; i < value_list.n_values; i++) { if (!value_list.list_value[i].match(other_value)) { return FALSE; } } return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match(other_value) || implication_.implied_template->match(other_value); case DYNAMIC_MATCH: return dyn_match->ptr->match(other_value); default: TTCN_error("Matching an uninitialized/unsupported template of enumerated type @RSRES.ConnectionState."); } return FALSE; } boolean ConnectionState_template::match(const ConnectionState& other_value, boolean) const { if (other_value.enum_value == ConnectionState::UNBOUND_VALUE) TTCN_error("Matching a template of enumerated type @RSRES.ConnectionState with an unbound value."); return match(other_value.enum_value); } ConnectionState::enum_type ConnectionState_template::valueof() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) TTCN_error("Performing a valueof or send operation on a non-specific template of enumerated type @RSRES.ConnectionState."); return single_value; } void ConnectionState_template::set_type(template_sel template_type, unsigned int list_length) { if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST && template_type != CONJUNCTION_MATCH) TTCN_error("Setting an invalid list type for a template of enumerated type @RSRES.ConnectionState."); clean_up(); set_selection(template_type); value_list.n_values = list_length; value_list.list_value = new ConnectionState_template[list_length]; } ConnectionState_template& ConnectionState_template::list_item(unsigned int list_index) { if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST && template_selection != CONJUNCTION_MATCH) TTCN_error("Accessing a list element in a non-list template of enumerated type @RSRES.ConnectionState."); if (list_index >= value_list.n_values) TTCN_error("Index overflow in a value list template of enumerated type @RSRES.ConnectionState."); return value_list.list_value[list_index]; } void ConnectionState_template::log() const { switch (template_selection) { case SPECIFIC_VALUE: TTCN_Logger::log_event_enum(ConnectionState::enum_to_str(single_value), single_value); break; case COMPLEMENTED_LIST: TTCN_Logger::log_event_str("complement"); case CONJUNCTION_MATCH: if (template_selection == CONJUNCTION_MATCH) { TTCN_Logger::log_event_str("conjunct"); } case VALUE_LIST: TTCN_Logger::log_char('('); for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); value_list.list_value[elem_count].log(); } TTCN_Logger::log_char(')'); break; case IMPLICATION_MATCH: implication_.precondition->log(); TTCN_Logger::log_event_str(" implies "); implication_.implied_template->log(); break; case DYNAMIC_MATCH: TTCN_Logger::log_event_str("@dynamic template"); break; default: log_generic(); } log_ifpresent(); } void ConnectionState_template::log_match(const ConnectionState& match_value, boolean) const { match_value.log(); TTCN_Logger::log_event_str(" with "); log(); if (match(match_value)) TTCN_Logger::log_event_str(" matched"); else TTCN_Logger::log_event_str(" unmatched"); } void ConnectionState_template::encode_text(Text_Buf& text_buf) const { encode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: text_buf.push_int(single_value); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: text_buf.push_int(value_list.n_values); for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++) value_list.list_value[elem_count].encode_text(text_buf); break; default: TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of enumerated type @RSRES.ConnectionState."); } } void ConnectionState_template::decode_text(Text_Buf& text_buf) { clean_up(); decode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value = (ConnectionState::enum_type)text_buf.pull_int().get_val(); if (!ConnectionState::is_valid_enum(single_value)) TTCN_error("Text decoder: Unknown numeric value %d was received for a template of enumerated type @RSRES.ConnectionState.", single_value); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: value_list.n_values = text_buf.pull_int().get_val(); value_list.list_value = new ConnectionState_template[value_list.n_values]; for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++) value_list.list_value[elem_count].decode_text(text_buf); break; default: TTCN_error("Text decoder: An unknown/unsupported selection was received for a template of enumerated type @RSRES.ConnectionState."); } } boolean ConnectionState_template::is_present(boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE; return !match_omit(legacy); } boolean ConnectionState_template::match_omit(boolean legacy) const { if (is_ifpresent) return TRUE; switch (template_selection) { case OMIT_VALUE: case ANY_OR_OMIT: return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match_omit() || implication_.implied_template->match_omit(); case VALUE_LIST: case COMPLEMENTED_LIST: if (legacy) { for (unsigned int i=0; iget_type()) { case Module_Param::MP_Omit: *this = OMIT_VALUE; break; case Module_Param::MP_Any: *this = ANY_VALUE; break; case Module_Param::MP_AnyOrNone: *this = ANY_OR_OMIT; break; case Module_Param::MP_List_Template: case Module_Param::MP_ComplementList_Template: case Module_Param::MP_ConjunctList_Template: { ConnectionState_template new_temp; new_temp.set_type(m_p->get_type()==Module_Param::MP_List_Template ? VALUE_LIST : (m_p->get_type() == Module_Param::MP_ConjunctList_Template ? CONJUNCTION_MATCH : COMPLEMENTED_LIST), m_p->get_size()); for (size_t p_i=0; p_iget_size(); p_i++) { new_temp.list_item(p_i).set_param(*m_p->get_elem(p_i)); } *this = new_temp; break; } case Module_Param::MP_Enumerated: { ConnectionState::enum_type enum_val = ConnectionState::str_to_enum(m_p->get_enumerated()); if (!ConnectionState::is_valid_enum(enum_val)) { param.error("Invalid enumerated value for type @RSRES.ConnectionState."); } *this = enum_val; } break; case Module_Param::MP_Implication_Template: { ConnectionState_template* precondition = new ConnectionState_template; precondition->set_param(*m_p->get_elem(0)); ConnectionState_template* implied_template = new ConnectionState_template; implied_template->set_param(*m_p->get_elem(1)); *this = ConnectionState_template(precondition, implied_template); } break; default: param.type_error("enumerated template", "@RSRES.ConnectionState"); } is_ifpresent = param.get_ifpresent(); } void ConnectionState_template::check_restriction(template_res t_res, const char* t_name, boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return; switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) { case TR_VALUE: if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return; break; case TR_OMIT: if (!is_ifpresent && (template_selection==OMIT_VALUE || template_selection==SPECIFIC_VALUE)) return; break; case TR_PRESENT: if (!match_omit(legacy)) return; break; default: return; } TTCN_error("Restriction `%s' on template of type %s violated.", get_res_name(t_res), t_name ? t_name : "@RSRES.ConnectionState"); } JsBank::JsBank() { } JsBank::JsBank(const CHARSTRING& par_peer, const ConnectionState& par_state, const RSPRO::ComponentIdentity& par_component__id, const INTEGER& par_bankId, const INTEGER& par_numberOfSlots) : field_peer(par_peer), field_state(par_state), field_component__id(par_component__id), field_bankId(par_bankId), field_numberOfSlots(par_numberOfSlots) { } JsBank::JsBank(const JsBank& other_value) { if(!other_value.is_bound()) TTCN_error("Copying an unbound value of type @RSRES.JsBank."); if (other_value.peer().is_bound()) field_peer = other_value.peer(); else field_peer.clean_up(); if (other_value.state().is_bound()) field_state = other_value.state(); else field_state.clean_up(); if (other_value.component__id().is_bound()) field_component__id = other_value.component__id(); else field_component__id.clean_up(); if (other_value.bankId().is_bound()) field_bankId = other_value.bankId(); else field_bankId.clean_up(); if (other_value.numberOfSlots().is_bound()) field_numberOfSlots = other_value.numberOfSlots(); else field_numberOfSlots.clean_up(); } void JsBank::clean_up() { field_peer.clean_up(); field_state.clean_up(); field_component__id.clean_up(); field_bankId.clean_up(); field_numberOfSlots.clean_up(); } const TTCN_Typedescriptor_t* JsBank::get_descriptor() const { return &JsBank_descr_; } JsBank& JsBank::operator=(const JsBank& other_value) { if (this != &other_value) { if(!other_value.is_bound()) TTCN_error("Assignment of an unbound value of type @RSRES.JsBank."); if (other_value.peer().is_bound()) field_peer = other_value.peer(); else field_peer.clean_up(); if (other_value.state().is_bound()) field_state = other_value.state(); else field_state.clean_up(); if (other_value.component__id().is_bound()) field_component__id = other_value.component__id(); else field_component__id.clean_up(); if (other_value.bankId().is_bound()) field_bankId = other_value.bankId(); else field_bankId.clean_up(); if (other_value.numberOfSlots().is_bound()) field_numberOfSlots = other_value.numberOfSlots(); else field_numberOfSlots.clean_up(); } return *this; } boolean JsBank::operator==(const JsBank& other_value) const { return field_peer==other_value.field_peer && field_state==other_value.field_state && field_component__id==other_value.field_component__id && field_bankId==other_value.field_bankId && field_numberOfSlots==other_value.field_numberOfSlots; } boolean JsBank::is_bound() const { return (field_peer.is_bound()) || (field_state.is_bound()) || (field_component__id.is_bound()) || (field_bankId.is_bound()) || (field_numberOfSlots.is_bound()); } boolean JsBank::is_value() const { return field_peer.is_value() && field_state.is_value() && field_component__id.is_value() && field_bankId.is_value() && field_numberOfSlots.is_value(); } void JsBank::log() const { if (!is_bound()) { TTCN_Logger::log_event_unbound(); return; } TTCN_Logger::log_event_str("{ peer := "); field_peer.log(); TTCN_Logger::log_event_str(", state := "); field_state.log(); TTCN_Logger::log_event_str(", component_id := "); field_component__id.log(); TTCN_Logger::log_event_str(", bankId := "); field_bankId.log(); TTCN_Logger::log_event_str(", numberOfSlots := "); field_numberOfSlots.log(); TTCN_Logger::log_event_str(" }"); } void JsBank::set_implicit_omit() { if (peer().is_bound()) peer().set_implicit_omit(); if (state().is_bound()) state().set_implicit_omit(); if (component__id().is_bound()) component__id().set_implicit_omit(); if (bankId().is_bound()) bankId().set_implicit_omit(); if (numberOfSlots().is_bound()) numberOfSlots().set_implicit_omit(); } void JsBank::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_VALUE, "record value"); switch (param.get_type()) { case Module_Param::MP_Value_List: if (50 && param.get_elem(0)->get_type()!=Module_Param::MP_NotUsed) peer().set_param(*param.get_elem(0)); if (param.get_size()>1 && param.get_elem(1)->get_type()!=Module_Param::MP_NotUsed) state().set_param(*param.get_elem(1)); if (param.get_size()>2 && param.get_elem(2)->get_type()!=Module_Param::MP_NotUsed) component__id().set_param(*param.get_elem(2)); if (param.get_size()>3 && param.get_elem(3)->get_type()!=Module_Param::MP_NotUsed) bankId().set_param(*param.get_elem(3)); if (param.get_size()>4 && param.get_elem(4)->get_type()!=Module_Param::MP_NotUsed) numberOfSlots().set_param(*param.get_elem(4)); break; case Module_Param::MP_Assignment_List: { Vector value_used(param.get_size()); value_used.resize(param.get_size(), FALSE); for (size_t val_idx=0; val_idxget_id()->get_name(), "peer")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { peer().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "state")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { state().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "component_id")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { component__id().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "bankId")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { bankId().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "numberOfSlots")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { numberOfSlots().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxerror("Non existent field name in type @RSRES.JsBank: %s", curr_param->get_id()->get_name()); break; } } break; default: param.type_error("record value", "@RSRES.JsBank"); } } void JsBank::encode_text(Text_Buf& text_buf) const { field_peer.encode_text(text_buf); field_state.encode_text(text_buf); field_component__id.encode_text(text_buf); field_bankId.encode_text(text_buf); field_numberOfSlots.encode_text(text_buf); } void JsBank::decode_text(Text_Buf& text_buf) { field_peer.decode_text(text_buf); field_state.decode_text(text_buf); field_component__id.decode_text(text_buf); field_bankId.decode_text(text_buf); field_numberOfSlots.decode_text(text_buf); } void JsBank::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) const { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name); unsigned BER_coding=va_arg(pvar, unsigned); BER_encode_chk_coding(BER_coding); ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding); tlv->put_in_buffer(p_buf); ASN_BER_TLV_t::destruct(tlv); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); RAW_enc_tr_pos rp; rp.level=0; rp.pos=NULL; RAW_enc_tree root(FALSE, NULL, &rp, 1, p_td.raw); RAW_encode(p_td, root); root.put_to_buf(p_buf); break;} case TTCN_EncDec::CT_TEXT: { TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); TEXT_encode(p_td,p_buf); break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XER_encode(*(p_td.xer),p_buf, XER_coding, 0, 0, 0); p_buf.put_c('\n'); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok(va_arg(pvar, int) != 0); JSON_encode(p_td, tok, FALSE); p_buf.put_s(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-encoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_encode(p_td, p_buf); break;} default: TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name); } va_end(pvar); } void JsBank::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name); unsigned L_form=va_arg(pvar, unsigned); ASN_BER_TLV_t tlv; BER_decode_str2TLV(p_buf, tlv, L_form); BER_decode_TLV(p_td, tlv, L_form); if(tlv.isComplete) p_buf.increase_pos(tlv.get_len()); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); raw_order_t r_order; switch(p_td.raw->top_bit_order) { case TOP_BIT_LEFT: r_order=ORDER_LSB; break; case TOP_BIT_RIGHT: default: r_order=ORDER_MSB; } int rawr = RAW_decode(p_td, p_buf, p_buf.get_len()*8, r_order); if(rawr<0) switch (-rawr) { case TTCN_EncDec::ET_INCOMPL_MSG: case TTCN_EncDec::ET_LEN_ERR: ec.error((TTCN_EncDec::error_type_t)-rawr, "Can not decode type '%s', because incomplete message was received", p_td.name); break; case 1: default: ec.error(TTCN_EncDec::ET_INVAL_MSG, "Can not decode type '%s', because invalid message was received", p_td.name); break; } break;} case TTCN_EncDec::CT_TEXT: { Limit_Token_List limit; TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); const unsigned char *b_data=p_buf.get_data(); int null_added=0; if(b_data[p_buf.get_len()-1]!='\0'){ null_added=1; p_buf.set_pos(p_buf.get_len()); p_buf.put_zero(8,ORDER_LSB); p_buf.rewind(); } if(TEXT_decode(p_td,p_buf,limit)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); if(null_added){ size_t actpos=p_buf.get_pos(); p_buf.set_pos(p_buf.get_len()-1); p_buf.cut_end(); p_buf.set_pos(actpos); } break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XmlReaderWrap reader(p_buf); for (int rd_ok=reader.Read(); rd_ok==1; rd_ok=reader.Read()) { if (reader.NodeType() == XML_READER_TYPE_ELEMENT) break; } XER_decode(*(p_td.xer), reader, XER_coding | XER_TOPLEVEL, XER_NONE, 0); size_t bytes = reader.ByteConsumed(); p_buf.set_pos(bytes); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok((const char*)p_buf.get_data(), p_buf.get_len()); if(JSON_decode(p_td, tok, FALSE, FALSE)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); p_buf.set_pos(tok.get_buf_pos()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-decoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_struct p_oer; OER_decode(p_td, p_buf, p_oer); break;} default: TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name); } va_end(pvar); } int JsBank::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_parent_is_map) const { if (!is_bound()) { TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "Encoding an unbound value of type @RSRES.JsBank."); return -1; } int enc_len = p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL); { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "peer"); enc_len += field_peer.JSON_encode(JsBank_peer_descr_, p_tok, FALSE); } { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "state"); enc_len += field_state.JSON_encode(JsBank_state_descr_, p_tok, FALSE); } { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "component_id"); enc_len += field_component__id.JSON_encode(JsBank_component__id_descr_, p_tok, FALSE); } { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "bankId"); enc_len += field_bankId.JSON_encode(JsBank_bankId_descr_, p_tok, FALSE); } { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "numberOfSlots"); enc_len += field_numberOfSlots.JSON_encode(JsBank_numberOfSlots_descr_, p_tok, FALSE); } enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_END, NULL); return enc_len; } int JsBank::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent, boolean p_parent_is_map, int) { if (p_td.json->default_value.type == JD_STANDARD && 0 == p_tok.get_buffer_length()) { *this = *static_cast(p_td.json->default_value.val); return 0; } json_token_t j_token = JSON_TOKEN_NONE; size_t dec_len = p_tok.get_next_token(&j_token, NULL, NULL); if (JSON_TOKEN_ERROR == j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } else if (JSON_TOKEN_OBJECT_START != j_token) { return JSON_ERROR_INVALID_TOKEN; } boolean peer_found = FALSE; boolean state_found = FALSE; boolean component__id_found = FALSE; boolean bankId_found = FALSE; boolean numberOfSlots_found = FALSE; while (TRUE) { char* fld_name = 0; size_t name_len = 0; size_t buf_pos = p_tok.get_buf_pos(); dec_len += p_tok.get_next_token(&j_token, &fld_name, &name_len); if (JSON_TOKEN_ERROR == j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_NAME_TOKEN_ERROR); return JSON_ERROR_FATAL; } else if (JSON_TOKEN_NAME != j_token) { p_tok.set_buf_pos(buf_pos); break; } else { if (4 == name_len && 0 == strncmp(fld_name, "peer", name_len)) { peer_found = TRUE; int ret_val = field_peer.JSON_decode(JsBank_peer_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 4, "peer"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else if (5 == name_len && 0 == strncmp(fld_name, "state", name_len)) { state_found = TRUE; int ret_val = field_state.JSON_decode(JsBank_state_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 5, "state"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else if (12 == name_len && 0 == strncmp(fld_name, "component_id", name_len)) { component__id_found = TRUE; int ret_val = field_component__id.JSON_decode(JsBank_component__id_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 12, "component_id"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else if (6 == name_len && 0 == strncmp(fld_name, "bankId", name_len)) { bankId_found = TRUE; int ret_val = field_bankId.JSON_decode(JsBank_bankId_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 6, "bankId"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else if (13 == name_len && 0 == strncmp(fld_name, "numberOfSlots", name_len)) { numberOfSlots_found = TRUE; int ret_val = field_numberOfSlots.JSON_decode(JsBank_numberOfSlots_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 13, "numberOfSlots"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else { if (p_silent) { return JSON_ERROR_INVALID_TOKEN; } JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_INVALID_NAME_ERROR, (int)name_len, fld_name); dec_len += p_tok.get_next_token(&j_token, NULL, NULL); if (JSON_TOKEN_NUMBER != j_token && JSON_TOKEN_STRING != j_token && JSON_TOKEN_LITERAL_TRUE != j_token && JSON_TOKEN_LITERAL_FALSE != j_token && JSON_TOKEN_LITERAL_NULL != j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, (int)name_len, fld_name); return JSON_ERROR_FATAL; } } } } dec_len += p_tok.get_next_token(&j_token, NULL, NULL); if (JSON_TOKEN_OBJECT_END != j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_OBJECT_END_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } if (!peer_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "peer"); return JSON_ERROR_FATAL; } if (!state_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "state"); return JSON_ERROR_FATAL; } if (!component__id_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "component_id"); return JSON_ERROR_FATAL; } if (!bankId_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "bankId"); return JSON_ERROR_FATAL; } if (!numberOfSlots_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "numberOfSlots"); return JSON_ERROR_FATAL; } return (int)dec_len; } struct JsBank_template::single_value_struct { CHARSTRING_template field_peer; ConnectionState_template field_state; RSPRO::ComponentIdentity_template field_component__id; INTEGER_template field_bankId; INTEGER_template field_numberOfSlots; }; void JsBank_template::set_specific() { if (template_selection != SPECIFIC_VALUE) { template_sel old_selection = template_selection; clean_up(); single_value = new single_value_struct; set_selection(SPECIFIC_VALUE); if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) { single_value->field_peer = ANY_VALUE; single_value->field_state = ANY_VALUE; single_value->field_component__id = ANY_VALUE; single_value->field_bankId = ANY_VALUE; single_value->field_numberOfSlots = ANY_VALUE; } } } void JsBank_template::copy_value(const JsBank& other_value) { single_value = new single_value_struct; if (other_value.peer().is_bound()) { single_value->field_peer = other_value.peer(); } else { single_value->field_peer.clean_up(); } if (other_value.state().is_bound()) { single_value->field_state = other_value.state(); } else { single_value->field_state.clean_up(); } if (other_value.component__id().is_bound()) { single_value->field_component__id = other_value.component__id(); } else { single_value->field_component__id.clean_up(); } if (other_value.bankId().is_bound()) { single_value->field_bankId = other_value.bankId(); } else { single_value->field_bankId.clean_up(); } if (other_value.numberOfSlots().is_bound()) { single_value->field_numberOfSlots = other_value.numberOfSlots(); } else { single_value->field_numberOfSlots.clean_up(); } set_selection(SPECIFIC_VALUE); } void JsBank_template::copy_template(const JsBank_template& other_value) { switch (other_value.template_selection) { case SPECIFIC_VALUE: single_value = new single_value_struct; if (UNINITIALIZED_TEMPLATE != other_value.peer().get_selection()) { single_value->field_peer = other_value.peer(); } else { single_value->field_peer.clean_up(); } if (UNINITIALIZED_TEMPLATE != other_value.state().get_selection()) { single_value->field_state = other_value.state(); } else { single_value->field_state.clean_up(); } if (UNINITIALIZED_TEMPLATE != other_value.component__id().get_selection()) { single_value->field_component__id = other_value.component__id(); } else { single_value->field_component__id.clean_up(); } if (UNINITIALIZED_TEMPLATE != other_value.bankId().get_selection()) { single_value->field_bankId = other_value.bankId(); } else { single_value->field_bankId.clean_up(); } if (UNINITIALIZED_TEMPLATE != other_value.numberOfSlots().get_selection()) { single_value->field_numberOfSlots = other_value.numberOfSlots(); } else { single_value->field_numberOfSlots.clean_up(); } case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = other_value.value_list.n_values; value_list.list_value = new JsBank_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]); break; case IMPLICATION_MATCH: implication_.precondition = new JsBank_template(*other_value.implication_.precondition); implication_.implied_template = new JsBank_template(*other_value.implication_.implied_template); break; case DYNAMIC_MATCH: dyn_match = other_value.dyn_match; dyn_match->ref_count++; break; default: TTCN_error("Copying an uninitialized/unsupported template of type @RSRES.JsBank."); break; } set_selection(other_value); } JsBank_template::JsBank_template() { } JsBank_template::JsBank_template(template_sel other_value) : Base_Template(other_value) { check_single_selection(other_value); } JsBank_template::JsBank_template(const JsBank& other_value) { copy_value(other_value); } JsBank_template::JsBank_template(const OPTIONAL& other_value) { switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsBank&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Creating a template of type @RSRES.JsBank from an unbound optional field."); } } JsBank_template::JsBank_template(JsBank_template* p_precondition, JsBank_template* p_implied_template) : Base_Template(IMPLICATION_MATCH) { implication_.precondition = p_precondition; implication_.implied_template = p_implied_template; } JsBank_template::JsBank_template(Dynamic_Match_Interface* p_dyn_match) : Base_Template(DYNAMIC_MATCH) { dyn_match = new dynmatch_struct; dyn_match->ptr = p_dyn_match; dyn_match->ref_count = 1; } JsBank_template::JsBank_template(const JsBank_template& other_value) : Base_Template() { copy_template(other_value); } JsBank_template::~JsBank_template() { clean_up(); } JsBank_template& JsBank_template::operator=(template_sel other_value) { check_single_selection(other_value); clean_up(); set_selection(other_value); return *this; } JsBank_template& JsBank_template::operator=(const JsBank& other_value) { clean_up(); copy_value(other_value); return *this; } JsBank_template& JsBank_template::operator=(const OPTIONAL& other_value) { clean_up(); switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsBank&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Assignment of an unbound optional field to a template of type @RSRES.JsBank."); } return *this; } JsBank_template& JsBank_template::operator=(const JsBank_template& other_value) { if (&other_value != this) { clean_up(); copy_template(other_value); } return *this; } boolean JsBank_template::match(const JsBank& other_value, boolean legacy) const { if (!other_value.is_bound()) return FALSE; switch (template_selection) { case ANY_VALUE: case ANY_OR_OMIT: return TRUE; case OMIT_VALUE: return FALSE; case SPECIFIC_VALUE: if(!other_value.peer().is_bound()) return FALSE; if(!single_value->field_peer.match(other_value.peer(), legacy))return FALSE; if(!other_value.state().is_bound()) return FALSE; if(!single_value->field_state.match(other_value.state(), legacy))return FALSE; if(!other_value.component__id().is_bound()) return FALSE; if(!single_value->field_component__id.match(other_value.component__id(), legacy))return FALSE; if(!other_value.bankId().is_bound()) return FALSE; if(!single_value->field_bankId.match(other_value.bankId(), legacy))return FALSE; if(!other_value.numberOfSlots().is_bound()) return FALSE; if(!single_value->field_numberOfSlots.match(other_value.numberOfSlots(), legacy))return FALSE; return TRUE; case VALUE_LIST: case COMPLEMENTED_LIST: for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) if (value_list.list_value[list_count].match(other_value, legacy)) return template_selection == VALUE_LIST; return template_selection == COMPLEMENTED_LIST; case CONJUNCTION_MATCH: for (unsigned int i = 0; i < value_list.n_values; i++) { if (!value_list.list_value[i].match(other_value)) { return FALSE; } } return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match(other_value) || implication_.implied_template->match(other_value); case DYNAMIC_MATCH: return dyn_match->ptr->match(other_value); default: TTCN_error("Matching an uninitialized/unsupported template of type @RSRES.JsBank."); } return FALSE; } boolean JsBank_template::is_bound() const { if (template_selection == UNINITIALIZED_TEMPLATE && !is_ifpresent) return FALSE; if (template_selection != SPECIFIC_VALUE) return TRUE; return single_value->field_peer.is_bound() || single_value->field_state.is_bound() || single_value->field_component__id.is_bound() || single_value->field_bankId.is_bound() || single_value->field_numberOfSlots.is_bound(); } boolean JsBank_template::is_value() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) return FALSE; return single_value->field_peer.is_value() && single_value->field_state.is_value() && single_value->field_component__id.is_value() && single_value->field_bankId.is_value() && single_value->field_numberOfSlots.is_value(); } void JsBank_template::clean_up() { switch (template_selection) { case SPECIFIC_VALUE: delete single_value; break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: delete [] value_list.list_value; break; case IMPLICATION_MATCH: delete implication_.precondition; delete implication_.implied_template; break; case DYNAMIC_MATCH: dyn_match->ref_count--; if (dyn_match->ref_count == 0) { delete dyn_match->ptr; delete dyn_match; } break; default: break; } template_selection = UNINITIALIZED_TEMPLATE; } JsBank JsBank_template::valueof() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) TTCN_error("Performing a valueof or send operation on a non-specific template of type @RSRES.JsBank."); JsBank ret_val; if (single_value->field_peer.is_bound()) { ret_val.peer() = single_value->field_peer.valueof(); } if (single_value->field_state.is_bound()) { ret_val.state() = single_value->field_state.valueof(); } if (single_value->field_component__id.is_bound()) { ret_val.component__id() = single_value->field_component__id.valueof(); } if (single_value->field_bankId.is_bound()) { ret_val.bankId() = single_value->field_bankId.valueof(); } if (single_value->field_numberOfSlots.is_bound()) { ret_val.numberOfSlots() = single_value->field_numberOfSlots.valueof(); } return ret_val; } void JsBank_template::set_type(template_sel template_type, unsigned int list_length) { if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST&& template_type != CONJUNCTION_MATCH) TTCN_error("Setting an invalid list for a template of type @RSRES.JsBank."); clean_up(); set_selection(template_type); value_list.n_values = list_length; value_list.list_value = new JsBank_template[list_length]; } JsBank_template& JsBank_template::list_item(unsigned int list_index) const { if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST&& template_selection != CONJUNCTION_MATCH) TTCN_error("Accessing a list element of a non-list template of type @RSRES.JsBank."); if (list_index >= value_list.n_values) TTCN_error("Index overflow in a value list template of type @RSRES.JsBank."); return value_list.list_value[list_index]; } CHARSTRING_template& JsBank_template::peer() { set_specific(); return single_value->field_peer; } const CHARSTRING_template& JsBank_template::peer() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field peer of a non-specific template of type @RSRES.JsBank."); return single_value->field_peer; } ConnectionState_template& JsBank_template::state() { set_specific(); return single_value->field_state; } const ConnectionState_template& JsBank_template::state() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field state of a non-specific template of type @RSRES.JsBank."); return single_value->field_state; } RSPRO::ComponentIdentity_template& JsBank_template::component__id() { set_specific(); return single_value->field_component__id; } const RSPRO::ComponentIdentity_template& JsBank_template::component__id() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field component_id of a non-specific template of type @RSRES.JsBank."); return single_value->field_component__id; } INTEGER_template& JsBank_template::bankId() { set_specific(); return single_value->field_bankId; } const INTEGER_template& JsBank_template::bankId() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field bankId of a non-specific template of type @RSRES.JsBank."); return single_value->field_bankId; } INTEGER_template& JsBank_template::numberOfSlots() { set_specific(); return single_value->field_numberOfSlots; } const INTEGER_template& JsBank_template::numberOfSlots() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field numberOfSlots of a non-specific template of type @RSRES.JsBank."); return single_value->field_numberOfSlots; } int JsBank_template::size_of() const { if (is_ifpresent) TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank which has an ifpresent attribute."); switch (template_selection) { case SPECIFIC_VALUE: return 5; case VALUE_LIST: { if (value_list.n_values<1) TTCN_error("Internal error: Performing sizeof() operation on a template of type @RSRES.JsBank containing an empty list."); int item_size = value_list.list_value[0].size_of(); for (unsigned int l_idx = 1; l_idx < value_list.n_values; l_idx++) { if (value_list.list_value[l_idx].size_of()!=item_size) TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank containing a value list with different sizes."); } return item_size; } case OMIT_VALUE: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank containing omit value."); case ANY_VALUE: case ANY_OR_OMIT: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank containing */? value."); case COMPLEMENTED_LIST: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank containing complemented list."); case CONJUNCTION_MATCH: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank containing a conjunction list match."); case IMPLICATION_MATCH: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank containing an implication match."); case DYNAMIC_MATCH: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsBank containing a dynamic match."); default: TTCN_error("Performing sizeof() operation on an uninitialized/unsupported template of type @RSRES.JsBank."); } return 0; } void JsBank_template::log() const { switch (template_selection) { case SPECIFIC_VALUE: TTCN_Logger::log_event_str("{ peer := "); single_value->field_peer.log(); TTCN_Logger::log_event_str(", state := "); single_value->field_state.log(); TTCN_Logger::log_event_str(", component_id := "); single_value->field_component__id.log(); TTCN_Logger::log_event_str(", bankId := "); single_value->field_bankId.log(); TTCN_Logger::log_event_str(", numberOfSlots := "); single_value->field_numberOfSlots.log(); TTCN_Logger::log_event_str(" }"); break; case COMPLEMENTED_LIST: TTCN_Logger::log_event_str("complement"); case CONJUNCTION_MATCH: if (template_selection == CONJUNCTION_MATCH) { TTCN_Logger::log_event_str("conjunct"); } case VALUE_LIST: TTCN_Logger::log_char('('); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) { if (list_count > 0) TTCN_Logger::log_event_str(", "); value_list.list_value[list_count].log(); } TTCN_Logger::log_char(')'); break; case IMPLICATION_MATCH: implication_.precondition->log(); TTCN_Logger::log_event_str(" implies "); implication_.implied_template->log(); break; case DYNAMIC_MATCH: TTCN_Logger::log_event_str("@dynamic template"); break; default: log_generic(); } log_ifpresent(); } void JsBank_template::log_match(const JsBank& match_value, boolean legacy) const { if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){ if(match(match_value, legacy)){ TTCN_Logger::print_logmatch_buffer(); TTCN_Logger::log_event_str(" matched"); } else{ if (template_selection == SPECIFIC_VALUE) { size_t previous_size = TTCN_Logger::get_logmatch_buffer_len(); if(!single_value->field_peer.match(match_value.peer(), legacy)){ TTCN_Logger::log_logmatch_info(".peer"); single_value->field_peer.log_match(match_value.peer(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } if(!single_value->field_state.match(match_value.state(), legacy)){ TTCN_Logger::log_logmatch_info(".state"); single_value->field_state.log_match(match_value.state(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } if(!single_value->field_component__id.match(match_value.component__id(), legacy)){ TTCN_Logger::log_logmatch_info(".component_id"); single_value->field_component__id.log_match(match_value.component__id(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } if(!single_value->field_bankId.match(match_value.bankId(), legacy)){ TTCN_Logger::log_logmatch_info(".bankId"); single_value->field_bankId.log_match(match_value.bankId(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } if(!single_value->field_numberOfSlots.match(match_value.numberOfSlots(), legacy)){ TTCN_Logger::log_logmatch_info(".numberOfSlots"); single_value->field_numberOfSlots.log_match(match_value.numberOfSlots(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } }else { TTCN_Logger::print_logmatch_buffer(); match_value.log(); TTCN_Logger::log_event_str(" with "); log(); TTCN_Logger::log_event_str(" unmatched"); } } return; } if (template_selection == SPECIFIC_VALUE) { TTCN_Logger::log_event_str("{ peer := "); single_value->field_peer.log_match(match_value.peer(), legacy); TTCN_Logger::log_event_str(", state := "); single_value->field_state.log_match(match_value.state(), legacy); TTCN_Logger::log_event_str(", component_id := "); single_value->field_component__id.log_match(match_value.component__id(), legacy); TTCN_Logger::log_event_str(", bankId := "); single_value->field_bankId.log_match(match_value.bankId(), legacy); TTCN_Logger::log_event_str(", numberOfSlots := "); single_value->field_numberOfSlots.log_match(match_value.numberOfSlots(), legacy); TTCN_Logger::log_event_str(" }"); } else { match_value.log(); TTCN_Logger::log_event_str(" with "); log(); if (match(match_value, legacy)) TTCN_Logger::log_event_str(" matched"); else TTCN_Logger::log_event_str(" unmatched"); } } void JsBank_template::encode_text(Text_Buf& text_buf) const { encode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value->field_peer.encode_text(text_buf); single_value->field_state.encode_text(text_buf); single_value->field_component__id.encode_text(text_buf); single_value->field_bankId.encode_text(text_buf); single_value->field_numberOfSlots.encode_text(text_buf); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: text_buf.push_int(value_list.n_values); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].encode_text(text_buf); break; default: TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of type @RSRES.JsBank."); } } void JsBank_template::decode_text(Text_Buf& text_buf) { clean_up(); decode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value = new single_value_struct; single_value->field_peer.decode_text(text_buf); single_value->field_state.decode_text(text_buf); single_value->field_component__id.decode_text(text_buf); single_value->field_bankId.decode_text(text_buf); single_value->field_numberOfSlots.decode_text(text_buf); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: value_list.n_values = text_buf.pull_int().get_val(); value_list.list_value = new JsBank_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].decode_text(text_buf); break; default: TTCN_error("Text decoder: An unknown/unsupported selection was received in a template of type @RSRES.JsBank."); } } void JsBank_template::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_TEMPLATE, "record template"); switch (param.get_type()) { case Module_Param::MP_Omit: *this = OMIT_VALUE; break; case Module_Param::MP_Any: *this = ANY_VALUE; break; case Module_Param::MP_AnyOrNone: *this = ANY_OR_OMIT; break; case Module_Param::MP_List_Template: case Module_Param::MP_ComplementList_Template: case Module_Param::MP_ConjunctList_Template: { JsBank_template new_temp; new_temp.set_type(param.get_type()==Module_Param::MP_List_Template ? VALUE_LIST : (param.get_type() == Module_Param::MP_ConjunctList_Template ? CONJUNCTION_MATCH : COMPLEMENTED_LIST), param.get_size()); for (size_t p_i=0; p_i0 && param.get_elem(0)->get_type()!=Module_Param::MP_NotUsed) peer().set_param(*param.get_elem(0)); if (param.get_size()>1 && param.get_elem(1)->get_type()!=Module_Param::MP_NotUsed) state().set_param(*param.get_elem(1)); if (param.get_size()>2 && param.get_elem(2)->get_type()!=Module_Param::MP_NotUsed) component__id().set_param(*param.get_elem(2)); if (param.get_size()>3 && param.get_elem(3)->get_type()!=Module_Param::MP_NotUsed) bankId().set_param(*param.get_elem(3)); if (param.get_size()>4 && param.get_elem(4)->get_type()!=Module_Param::MP_NotUsed) numberOfSlots().set_param(*param.get_elem(4)); break; case Module_Param::MP_Assignment_List: { Vector value_used(param.get_size()); value_used.resize(param.get_size(), FALSE); for (size_t val_idx=0; val_idxget_id()->get_name(), "peer")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { peer().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "state")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { state().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "component_id")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { component__id().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "bankId")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { bankId().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "numberOfSlots")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { numberOfSlots().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxerror("Non existent field name in type @RSRES.JsBank: %s", curr_param->get_id()->get_name()); break; } } break; case Module_Param::MP_Implication_Template: { JsBank_template* precondition = new JsBank_template; precondition->set_param(*param.get_elem(0)); JsBank_template* implied_template = new JsBank_template; implied_template->set_param(*param.get_elem(1)); *this = JsBank_template(precondition, implied_template); } break; default: param.type_error("record template", "@RSRES.JsBank"); } is_ifpresent = param.get_ifpresent(); } void JsBank_template::check_restriction(template_res t_res, const char* t_name, boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return; switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) { case TR_OMIT: if (template_selection==OMIT_VALUE) return; case TR_VALUE: if (template_selection!=SPECIFIC_VALUE || is_ifpresent) break; single_value->field_peer.check_restriction(t_res, t_name ? t_name : "@RSRES.JsBank"); single_value->field_state.check_restriction(t_res, t_name ? t_name : "@RSRES.JsBank"); single_value->field_component__id.check_restriction(t_res, t_name ? t_name : "@RSRES.JsBank"); single_value->field_bankId.check_restriction(t_res, t_name ? t_name : "@RSRES.JsBank"); single_value->field_numberOfSlots.check_restriction(t_res, t_name ? t_name : "@RSRES.JsBank"); return; case TR_PRESENT: if (!match_omit(legacy)) return; break; default: return; } TTCN_error("Restriction `%s' on template of type %s violated.", get_res_name(t_res), t_name ? t_name : "@RSRES.JsBank"); } boolean JsBank_template::is_present(boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE; return !match_omit(legacy); } boolean JsBank_template::match_omit(boolean legacy) const { if (is_ifpresent) return TRUE; switch (template_selection) { case OMIT_VALUE: case ANY_OR_OMIT: return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match_omit() || implication_.implied_template->match_omit(); case VALUE_LIST: case COMPLEMENTED_LIST: if (legacy) { for (unsigned int l_idx=0; l_idxref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; } JsBanks::JsBanks(const JsBanks& other_value) { if (!other_value.is_bound()) TTCN_error("Copying an unbound value of type @RSRES.JsBanks."); val_ptr = other_value.val_ptr; val_ptr->ref_count++; } JsBanks::~JsBanks() { clean_up(); if (val_ptr != NULL) val_ptr = NULL; } void JsBanks::clean_up() { if (val_ptr != NULL) { if (val_ptr->ref_count > 1) { val_ptr->ref_count--; val_ptr = NULL; } else if (val_ptr->ref_count == 1) { for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) if (val_ptr->value_elements[elem_count] != NULL) delete val_ptr->value_elements[elem_count]; free_pointers((void**)val_ptr->value_elements); delete val_ptr; val_ptr = NULL; } else TTCN_error("Internal error: Invalid reference counter in a record of/set of value."); } } JsBanks& JsBanks::operator=(null_type) { clean_up(); val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; return *this; } JsBanks& JsBanks::operator=(const JsBanks& other_value) { if (other_value.val_ptr == NULL) TTCN_error("Assigning an unbound value of type @RSRES.JsBanks."); if (this != &other_value) { clean_up(); val_ptr = other_value.val_ptr; val_ptr->ref_count++; } return *this; } boolean JsBanks::operator==(null_type) const { if (val_ptr == NULL) TTCN_error("The left operand of comparison is an unbound value of type @RSRES.JsBanks."); return val_ptr->n_elements == 0 ; } boolean JsBanks::operator==(const JsBanks& other_value) const { if (val_ptr == NULL) TTCN_error("The left operand of comparison is an unbound value of type @RSRES.JsBanks."); if (other_value.val_ptr == NULL) TTCN_error("The right operand of comparison is an unbound value of type @RSRES.JsBanks."); if (val_ptr == other_value.val_ptr) return TRUE; if (val_ptr->n_elements != (other_value.val_ptr)->n_elements) return FALSE; for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++){ if (val_ptr->value_elements[elem_count] != NULL){ if ((other_value.val_ptr)->value_elements[elem_count] != NULL){ if (*val_ptr->value_elements[elem_count] != *(other_value.val_ptr)->value_elements[elem_count]) return FALSE; } else return FALSE; } else { if ((other_value.val_ptr)->value_elements[elem_count] != NULL) return FALSE; } } return TRUE; } JsBank& JsBanks::operator[](int index_value) { if (index_value < 0) TTCN_error("Accessing an element of type @RSRES.JsBanks using a negative index: %d.", index_value); if (val_ptr == NULL) { val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; } else if (val_ptr->ref_count > 1) { struct recordof_setof_struct *new_val_ptr = new recordof_setof_struct; new_val_ptr->ref_count = 1; new_val_ptr->n_elements = (index_value >= val_ptr->n_elements) ? index_value + 1 : val_ptr->n_elements; new_val_ptr->value_elements = (JsBank**)allocate_pointers(new_val_ptr->n_elements); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++){ if (val_ptr->value_elements[elem_count] != NULL){ new_val_ptr->value_elements[elem_count] = new JsBank(*(val_ptr->value_elements[elem_count])); } } clean_up(); val_ptr = new_val_ptr; } if (index_value >= val_ptr->n_elements) set_size(index_value + 1); if (val_ptr->value_elements[index_value] == NULL) { val_ptr->value_elements[index_value] = new JsBank; } return *val_ptr->value_elements[index_value]; } JsBank& JsBanks::operator[](const INTEGER& index_value) { index_value.must_bound("Using an unbound integer value for indexing a value of type @RSRES.JsBanks."); return (*this)[(int)index_value]; } const JsBank& JsBanks::operator[](int index_value) const { if (val_ptr == NULL) TTCN_error("Accessing an element in an unbound value of type @RSRES.JsBanks."); if (index_value < 0) TTCN_error("Accessing an element of type @RSRES.JsBanks using a negative index: %d.", index_value); if (index_value >= val_ptr->n_elements) TTCN_error("Index overflow in a value of type @RSRES.JsBanks: The index is %d, but the value has only %d elements.", index_value, val_ptr->n_elements); return (val_ptr->value_elements[index_value] == NULL) ? UNBOUND_ELEM : *val_ptr->value_elements[index_value]; } const JsBank& JsBanks::operator[](const INTEGER& index_value) const { index_value.must_bound("Using an unbound integer value for indexing a value of type @RSRES.JsBanks."); return (*this)[(int)index_value]; } JsBanks JsBanks::operator<<=(int rotate_count) const { return *this >>= (-rotate_count); } JsBanks JsBanks::operator<<=(const INTEGER& rotate_count) const { rotate_count.must_bound("Unbound integer operand of rotate left operator."); return *this >>= (int)(-rotate_count); } JsBanks JsBanks::operator>>=(const INTEGER& rotate_count) const { rotate_count.must_bound("Unbound integer operand of rotate right operator."); return *this >>= (int)rotate_count; } JsBanks JsBanks::operator>>=(int rotate_count) const { if (val_ptr == NULL) TTCN_error("Performing rotation operation on an unbound value of type @RSRES.JsBanks."); if (val_ptr->n_elements == 0) return *this; int rc; if (rotate_count>=0) rc = rotate_count % val_ptr->n_elements; else rc = val_ptr->n_elements - ((-rotate_count) % val_ptr->n_elements); if (rc == 0) return *this; JsBanks ret_val; ret_val.set_size(val_ptr->n_elements); for (int i=0; in_elements; i++) { if (val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[(i+rc)%val_ptr->n_elements] =new JsBank(*val_ptr->value_elements[i]); } } return ret_val; } JsBanks JsBanks::operator+(const JsBanks& other_value) const { if (val_ptr == NULL || other_value.val_ptr == NULL) TTCN_error("Unbound operand of @RSRES.JsBanks concatenation."); if (val_ptr->n_elements == 0) return other_value; if (other_value.val_ptr->n_elements == 0) return *this; JsBanks ret_val; ret_val.set_size(val_ptr->n_elements+other_value.val_ptr->n_elements); for (int i=0; in_elements; i++) { if (val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i] = new JsBank(*val_ptr->value_elements[i]); } } for (int i=0; in_elements; i++) { if (other_value.val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i+val_ptr->n_elements] = new JsBank(*other_value.val_ptr->value_elements[i]); } } return ret_val; } JsBanks JsBanks::substr(int index, int returncount) const { if (val_ptr == NULL) TTCN_error("The first argument of substr() is an unbound value of type @RSRES.JsBanks."); check_substr_arguments(val_ptr->n_elements, index, returncount, "@RSRES.JsBanks","element"); JsBanks ret_val; ret_val.set_size(returncount); for (int i=0; ivalue_elements[i+index] != NULL) { ret_val.val_ptr->value_elements[i] = new JsBank(*val_ptr->value_elements[i+index]); } } return ret_val; } JsBanks JsBanks::replace(int index, int len, const JsBanks& repl) const { if (val_ptr == NULL) TTCN_error("The first argument of replace() is an unbound value of type @RSRES.JsBanks."); if (repl.val_ptr == NULL) TTCN_error("The fourth argument of replace() is an unbound value of type @RSRES.JsBanks."); check_replace_arguments(val_ptr->n_elements, index, len, "@RSRES.JsBanks","element"); JsBanks ret_val; ret_val.set_size(val_ptr->n_elements + repl.val_ptr->n_elements - len); for (int i = 0; i < index; i++) { if (val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i] = new JsBank(*val_ptr->value_elements[i]); } } for (int i = 0; i < repl.val_ptr->n_elements; i++) { if (repl.val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i+index] = new JsBank(*repl.val_ptr->value_elements[i]); } } for (int i = 0; i < val_ptr->n_elements - index - len; i++) { if (val_ptr->value_elements[index+i+len] != NULL) { ret_val.val_ptr->value_elements[index+i+repl.val_ptr->n_elements] = new JsBank(*val_ptr->value_elements[index+i+len]); } } return ret_val; } JsBanks JsBanks::replace(int index, int len, const JsBanks_template& repl) const { if (!repl.is_value()) TTCN_error("The fourth argument of function replace() is a template with non-specific value."); return replace(index, len, repl.valueof()); } void JsBanks::set_size(int new_size) { if (new_size < 0) TTCN_error("Internal error: Setting a negative size for a value of type @RSRES.JsBanks."); if (val_ptr == NULL) { val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; } else if (val_ptr->ref_count > 1) { struct recordof_setof_struct *new_val_ptr = new recordof_setof_struct; new_val_ptr->ref_count = 1; new_val_ptr->n_elements = (new_size < val_ptr->n_elements) ? new_size : val_ptr->n_elements; new_val_ptr->value_elements = (JsBank**)allocate_pointers(new_val_ptr->n_elements); for (int elem_count = 0; elem_count < new_val_ptr->n_elements; elem_count++) { if (val_ptr->value_elements[elem_count] != NULL){ new_val_ptr->value_elements[elem_count] = new JsBank(*(val_ptr->value_elements[elem_count])); } } clean_up(); val_ptr = new_val_ptr; } if (new_size > val_ptr->n_elements) { val_ptr->value_elements = (JsBank**)reallocate_pointers((void**)val_ptr->value_elements, val_ptr->n_elements, new_size); #ifdef TITAN_MEMORY_DEBUG_SET_RECORD_OF if((val_ptr->n_elements/1000)!=(new_size/1000)) TTCN_warning("New size of type @RSRES.JsBanks: %d",new_size); #endif val_ptr->n_elements = new_size; } else if (new_size < val_ptr->n_elements) { for (int elem_count = new_size; elem_count < val_ptr->n_elements; elem_count++) if (val_ptr->value_elements[elem_count] != NULL)delete val_ptr->value_elements[elem_count]; val_ptr->value_elements = (JsBank**)reallocate_pointers((void**)val_ptr->value_elements, val_ptr->n_elements, new_size); val_ptr->n_elements = new_size; } } boolean JsBanks::is_value() const { if (val_ptr == NULL) return FALSE; for(int i = 0; i < val_ptr->n_elements; ++i) { if (val_ptr->value_elements[i] == NULL || !val_ptr->value_elements[i]->is_value()) return FALSE; } return TRUE; } int JsBanks::size_of() const { if (val_ptr == NULL) TTCN_error("Performing sizeof operation on an unbound value of type @RSRES.JsBanks."); return val_ptr->n_elements; } int JsBanks::lengthof() const { if (val_ptr == NULL) TTCN_error("Performing lengthof operation on an unbound value of type @RSRES.JsBanks."); for (int my_length=val_ptr->n_elements; my_length>0; my_length--) if (val_ptr->value_elements[my_length-1] != NULL) return my_length; return 0; } void JsBanks::log() const { if (val_ptr == NULL) {; TTCN_Logger::log_event_unbound(); return; } switch (val_ptr->n_elements) { case 0: TTCN_Logger::log_event_str("{ }"); break; default: TTCN_Logger::log_event_str("{ "); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); (*this)[elem_count].log(); } TTCN_Logger::log_event_str(" }"); } } void JsBanks::set_implicit_omit() { if (val_ptr == NULL) return; for (int i = 0; i < val_ptr->n_elements; i++) { if (val_ptr->value_elements[i] != NULL) val_ptr->value_elements[i]->set_implicit_omit(); } } void JsBanks::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_VALUE|Module_Param::BC_LIST, "record of value"); switch (param.get_operation_type()) { case Module_Param::OT_ASSIGN: if (param.get_type()==Module_Param::MP_Value_List && param.get_size()==0) { *this = NULL_VALUE; return; } switch (param.get_type()) { case Module_Param::MP_Value_List: set_size(param.get_size()); for (size_t i=0; iget_type()!=Module_Param::MP_NotUsed) { (*this)[i].set_param(*curr); if (!(*this)[i].is_bound()) { delete val_ptr->value_elements[i]; val_ptr->value_elements[i] = NULL; } } } break; case Module_Param::MP_Indexed_List: for (size_t i=0; iget_id()->get_index()].set_param(*curr); if (!(*this)[curr->get_id()->get_index()].is_bound()) { delete val_ptr->value_elements[curr->get_id()->get_index()]; val_ptr->value_elements[curr->get_id()->get_index()] = NULL; } } break; default: param.type_error("record of value", "@RSRES.JsBanks"); } break; case Module_Param::OT_CONCAT: switch (param.get_type()) { case Module_Param::MP_Value_List: { if (!is_bound()) *this = NULL_VALUE; int start_idx = lengthof(); for (size_t i=0; iget_type()!=Module_Param::MP_NotUsed)) { (*this)[start_idx+(int)i].set_param(*curr); } } } break; case Module_Param::MP_Indexed_List: param.error("Cannot concatenate an indexed value list"); break; default: param.type_error("record of value", "@RSRES.JsBanks"); } break; default: TTCN_error("Internal error: Unknown operation type."); } } void JsBanks::encode_text(Text_Buf& text_buf) const { if (val_ptr == NULL) TTCN_error("Text encoder: Encoding an unbound value of type @RSRES.JsBanks."); text_buf.push_int(val_ptr->n_elements); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) (*this)[elem_count].encode_text(text_buf); } void JsBanks::decode_text(Text_Buf& text_buf) { clean_up(); val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = text_buf.pull_int().get_val(); if (val_ptr->n_elements < 0) TTCN_error("Text decoder: Negative size was received for a value of type @RSRES.JsBanks."); val_ptr->value_elements = (JsBank**)allocate_pointers(val_ptr->n_elements); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) { val_ptr->value_elements[elem_count] = new JsBank; val_ptr->value_elements[elem_count]->decode_text(text_buf); } } void JsBanks::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) const { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name); unsigned BER_coding=va_arg(pvar, unsigned); BER_encode_chk_coding(BER_coding); ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding); tlv->put_in_buffer(p_buf); ASN_BER_TLV_t::destruct(tlv); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); RAW_enc_tr_pos rp; rp.level=0; rp.pos=NULL; RAW_enc_tree root(FALSE, NULL, &rp, 1, p_td.raw); RAW_encode(p_td, root); root.put_to_buf(p_buf); break;} case TTCN_EncDec::CT_TEXT: { TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); TEXT_encode(p_td,p_buf); break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XER_encode(*(p_td.xer),p_buf, XER_coding, 0, 0, 0); p_buf.put_c('\n'); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok(va_arg(pvar, int) != 0); JSON_encode(p_td, tok, FALSE); p_buf.put_s(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-encoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_encode(p_td, p_buf); break;} default: TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name); } va_end(pvar); } void JsBanks::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name); unsigned L_form=va_arg(pvar, unsigned); ASN_BER_TLV_t tlv; BER_decode_str2TLV(p_buf, tlv, L_form); BER_decode_TLV(p_td, tlv, L_form); if(tlv.isComplete) p_buf.increase_pos(tlv.get_len()); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); raw_order_t r_order; switch(p_td.raw->top_bit_order) { case TOP_BIT_LEFT: r_order=ORDER_LSB; break; case TOP_BIT_RIGHT: default: r_order=ORDER_MSB; } int rawr = RAW_decode(p_td, p_buf, p_buf.get_len()*8, r_order); if(rawr<0) switch (-rawr) { case TTCN_EncDec::ET_INCOMPL_MSG: case TTCN_EncDec::ET_LEN_ERR: ec.error((TTCN_EncDec::error_type_t)-rawr, "Can not decode type '%s', because incomplete message was received", p_td.name); break; case 1: default: ec.error(TTCN_EncDec::ET_INVAL_MSG, "Can not decode type '%s', because invalid message was received", p_td.name); break; } break;} case TTCN_EncDec::CT_TEXT: { Limit_Token_List limit; TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); const unsigned char *b_data=p_buf.get_data(); int null_added=0; if(b_data[p_buf.get_len()-1]!='\0'){ null_added=1; p_buf.set_pos(p_buf.get_len()); p_buf.put_zero(8,ORDER_LSB); p_buf.rewind(); } if(TEXT_decode(p_td,p_buf,limit)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); if(null_added){ size_t actpos=p_buf.get_pos(); p_buf.set_pos(p_buf.get_len()-1); p_buf.cut_end(); p_buf.set_pos(actpos); } break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XmlReaderWrap reader(p_buf); for (int rd_ok=reader.Read(); rd_ok==1; rd_ok=reader.Read()) { if (reader.NodeType() == XML_READER_TYPE_ELEMENT) break; } XER_decode(*(p_td.xer), reader, XER_coding | XER_TOPLEVEL, XER_NONE, 0); size_t bytes = reader.ByteConsumed(); p_buf.set_pos(bytes); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok((const char*)p_buf.get_data(), p_buf.get_len()); if(JSON_decode(p_td, tok, FALSE, FALSE)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); p_buf.set_pos(tok.get_buf_pos()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-decoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_struct p_oer; OER_decode(p_td, p_buf, p_oer); break;} default: TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name); } va_end(pvar); } int JsBanks::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean) const { if (!is_bound()) { TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "Encoding an unbound value of type @RSRES.JsBanks."); return -1; } int enc_len = p_tok.put_next_token(p_td.json->as_map ? JSON_TOKEN_OBJECT_START : JSON_TOKEN_ARRAY_START, NULL); for (int i = 0; i < val_ptr->n_elements; ++i) { if (p_td.json->metainfo_unbound && !(*this)[i].is_bound()) { enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL); enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "metainfo []"); enc_len += p_tok.put_next_token(JSON_TOKEN_STRING, "\"unbound\""); enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_END, NULL); } else { int ret_val = (*this)[i].JSON_encode(*p_td.oftype_descr, p_tok, p_td.json->as_map); if (0 > ret_val) break; enc_len += ret_val; } } enc_len += p_tok.put_next_token(p_td.json->as_map ? JSON_TOKEN_OBJECT_END : JSON_TOKEN_ARRAY_END, NULL); return enc_len; } int JsBanks::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent, boolean, int) { if (p_td.json->default_value.type == JD_STANDARD && 0 == p_tok.get_buffer_length()) { *this = *static_cast(p_td.json->default_value.val); return 0; } if (p_td.json->default_value.type == JD_LEGACY && 0 == p_tok.get_buffer_length()) { set_size(0); return strlen(p_td.json->default_value.str); } json_token_t token = JSON_TOKEN_NONE; size_t dec_len = p_tok.get_next_token(&token, NULL, NULL); if (JSON_TOKEN_ERROR == token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } else if ((!p_td.json->as_map && JSON_TOKEN_ARRAY_START != token) || (p_td.json->as_map && JSON_TOKEN_OBJECT_START != token)) { return JSON_ERROR_INVALID_TOKEN; } set_size(0); for (int nof_elements = 0; TRUE; ++nof_elements) { size_t buf_pos = p_tok.get_buf_pos(); size_t ret_val; if (p_td.json->metainfo_unbound) { ret_val = p_tok.get_next_token(&token, NULL, NULL); if (JSON_TOKEN_OBJECT_START == token) { char* value = NULL; size_t value_len = 0; ret_val += p_tok.get_next_token(&token, &value, &value_len); if (JSON_TOKEN_NAME == token && 11 == value_len && 0 == strncmp(value, "metainfo []", 11)) { ret_val += p_tok.get_next_token(&token, &value, &value_len); if (JSON_TOKEN_STRING == token && 9 == value_len && 0 == strncmp(value, "\"unbound\"", 9)) { ret_val = p_tok.get_next_token(&token, NULL, NULL); if (JSON_TOKEN_OBJECT_END == token) { dec_len += ret_val; continue; } } } } p_tok.set_buf_pos(buf_pos); } JsBank* val = new JsBank; int ret_val2 = val->JSON_decode(*p_td.oftype_descr, p_tok, p_silent, p_td.json->as_map); if (JSON_ERROR_INVALID_TOKEN == ret_val2) { p_tok.set_buf_pos(buf_pos); delete val; break; } else if (JSON_ERROR_FATAL == ret_val2) { delete val; if (p_silent) { clean_up(); } return JSON_ERROR_FATAL; } val_ptr->value_elements = (JsBank**)reallocate_pointers( (void**)val_ptr->value_elements, val_ptr->n_elements, nof_elements + 1); val_ptr->value_elements[nof_elements] = val; val_ptr->n_elements = nof_elements + 1; dec_len += (size_t)ret_val2; } dec_len += p_tok.get_next_token(&token, NULL, NULL); if ((!p_td.json->as_map && JSON_TOKEN_ARRAY_END != token) || (p_td.json->as_map && JSON_TOKEN_OBJECT_END != token)) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_REC_OF_END_TOKEN_ERROR, ""); if (p_silent) { clean_up(); } return JSON_ERROR_FATAL; } return (int)dec_len; } void JsBanks_template::copy_value(const JsBanks& other_value) { if (!other_value.is_bound()) TTCN_error("Initialization of a template of type @RSRES.JsBanks with an unbound value."); single_value.n_elements = other_value.size_of(); single_value.value_elements = (JsBank_template**)allocate_pointers(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (other_value[elem_count].is_bound()) { single_value.value_elements[elem_count] = new JsBank_template(other_value[elem_count]); } else { single_value.value_elements[elem_count] = new JsBank_template; } } set_selection(SPECIFIC_VALUE); } void JsBanks_template::copy_template(const JsBanks_template& other_value) { switch (other_value.template_selection) { case SPECIFIC_VALUE: single_value.n_elements = other_value.single_value.n_elements; single_value.value_elements = (JsBank_template**)allocate_pointers(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (UNINITIALIZED_TEMPLATE != other_value.single_value.value_elements[elem_count]->get_selection()) { single_value.value_elements[elem_count] = new JsBank_template(*other_value.single_value.value_elements[elem_count]); } else { single_value.value_elements[elem_count] = new JsBank_template; } } case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = other_value.value_list.n_values; value_list.list_value = new JsBanks_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]); break; case IMPLICATION_MATCH: implication_.precondition = new JsBanks_template(*other_value.implication_.precondition); implication_.implied_template = new JsBanks_template(*other_value.implication_.implied_template); break; case DYNAMIC_MATCH: dyn_match = other_value.dyn_match; dyn_match->ref_count++; break; default: TTCN_error("Copying an uninitialized/unsupported template of type @RSRES.JsBanks."); break; } set_selection(other_value); } boolean JsBanks_template::match_function_specific(const Base_Type *value_ptr, int value_index, const Restricted_Length_Template *template_ptr, int template_index, boolean legacy) { if (value_index >= 0) return ((const JsBanks_template*)template_ptr)->single_value.value_elements[template_index]->match((*(const JsBanks*)value_ptr)[value_index], legacy); else return ((const JsBanks_template*)template_ptr)->single_value.value_elements[template_index]->is_any_or_omit(); } JsBanks_template::JsBanks_template() { } JsBanks_template::JsBanks_template(template_sel other_value) : Base_Record_Of_Template(other_value) { check_single_selection(other_value); } JsBanks_template::JsBanks_template(null_type) : Base_Record_Of_Template(SPECIFIC_VALUE) { single_value.n_elements = 0; single_value.value_elements = NULL; } JsBanks_template::JsBanks_template(const JsBanks& other_value) { copy_value(other_value); } JsBanks_template::JsBanks_template(const OPTIONAL& other_value) { switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsBanks&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Creating a template of type @RSRES.JsBanks from an unbound optional field."); } } JsBanks_template::JsBanks_template(JsBanks_template* p_precondition, JsBanks_template* p_implied_template) : Base_Record_Of_Template(IMPLICATION_MATCH) { implication_.precondition = p_precondition; implication_.implied_template = p_implied_template; } JsBanks_template::JsBanks_template(Dynamic_Match_Interface* p_dyn_match) : Base_Record_Of_Template(DYNAMIC_MATCH) { dyn_match = new dynmatch_struct; dyn_match->ptr = p_dyn_match; dyn_match->ref_count = 1; } JsBanks_template::JsBanks_template(const JsBanks_template& other_value) : Base_Record_Of_Template() { copy_template(other_value); } JsBanks_template::~JsBanks_template() { clean_up(); } void JsBanks_template::clean_up() { switch (template_selection) { case SPECIFIC_VALUE: for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) delete single_value.value_elements[elem_count]; free_pointers((void**)single_value.value_elements); break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: delete [] value_list.list_value; break; case IMPLICATION_MATCH: delete implication_.precondition; delete implication_.implied_template; break; case DYNAMIC_MATCH: dyn_match->ref_count--; if (dyn_match->ref_count == 0) { delete dyn_match->ptr; delete dyn_match; } break; default: break; } template_selection = UNINITIALIZED_TEMPLATE; } JsBanks_template& JsBanks_template::operator=(template_sel other_value) { check_single_selection(other_value); clean_up(); set_selection(other_value); return *this; } JsBanks_template& JsBanks_template::operator=(null_type) { clean_up(); set_selection(SPECIFIC_VALUE); single_value.n_elements = 0; single_value.value_elements = NULL; return *this; } JsBanks_template& JsBanks_template::operator=(const JsBanks& other_value) { clean_up(); copy_value(other_value); return *this; } JsBanks_template& JsBanks_template::operator=(const OPTIONAL& other_value) { clean_up(); switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsBanks&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Assignment of an unbound optional field to a template of type @RSRES.JsBanks."); } return *this; } JsBanks_template& JsBanks_template::operator=(const JsBanks_template& other_value) { if (&other_value != this) { clean_up(); copy_template(other_value); } return *this; } JsBank_template& JsBanks_template::operator[](int index_value) { if (index_value < 0) TTCN_error("Accessing an element of a template for type @RSRES.JsBanks using a negative index: %d.", index_value); switch (template_selection) { case SPECIFIC_VALUE: if(index_value < single_value.n_elements) break; // no break case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: case UNINITIALIZED_TEMPLATE: set_size(index_value + 1); break; default: TTCN_error("Accessing an element of a non-specific template for type @RSRES.JsBanks."); break; } return *single_value.value_elements[index_value]; } JsBank_template& JsBanks_template::operator[](const INTEGER& index_value) { index_value.must_bound("Using an unbound integer value for indexing a template of type @RSRES.JsBanks."); return (*this)[(int)index_value]; } const JsBank_template& JsBanks_template::operator[](int index_value) const { if (index_value < 0) TTCN_error("Accessing an element of a template for type @RSRES.JsBanks using a negative index: %d.", index_value); if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing an element of a non-specific template for type @RSRES.JsBanks."); if (index_value >= single_value.n_elements) TTCN_error("Index overflow in a template of type @RSRES.JsBanks: The index is %d, but the template has only %d elements.", index_value, single_value.n_elements); return *single_value.value_elements[index_value]; } const JsBank_template& JsBanks_template::operator[](const INTEGER& index_value) const { index_value.must_bound("Using an unbound integer value for indexing a template of type @RSRES.JsBanks."); return (*this)[(int)index_value]; } void JsBanks_template::set_size(int new_size) { if (new_size < 0) TTCN_error("Internal error: Setting a negative size for a template of type @RSRES.JsBanks."); template_sel old_selection = template_selection; if (old_selection != SPECIFIC_VALUE) { clean_up(); set_selection(SPECIFIC_VALUE); single_value.n_elements = 0; single_value.value_elements = NULL; } if (new_size > single_value.n_elements) { single_value.value_elements = (JsBank_template**)reallocate_pointers((void**)single_value.value_elements, single_value.n_elements, new_size); if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) { for (int elem_count = single_value.n_elements; elem_count < new_size; elem_count++) single_value.value_elements[elem_count] = new JsBank_template(ANY_VALUE); } else { for (int elem_count = single_value.n_elements; elem_count < new_size; elem_count++) single_value.value_elements[elem_count] = new JsBank_template; } single_value.n_elements = new_size; } else if (new_size < single_value.n_elements) { for (int elem_count = new_size; elem_count < single_value.n_elements; elem_count++) delete single_value.value_elements[elem_count]; single_value.value_elements = (JsBank_template**)reallocate_pointers((void**)single_value.value_elements, single_value.n_elements, new_size); single_value.n_elements = new_size; } } int JsBanks_template::n_elem() const { switch (template_selection) { case SPECIFIC_VALUE: return single_value.n_elements; break; case VALUE_LIST: return value_list.n_values; break; default: TTCN_error("Performing n_elem"); } } int JsBanks_template::size_of(boolean is_size) const { const char* op_name = is_size ? "size" : "length"; int min_size; boolean has_any_or_none; if (is_ifpresent) TTCN_error("Performing %sof() operation on a template of type @RSRES.JsBanks which has an ifpresent attribute.", op_name); switch (template_selection) { case SPECIFIC_VALUE: { min_size = 0; has_any_or_none = FALSE; int elem_count = single_value.n_elements; if (!is_size) { while (elem_count>0 && !single_value.value_elements[elem_count-1]->is_bound()) elem_count--; } for (int i=0; iget_selection()) { case OMIT_VALUE: TTCN_error("Performing %sof() operation on a template of type @RSRES.JsBanks containing omit element.", op_name); case ANY_OR_OMIT: has_any_or_none = TRUE; break; default: min_size++; break; } } } break; case OMIT_VALUE: TTCN_error("Performing %sof() operation on a template of type @RSRES.JsBanks containing omit value.", op_name); case ANY_VALUE: case ANY_OR_OMIT: min_size = 0; has_any_or_none = TRUE; break; case VALUE_LIST: { if (value_list.n_values<1) TTCN_error("Performing %sof() operation on a template of type @RSRES.JsBanks containing an empty list.", op_name); int item_size = value_list.list_value[0].size_of(is_size); for (unsigned int i = 1; i < value_list.n_values; i++) { if (value_list.list_value[i].size_of(is_size)!=item_size) TTCN_error("Performing %sof() operation on a template of type @RSRES.JsBanks containing a value list with different sizes.", op_name); } min_size = item_size; has_any_or_none = FALSE; break; } case COMPLEMENTED_LIST: TTCN_error("Performing %sof() operation on a template of type @RSRES.JsBanks containing complemented list.", op_name); default: TTCN_error("Performing %sof() operation on an uninitialized/unsupported template of type @RSRES.JsBanks.", op_name); } return check_section_is_single(min_size, has_any_or_none, op_name, "a", "template of type @RSRES.JsBanks"); } boolean JsBanks_template::match(const JsBanks& other_value, boolean legacy) const { if (!other_value.is_bound()) return FALSE; int value_length = other_value.size_of(); if (!match_length(value_length)) return FALSE; switch (template_selection) { case SPECIFIC_VALUE: return match_record_of(&other_value, value_length, this, single_value.n_elements, match_function_specific, legacy); case OMIT_VALUE: return FALSE; case ANY_VALUE: case ANY_OR_OMIT: return TRUE; case VALUE_LIST: case COMPLEMENTED_LIST: for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) if (value_list.list_value[list_count].match(other_value, legacy)) return template_selection == VALUE_LIST; return template_selection == COMPLEMENTED_LIST; case CONJUNCTION_MATCH: for (unsigned int i = 0; i < value_list.n_values; i++) { if (!value_list.list_value[i].match(other_value)) { return FALSE; } } return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match(other_value) || implication_.implied_template->match(other_value); case DYNAMIC_MATCH: return dyn_match->ptr->match(other_value); default: TTCN_error("Matching with an uninitialized/unsupported template of type @RSRES.JsBanks."); } return FALSE; } boolean JsBanks_template::is_value() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) return FALSE; for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) if (!single_value.value_elements[elem_count]->is_value()) return FALSE; return TRUE; } JsBanks JsBanks_template::valueof() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) TTCN_error("Performing a valueof or send operation on a non-specific template of type @RSRES.JsBanks."); JsBanks ret_val; ret_val.set_size(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) if (single_value.value_elements[elem_count]->is_bound()) { ret_val[elem_count] = single_value.value_elements[elem_count]->valueof(); } return ret_val; } JsBanks JsBanks_template::substr(int index, int returncount) const { if (!is_value()) TTCN_error("The first argument of function substr() is a template with non-specific value."); return valueof().substr(index, returncount); } JsBanks JsBanks_template::replace(int index, int len, const JsBanks_template& repl) const { if (!is_value()) TTCN_error("The first argument of function replace() is a template with non-specific value."); if (!repl.is_value()) TTCN_error("The fourth argument of function replace() is a template with non-specific value."); return valueof().replace(index, len, repl.valueof()); } JsBanks JsBanks_template::replace(int index, int len, const JsBanks& repl) const { if (!is_value()) TTCN_error("The first argument of function replace() is a template with non-specific value."); return valueof().replace(index, len, repl); } void JsBanks_template::set_type(template_sel template_type, unsigned int list_length) { clean_up(); switch (template_type) { case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = list_length; value_list.list_value = new JsBanks_template[list_length]; break; default: TTCN_error("Internal error: Setting an invalid type for a template of type @RSRES.JsBanks."); } set_selection(template_type); } JsBanks_template& JsBanks_template::list_item(unsigned int list_index) { if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST && template_selection != CONJUNCTION_MATCH) TTCN_error("Internal error: Accessing a list element of a non-list template of type @RSRES.JsBanks."); if (list_index >= value_list.n_values) TTCN_error("Internal error: Index overflow in a value list template of type @RSRES.JsBanks."); return value_list.list_value[list_index]; } void JsBanks_template::log() const { switch (template_selection) { case SPECIFIC_VALUE: if (single_value.n_elements > 0) { TTCN_Logger::log_event_str("{ "); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); if (permutation_starts_at(elem_count)) TTCN_Logger::log_event_str("permutation("); single_value.value_elements[elem_count]->log(); if (permutation_ends_at(elem_count)) TTCN_Logger::log_char(')'); } TTCN_Logger::log_event_str(" }"); } else TTCN_Logger::log_event_str("{ }"); break; case COMPLEMENTED_LIST: TTCN_Logger::log_event_str("complement"); case CONJUNCTION_MATCH: if (template_selection == CONJUNCTION_MATCH) { TTCN_Logger::log_event_str("conjunct"); } case VALUE_LIST: TTCN_Logger::log_char('('); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) { if (list_count > 0) TTCN_Logger::log_event_str(", "); value_list.list_value[list_count].log(); } TTCN_Logger::log_char(')'); break; case IMPLICATION_MATCH: implication_.precondition->log(); TTCN_Logger::log_event_str(" implies "); implication_.implied_template->log(); break; case DYNAMIC_MATCH: TTCN_Logger::log_event_str("@dynamic template"); break; default: log_generic(); } log_restricted(); log_ifpresent(); } void JsBanks_template::log_match(const JsBanks& match_value, boolean legacy) const { if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){ if(match(match_value, legacy)){ TTCN_Logger::print_logmatch_buffer(); TTCN_Logger::log_event_str(" matched"); }else{ if (template_selection == SPECIFIC_VALUE && single_value.n_elements > 0 && get_number_of_permutations() == 0 && single_value.n_elements == match_value.size_of()) { size_t previous_size = TTCN_Logger::get_logmatch_buffer_len(); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if(!single_value.value_elements[elem_count]->match(match_value[elem_count], legacy)){ TTCN_Logger::log_logmatch_info("[%d]", elem_count); single_value.value_elements[elem_count]->log_match(match_value[elem_count], legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } } log_match_length(single_value.n_elements); } else { TTCN_Logger::print_logmatch_buffer(); match_value.log(); TTCN_Logger::log_event_str(" with "); log(); TTCN_Logger::log_event_str(" unmatched"); } } return; } if (template_selection == SPECIFIC_VALUE && single_value.n_elements > 0 && get_number_of_permutations() == 0 && single_value.n_elements == match_value.size_of()) { TTCN_Logger::log_event_str("{ "); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); single_value.value_elements[elem_count]->log_match(match_value[elem_count], legacy); } TTCN_Logger::log_event_str(" }"); log_match_length(single_value.n_elements); } else { match_value.log(); TTCN_Logger::log_event_str(" with "); log(); if (match(match_value, legacy)) TTCN_Logger::log_event_str(" matched"); else TTCN_Logger::log_event_str(" unmatched"); } } void JsBanks_template::encode_text(Text_Buf& text_buf) const { encode_text_permutation(text_buf); switch (template_selection) { case SPECIFIC_VALUE: text_buf.push_int(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) single_value.value_elements[elem_count]->encode_text(text_buf); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: text_buf.push_int(value_list.n_values); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].encode_text(text_buf); break; default: TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of type @RSRES.JsBanks."); } } void JsBanks_template::decode_text(Text_Buf& text_buf) { clean_up(); decode_text_permutation(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value.n_elements = text_buf.pull_int().get_val(); if (single_value.n_elements < 0) TTCN_error("Text decoder: Negative size was received for a template of type @RSRES.JsBanks."); single_value.value_elements = (JsBank_template**)allocate_pointers(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { single_value.value_elements[elem_count] = new JsBank_template; single_value.value_elements[elem_count]->decode_text(text_buf); } case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: value_list.n_values = text_buf.pull_int().get_val(); value_list.list_value = new JsBanks_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].decode_text(text_buf); break; default: TTCN_error("Text decoder: An unknown/unsupported selection was received for a template of type @RSRES.JsBanks."); } } boolean JsBanks_template::is_present(boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE; return !match_omit(legacy); } boolean JsBanks_template::match_omit(boolean legacy) const { if (is_ifpresent) return TRUE; switch (template_selection) { case OMIT_VALUE: case ANY_OR_OMIT: return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match_omit() || implication_.implied_template->match_omit(); case VALUE_LIST: case COMPLEMENTED_LIST: if (legacy) { for (unsigned int i=0; iget_id()->get_index())].set_param(*param.get_elem(p_i)); } break; case Module_Param::MP_Value_List: { set_size(param.get_size()); int curr_idx = 0; for (size_t p_i=0; p_iget_type()) { case Module_Param::MP_NotUsed: curr_idx++; break; case Module_Param::MP_Permutation_Template: { int perm_start_idx = curr_idx; Module_Param* param_i = param.get_elem(p_i); for (size_t perm_i=0; perm_iget_size(); perm_i++) { (*this)[curr_idx].set_param(*(param_i->get_elem(perm_i))); curr_idx++; } int perm_end_idx = curr_idx - 1; add_permutation(perm_start_idx, perm_end_idx); } break; default: (*this)[curr_idx].set_param(*param.get_elem(p_i)); curr_idx++; } } } break; case Module_Param::MP_Implication_Template: { JsBanks_template* precondition = new JsBanks_template; precondition->set_param(*param.get_elem(0)); JsBanks_template* implied_template = new JsBanks_template; implied_template->set_param(*param.get_elem(1)); *this = JsBanks_template(precondition, implied_template); } break; default: param.type_error("record of template", "@RSRES.JsBanks"); } is_ifpresent = param.get_ifpresent(); set_length_range(param); } void JsBanks_template::check_restriction(template_res t_res, const char* t_name, boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return; switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) { case TR_OMIT: if (template_selection==OMIT_VALUE) return; case TR_VALUE: if (template_selection!=SPECIFIC_VALUE || is_ifpresent) break; for (int i=0; icheck_restriction(t_res, t_name ? t_name : "@RSRES.JsBanks"); return; case TR_PRESENT: if (!match_omit(legacy)) return; break; default: return; } TTCN_error("Restriction `%s' on template of type %s violated.", get_res_name(t_res), t_name ? t_name : "@RSRES.JsBanks"); } boolean JsBanks_template::get_istemplate_kind(const char* type) const { if (!strcmp(type, "AnyElement")) { if (template_selection != SPECIFIC_VALUE) { return FALSE; } for (int i = 0; i < single_value.n_elements; i++) { if (single_value.value_elements[i]->get_selection() == ANY_VALUE) { return TRUE; } } return FALSE; } else if (!strcmp(type, "AnyElementsOrNone")) { if (template_selection != SPECIFIC_VALUE) { return FALSE; } for (int i = 0; i < single_value.n_elements; i++) { if (single_value.value_elements[i]->get_selection() == ANY_OR_OMIT) { return TRUE; } } return FALSE; } else if (!strcmp(type, "permutation")) { return number_of_permutations; } else if (!strcmp(type, "length")) { return length_restriction_type != NO_LENGTH_RESTRICTION; } else { return Base_Template::get_istemplate_kind(type); } } JsClient::JsClient() { } JsClient::JsClient(const CHARSTRING& par_peer, const ConnectionState& par_state, const RSPRO::ComponentIdentity& par_component__id) : field_peer(par_peer), field_state(par_state), field_component__id(par_component__id) { } JsClient::JsClient(const JsClient& other_value) { if(!other_value.is_bound()) TTCN_error("Copying an unbound value of type @RSRES.JsClient."); if (other_value.peer().is_bound()) field_peer = other_value.peer(); else field_peer.clean_up(); if (other_value.state().is_bound()) field_state = other_value.state(); else field_state.clean_up(); if (other_value.component__id().is_bound()) field_component__id = other_value.component__id(); else field_component__id.clean_up(); } void JsClient::clean_up() { field_peer.clean_up(); field_state.clean_up(); field_component__id.clean_up(); } const TTCN_Typedescriptor_t* JsClient::get_descriptor() const { return &JsClient_descr_; } JsClient& JsClient::operator=(const JsClient& other_value) { if (this != &other_value) { if(!other_value.is_bound()) TTCN_error("Assignment of an unbound value of type @RSRES.JsClient."); if (other_value.peer().is_bound()) field_peer = other_value.peer(); else field_peer.clean_up(); if (other_value.state().is_bound()) field_state = other_value.state(); else field_state.clean_up(); if (other_value.component__id().is_bound()) field_component__id = other_value.component__id(); else field_component__id.clean_up(); } return *this; } boolean JsClient::operator==(const JsClient& other_value) const { return field_peer==other_value.field_peer && field_state==other_value.field_state && field_component__id==other_value.field_component__id; } boolean JsClient::is_bound() const { return (field_peer.is_bound()) || (field_state.is_bound()) || (field_component__id.is_bound()); } boolean JsClient::is_value() const { return field_peer.is_value() && field_state.is_value() && field_component__id.is_value(); } void JsClient::log() const { if (!is_bound()) { TTCN_Logger::log_event_unbound(); return; } TTCN_Logger::log_event_str("{ peer := "); field_peer.log(); TTCN_Logger::log_event_str(", state := "); field_state.log(); TTCN_Logger::log_event_str(", component_id := "); field_component__id.log(); TTCN_Logger::log_event_str(" }"); } void JsClient::set_implicit_omit() { if (peer().is_bound()) peer().set_implicit_omit(); if (state().is_bound()) state().set_implicit_omit(); if (component__id().is_bound()) component__id().set_implicit_omit(); } void JsClient::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_VALUE, "record value"); switch (param.get_type()) { case Module_Param::MP_Value_List: if (30 && param.get_elem(0)->get_type()!=Module_Param::MP_NotUsed) peer().set_param(*param.get_elem(0)); if (param.get_size()>1 && param.get_elem(1)->get_type()!=Module_Param::MP_NotUsed) state().set_param(*param.get_elem(1)); if (param.get_size()>2 && param.get_elem(2)->get_type()!=Module_Param::MP_NotUsed) component__id().set_param(*param.get_elem(2)); break; case Module_Param::MP_Assignment_List: { Vector value_used(param.get_size()); value_used.resize(param.get_size(), FALSE); for (size_t val_idx=0; val_idxget_id()->get_name(), "peer")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { peer().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "state")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { state().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "component_id")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { component__id().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxerror("Non existent field name in type @RSRES.JsClient: %s", curr_param->get_id()->get_name()); break; } } break; default: param.type_error("record value", "@RSRES.JsClient"); } } void JsClient::encode_text(Text_Buf& text_buf) const { field_peer.encode_text(text_buf); field_state.encode_text(text_buf); field_component__id.encode_text(text_buf); } void JsClient::decode_text(Text_Buf& text_buf) { field_peer.decode_text(text_buf); field_state.decode_text(text_buf); field_component__id.decode_text(text_buf); } void JsClient::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) const { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name); unsigned BER_coding=va_arg(pvar, unsigned); BER_encode_chk_coding(BER_coding); ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding); tlv->put_in_buffer(p_buf); ASN_BER_TLV_t::destruct(tlv); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); RAW_enc_tr_pos rp; rp.level=0; rp.pos=NULL; RAW_enc_tree root(FALSE, NULL, &rp, 1, p_td.raw); RAW_encode(p_td, root); root.put_to_buf(p_buf); break;} case TTCN_EncDec::CT_TEXT: { TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); TEXT_encode(p_td,p_buf); break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XER_encode(*(p_td.xer),p_buf, XER_coding, 0, 0, 0); p_buf.put_c('\n'); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok(va_arg(pvar, int) != 0); JSON_encode(p_td, tok, FALSE); p_buf.put_s(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-encoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_encode(p_td, p_buf); break;} default: TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name); } va_end(pvar); } void JsClient::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name); unsigned L_form=va_arg(pvar, unsigned); ASN_BER_TLV_t tlv; BER_decode_str2TLV(p_buf, tlv, L_form); BER_decode_TLV(p_td, tlv, L_form); if(tlv.isComplete) p_buf.increase_pos(tlv.get_len()); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); raw_order_t r_order; switch(p_td.raw->top_bit_order) { case TOP_BIT_LEFT: r_order=ORDER_LSB; break; case TOP_BIT_RIGHT: default: r_order=ORDER_MSB; } int rawr = RAW_decode(p_td, p_buf, p_buf.get_len()*8, r_order); if(rawr<0) switch (-rawr) { case TTCN_EncDec::ET_INCOMPL_MSG: case TTCN_EncDec::ET_LEN_ERR: ec.error((TTCN_EncDec::error_type_t)-rawr, "Can not decode type '%s', because incomplete message was received", p_td.name); break; case 1: default: ec.error(TTCN_EncDec::ET_INVAL_MSG, "Can not decode type '%s', because invalid message was received", p_td.name); break; } break;} case TTCN_EncDec::CT_TEXT: { Limit_Token_List limit; TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); const unsigned char *b_data=p_buf.get_data(); int null_added=0; if(b_data[p_buf.get_len()-1]!='\0'){ null_added=1; p_buf.set_pos(p_buf.get_len()); p_buf.put_zero(8,ORDER_LSB); p_buf.rewind(); } if(TEXT_decode(p_td,p_buf,limit)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); if(null_added){ size_t actpos=p_buf.get_pos(); p_buf.set_pos(p_buf.get_len()-1); p_buf.cut_end(); p_buf.set_pos(actpos); } break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XmlReaderWrap reader(p_buf); for (int rd_ok=reader.Read(); rd_ok==1; rd_ok=reader.Read()) { if (reader.NodeType() == XML_READER_TYPE_ELEMENT) break; } XER_decode(*(p_td.xer), reader, XER_coding | XER_TOPLEVEL, XER_NONE, 0); size_t bytes = reader.ByteConsumed(); p_buf.set_pos(bytes); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok((const char*)p_buf.get_data(), p_buf.get_len()); if(JSON_decode(p_td, tok, FALSE, FALSE)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); p_buf.set_pos(tok.get_buf_pos()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-decoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_struct p_oer; OER_decode(p_td, p_buf, p_oer); break;} default: TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name); } va_end(pvar); } int JsClient::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_parent_is_map) const { if (!is_bound()) { TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "Encoding an unbound value of type @RSRES.JsClient."); return -1; } int enc_len = p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL); { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "peer"); enc_len += field_peer.JSON_encode(JsClient_peer_descr_, p_tok, FALSE); } { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "state"); enc_len += field_state.JSON_encode(JsClient_state_descr_, p_tok, FALSE); } { enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "component_id"); enc_len += field_component__id.JSON_encode(JsClient_component__id_descr_, p_tok, FALSE); } enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_END, NULL); return enc_len; } int JsClient::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent, boolean p_parent_is_map, int) { if (p_td.json->default_value.type == JD_STANDARD && 0 == p_tok.get_buffer_length()) { *this = *static_cast(p_td.json->default_value.val); return 0; } json_token_t j_token = JSON_TOKEN_NONE; size_t dec_len = p_tok.get_next_token(&j_token, NULL, NULL); if (JSON_TOKEN_ERROR == j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } else if (JSON_TOKEN_OBJECT_START != j_token) { return JSON_ERROR_INVALID_TOKEN; } boolean peer_found = FALSE; boolean state_found = FALSE; boolean component__id_found = FALSE; while (TRUE) { char* fld_name = 0; size_t name_len = 0; size_t buf_pos = p_tok.get_buf_pos(); dec_len += p_tok.get_next_token(&j_token, &fld_name, &name_len); if (JSON_TOKEN_ERROR == j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_NAME_TOKEN_ERROR); return JSON_ERROR_FATAL; } else if (JSON_TOKEN_NAME != j_token) { p_tok.set_buf_pos(buf_pos); break; } else { if (4 == name_len && 0 == strncmp(fld_name, "peer", name_len)) { peer_found = TRUE; int ret_val = field_peer.JSON_decode(JsClient_peer_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 4, "peer"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else if (5 == name_len && 0 == strncmp(fld_name, "state", name_len)) { state_found = TRUE; int ret_val = field_state.JSON_decode(JsClient_state_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 5, "state"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else if (12 == name_len && 0 == strncmp(fld_name, "component_id", name_len)) { component__id_found = TRUE; int ret_val = field_component__id.JSON_decode(JsClient_component__id_descr_, p_tok, p_silent, FALSE); if (0 > ret_val) { if (JSON_ERROR_INVALID_TOKEN == ret_val) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, 12, "component_id"); } return JSON_ERROR_FATAL; } dec_len += (size_t)ret_val; } else { if (p_silent) { return JSON_ERROR_INVALID_TOKEN; } JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_INVALID_NAME_ERROR, (int)name_len, fld_name); dec_len += p_tok.get_next_token(&j_token, NULL, NULL); if (JSON_TOKEN_NUMBER != j_token && JSON_TOKEN_STRING != j_token && JSON_TOKEN_LITERAL_TRUE != j_token && JSON_TOKEN_LITERAL_FALSE != j_token && JSON_TOKEN_LITERAL_NULL != j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, (int)name_len, fld_name); return JSON_ERROR_FATAL; } } } } dec_len += p_tok.get_next_token(&j_token, NULL, NULL); if (JSON_TOKEN_OBJECT_END != j_token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_OBJECT_END_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } if (!peer_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "peer"); return JSON_ERROR_FATAL; } if (!state_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "state"); return JSON_ERROR_FATAL; } if (!component__id_found) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_MISSING_FIELD_ERROR, "component_id"); return JSON_ERROR_FATAL; } return (int)dec_len; } struct JsClient_template::single_value_struct { CHARSTRING_template field_peer; ConnectionState_template field_state; RSPRO::ComponentIdentity_template field_component__id; }; void JsClient_template::set_specific() { if (template_selection != SPECIFIC_VALUE) { template_sel old_selection = template_selection; clean_up(); single_value = new single_value_struct; set_selection(SPECIFIC_VALUE); if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) { single_value->field_peer = ANY_VALUE; single_value->field_state = ANY_VALUE; single_value->field_component__id = ANY_VALUE; } } } void JsClient_template::copy_value(const JsClient& other_value) { single_value = new single_value_struct; if (other_value.peer().is_bound()) { single_value->field_peer = other_value.peer(); } else { single_value->field_peer.clean_up(); } if (other_value.state().is_bound()) { single_value->field_state = other_value.state(); } else { single_value->field_state.clean_up(); } if (other_value.component__id().is_bound()) { single_value->field_component__id = other_value.component__id(); } else { single_value->field_component__id.clean_up(); } set_selection(SPECIFIC_VALUE); } void JsClient_template::copy_template(const JsClient_template& other_value) { switch (other_value.template_selection) { case SPECIFIC_VALUE: single_value = new single_value_struct; if (UNINITIALIZED_TEMPLATE != other_value.peer().get_selection()) { single_value->field_peer = other_value.peer(); } else { single_value->field_peer.clean_up(); } if (UNINITIALIZED_TEMPLATE != other_value.state().get_selection()) { single_value->field_state = other_value.state(); } else { single_value->field_state.clean_up(); } if (UNINITIALIZED_TEMPLATE != other_value.component__id().get_selection()) { single_value->field_component__id = other_value.component__id(); } else { single_value->field_component__id.clean_up(); } case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = other_value.value_list.n_values; value_list.list_value = new JsClient_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]); break; case IMPLICATION_MATCH: implication_.precondition = new JsClient_template(*other_value.implication_.precondition); implication_.implied_template = new JsClient_template(*other_value.implication_.implied_template); break; case DYNAMIC_MATCH: dyn_match = other_value.dyn_match; dyn_match->ref_count++; break; default: TTCN_error("Copying an uninitialized/unsupported template of type @RSRES.JsClient."); break; } set_selection(other_value); } JsClient_template::JsClient_template() { } JsClient_template::JsClient_template(template_sel other_value) : Base_Template(other_value) { check_single_selection(other_value); } JsClient_template::JsClient_template(const JsClient& other_value) { copy_value(other_value); } JsClient_template::JsClient_template(const OPTIONAL& other_value) { switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsClient&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Creating a template of type @RSRES.JsClient from an unbound optional field."); } } JsClient_template::JsClient_template(JsClient_template* p_precondition, JsClient_template* p_implied_template) : Base_Template(IMPLICATION_MATCH) { implication_.precondition = p_precondition; implication_.implied_template = p_implied_template; } JsClient_template::JsClient_template(Dynamic_Match_Interface* p_dyn_match) : Base_Template(DYNAMIC_MATCH) { dyn_match = new dynmatch_struct; dyn_match->ptr = p_dyn_match; dyn_match->ref_count = 1; } JsClient_template::JsClient_template(const JsClient_template& other_value) : Base_Template() { copy_template(other_value); } JsClient_template::~JsClient_template() { clean_up(); } JsClient_template& JsClient_template::operator=(template_sel other_value) { check_single_selection(other_value); clean_up(); set_selection(other_value); return *this; } JsClient_template& JsClient_template::operator=(const JsClient& other_value) { clean_up(); copy_value(other_value); return *this; } JsClient_template& JsClient_template::operator=(const OPTIONAL& other_value) { clean_up(); switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsClient&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Assignment of an unbound optional field to a template of type @RSRES.JsClient."); } return *this; } JsClient_template& JsClient_template::operator=(const JsClient_template& other_value) { if (&other_value != this) { clean_up(); copy_template(other_value); } return *this; } boolean JsClient_template::match(const JsClient& other_value, boolean legacy) const { if (!other_value.is_bound()) return FALSE; switch (template_selection) { case ANY_VALUE: case ANY_OR_OMIT: return TRUE; case OMIT_VALUE: return FALSE; case SPECIFIC_VALUE: if(!other_value.peer().is_bound()) return FALSE; if(!single_value->field_peer.match(other_value.peer(), legacy))return FALSE; if(!other_value.state().is_bound()) return FALSE; if(!single_value->field_state.match(other_value.state(), legacy))return FALSE; if(!other_value.component__id().is_bound()) return FALSE; if(!single_value->field_component__id.match(other_value.component__id(), legacy))return FALSE; return TRUE; case VALUE_LIST: case COMPLEMENTED_LIST: for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) if (value_list.list_value[list_count].match(other_value, legacy)) return template_selection == VALUE_LIST; return template_selection == COMPLEMENTED_LIST; case CONJUNCTION_MATCH: for (unsigned int i = 0; i < value_list.n_values; i++) { if (!value_list.list_value[i].match(other_value)) { return FALSE; } } return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match(other_value) || implication_.implied_template->match(other_value); case DYNAMIC_MATCH: return dyn_match->ptr->match(other_value); default: TTCN_error("Matching an uninitialized/unsupported template of type @RSRES.JsClient."); } return FALSE; } boolean JsClient_template::is_bound() const { if (template_selection == UNINITIALIZED_TEMPLATE && !is_ifpresent) return FALSE; if (template_selection != SPECIFIC_VALUE) return TRUE; return single_value->field_peer.is_bound() || single_value->field_state.is_bound() || single_value->field_component__id.is_bound(); } boolean JsClient_template::is_value() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) return FALSE; return single_value->field_peer.is_value() && single_value->field_state.is_value() && single_value->field_component__id.is_value(); } void JsClient_template::clean_up() { switch (template_selection) { case SPECIFIC_VALUE: delete single_value; break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: delete [] value_list.list_value; break; case IMPLICATION_MATCH: delete implication_.precondition; delete implication_.implied_template; break; case DYNAMIC_MATCH: dyn_match->ref_count--; if (dyn_match->ref_count == 0) { delete dyn_match->ptr; delete dyn_match; } break; default: break; } template_selection = UNINITIALIZED_TEMPLATE; } JsClient JsClient_template::valueof() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) TTCN_error("Performing a valueof or send operation on a non-specific template of type @RSRES.JsClient."); JsClient ret_val; if (single_value->field_peer.is_bound()) { ret_val.peer() = single_value->field_peer.valueof(); } if (single_value->field_state.is_bound()) { ret_val.state() = single_value->field_state.valueof(); } if (single_value->field_component__id.is_bound()) { ret_val.component__id() = single_value->field_component__id.valueof(); } return ret_val; } void JsClient_template::set_type(template_sel template_type, unsigned int list_length) { if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST&& template_type != CONJUNCTION_MATCH) TTCN_error("Setting an invalid list for a template of type @RSRES.JsClient."); clean_up(); set_selection(template_type); value_list.n_values = list_length; value_list.list_value = new JsClient_template[list_length]; } JsClient_template& JsClient_template::list_item(unsigned int list_index) const { if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST&& template_selection != CONJUNCTION_MATCH) TTCN_error("Accessing a list element of a non-list template of type @RSRES.JsClient."); if (list_index >= value_list.n_values) TTCN_error("Index overflow in a value list template of type @RSRES.JsClient."); return value_list.list_value[list_index]; } CHARSTRING_template& JsClient_template::peer() { set_specific(); return single_value->field_peer; } const CHARSTRING_template& JsClient_template::peer() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field peer of a non-specific template of type @RSRES.JsClient."); return single_value->field_peer; } ConnectionState_template& JsClient_template::state() { set_specific(); return single_value->field_state; } const ConnectionState_template& JsClient_template::state() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field state of a non-specific template of type @RSRES.JsClient."); return single_value->field_state; } RSPRO::ComponentIdentity_template& JsClient_template::component__id() { set_specific(); return single_value->field_component__id; } const RSPRO::ComponentIdentity_template& JsClient_template::component__id() const { if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field component_id of a non-specific template of type @RSRES.JsClient."); return single_value->field_component__id; } int JsClient_template::size_of() const { if (is_ifpresent) TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient which has an ifpresent attribute."); switch (template_selection) { case SPECIFIC_VALUE: return 3; case VALUE_LIST: { if (value_list.n_values<1) TTCN_error("Internal error: Performing sizeof() operation on a template of type @RSRES.JsClient containing an empty list."); int item_size = value_list.list_value[0].size_of(); for (unsigned int l_idx = 1; l_idx < value_list.n_values; l_idx++) { if (value_list.list_value[l_idx].size_of()!=item_size) TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient containing a value list with different sizes."); } return item_size; } case OMIT_VALUE: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient containing omit value."); case ANY_VALUE: case ANY_OR_OMIT: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient containing */? value."); case COMPLEMENTED_LIST: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient containing complemented list."); case CONJUNCTION_MATCH: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient containing a conjunction list match."); case IMPLICATION_MATCH: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient containing an implication match."); case DYNAMIC_MATCH: TTCN_error("Performing sizeof() operation on a template of type @RSRES.JsClient containing a dynamic match."); default: TTCN_error("Performing sizeof() operation on an uninitialized/unsupported template of type @RSRES.JsClient."); } return 0; } void JsClient_template::log() const { switch (template_selection) { case SPECIFIC_VALUE: TTCN_Logger::log_event_str("{ peer := "); single_value->field_peer.log(); TTCN_Logger::log_event_str(", state := "); single_value->field_state.log(); TTCN_Logger::log_event_str(", component_id := "); single_value->field_component__id.log(); TTCN_Logger::log_event_str(" }"); break; case COMPLEMENTED_LIST: TTCN_Logger::log_event_str("complement"); case CONJUNCTION_MATCH: if (template_selection == CONJUNCTION_MATCH) { TTCN_Logger::log_event_str("conjunct"); } case VALUE_LIST: TTCN_Logger::log_char('('); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) { if (list_count > 0) TTCN_Logger::log_event_str(", "); value_list.list_value[list_count].log(); } TTCN_Logger::log_char(')'); break; case IMPLICATION_MATCH: implication_.precondition->log(); TTCN_Logger::log_event_str(" implies "); implication_.implied_template->log(); break; case DYNAMIC_MATCH: TTCN_Logger::log_event_str("@dynamic template"); break; default: log_generic(); } log_ifpresent(); } void JsClient_template::log_match(const JsClient& match_value, boolean legacy) const { if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){ if(match(match_value, legacy)){ TTCN_Logger::print_logmatch_buffer(); TTCN_Logger::log_event_str(" matched"); } else{ if (template_selection == SPECIFIC_VALUE) { size_t previous_size = TTCN_Logger::get_logmatch_buffer_len(); if(!single_value->field_peer.match(match_value.peer(), legacy)){ TTCN_Logger::log_logmatch_info(".peer"); single_value->field_peer.log_match(match_value.peer(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } if(!single_value->field_state.match(match_value.state(), legacy)){ TTCN_Logger::log_logmatch_info(".state"); single_value->field_state.log_match(match_value.state(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } if(!single_value->field_component__id.match(match_value.component__id(), legacy)){ TTCN_Logger::log_logmatch_info(".component_id"); single_value->field_component__id.log_match(match_value.component__id(), legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } }else { TTCN_Logger::print_logmatch_buffer(); match_value.log(); TTCN_Logger::log_event_str(" with "); log(); TTCN_Logger::log_event_str(" unmatched"); } } return; } if (template_selection == SPECIFIC_VALUE) { TTCN_Logger::log_event_str("{ peer := "); single_value->field_peer.log_match(match_value.peer(), legacy); TTCN_Logger::log_event_str(", state := "); single_value->field_state.log_match(match_value.state(), legacy); TTCN_Logger::log_event_str(", component_id := "); single_value->field_component__id.log_match(match_value.component__id(), legacy); TTCN_Logger::log_event_str(" }"); } else { match_value.log(); TTCN_Logger::log_event_str(" with "); log(); if (match(match_value, legacy)) TTCN_Logger::log_event_str(" matched"); else TTCN_Logger::log_event_str(" unmatched"); } } void JsClient_template::encode_text(Text_Buf& text_buf) const { encode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value->field_peer.encode_text(text_buf); single_value->field_state.encode_text(text_buf); single_value->field_component__id.encode_text(text_buf); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: text_buf.push_int(value_list.n_values); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].encode_text(text_buf); break; default: TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of type @RSRES.JsClient."); } } void JsClient_template::decode_text(Text_Buf& text_buf) { clean_up(); decode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value = new single_value_struct; single_value->field_peer.decode_text(text_buf); single_value->field_state.decode_text(text_buf); single_value->field_component__id.decode_text(text_buf); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: value_list.n_values = text_buf.pull_int().get_val(); value_list.list_value = new JsClient_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].decode_text(text_buf); break; default: TTCN_error("Text decoder: An unknown/unsupported selection was received in a template of type @RSRES.JsClient."); } } void JsClient_template::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_TEMPLATE, "record template"); switch (param.get_type()) { case Module_Param::MP_Omit: *this = OMIT_VALUE; break; case Module_Param::MP_Any: *this = ANY_VALUE; break; case Module_Param::MP_AnyOrNone: *this = ANY_OR_OMIT; break; case Module_Param::MP_List_Template: case Module_Param::MP_ComplementList_Template: case Module_Param::MP_ConjunctList_Template: { JsClient_template new_temp; new_temp.set_type(param.get_type()==Module_Param::MP_List_Template ? VALUE_LIST : (param.get_type() == Module_Param::MP_ConjunctList_Template ? CONJUNCTION_MATCH : COMPLEMENTED_LIST), param.get_size()); for (size_t p_i=0; p_i0 && param.get_elem(0)->get_type()!=Module_Param::MP_NotUsed) peer().set_param(*param.get_elem(0)); if (param.get_size()>1 && param.get_elem(1)->get_type()!=Module_Param::MP_NotUsed) state().set_param(*param.get_elem(1)); if (param.get_size()>2 && param.get_elem(2)->get_type()!=Module_Param::MP_NotUsed) component__id().set_param(*param.get_elem(2)); break; case Module_Param::MP_Assignment_List: { Vector value_used(param.get_size()); value_used.resize(param.get_size(), FALSE); for (size_t val_idx=0; val_idxget_id()->get_name(), "peer")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { peer().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "state")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { state().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxget_id()->get_name(), "component_id")) { if (curr_param->get_type()!=Module_Param::MP_NotUsed) { component__id().set_param(*curr_param); } value_used[val_idx]=TRUE; } } for (size_t val_idx=0; val_idxerror("Non existent field name in type @RSRES.JsClient: %s", curr_param->get_id()->get_name()); break; } } break; case Module_Param::MP_Implication_Template: { JsClient_template* precondition = new JsClient_template; precondition->set_param(*param.get_elem(0)); JsClient_template* implied_template = new JsClient_template; implied_template->set_param(*param.get_elem(1)); *this = JsClient_template(precondition, implied_template); } break; default: param.type_error("record template", "@RSRES.JsClient"); } is_ifpresent = param.get_ifpresent(); } void JsClient_template::check_restriction(template_res t_res, const char* t_name, boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return; switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) { case TR_OMIT: if (template_selection==OMIT_VALUE) return; case TR_VALUE: if (template_selection!=SPECIFIC_VALUE || is_ifpresent) break; single_value->field_peer.check_restriction(t_res, t_name ? t_name : "@RSRES.JsClient"); single_value->field_state.check_restriction(t_res, t_name ? t_name : "@RSRES.JsClient"); single_value->field_component__id.check_restriction(t_res, t_name ? t_name : "@RSRES.JsClient"); return; case TR_PRESENT: if (!match_omit(legacy)) return; break; default: return; } TTCN_error("Restriction `%s' on template of type %s violated.", get_res_name(t_res), t_name ? t_name : "@RSRES.JsClient"); } boolean JsClient_template::is_present(boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE; return !match_omit(legacy); } boolean JsClient_template::match_omit(boolean legacy) const { if (is_ifpresent) return TRUE; switch (template_selection) { case OMIT_VALUE: case ANY_OR_OMIT: return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match_omit() || implication_.implied_template->match_omit(); case VALUE_LIST: case COMPLEMENTED_LIST: if (legacy) { for (unsigned int l_idx=0; l_idxref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; } JsClients::JsClients(const JsClients& other_value) { if (!other_value.is_bound()) TTCN_error("Copying an unbound value of type @RSRES.JsClients."); val_ptr = other_value.val_ptr; val_ptr->ref_count++; } JsClients::~JsClients() { clean_up(); if (val_ptr != NULL) val_ptr = NULL; } void JsClients::clean_up() { if (val_ptr != NULL) { if (val_ptr->ref_count > 1) { val_ptr->ref_count--; val_ptr = NULL; } else if (val_ptr->ref_count == 1) { for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) if (val_ptr->value_elements[elem_count] != NULL) delete val_ptr->value_elements[elem_count]; free_pointers((void**)val_ptr->value_elements); delete val_ptr; val_ptr = NULL; } else TTCN_error("Internal error: Invalid reference counter in a record of/set of value."); } } JsClients& JsClients::operator=(null_type) { clean_up(); val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; return *this; } JsClients& JsClients::operator=(const JsClients& other_value) { if (other_value.val_ptr == NULL) TTCN_error("Assigning an unbound value of type @RSRES.JsClients."); if (this != &other_value) { clean_up(); val_ptr = other_value.val_ptr; val_ptr->ref_count++; } return *this; } boolean JsClients::operator==(null_type) const { if (val_ptr == NULL) TTCN_error("The left operand of comparison is an unbound value of type @RSRES.JsClients."); return val_ptr->n_elements == 0 ; } boolean JsClients::operator==(const JsClients& other_value) const { if (val_ptr == NULL) TTCN_error("The left operand of comparison is an unbound value of type @RSRES.JsClients."); if (other_value.val_ptr == NULL) TTCN_error("The right operand of comparison is an unbound value of type @RSRES.JsClients."); if (val_ptr == other_value.val_ptr) return TRUE; if (val_ptr->n_elements != (other_value.val_ptr)->n_elements) return FALSE; for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++){ if (val_ptr->value_elements[elem_count] != NULL){ if ((other_value.val_ptr)->value_elements[elem_count] != NULL){ if (*val_ptr->value_elements[elem_count] != *(other_value.val_ptr)->value_elements[elem_count]) return FALSE; } else return FALSE; } else { if ((other_value.val_ptr)->value_elements[elem_count] != NULL) return FALSE; } } return TRUE; } JsClient& JsClients::operator[](int index_value) { if (index_value < 0) TTCN_error("Accessing an element of type @RSRES.JsClients using a negative index: %d.", index_value); if (val_ptr == NULL) { val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; } else if (val_ptr->ref_count > 1) { struct recordof_setof_struct *new_val_ptr = new recordof_setof_struct; new_val_ptr->ref_count = 1; new_val_ptr->n_elements = (index_value >= val_ptr->n_elements) ? index_value + 1 : val_ptr->n_elements; new_val_ptr->value_elements = (JsClient**)allocate_pointers(new_val_ptr->n_elements); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++){ if (val_ptr->value_elements[elem_count] != NULL){ new_val_ptr->value_elements[elem_count] = new JsClient(*(val_ptr->value_elements[elem_count])); } } clean_up(); val_ptr = new_val_ptr; } if (index_value >= val_ptr->n_elements) set_size(index_value + 1); if (val_ptr->value_elements[index_value] == NULL) { val_ptr->value_elements[index_value] = new JsClient; } return *val_ptr->value_elements[index_value]; } JsClient& JsClients::operator[](const INTEGER& index_value) { index_value.must_bound("Using an unbound integer value for indexing a value of type @RSRES.JsClients."); return (*this)[(int)index_value]; } const JsClient& JsClients::operator[](int index_value) const { if (val_ptr == NULL) TTCN_error("Accessing an element in an unbound value of type @RSRES.JsClients."); if (index_value < 0) TTCN_error("Accessing an element of type @RSRES.JsClients using a negative index: %d.", index_value); if (index_value >= val_ptr->n_elements) TTCN_error("Index overflow in a value of type @RSRES.JsClients: The index is %d, but the value has only %d elements.", index_value, val_ptr->n_elements); return (val_ptr->value_elements[index_value] == NULL) ? UNBOUND_ELEM : *val_ptr->value_elements[index_value]; } const JsClient& JsClients::operator[](const INTEGER& index_value) const { index_value.must_bound("Using an unbound integer value for indexing a value of type @RSRES.JsClients."); return (*this)[(int)index_value]; } JsClients JsClients::operator<<=(int rotate_count) const { return *this >>= (-rotate_count); } JsClients JsClients::operator<<=(const INTEGER& rotate_count) const { rotate_count.must_bound("Unbound integer operand of rotate left operator."); return *this >>= (int)(-rotate_count); } JsClients JsClients::operator>>=(const INTEGER& rotate_count) const { rotate_count.must_bound("Unbound integer operand of rotate right operator."); return *this >>= (int)rotate_count; } JsClients JsClients::operator>>=(int rotate_count) const { if (val_ptr == NULL) TTCN_error("Performing rotation operation on an unbound value of type @RSRES.JsClients."); if (val_ptr->n_elements == 0) return *this; int rc; if (rotate_count>=0) rc = rotate_count % val_ptr->n_elements; else rc = val_ptr->n_elements - ((-rotate_count) % val_ptr->n_elements); if (rc == 0) return *this; JsClients ret_val; ret_val.set_size(val_ptr->n_elements); for (int i=0; in_elements; i++) { if (val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[(i+rc)%val_ptr->n_elements] =new JsClient(*val_ptr->value_elements[i]); } } return ret_val; } JsClients JsClients::operator+(const JsClients& other_value) const { if (val_ptr == NULL || other_value.val_ptr == NULL) TTCN_error("Unbound operand of @RSRES.JsClients concatenation."); if (val_ptr->n_elements == 0) return other_value; if (other_value.val_ptr->n_elements == 0) return *this; JsClients ret_val; ret_val.set_size(val_ptr->n_elements+other_value.val_ptr->n_elements); for (int i=0; in_elements; i++) { if (val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i] = new JsClient(*val_ptr->value_elements[i]); } } for (int i=0; in_elements; i++) { if (other_value.val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i+val_ptr->n_elements] = new JsClient(*other_value.val_ptr->value_elements[i]); } } return ret_val; } JsClients JsClients::substr(int index, int returncount) const { if (val_ptr == NULL) TTCN_error("The first argument of substr() is an unbound value of type @RSRES.JsClients."); check_substr_arguments(val_ptr->n_elements, index, returncount, "@RSRES.JsClients","element"); JsClients ret_val; ret_val.set_size(returncount); for (int i=0; ivalue_elements[i+index] != NULL) { ret_val.val_ptr->value_elements[i] = new JsClient(*val_ptr->value_elements[i+index]); } } return ret_val; } JsClients JsClients::replace(int index, int len, const JsClients& repl) const { if (val_ptr == NULL) TTCN_error("The first argument of replace() is an unbound value of type @RSRES.JsClients."); if (repl.val_ptr == NULL) TTCN_error("The fourth argument of replace() is an unbound value of type @RSRES.JsClients."); check_replace_arguments(val_ptr->n_elements, index, len, "@RSRES.JsClients","element"); JsClients ret_val; ret_val.set_size(val_ptr->n_elements + repl.val_ptr->n_elements - len); for (int i = 0; i < index; i++) { if (val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i] = new JsClient(*val_ptr->value_elements[i]); } } for (int i = 0; i < repl.val_ptr->n_elements; i++) { if (repl.val_ptr->value_elements[i] != NULL) { ret_val.val_ptr->value_elements[i+index] = new JsClient(*repl.val_ptr->value_elements[i]); } } for (int i = 0; i < val_ptr->n_elements - index - len; i++) { if (val_ptr->value_elements[index+i+len] != NULL) { ret_val.val_ptr->value_elements[index+i+repl.val_ptr->n_elements] = new JsClient(*val_ptr->value_elements[index+i+len]); } } return ret_val; } JsClients JsClients::replace(int index, int len, const JsClients_template& repl) const { if (!repl.is_value()) TTCN_error("The fourth argument of function replace() is a template with non-specific value."); return replace(index, len, repl.valueof()); } void JsClients::set_size(int new_size) { if (new_size < 0) TTCN_error("Internal error: Setting a negative size for a value of type @RSRES.JsClients."); if (val_ptr == NULL) { val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = 0; val_ptr->value_elements = NULL; } else if (val_ptr->ref_count > 1) { struct recordof_setof_struct *new_val_ptr = new recordof_setof_struct; new_val_ptr->ref_count = 1; new_val_ptr->n_elements = (new_size < val_ptr->n_elements) ? new_size : val_ptr->n_elements; new_val_ptr->value_elements = (JsClient**)allocate_pointers(new_val_ptr->n_elements); for (int elem_count = 0; elem_count < new_val_ptr->n_elements; elem_count++) { if (val_ptr->value_elements[elem_count] != NULL){ new_val_ptr->value_elements[elem_count] = new JsClient(*(val_ptr->value_elements[elem_count])); } } clean_up(); val_ptr = new_val_ptr; } if (new_size > val_ptr->n_elements) { val_ptr->value_elements = (JsClient**)reallocate_pointers((void**)val_ptr->value_elements, val_ptr->n_elements, new_size); #ifdef TITAN_MEMORY_DEBUG_SET_RECORD_OF if((val_ptr->n_elements/1000)!=(new_size/1000)) TTCN_warning("New size of type @RSRES.JsClients: %d",new_size); #endif val_ptr->n_elements = new_size; } else if (new_size < val_ptr->n_elements) { for (int elem_count = new_size; elem_count < val_ptr->n_elements; elem_count++) if (val_ptr->value_elements[elem_count] != NULL)delete val_ptr->value_elements[elem_count]; val_ptr->value_elements = (JsClient**)reallocate_pointers((void**)val_ptr->value_elements, val_ptr->n_elements, new_size); val_ptr->n_elements = new_size; } } boolean JsClients::is_value() const { if (val_ptr == NULL) return FALSE; for(int i = 0; i < val_ptr->n_elements; ++i) { if (val_ptr->value_elements[i] == NULL || !val_ptr->value_elements[i]->is_value()) return FALSE; } return TRUE; } int JsClients::size_of() const { if (val_ptr == NULL) TTCN_error("Performing sizeof operation on an unbound value of type @RSRES.JsClients."); return val_ptr->n_elements; } int JsClients::lengthof() const { if (val_ptr == NULL) TTCN_error("Performing lengthof operation on an unbound value of type @RSRES.JsClients."); for (int my_length=val_ptr->n_elements; my_length>0; my_length--) if (val_ptr->value_elements[my_length-1] != NULL) return my_length; return 0; } void JsClients::log() const { if (val_ptr == NULL) {; TTCN_Logger::log_event_unbound(); return; } switch (val_ptr->n_elements) { case 0: TTCN_Logger::log_event_str("{ }"); break; default: TTCN_Logger::log_event_str("{ "); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); (*this)[elem_count].log(); } TTCN_Logger::log_event_str(" }"); } } void JsClients::set_implicit_omit() { if (val_ptr == NULL) return; for (int i = 0; i < val_ptr->n_elements; i++) { if (val_ptr->value_elements[i] != NULL) val_ptr->value_elements[i]->set_implicit_omit(); } } void JsClients::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_VALUE|Module_Param::BC_LIST, "record of value"); switch (param.get_operation_type()) { case Module_Param::OT_ASSIGN: if (param.get_type()==Module_Param::MP_Value_List && param.get_size()==0) { *this = NULL_VALUE; return; } switch (param.get_type()) { case Module_Param::MP_Value_List: set_size(param.get_size()); for (size_t i=0; iget_type()!=Module_Param::MP_NotUsed) { (*this)[i].set_param(*curr); if (!(*this)[i].is_bound()) { delete val_ptr->value_elements[i]; val_ptr->value_elements[i] = NULL; } } } break; case Module_Param::MP_Indexed_List: for (size_t i=0; iget_id()->get_index()].set_param(*curr); if (!(*this)[curr->get_id()->get_index()].is_bound()) { delete val_ptr->value_elements[curr->get_id()->get_index()]; val_ptr->value_elements[curr->get_id()->get_index()] = NULL; } } break; default: param.type_error("record of value", "@RSRES.JsClients"); } break; case Module_Param::OT_CONCAT: switch (param.get_type()) { case Module_Param::MP_Value_List: { if (!is_bound()) *this = NULL_VALUE; int start_idx = lengthof(); for (size_t i=0; iget_type()!=Module_Param::MP_NotUsed)) { (*this)[start_idx+(int)i].set_param(*curr); } } } break; case Module_Param::MP_Indexed_List: param.error("Cannot concatenate an indexed value list"); break; default: param.type_error("record of value", "@RSRES.JsClients"); } break; default: TTCN_error("Internal error: Unknown operation type."); } } void JsClients::encode_text(Text_Buf& text_buf) const { if (val_ptr == NULL) TTCN_error("Text encoder: Encoding an unbound value of type @RSRES.JsClients."); text_buf.push_int(val_ptr->n_elements); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) (*this)[elem_count].encode_text(text_buf); } void JsClients::decode_text(Text_Buf& text_buf) { clean_up(); val_ptr = new recordof_setof_struct; val_ptr->ref_count = 1; val_ptr->n_elements = text_buf.pull_int().get_val(); if (val_ptr->n_elements < 0) TTCN_error("Text decoder: Negative size was received for a value of type @RSRES.JsClients."); val_ptr->value_elements = (JsClient**)allocate_pointers(val_ptr->n_elements); for (int elem_count = 0; elem_count < val_ptr->n_elements; elem_count++) { val_ptr->value_elements[elem_count] = new JsClient; val_ptr->value_elements[elem_count]->decode_text(text_buf); } } void JsClients::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) const { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name); unsigned BER_coding=va_arg(pvar, unsigned); BER_encode_chk_coding(BER_coding); ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding); tlv->put_in_buffer(p_buf); ASN_BER_TLV_t::destruct(tlv); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); RAW_enc_tr_pos rp; rp.level=0; rp.pos=NULL; RAW_enc_tree root(FALSE, NULL, &rp, 1, p_td.raw); RAW_encode(p_td, root); root.put_to_buf(p_buf); break;} case TTCN_EncDec::CT_TEXT: { TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); TEXT_encode(p_td,p_buf); break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XER_encode(*(p_td.xer),p_buf, XER_coding, 0, 0, 0); p_buf.put_c('\n'); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok(va_arg(pvar, int) != 0); JSON_encode(p_td, tok, FALSE); p_buf.put_s(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-encoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_encode(p_td, p_buf); break;} default: TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name); } va_end(pvar); } void JsClients::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name); unsigned L_form=va_arg(pvar, unsigned); ASN_BER_TLV_t tlv; BER_decode_str2TLV(p_buf, tlv, L_form); BER_decode_TLV(p_td, tlv, L_form); if(tlv.isComplete) p_buf.increase_pos(tlv.get_len()); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); raw_order_t r_order; switch(p_td.raw->top_bit_order) { case TOP_BIT_LEFT: r_order=ORDER_LSB; break; case TOP_BIT_RIGHT: default: r_order=ORDER_MSB; } int rawr = RAW_decode(p_td, p_buf, p_buf.get_len()*8, r_order); if(rawr<0) switch (-rawr) { case TTCN_EncDec::ET_INCOMPL_MSG: case TTCN_EncDec::ET_LEN_ERR: ec.error((TTCN_EncDec::error_type_t)-rawr, "Can not decode type '%s', because incomplete message was received", p_td.name); break; case 1: default: ec.error(TTCN_EncDec::ET_INVAL_MSG, "Can not decode type '%s', because invalid message was received", p_td.name); break; } break;} case TTCN_EncDec::CT_TEXT: { Limit_Token_List limit; TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); const unsigned char *b_data=p_buf.get_data(); int null_added=0; if(b_data[p_buf.get_len()-1]!='\0'){ null_added=1; p_buf.set_pos(p_buf.get_len()); p_buf.put_zero(8,ORDER_LSB); p_buf.rewind(); } if(TEXT_decode(p_td,p_buf,limit)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); if(null_added){ size_t actpos=p_buf.get_pos(); p_buf.set_pos(p_buf.get_len()-1); p_buf.cut_end(); p_buf.set_pos(actpos); } break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XmlReaderWrap reader(p_buf); for (int rd_ok=reader.Read(); rd_ok==1; rd_ok=reader.Read()) { if (reader.NodeType() == XML_READER_TYPE_ELEMENT) break; } XER_decode(*(p_td.xer), reader, XER_coding | XER_TOPLEVEL, XER_NONE, 0); size_t bytes = reader.ByteConsumed(); p_buf.set_pos(bytes); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok((const char*)p_buf.get_data(), p_buf.get_len()); if(JSON_decode(p_td, tok, FALSE, FALSE)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); p_buf.set_pos(tok.get_buf_pos()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-decoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_struct p_oer; OER_decode(p_td, p_buf, p_oer); break;} default: TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name); } va_end(pvar); } int JsClients::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean) const { if (!is_bound()) { TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "Encoding an unbound value of type @RSRES.JsClients."); return -1; } int enc_len = p_tok.put_next_token(p_td.json->as_map ? JSON_TOKEN_OBJECT_START : JSON_TOKEN_ARRAY_START, NULL); for (int i = 0; i < val_ptr->n_elements; ++i) { if (p_td.json->metainfo_unbound && !(*this)[i].is_bound()) { enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL); enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "metainfo []"); enc_len += p_tok.put_next_token(JSON_TOKEN_STRING, "\"unbound\""); enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_END, NULL); } else { int ret_val = (*this)[i].JSON_encode(*p_td.oftype_descr, p_tok, p_td.json->as_map); if (0 > ret_val) break; enc_len += ret_val; } } enc_len += p_tok.put_next_token(p_td.json->as_map ? JSON_TOKEN_OBJECT_END : JSON_TOKEN_ARRAY_END, NULL); return enc_len; } int JsClients::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent, boolean, int) { if (p_td.json->default_value.type == JD_STANDARD && 0 == p_tok.get_buffer_length()) { *this = *static_cast(p_td.json->default_value.val); return 0; } if (p_td.json->default_value.type == JD_LEGACY && 0 == p_tok.get_buffer_length()) { set_size(0); return strlen(p_td.json->default_value.str); } json_token_t token = JSON_TOKEN_NONE; size_t dec_len = p_tok.get_next_token(&token, NULL, NULL); if (JSON_TOKEN_ERROR == token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } else if ((!p_td.json->as_map && JSON_TOKEN_ARRAY_START != token) || (p_td.json->as_map && JSON_TOKEN_OBJECT_START != token)) { return JSON_ERROR_INVALID_TOKEN; } set_size(0); for (int nof_elements = 0; TRUE; ++nof_elements) { size_t buf_pos = p_tok.get_buf_pos(); size_t ret_val; if (p_td.json->metainfo_unbound) { ret_val = p_tok.get_next_token(&token, NULL, NULL); if (JSON_TOKEN_OBJECT_START == token) { char* value = NULL; size_t value_len = 0; ret_val += p_tok.get_next_token(&token, &value, &value_len); if (JSON_TOKEN_NAME == token && 11 == value_len && 0 == strncmp(value, "metainfo []", 11)) { ret_val += p_tok.get_next_token(&token, &value, &value_len); if (JSON_TOKEN_STRING == token && 9 == value_len && 0 == strncmp(value, "\"unbound\"", 9)) { ret_val = p_tok.get_next_token(&token, NULL, NULL); if (JSON_TOKEN_OBJECT_END == token) { dec_len += ret_val; continue; } } } } p_tok.set_buf_pos(buf_pos); } JsClient* val = new JsClient; int ret_val2 = val->JSON_decode(*p_td.oftype_descr, p_tok, p_silent, p_td.json->as_map); if (JSON_ERROR_INVALID_TOKEN == ret_val2) { p_tok.set_buf_pos(buf_pos); delete val; break; } else if (JSON_ERROR_FATAL == ret_val2) { delete val; if (p_silent) { clean_up(); } return JSON_ERROR_FATAL; } val_ptr->value_elements = (JsClient**)reallocate_pointers( (void**)val_ptr->value_elements, val_ptr->n_elements, nof_elements + 1); val_ptr->value_elements[nof_elements] = val; val_ptr->n_elements = nof_elements + 1; dec_len += (size_t)ret_val2; } dec_len += p_tok.get_next_token(&token, NULL, NULL); if ((!p_td.json->as_map && JSON_TOKEN_ARRAY_END != token) || (p_td.json->as_map && JSON_TOKEN_OBJECT_END != token)) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_REC_OF_END_TOKEN_ERROR, ""); if (p_silent) { clean_up(); } return JSON_ERROR_FATAL; } return (int)dec_len; } void JsClients_template::copy_value(const JsClients& other_value) { if (!other_value.is_bound()) TTCN_error("Initialization of a template of type @RSRES.JsClients with an unbound value."); single_value.n_elements = other_value.size_of(); single_value.value_elements = (JsClient_template**)allocate_pointers(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (other_value[elem_count].is_bound()) { single_value.value_elements[elem_count] = new JsClient_template(other_value[elem_count]); } else { single_value.value_elements[elem_count] = new JsClient_template; } } set_selection(SPECIFIC_VALUE); } void JsClients_template::copy_template(const JsClients_template& other_value) { switch (other_value.template_selection) { case SPECIFIC_VALUE: single_value.n_elements = other_value.single_value.n_elements; single_value.value_elements = (JsClient_template**)allocate_pointers(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (UNINITIALIZED_TEMPLATE != other_value.single_value.value_elements[elem_count]->get_selection()) { single_value.value_elements[elem_count] = new JsClient_template(*other_value.single_value.value_elements[elem_count]); } else { single_value.value_elements[elem_count] = new JsClient_template; } } case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = other_value.value_list.n_values; value_list.list_value = new JsClients_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]); break; case IMPLICATION_MATCH: implication_.precondition = new JsClients_template(*other_value.implication_.precondition); implication_.implied_template = new JsClients_template(*other_value.implication_.implied_template); break; case DYNAMIC_MATCH: dyn_match = other_value.dyn_match; dyn_match->ref_count++; break; default: TTCN_error("Copying an uninitialized/unsupported template of type @RSRES.JsClients."); break; } set_selection(other_value); } boolean JsClients_template::match_function_specific(const Base_Type *value_ptr, int value_index, const Restricted_Length_Template *template_ptr, int template_index, boolean legacy) { if (value_index >= 0) return ((const JsClients_template*)template_ptr)->single_value.value_elements[template_index]->match((*(const JsClients*)value_ptr)[value_index], legacy); else return ((const JsClients_template*)template_ptr)->single_value.value_elements[template_index]->is_any_or_omit(); } JsClients_template::JsClients_template() { } JsClients_template::JsClients_template(template_sel other_value) : Base_Record_Of_Template(other_value) { check_single_selection(other_value); } JsClients_template::JsClients_template(null_type) : Base_Record_Of_Template(SPECIFIC_VALUE) { single_value.n_elements = 0; single_value.value_elements = NULL; } JsClients_template::JsClients_template(const JsClients& other_value) { copy_value(other_value); } JsClients_template::JsClients_template(const OPTIONAL& other_value) { switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsClients&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Creating a template of type @RSRES.JsClients from an unbound optional field."); } } JsClients_template::JsClients_template(JsClients_template* p_precondition, JsClients_template* p_implied_template) : Base_Record_Of_Template(IMPLICATION_MATCH) { implication_.precondition = p_precondition; implication_.implied_template = p_implied_template; } JsClients_template::JsClients_template(Dynamic_Match_Interface* p_dyn_match) : Base_Record_Of_Template(DYNAMIC_MATCH) { dyn_match = new dynmatch_struct; dyn_match->ptr = p_dyn_match; dyn_match->ref_count = 1; } JsClients_template::JsClients_template(const JsClients_template& other_value) : Base_Record_Of_Template() { copy_template(other_value); } JsClients_template::~JsClients_template() { clean_up(); } void JsClients_template::clean_up() { switch (template_selection) { case SPECIFIC_VALUE: for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) delete single_value.value_elements[elem_count]; free_pointers((void**)single_value.value_elements); break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: delete [] value_list.list_value; break; case IMPLICATION_MATCH: delete implication_.precondition; delete implication_.implied_template; break; case DYNAMIC_MATCH: dyn_match->ref_count--; if (dyn_match->ref_count == 0) { delete dyn_match->ptr; delete dyn_match; } break; default: break; } template_selection = UNINITIALIZED_TEMPLATE; } JsClients_template& JsClients_template::operator=(template_sel other_value) { check_single_selection(other_value); clean_up(); set_selection(other_value); return *this; } JsClients_template& JsClients_template::operator=(null_type) { clean_up(); set_selection(SPECIFIC_VALUE); single_value.n_elements = 0; single_value.value_elements = NULL; return *this; } JsClients_template& JsClients_template::operator=(const JsClients& other_value) { clean_up(); copy_value(other_value); return *this; } JsClients_template& JsClients_template::operator=(const OPTIONAL& other_value) { clean_up(); switch (other_value.get_selection()) { case OPTIONAL_PRESENT: copy_value((const JsClients&)other_value); break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Assignment of an unbound optional field to a template of type @RSRES.JsClients."); } return *this; } JsClients_template& JsClients_template::operator=(const JsClients_template& other_value) { if (&other_value != this) { clean_up(); copy_template(other_value); } return *this; } JsClient_template& JsClients_template::operator[](int index_value) { if (index_value < 0) TTCN_error("Accessing an element of a template for type @RSRES.JsClients using a negative index: %d.", index_value); switch (template_selection) { case SPECIFIC_VALUE: if(index_value < single_value.n_elements) break; // no break case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: case UNINITIALIZED_TEMPLATE: set_size(index_value + 1); break; default: TTCN_error("Accessing an element of a non-specific template for type @RSRES.JsClients."); break; } return *single_value.value_elements[index_value]; } JsClient_template& JsClients_template::operator[](const INTEGER& index_value) { index_value.must_bound("Using an unbound integer value for indexing a template of type @RSRES.JsClients."); return (*this)[(int)index_value]; } const JsClient_template& JsClients_template::operator[](int index_value) const { if (index_value < 0) TTCN_error("Accessing an element of a template for type @RSRES.JsClients using a negative index: %d.", index_value); if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing an element of a non-specific template for type @RSRES.JsClients."); if (index_value >= single_value.n_elements) TTCN_error("Index overflow in a template of type @RSRES.JsClients: The index is %d, but the template has only %d elements.", index_value, single_value.n_elements); return *single_value.value_elements[index_value]; } const JsClient_template& JsClients_template::operator[](const INTEGER& index_value) const { index_value.must_bound("Using an unbound integer value for indexing a template of type @RSRES.JsClients."); return (*this)[(int)index_value]; } void JsClients_template::set_size(int new_size) { if (new_size < 0) TTCN_error("Internal error: Setting a negative size for a template of type @RSRES.JsClients."); template_sel old_selection = template_selection; if (old_selection != SPECIFIC_VALUE) { clean_up(); set_selection(SPECIFIC_VALUE); single_value.n_elements = 0; single_value.value_elements = NULL; } if (new_size > single_value.n_elements) { single_value.value_elements = (JsClient_template**)reallocate_pointers((void**)single_value.value_elements, single_value.n_elements, new_size); if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) { for (int elem_count = single_value.n_elements; elem_count < new_size; elem_count++) single_value.value_elements[elem_count] = new JsClient_template(ANY_VALUE); } else { for (int elem_count = single_value.n_elements; elem_count < new_size; elem_count++) single_value.value_elements[elem_count] = new JsClient_template; } single_value.n_elements = new_size; } else if (new_size < single_value.n_elements) { for (int elem_count = new_size; elem_count < single_value.n_elements; elem_count++) delete single_value.value_elements[elem_count]; single_value.value_elements = (JsClient_template**)reallocate_pointers((void**)single_value.value_elements, single_value.n_elements, new_size); single_value.n_elements = new_size; } } int JsClients_template::n_elem() const { switch (template_selection) { case SPECIFIC_VALUE: return single_value.n_elements; break; case VALUE_LIST: return value_list.n_values; break; default: TTCN_error("Performing n_elem"); } } int JsClients_template::size_of(boolean is_size) const { const char* op_name = is_size ? "size" : "length"; int min_size; boolean has_any_or_none; if (is_ifpresent) TTCN_error("Performing %sof() operation on a template of type @RSRES.JsClients which has an ifpresent attribute.", op_name); switch (template_selection) { case SPECIFIC_VALUE: { min_size = 0; has_any_or_none = FALSE; int elem_count = single_value.n_elements; if (!is_size) { while (elem_count>0 && !single_value.value_elements[elem_count-1]->is_bound()) elem_count--; } for (int i=0; iget_selection()) { case OMIT_VALUE: TTCN_error("Performing %sof() operation on a template of type @RSRES.JsClients containing omit element.", op_name); case ANY_OR_OMIT: has_any_or_none = TRUE; break; default: min_size++; break; } } } break; case OMIT_VALUE: TTCN_error("Performing %sof() operation on a template of type @RSRES.JsClients containing omit value.", op_name); case ANY_VALUE: case ANY_OR_OMIT: min_size = 0; has_any_or_none = TRUE; break; case VALUE_LIST: { if (value_list.n_values<1) TTCN_error("Performing %sof() operation on a template of type @RSRES.JsClients containing an empty list.", op_name); int item_size = value_list.list_value[0].size_of(is_size); for (unsigned int i = 1; i < value_list.n_values; i++) { if (value_list.list_value[i].size_of(is_size)!=item_size) TTCN_error("Performing %sof() operation on a template of type @RSRES.JsClients containing a value list with different sizes.", op_name); } min_size = item_size; has_any_or_none = FALSE; break; } case COMPLEMENTED_LIST: TTCN_error("Performing %sof() operation on a template of type @RSRES.JsClients containing complemented list.", op_name); default: TTCN_error("Performing %sof() operation on an uninitialized/unsupported template of type @RSRES.JsClients.", op_name); } return check_section_is_single(min_size, has_any_or_none, op_name, "a", "template of type @RSRES.JsClients"); } boolean JsClients_template::match(const JsClients& other_value, boolean legacy) const { if (!other_value.is_bound()) return FALSE; int value_length = other_value.size_of(); if (!match_length(value_length)) return FALSE; switch (template_selection) { case SPECIFIC_VALUE: return match_record_of(&other_value, value_length, this, single_value.n_elements, match_function_specific, legacy); case OMIT_VALUE: return FALSE; case ANY_VALUE: case ANY_OR_OMIT: return TRUE; case VALUE_LIST: case COMPLEMENTED_LIST: for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) if (value_list.list_value[list_count].match(other_value, legacy)) return template_selection == VALUE_LIST; return template_selection == COMPLEMENTED_LIST; case CONJUNCTION_MATCH: for (unsigned int i = 0; i < value_list.n_values; i++) { if (!value_list.list_value[i].match(other_value)) { return FALSE; } } return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match(other_value) || implication_.implied_template->match(other_value); case DYNAMIC_MATCH: return dyn_match->ptr->match(other_value); default: TTCN_error("Matching with an uninitialized/unsupported template of type @RSRES.JsClients."); } return FALSE; } boolean JsClients_template::is_value() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) return FALSE; for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) if (!single_value.value_elements[elem_count]->is_value()) return FALSE; return TRUE; } JsClients JsClients_template::valueof() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) TTCN_error("Performing a valueof or send operation on a non-specific template of type @RSRES.JsClients."); JsClients ret_val; ret_val.set_size(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) if (single_value.value_elements[elem_count]->is_bound()) { ret_val[elem_count] = single_value.value_elements[elem_count]->valueof(); } return ret_val; } JsClients JsClients_template::substr(int index, int returncount) const { if (!is_value()) TTCN_error("The first argument of function substr() is a template with non-specific value."); return valueof().substr(index, returncount); } JsClients JsClients_template::replace(int index, int len, const JsClients_template& repl) const { if (!is_value()) TTCN_error("The first argument of function replace() is a template with non-specific value."); if (!repl.is_value()) TTCN_error("The fourth argument of function replace() is a template with non-specific value."); return valueof().replace(index, len, repl.valueof()); } JsClients JsClients_template::replace(int index, int len, const JsClients& repl) const { if (!is_value()) TTCN_error("The first argument of function replace() is a template with non-specific value."); return valueof().replace(index, len, repl); } void JsClients_template::set_type(template_sel template_type, unsigned int list_length) { clean_up(); switch (template_type) { case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = list_length; value_list.list_value = new JsClients_template[list_length]; break; default: TTCN_error("Internal error: Setting an invalid type for a template of type @RSRES.JsClients."); } set_selection(template_type); } JsClients_template& JsClients_template::list_item(unsigned int list_index) { if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST && template_selection != CONJUNCTION_MATCH) TTCN_error("Internal error: Accessing a list element of a non-list template of type @RSRES.JsClients."); if (list_index >= value_list.n_values) TTCN_error("Internal error: Index overflow in a value list template of type @RSRES.JsClients."); return value_list.list_value[list_index]; } void JsClients_template::log() const { switch (template_selection) { case SPECIFIC_VALUE: if (single_value.n_elements > 0) { TTCN_Logger::log_event_str("{ "); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); if (permutation_starts_at(elem_count)) TTCN_Logger::log_event_str("permutation("); single_value.value_elements[elem_count]->log(); if (permutation_ends_at(elem_count)) TTCN_Logger::log_char(')'); } TTCN_Logger::log_event_str(" }"); } else TTCN_Logger::log_event_str("{ }"); break; case COMPLEMENTED_LIST: TTCN_Logger::log_event_str("complement"); case CONJUNCTION_MATCH: if (template_selection == CONJUNCTION_MATCH) { TTCN_Logger::log_event_str("conjunct"); } case VALUE_LIST: TTCN_Logger::log_char('('); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) { if (list_count > 0) TTCN_Logger::log_event_str(", "); value_list.list_value[list_count].log(); } TTCN_Logger::log_char(')'); break; case IMPLICATION_MATCH: implication_.precondition->log(); TTCN_Logger::log_event_str(" implies "); implication_.implied_template->log(); break; case DYNAMIC_MATCH: TTCN_Logger::log_event_str("@dynamic template"); break; default: log_generic(); } log_restricted(); log_ifpresent(); } void JsClients_template::log_match(const JsClients& match_value, boolean legacy) const { if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){ if(match(match_value, legacy)){ TTCN_Logger::print_logmatch_buffer(); TTCN_Logger::log_event_str(" matched"); }else{ if (template_selection == SPECIFIC_VALUE && single_value.n_elements > 0 && get_number_of_permutations() == 0 && single_value.n_elements == match_value.size_of()) { size_t previous_size = TTCN_Logger::get_logmatch_buffer_len(); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if(!single_value.value_elements[elem_count]->match(match_value[elem_count], legacy)){ TTCN_Logger::log_logmatch_info("[%d]", elem_count); single_value.value_elements[elem_count]->log_match(match_value[elem_count], legacy); TTCN_Logger::set_logmatch_buffer_len(previous_size); } } log_match_length(single_value.n_elements); } else { TTCN_Logger::print_logmatch_buffer(); match_value.log(); TTCN_Logger::log_event_str(" with "); log(); TTCN_Logger::log_event_str(" unmatched"); } } return; } if (template_selection == SPECIFIC_VALUE && single_value.n_elements > 0 && get_number_of_permutations() == 0 && single_value.n_elements == match_value.size_of()) { TTCN_Logger::log_event_str("{ "); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); single_value.value_elements[elem_count]->log_match(match_value[elem_count], legacy); } TTCN_Logger::log_event_str(" }"); log_match_length(single_value.n_elements); } else { match_value.log(); TTCN_Logger::log_event_str(" with "); log(); if (match(match_value, legacy)) TTCN_Logger::log_event_str(" matched"); else TTCN_Logger::log_event_str(" unmatched"); } } void JsClients_template::encode_text(Text_Buf& text_buf) const { encode_text_permutation(text_buf); switch (template_selection) { case SPECIFIC_VALUE: text_buf.push_int(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) single_value.value_elements[elem_count]->encode_text(text_buf); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: text_buf.push_int(value_list.n_values); for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].encode_text(text_buf); break; default: TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of type @RSRES.JsClients."); } } void JsClients_template::decode_text(Text_Buf& text_buf) { clean_up(); decode_text_permutation(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value.n_elements = text_buf.pull_int().get_val(); if (single_value.n_elements < 0) TTCN_error("Text decoder: Negative size was received for a template of type @RSRES.JsClients."); single_value.value_elements = (JsClient_template**)allocate_pointers(single_value.n_elements); for (int elem_count = 0; elem_count < single_value.n_elements; elem_count++) { single_value.value_elements[elem_count] = new JsClient_template; single_value.value_elements[elem_count]->decode_text(text_buf); } case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: value_list.n_values = text_buf.pull_int().get_val(); value_list.list_value = new JsClients_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].decode_text(text_buf); break; default: TTCN_error("Text decoder: An unknown/unsupported selection was received for a template of type @RSRES.JsClients."); } } boolean JsClients_template::is_present(boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE; return !match_omit(legacy); } boolean JsClients_template::match_omit(boolean legacy) const { if (is_ifpresent) return TRUE; switch (template_selection) { case OMIT_VALUE: case ANY_OR_OMIT: return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match_omit() || implication_.implied_template->match_omit(); case VALUE_LIST: case COMPLEMENTED_LIST: if (legacy) { for (unsigned int i=0; iget_id()->get_index())].set_param(*param.get_elem(p_i)); } break; case Module_Param::MP_Value_List: { set_size(param.get_size()); int curr_idx = 0; for (size_t p_i=0; p_iget_type()) { case Module_Param::MP_NotUsed: curr_idx++; break; case Module_Param::MP_Permutation_Template: { int perm_start_idx = curr_idx; Module_Param* param_i = param.get_elem(p_i); for (size_t perm_i=0; perm_iget_size(); perm_i++) { (*this)[curr_idx].set_param(*(param_i->get_elem(perm_i))); curr_idx++; } int perm_end_idx = curr_idx - 1; add_permutation(perm_start_idx, perm_end_idx); } break; default: (*this)[curr_idx].set_param(*param.get_elem(p_i)); curr_idx++; } } } break; case Module_Param::MP_Implication_Template: { JsClients_template* precondition = new JsClients_template; precondition->set_param(*param.get_elem(0)); JsClients_template* implied_template = new JsClients_template; implied_template->set_param(*param.get_elem(1)); *this = JsClients_template(precondition, implied_template); } break; default: param.type_error("record of template", "@RSRES.JsClients"); } is_ifpresent = param.get_ifpresent(); set_length_range(param); } void JsClients_template::check_restriction(template_res t_res, const char* t_name, boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return; switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) { case TR_OMIT: if (template_selection==OMIT_VALUE) return; case TR_VALUE: if (template_selection!=SPECIFIC_VALUE || is_ifpresent) break; for (int i=0; icheck_restriction(t_res, t_name ? t_name : "@RSRES.JsClients"); return; case TR_PRESENT: if (!match_omit(legacy)) return; break; default: return; } TTCN_error("Restriction `%s' on template of type %s violated.", get_res_name(t_res), t_name ? t_name : "@RSRES.JsClients"); } boolean JsClients_template::get_istemplate_kind(const char* type) const { if (!strcmp(type, "AnyElement")) { if (template_selection != SPECIFIC_VALUE) { return FALSE; } for (int i = 0; i < single_value.n_elements; i++) { if (single_value.value_elements[i]->get_selection() == ANY_VALUE) { return TRUE; } } return FALSE; } else if (!strcmp(type, "AnyElementsOrNone")) { if (template_selection != SPECIFIC_VALUE) { return FALSE; } for (int i = 0; i < single_value.n_elements; i++) { if (single_value.value_elements[i]->get_selection() == ANY_OR_OMIT) { return TRUE; } } return FALSE; } else if (!strcmp(type, "permutation")) { return number_of_permutations; } else if (!strcmp(type, "length")) { return length_restriction_type != NO_LENGTH_RESTRICTION; } else { return Base_Template::get_istemplate_kind(type); } } SlotmapState::SlotmapState() { enum_value = UNBOUND_VALUE; } SlotmapState::SlotmapState(int other_value) { if (!is_valid_enum(other_value)) TTCN_error("Initializing a variable of enumerated type @RSRES.SlotmapState with invalid numeric value %d.", other_value); enum_value = (enum_type)other_value; } SlotmapState::SlotmapState(enum_type other_value) { enum_value = other_value; } SlotmapState::SlotmapState(const SlotmapState& other_value) : Base_Type() { if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("Copying an unbound value of enumerated type @RSRES.SlotmapState."); enum_value = other_value.enum_value; } SlotmapState& SlotmapState::operator=(int other_value) { if (!is_valid_enum(other_value)) TTCN_error("Assigning unknown numeric value %d to a variable of enumerated type @RSRES.SlotmapState.", other_value); enum_value = (enum_type)other_value; return *this; } SlotmapState& SlotmapState::operator=(enum_type other_value) { enum_value = other_value; return *this; } SlotmapState& SlotmapState::operator=(const SlotmapState& other_value) { if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("Assignment of an unbound value of enumerated type @RSRES.SlotmapState."); enum_value = other_value.enum_value; return *this; } boolean SlotmapState::operator==(enum_type other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); return enum_value == other_value; } boolean SlotmapState::operator==(const SlotmapState& other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); return enum_value == other_value.enum_value; } boolean SlotmapState::operator<(enum_type other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); return enum_value < other_value; } boolean SlotmapState::operator<(const SlotmapState& other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); return enum_value < other_value.enum_value; } boolean SlotmapState::operator>(enum_type other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); return enum_value > other_value; } boolean SlotmapState::operator>(const SlotmapState& other_value) const { if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @RSRES.SlotmapState."); return enum_value > other_value.enum_value; } const char *SlotmapState::enum_to_str(enum_type enum_par) { switch (enum_par) { case NEW: return "NEW"; case UNACKNOWLEDGED: return "UNACKNOWLEDGED"; case ACTIVE: return "ACTIVE"; case DELETE__REQ: return "DELETE_REQ"; case DELETING: return "DELETING"; default: return ""; } } SlotmapState::enum_type SlotmapState::str_to_enum(const char *str_par) { if (!strcmp(str_par, "NEW")) return NEW; else if (!strcmp(str_par, "UNACKNOWLEDGED")) return UNACKNOWLEDGED; else if (!strcmp(str_par, "ACTIVE")) return ACTIVE; else if (!strcmp(str_par, "DELETE_REQ")) return DELETE__REQ; else if (!strcmp(str_par, "DELETING")) return DELETING; else return UNKNOWN_VALUE; } boolean SlotmapState::is_valid_enum(int int_par) { switch (int_par) { case 0: case 1: case 2: case 3: case 4: return TRUE; default: return FALSE; } } int SlotmapState::enum2int(enum_type enum_par) { if (enum_par==UNBOUND_VALUE || enum_par==UNKNOWN_VALUE) TTCN_error("The argument of function enum2int() is an %s value of enumerated type @RSRES.SlotmapState.", enum_par==UNBOUND_VALUE?"unbound":"invalid"); return enum_par; } int SlotmapState::enum2int(const SlotmapState& enum_par) { if (enum_par.enum_value==UNBOUND_VALUE || enum_par.enum_value==UNKNOWN_VALUE) TTCN_error("The argument of function enum2int() is an %s value of enumerated type @RSRES.SlotmapState.", enum_par==UNBOUND_VALUE?"unbound":"invalid"); return enum_par.enum_value; } void SlotmapState::int2enum(int int_val) { if (!is_valid_enum(int_val)) TTCN_error("Assigning invalid numeric value %d to a variable of enumerated type @RSRES.SlotmapState.", int_val); enum_value = (enum_type)int_val; } SlotmapState::operator SlotmapState::enum_type() const { if (enum_value == UNBOUND_VALUE) TTCN_error("Using the value of an unbound variable of enumerated type @RSRES.SlotmapState."); return enum_value; } void SlotmapState::log() const { if (enum_value != UNBOUND_VALUE) TTCN_Logger::log_event_enum(enum_to_str(enum_value), enum_value); else TTCN_Logger::log_event_unbound(); } void SlotmapState::set_param(Module_Param& param) { param.basic_check(Module_Param::BC_VALUE, "enumerated value"); if (param.get_type()!=Module_Param::MP_Enumerated) param.type_error("enumerated value", "@RSRES.SlotmapState"); enum_value = str_to_enum(param.get_enumerated()); if (!is_valid_enum(enum_value)) { param.error("Invalid enumerated value for type @RSRES.SlotmapState."); } } void SlotmapState::encode_text(Text_Buf& text_buf) const { if (enum_value == UNBOUND_VALUE) TTCN_error("Text encoder: Encoding an unbound value of enumerated type @RSRES.SlotmapState."); text_buf.push_int(enum_value); } void SlotmapState::decode_text(Text_Buf& text_buf) { enum_value = (enum_type)text_buf.pull_int().get_val(); if (!is_valid_enum(enum_value)) TTCN_error("Text decoder: Unknown numeric value %d was received for enumerated type @RSRES.SlotmapState.", enum_value); } void SlotmapState::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) const { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name); unsigned BER_coding=va_arg(pvar, unsigned); BER_encode_chk_coding(BER_coding); ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding); tlv->put_in_buffer(p_buf); ASN_BER_TLV_t::destruct(tlv); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); RAW_enc_tr_pos rp; rp.level=0; rp.pos=NULL; RAW_enc_tree root(TRUE, NULL, &rp, 1, p_td.raw); RAW_encode(p_td, root); root.put_to_buf(p_buf); break;} case TTCN_EncDec::CT_TEXT: { TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); TEXT_encode(p_td,p_buf); break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XER_encode(*(p_td.xer),p_buf, XER_coding, 0, 0, 0); p_buf.put_c('\n'); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok(va_arg(pvar, int) != 0); JSON_encode(p_td, tok, FALSE); p_buf.put_s(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-encoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_encode(p_td, p_buf); break;} default: TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name); } va_end(pvar); } void SlotmapState::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) { va_list pvar; va_start(pvar, p_coding); switch(p_coding) { case TTCN_EncDec::CT_BER: { TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name); unsigned L_form=va_arg(pvar, unsigned); ASN_BER_TLV_t tlv; BER_decode_str2TLV(p_buf, tlv, L_form); BER_decode_TLV(p_td, tlv, L_form); if(tlv.isComplete) p_buf.increase_pos(tlv.get_len()); break;} case TTCN_EncDec::CT_RAW: { TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name); if(!p_td.raw) TTCN_EncDec_ErrorContext::error_internal ("No RAW descriptor available for type '%s'.", p_td.name); raw_order_t r_order; switch(p_td.raw->top_bit_order) { case TOP_BIT_LEFT: r_order=ORDER_LSB; break; case TOP_BIT_RIGHT: default: r_order=ORDER_MSB; } int rawr = RAW_decode(p_td, p_buf, p_buf.get_len()*8, r_order); if(rawr<0) switch (-rawr) { case TTCN_EncDec::ET_INCOMPL_MSG: case TTCN_EncDec::ET_LEN_ERR: ec.error((TTCN_EncDec::error_type_t)-rawr, "Can not decode type '%s', because incomplete message was received", p_td.name); break; case 1: default: ec.error(TTCN_EncDec::ET_INVAL_MSG, "Can not decode type '%s', because invalid message was received", p_td.name); break; } break;} case TTCN_EncDec::CT_TEXT: { Limit_Token_List limit; TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name); if(!p_td.text) TTCN_EncDec_ErrorContext::error_internal ("No TEXT descriptor available for type '%s'.", p_td.name); const unsigned char *b_data=p_buf.get_data(); int null_added=0; if(b_data[p_buf.get_len()-1]!='\0'){ null_added=1; p_buf.set_pos(p_buf.get_len()); p_buf.put_zero(8,ORDER_LSB); p_buf.rewind(); } if(TEXT_decode(p_td,p_buf,limit)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); if(null_added){ size_t actpos=p_buf.get_pos(); p_buf.set_pos(p_buf.get_len()-1); p_buf.cut_end(); p_buf.set_pos(actpos); } break;} case TTCN_EncDec::CT_XER: { TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name); unsigned XER_coding=va_arg(pvar, unsigned); XER_encode_chk_coding(XER_coding, p_td); XmlReaderWrap reader(p_buf); for (int rd_ok=reader.Read(); rd_ok==1; rd_ok=reader.Read()) { if (reader.NodeType() == XML_READER_TYPE_ELEMENT) break; } XER_decode(*(p_td.xer), reader, XER_coding | XER_TOPLEVEL, XER_NONE, 0); size_t bytes = reader.ByteConsumed(); p_buf.set_pos(bytes); break;} case TTCN_EncDec::CT_JSON: { TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name); if(!p_td.json) TTCN_EncDec_ErrorContext::error_internal ("No JSON descriptor available for type '%s'.", p_td.name); JSON_Tokenizer tok((const char*)p_buf.get_data(), p_buf.get_len()); if(JSON_decode(p_td, tok, FALSE, FALSE)<0) ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name); p_buf.set_pos(tok.get_buf_pos()); break;} case TTCN_EncDec::CT_OER: { TTCN_EncDec_ErrorContext ec("While OER-decoding type '%s': ", p_td.name); if(!p_td.oer) TTCN_EncDec_ErrorContext::error_internal ("No OER descriptor available for type '%s'.", p_td.name); OER_struct p_oer; OER_decode(p_td, p_buf, p_oer); break;} default: TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name); } va_end(pvar); } int SlotmapState::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean) const { if (enum_value == UNBOUND_VALUE) { TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "Encoding an unbound value of enumerated type @RSRES.SlotmapState."); return -1; } if (p_td.json->use_null) { return p_tok.put_next_token(JSON_TOKEN_LITERAL_NULL); } char* tmp_str; if (p_td.json->as_number) { tmp_str = mprintf("%d", enum_value); } else { boolean text_found = false; for (size_t i = 0; i < p_td.json->nof_enum_texts; ++i) { if (p_td.json->enum_texts[i].index == enum_value) { tmp_str = mprintf("\"%s\"", p_td.json->enum_texts[i].text); text_found = true; break; } } if (!text_found) { tmp_str = mprintf("\"%s\"", enum_to_str(enum_value)); } } int enc_len = p_tok.put_next_token(p_td.json->as_number ? JSON_TOKEN_NUMBER : JSON_TOKEN_STRING, tmp_str); Free(tmp_str); return enc_len; } int SlotmapState::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent, boolean, int) { json_token_t token = JSON_TOKEN_NONE; char* value = 0; size_t value_len = 0; boolean error = FALSE; size_t dec_len = 0; boolean use_default = FALSE; if (p_td.json->default_value.type == JD_STANDARD && 0 == p_tok.get_buffer_length()) { *this = *static_cast(p_td.json->default_value.val); return dec_len; } if (p_td.json->default_value.type == JD_LEGACY && 0 == p_tok.get_buffer_length()) { value = const_cast(p_td.json->default_value.str); value_len = strlen(value); use_default = TRUE; } else { dec_len = p_tok.get_next_token(&token, &value, &value_len); } if (JSON_TOKEN_ERROR == token) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, ""); return JSON_ERROR_FATAL; } else if (JSON_TOKEN_LITERAL_NULL == token && p_td.json->use_null) { enum_value = NEW; } else if (!p_td.json->use_null && ((JSON_TOKEN_STRING == token && !p_td.json->as_number) || use_default)) { if (use_default || (value_len > 2 && value[0] == '\"' && value[value_len - 1] == '\"')) { if (!use_default) value[value_len - 1] = 0; boolean text_found = false; for (size_t i = 0; i < p_td.json->nof_enum_texts; ++i) { if (strcmp(p_td.json->enum_texts[i].text, value + (use_default ? 0 : 1)) == 0) { enum_value = static_cast(p_td.json->enum_texts[i].index); text_found = true; break; } } if (!text_found) { enum_value = str_to_enum(value + (use_default ? 0 : 1)); } if (!use_default) value[value_len - 1] = '\"'; if (UNKNOWN_VALUE == enum_value) { error = TRUE; } } else { error = TRUE; } } else if (!p_td.json->use_null && JSON_TOKEN_NUMBER == token && p_td.json->as_number) { char* value_str = mcopystrn(value, value_len); int number = atoi(value_str); if (strchr(value_str, '.') != NULL || strchr(value_str, 'e') != NULL || strchr(value_str, 'E') != NULL) { error = TRUE; } else if (is_valid_enum(number)) { enum_value = static_cast(number); } else { error = TRUE; } Free(value_str); } else { enum_value = UNBOUND_VALUE; return JSON_ERROR_INVALID_TOKEN; } if (error) { JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FORMAT_ERROR, p_td.json->as_number ? "number" : "string", "enumerated"); enum_value = UNBOUND_VALUE; return JSON_ERROR_FATAL; } return (int)dec_len; } void SlotmapState_template::copy_template(const SlotmapState_template& other_value) { set_selection(other_value); switch (template_selection) { case SPECIFIC_VALUE: single_value = other_value.single_value; break; case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: value_list.n_values = other_value.value_list.n_values; value_list.list_value = new SlotmapState_template[value_list.n_values]; for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]); break; case IMPLICATION_MATCH: implication_.precondition = new SlotmapState_template(*other_value.implication_.precondition); implication_.implied_template = new SlotmapState_template(*other_value.implication_.implied_template); break; case DYNAMIC_MATCH: dyn_match = other_value.dyn_match; dyn_match->ref_count++; break; default: TTCN_error("Copying an uninitialized/unsupported template of enumerated type @RSRES.SlotmapState."); } } SlotmapState_template::SlotmapState_template() { } SlotmapState_template::SlotmapState_template(template_sel other_value) : Base_Template(other_value) { check_single_selection(other_value); } SlotmapState_template::SlotmapState_template(int other_value) : Base_Template(SPECIFIC_VALUE) { if (!SlotmapState::is_valid_enum(other_value)) TTCN_error("Initializing a template of enumerated type @RSRES.SlotmapState with unknown numeric value %d.", other_value); single_value = (SlotmapState::enum_type)other_value; } SlotmapState_template::SlotmapState_template(SlotmapState::enum_type other_value) : Base_Template(SPECIFIC_VALUE) { single_value = other_value; } SlotmapState_template::SlotmapState_template(const SlotmapState& other_value) : Base_Template(SPECIFIC_VALUE) { if (other_value.enum_value == SlotmapState::UNBOUND_VALUE) TTCN_error("Creating a template from an unbound value of enumerated type @RSRES.SlotmapState."); single_value = other_value.enum_value; } SlotmapState_template::SlotmapState_template(const OPTIONAL& other_value) { switch (other_value.get_selection()) { case OPTIONAL_PRESENT: set_selection(SPECIFIC_VALUE); single_value = (SlotmapState::enum_type)(const SlotmapState&)other_value; break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Creating a template of enumerated type @RSRES.SlotmapState from an unbound optional field."); } } SlotmapState_template::SlotmapState_template(SlotmapState_template* p_precondition, SlotmapState_template* p_implied_template) : Base_Template(IMPLICATION_MATCH) { implication_.precondition = p_precondition; implication_.implied_template = p_implied_template; } SlotmapState_template::SlotmapState_template(Dynamic_Match_Interface* p_dyn_match) : Base_Template(DYNAMIC_MATCH) { dyn_match = new dynmatch_struct; dyn_match->ptr = p_dyn_match; dyn_match->ref_count = 1; } SlotmapState_template::SlotmapState_template(const SlotmapState_template& other_value) : Base_Template() { copy_template(other_value); } SlotmapState_template::~SlotmapState_template() { clean_up(); } boolean SlotmapState_template::is_bound() const { if (template_selection == UNINITIALIZED_TEMPLATE && !is_ifpresent) return FALSE; return TRUE; } boolean SlotmapState_template::is_value() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) return FALSE; return single_value != SlotmapState::UNBOUND_VALUE; } void SlotmapState_template::clean_up() { switch (template_selection) { case VALUE_LIST: case COMPLEMENTED_LIST: case CONJUNCTION_MATCH: delete [] value_list.list_value; break; case IMPLICATION_MATCH: delete implication_.precondition; delete implication_.implied_template; break; case DYNAMIC_MATCH: dyn_match->ref_count--; if (dyn_match->ref_count == 0) { delete dyn_match->ptr; delete dyn_match; } break; default: break; } template_selection = UNINITIALIZED_TEMPLATE; } SlotmapState_template& SlotmapState_template::operator=(template_sel other_value) { check_single_selection(other_value); clean_up(); set_selection(other_value); return *this; } SlotmapState_template& SlotmapState_template::operator=(int other_value) { if (!SlotmapState::is_valid_enum(other_value)) TTCN_warning("Assigning unknown numeric value %d to a template of enumerated type @RSRES.SlotmapState.", other_value); clean_up(); set_selection(SPECIFIC_VALUE); single_value = (SlotmapState::enum_type)other_value; return *this; } SlotmapState_template& SlotmapState_template::operator=(SlotmapState::enum_type other_value) { clean_up(); set_selection(SPECIFIC_VALUE); single_value = other_value; return *this; } SlotmapState_template& SlotmapState_template::operator=(const SlotmapState& other_value) { if (other_value.enum_value == SlotmapState::UNBOUND_VALUE) TTCN_error("Assignment of an unbound value of enumerated type @RSRES.SlotmapState to a template."); clean_up(); set_selection(SPECIFIC_VALUE); single_value = other_value.enum_value; return *this; } SlotmapState_template& SlotmapState_template::operator=(const OPTIONAL& other_value) { clean_up(); switch (other_value.get_selection()) { case OPTIONAL_PRESENT: set_selection(SPECIFIC_VALUE); single_value = (SlotmapState::enum_type)(const SlotmapState&)other_value; break; case OPTIONAL_OMIT: set_selection(OMIT_VALUE); break; default: TTCN_error("Assignment of an unbound optional field to a template of enumerated type @RSRES.SlotmapState."); } return *this; } SlotmapState_template& SlotmapState_template::operator=(const SlotmapState_template& other_value) { if (&other_value != this) { clean_up(); copy_template(other_value); } return *this; } boolean SlotmapState_template::match(SlotmapState::enum_type other_value, boolean) const { switch (template_selection) { case SPECIFIC_VALUE: return single_value == other_value; case OMIT_VALUE: return FALSE; case ANY_VALUE: case ANY_OR_OMIT: return TRUE; case VALUE_LIST: case COMPLEMENTED_LIST: for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) if (value_list.list_value[list_count].match(other_value)) return template_selection == VALUE_LIST; return template_selection == COMPLEMENTED_LIST; case CONJUNCTION_MATCH: for (unsigned int i = 0; i < value_list.n_values; i++) { if (!value_list.list_value[i].match(other_value)) { return FALSE; } } return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match(other_value) || implication_.implied_template->match(other_value); case DYNAMIC_MATCH: return dyn_match->ptr->match(other_value); default: TTCN_error("Matching an uninitialized/unsupported template of enumerated type @RSRES.SlotmapState."); } return FALSE; } boolean SlotmapState_template::match(const SlotmapState& other_value, boolean) const { if (other_value.enum_value == SlotmapState::UNBOUND_VALUE) TTCN_error("Matching a template of enumerated type @RSRES.SlotmapState with an unbound value."); return match(other_value.enum_value); } SlotmapState::enum_type SlotmapState_template::valueof() const { if (template_selection != SPECIFIC_VALUE || is_ifpresent) TTCN_error("Performing a valueof or send operation on a non-specific template of enumerated type @RSRES.SlotmapState."); return single_value; } void SlotmapState_template::set_type(template_sel template_type, unsigned int list_length) { if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST && template_type != CONJUNCTION_MATCH) TTCN_error("Setting an invalid list type for a template of enumerated type @RSRES.SlotmapState."); clean_up(); set_selection(template_type); value_list.n_values = list_length; value_list.list_value = new SlotmapState_template[list_length]; } SlotmapState_template& SlotmapState_template::list_item(unsigned int list_index) { if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST && template_selection != CONJUNCTION_MATCH) TTCN_error("Accessing a list element in a non-list template of enumerated type @RSRES.SlotmapState."); if (list_index >= value_list.n_values) TTCN_error("Index overflow in a value list template of enumerated type @RSRES.SlotmapState."); return value_list.list_value[list_index]; } void SlotmapState_template::log() const { switch (template_selection) { case SPECIFIC_VALUE: TTCN_Logger::log_event_enum(SlotmapState::enum_to_str(single_value), single_value); break; case COMPLEMENTED_LIST: TTCN_Logger::log_event_str("complement"); case CONJUNCTION_MATCH: if (template_selection == CONJUNCTION_MATCH) { TTCN_Logger::log_event_str("conjunct"); } case VALUE_LIST: TTCN_Logger::log_char('('); for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++) { if (elem_count > 0) TTCN_Logger::log_event_str(", "); value_list.list_value[elem_count].log(); } TTCN_Logger::log_char(')'); break; case IMPLICATION_MATCH: implication_.precondition->log(); TTCN_Logger::log_event_str(" implies "); implication_.implied_template->log(); break; case DYNAMIC_MATCH: TTCN_Logger::log_event_str("@dynamic template"); break; default: log_generic(); } log_ifpresent(); } void SlotmapState_template::log_match(const SlotmapState& match_value, boolean) const { match_value.log(); TTCN_Logger::log_event_str(" with "); log(); if (match(match_value)) TTCN_Logger::log_event_str(" matched"); else TTCN_Logger::log_event_str(" unmatched"); } void SlotmapState_template::encode_text(Text_Buf& text_buf) const { encode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: text_buf.push_int(single_value); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: text_buf.push_int(value_list.n_values); for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++) value_list.list_value[elem_count].encode_text(text_buf); break; default: TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of enumerated type @RSRES.SlotmapState."); } } void SlotmapState_template::decode_text(Text_Buf& text_buf) { clean_up(); decode_text_base(text_buf); switch (template_selection) { case SPECIFIC_VALUE: single_value = (SlotmapState::enum_type)text_buf.pull_int().get_val(); if (!SlotmapState::is_valid_enum(single_value)) TTCN_error("Text decoder: Unknown numeric value %d was received for a template of enumerated type @RSRES.SlotmapState.", single_value); case OMIT_VALUE: case ANY_VALUE: case ANY_OR_OMIT: break; case VALUE_LIST: case COMPLEMENTED_LIST: value_list.n_values = text_buf.pull_int().get_val(); value_list.list_value = new SlotmapState_template[value_list.n_values]; for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++) value_list.list_value[elem_count].decode_text(text_buf); break; default: TTCN_error("Text decoder: An unknown/unsupported selection was received for a template of enumerated type @RSRES.SlotmapState."); } } boolean SlotmapState_template::is_present(boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE; return !match_omit(legacy); } boolean SlotmapState_template::match_omit(boolean legacy) const { if (is_ifpresent) return TRUE; switch (template_selection) { case OMIT_VALUE: case ANY_OR_OMIT: return TRUE; case IMPLICATION_MATCH: return !implication_.precondition->match_omit() || implication_.implied_template->match_omit(); case VALUE_LIST: case COMPLEMENTED_LIST: if (legacy) { for (unsigned int i=0; iget_type()) { case Module_Param::MP_Omit: *this = OMIT_VALUE; break; case Module_Param::MP_Any: *this = ANY_VALUE; break; case Module_Param::MP_AnyOrNone: *this = ANY_OR_OMIT; break; case Module_Param::MP_List_Template: case Module_Param::MP_ComplementList_Template: case Module_Param::MP_ConjunctList_Template: { SlotmapState_template new_temp; new_temp.set_type(m_p->get_type()==Module_Param::MP_List_Template ? VALUE_LIST : (m_p->get_type() == Module_Param::MP_ConjunctList_Template ? CONJUNCTION_MATCH : COMPLEMENTED_LIST), m_p->get_size()); for (size_t p_i=0; p_iget_size(); p_i++) { new_temp.list_item(p_i).set_param(*m_p->get_elem(p_i)); } *this = new_temp; break; } case Module_Param::MP_Enumerated: { SlotmapState::enum_type enum_val = SlotmapState::str_to_enum(m_p->get_enumerated()); if (!SlotmapState::is_valid_enum(enum_val)) { param.error("Invalid enumerated value for type @RSRES.SlotmapState."); } *this = enum_val; } break; case Module_Param::MP_Implication_Template: { SlotmapState_template* precondition = new SlotmapState_template; precondition->set_param(*m_p->get_elem(0)); SlotmapState_template* implied_template = new SlotmapState_template; implied_template->set_param(*m_p->get_elem(1)); *this = SlotmapState_template(precondition, implied_template); } break; default: param.type_error("enumerated template", "@RSRES.SlotmapState"); } is_ifpresent = param.get_ifpresent(); } void SlotmapState_template::check_restriction(template_res t_res, const char* t_name, boolean legacy) const { if (template_selection==UNINITIALIZED_TEMPLATE) return; switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) { case TR_VALUE: if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return; break; case TR_OMIT: if (!is_ifpresent && (template_selection==OMIT_VALUE || template_selection==SPECIFIC_VALUE)) return; break; case TR_PRESENT: if (!match_omit(legacy)) return; break; default: return; } TTCN_error("Restriction `%s' on template of type %s violated.", get_res_name(t_res), t_name ? t_name : "@RSRES.SlotmapState"); } } /* end of namespace */