Merge "implemented decmatch (artf724241)"
[deliverable/titan.core.git] / core / ASN_External.cc
CommitLineData
d44e3c4f 1/******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Baranyi, Botond
11 * Beres, Szabolcs
12 * Delic, Adam
13 * Forstner, Matyas
14 * Kovacs, Ferenc
15 * Raduly, Csaba
16 * Szabados, Kristof
17 * Szabo, Bence Janos
18 * Szabo, Janos Zoltan – initial implementation
19 * Szalai, Gabor
20 *
21 ******************************************************************************/
970ed795
EL
22#include <string.h>
23
24#include "ASN_External.hh"
25
26#include "ASN_Any.hh"
27#include "ASN_Null.hh"
28#include "Bitstring.hh"
29#include "Integer.hh"
30#include "Objid.hh"
31#include "Octetstring.hh"
32#include "Universal_charstring.hh"
33
34#include "Parameters.h"
35#include "Param_Types.hh"
36#include "Error.hh"
37#include "Logger.hh"
38#include "Encdec.hh"
39#include "BER.hh"
40#include "Addfunc.hh"
41
42#include "../common/dbgnew.hh"
43
44/*
45 * This type is used to BER encode/decode the EXTERNAL type.
46 * For details, see X.690 8.18.
47 */
48
49/*
50
51to do when regenerating:
52
53in .hh file:
54
55add __SUNPRO_CC ifdefs for single_value_struct
56
57delete encode/decode members except for EXTERNAL
58
59in .cc file:
60
61leave transfer syntax in anonymous namespace
62
63delete encode/decode members except for EXTERNAL
64leave EXTERNAL::BER_encode_TLV() -- written by hand
65leave EXTERNAL::BER_decode_TLV() -- written by hand
66
67replace '@EXTERNAL' with 'EXTERNAL'
68
69remove RAW and TEXT enc/dec functions
70
71*/
72
73namespace { /* anonymous namespace */
74
75 class EXTERNALtransfer_encoding;
76 class EXTERNALtransfer;
77
78 class EXTERNALtransfer_encoding : public Base_Type {
79 public:
80 enum union_selection_type { UNBOUND_VALUE = 0, ALT_single__ASN1__type = 1, ALT_octet__aligned = 2, ALT_arbitrary = 3 };
81 private:
82 union_selection_type union_selection;
83 union {
84 ASN_ANY *field_single__ASN1__type;
85 OCTETSTRING *field_octet__aligned;
86 BITSTRING *field_arbitrary;
87 };
88 void clean_up();
89 void copy_value(const EXTERNALtransfer_encoding& other_value);
90
91 public:
92 EXTERNALtransfer_encoding()
93 { union_selection = UNBOUND_VALUE; }
94 EXTERNALtransfer_encoding(const EXTERNALtransfer_encoding& other_value)
95 : Base_Type(other_value)
96 { copy_value(other_value); }
97 ~EXTERNALtransfer_encoding() { clean_up(); }
98 EXTERNALtransfer_encoding& operator=(const EXTERNALtransfer_encoding& other_value);
99 ASN_ANY& single__ASN1__type();
100 const ASN_ANY& single__ASN1__type() const;
101 OCTETSTRING& octet__aligned();
102 const OCTETSTRING& octet__aligned() const;
103 BITSTRING& arbitrary();
104 const BITSTRING& arbitrary() const;
105 inline union_selection_type get_selection() const { return union_selection; }
106#ifdef TITAN_RUNTIME_2
107 void set_param(Module_Param& /*param*/) { TTCN_error("Internal error: EXTERNALtransfer_encoding::set_param() called."); }
3abe9331 108 Module_Param* get_param(Module_Param_Name& param_name) const { TTCN_error("Internal error: EXTERNALtransfer_encoding::get_param() called."); }
970ed795
EL
109 void encode_text(Text_Buf& /*text_buf*/) const { TTCN_error("Internal error: EXTERNALtransfer_encoding::encode_text() called."); }
110 void decode_text(Text_Buf& /*text_buf*/) { TTCN_error("Internal error: EXTERNALtransfer_encoding::decode_text() called."); }
111 boolean is_bound() const { return union_selection!=UNBOUND_VALUE; }
112 boolean is_equal(const Base_Type* /*other_value*/) const { TTCN_error("Internal error: EXTERNALtransfer_encoding::is_equal() called."); }
113 void set_value(const Base_Type* /*other_value*/) { TTCN_error("Internal error: EXTERNALtransfer_encoding::set_value() called."); }
114 Base_Type* clone() const { TTCN_error("Internal error: EXTERNALtransfer_encoding::clone() called."); }
115 const TTCN_Typedescriptor_t* get_descriptor() const { TTCN_error("Internal error: EXTERNALtransfer_encoding::get_descriptor() called."); }
116#endif
117 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const;
118 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form);
119 int XER_encode(const XERdescriptor_t& p_td,
af710487 120 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
970ed795 121 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
feade998 122 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
970ed795
EL
123 private:
124 boolean BER_decode_set_selection(const ASN_BER_TLV_t& p_tlv);
125 public:
126 boolean BER_decode_isMyMsg(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv);
127 };
128
129 /** This class is used to encode/decode the EXTERNAL type.
130 *
131 * The sequence type used for encoding/decoding the EXTERNAL type
132 * differs from the associated type of EXTERNAL. See
133 * = X.690 (BER), 8.18.1 ;
134 * = X.691 (PER), 26.1 ;
135 * = X.693 (XER), 8.4
136 *
137 * The actual encoding/decoding is performed by this class and its members.
138 * Data is transferred to/from an object of class EXTERNAL. */
139 class EXTERNALtransfer : public Base_Type {
140 OPTIONAL<OBJID> field_direct__reference;
141 OPTIONAL<INTEGER> field_indirect__reference;
142 OPTIONAL<ObjectDescriptor> field_data__value__descriptor;
143 EXTERNALtransfer_encoding field_encoding;
144 public:
145 void load(const EXTERNAL& ex);
146 inline OPTIONAL<OBJID>& direct__reference()
147 {return field_direct__reference;}
148 inline const OPTIONAL<OBJID>& direct__reference() const
149 {return field_direct__reference;}
150 inline OPTIONAL<INTEGER>& indirect__reference()
151 {return field_indirect__reference;}
152 inline const OPTIONAL<INTEGER>& indirect__reference() const
153 {return field_indirect__reference;}
154 inline OPTIONAL<ObjectDescriptor>& data__value__descriptor()
155 {return field_data__value__descriptor;}
156 inline const OPTIONAL<ObjectDescriptor>& data__value__descriptor() const
157 {return field_data__value__descriptor;}
158 inline EXTERNALtransfer_encoding& encoding()
159 {return field_encoding;}
160 inline const EXTERNALtransfer_encoding& encoding() const
161 {return field_encoding;}
162#ifdef TITAN_RUNTIME_2
163 void set_param(Module_Param& /*param*/) { TTCN_error("Internal error: EXTERNALtransfer::set_param() called."); }
3abe9331 164 Module_Param* get_param(Module_Param_Name& param_name) const { TTCN_error("Internal error: EXTERNALtransfer::get_param() called."); }
970ed795
EL
165 void encode_text(Text_Buf& /*text_buf*/) const { TTCN_error("Internal error: EXTERNALtransfer::encode_text() called."); }
166 void decode_text(Text_Buf& /*text_buf*/) { TTCN_error("Internal error: EXTERNALtransfer::decode_text() called."); }
167 boolean is_bound() const { TTCN_error("Internal error: EXTERNALtransfer::is_bound() called."); }
168 boolean is_value() const { TTCN_error("Internal error: EXTERNALtransfer::is_value() called."); }
169 void clean_up() { TTCN_error("Internal error: EXTERNALtransfer::clean_up() called."); }
170 boolean is_equal(const Base_Type* /*other_value*/) const { TTCN_error("Internal error: EXTERNALtransfer::is_equal() called."); }
171 void set_value(const Base_Type* /*other_value*/) { TTCN_error("Internal error: EXTERNALtransfer::set_value() called."); }
172 Base_Type* clone() const { TTCN_error("Internal error: EXTERNALtransfer::clone() called."); }
173 const TTCN_Typedescriptor_t* get_descriptor() const { TTCN_error("Internal error: EXTERNALtransfer::get_descriptor() called."); }
174#endif
175 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const;
176 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form);
177 int XER_encode(const XERdescriptor_t& p_td,
af710487 178 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
970ed795 179 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
feade998 180 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
970ed795
EL
181 };
182
183 /** Transform the information from the visible format to the encoding format
184 *
185 * Called from EXTERNAL::XER_encode() */
186 void EXTERNALtransfer::load(const EXTERNAL& ex)
187 {
188 // ALT_syntaxes, ALT_transfer__syntax and ALT_fixed do not appear below.
189 // These are forbidden for the EXTERNAL type.
190 switch(ex.identification().get_selection()) {
191 case EXTERNAL_identification::ALT_syntax:
192 field_direct__reference=ex.identification().syntax();
193 break;
194 case EXTERNAL_identification::ALT_context__negotiation:
195 field_direct__reference=ex.identification().context__negotiation().transfer__syntax();
196 break;
197 default:
198 field_direct__reference=OMIT_VALUE;
199 break;
200 }
201 switch(ex.identification().get_selection()) {
202 case EXTERNAL_identification::ALT_presentation__context__id:
203 field_indirect__reference=ex.identification().presentation__context__id();
204 break;
205 case EXTERNAL_identification::ALT_context__negotiation:
206 field_indirect__reference=ex.identification().context__negotiation().presentation__context__id();
207 break;
208 default:
209 field_indirect__reference=OMIT_VALUE;
210 break;
211 }
212 field_data__value__descriptor=ex.data__value__descriptor();
213 field_encoding.octet__aligned()=ex.data__value();
214 }
215
a38c6d4c 216 static const TTCN_Typedescriptor_t EXTERNALtransfer_encoding_descr_ = { "EXTERNALtransfer.encoding", &CHOICE_ber_, NULL, NULL, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE };
970ed795
EL
217
218 static const ASN_Tag_t EXTERNALtransfer_encoding_single__ASN1__type_tag_[] = { { ASN_TAG_CONT, 0u } };
219 static const ASN_BERdescriptor_t EXTERNALtransfer_encoding_single__ASN1__type_ber_ = { 1u, EXTERNALtransfer_encoding_single__ASN1__type_tag_ };
a38c6d4c 220 static const TTCN_Typedescriptor_t EXTERNALtransfer_encoding_single__ASN1__type_descr_ = { "EXTERNALtransfer.encoding.single-ASN1-type", &EXTERNALtransfer_encoding_single__ASN1__type_ber_, NULL, NULL, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE };
970ed795
EL
221
222 static const ASN_Tag_t EXTERNALtransfer_encoding_octet__aligned_tag_[] = { { ASN_TAG_CONT, 1u } };
223 static const ASN_BERdescriptor_t EXTERNALtransfer_encoding_octet__aligned_ber_ = { 1u, EXTERNALtransfer_encoding_octet__aligned_tag_ };
a38c6d4c 224 static const TTCN_Typedescriptor_t EXTERNALtransfer_encoding_octet__aligned_descr_ = { "EXTERNALtransfer.encoding.octet-aligned", &EXTERNALtransfer_encoding_octet__aligned_ber_, NULL, NULL, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE };
970ed795
EL
225
226 static const ASN_Tag_t EXTERNALtransfer_encoding_arbitrary_tag_[] = { { ASN_TAG_CONT, 2u } };
227 static const ASN_BERdescriptor_t EXTERNALtransfer_encoding_arbitrary_ber_ = { 1u, EXTERNALtransfer_encoding_arbitrary_tag_ };
a38c6d4c 228 static const TTCN_Typedescriptor_t EXTERNALtransfer_encoding_arbitrary_descr_ = { "EXTERNALtransfer.encoding.arbitrary", &EXTERNALtransfer_encoding_arbitrary_ber_, NULL, NULL, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE };
970ed795
EL
229
230 /* Member functions of C++ classes */
231
232 void EXTERNALtransfer_encoding::clean_up()
233 {
234 switch (union_selection) {
235 case ALT_single__ASN1__type:
236 delete field_single__ASN1__type;
237 break;
238 case ALT_octet__aligned:
239 delete field_octet__aligned;
240 break;
241 case ALT_arbitrary:
242 delete field_arbitrary;
243 break;
244 default:
245 break;
246 }
247 union_selection = UNBOUND_VALUE;
248 }
249
250 void EXTERNALtransfer_encoding::copy_value(const EXTERNALtransfer_encoding& other_value)
251 {
252 switch (other_value.union_selection) {
253 case ALT_single__ASN1__type:
254 field_single__ASN1__type = new ASN_ANY(*other_value.field_single__ASN1__type);
255 break;
256 case ALT_octet__aligned:
257 field_octet__aligned = new OCTETSTRING(*other_value.field_octet__aligned);
258 break;
259 case ALT_arbitrary:
260 field_arbitrary = new BITSTRING(*other_value.field_arbitrary);
261 break;
262 default:
263 TTCN_error("Assignment of an unbound union value of type EXTERNALtransfer.encoding.");
264 }
265 union_selection = other_value.union_selection;
266 }
267
268 EXTERNALtransfer_encoding& EXTERNALtransfer_encoding::operator=(const EXTERNALtransfer_encoding& other_value)
269 {
270 if(this != &other_value) {
271 clean_up();
272 copy_value(other_value);
273 }
274 return *this;
275 }
276
277 ASN_ANY& EXTERNALtransfer_encoding::single__ASN1__type()
278 {
279 if (union_selection != ALT_single__ASN1__type) {
280 clean_up();
281 field_single__ASN1__type = new ASN_ANY;
282 union_selection = ALT_single__ASN1__type;
283 }
284 return *field_single__ASN1__type;
285 }
286
287 const ASN_ANY& EXTERNALtransfer_encoding::single__ASN1__type() const
288 {
289 if (union_selection != ALT_single__ASN1__type) TTCN_error("Using non-selected field single-ASN1-type in a value of union type EXTERNALtransfer.encoding.");
290 return *field_single__ASN1__type;
291 }
292
293 OCTETSTRING& EXTERNALtransfer_encoding::octet__aligned()
294 {
295 if (union_selection != ALT_octet__aligned) {
296 clean_up();
297 field_octet__aligned = new OCTETSTRING;
298 union_selection = ALT_octet__aligned;
299 }
300 return *field_octet__aligned;
301 }
302
303 const OCTETSTRING& EXTERNALtransfer_encoding::octet__aligned() const
304 {
305 if (union_selection != ALT_octet__aligned) TTCN_error("Using non-selected field octet-aligned in a value of union type EXTERNALtransfer.encoding.");
306 return *field_octet__aligned;
307 }
308
309 BITSTRING& EXTERNALtransfer_encoding::arbitrary()
310 {
311 if (union_selection != ALT_arbitrary) {
312 clean_up();
313 field_arbitrary = new BITSTRING;
314 union_selection = ALT_arbitrary;
315 }
316 return *field_arbitrary;
317 }
318
319 const BITSTRING& EXTERNALtransfer_encoding::arbitrary() const
320 {
321 if (union_selection != ALT_arbitrary) TTCN_error("Using non-selected field arbitrary in a value of union type EXTERNALtransfer.encoding.");
322 return *field_arbitrary;
323 }
324
325 ASN_BER_TLV_t* EXTERNALtransfer_encoding::BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const
326 {
327 BER_chk_descr(p_td);
328 ASN_BER_TLV_t *new_tlv;
329 TTCN_EncDec_ErrorContext ec_0("Alternative '");
330 TTCN_EncDec_ErrorContext ec_1;
331 switch (union_selection) {
332 case ALT_single__ASN1__type:
333 ec_1.set_msg("single-ASN1-type': ");
334 new_tlv=field_single__ASN1__type->BER_encode_TLV(EXTERNALtransfer_encoding_single__ASN1__type_descr_, p_coding);
335 break;
336 case ALT_octet__aligned:
337 ec_1.set_msg("octet-aligned': ");
338 new_tlv=field_octet__aligned->BER_encode_TLV(EXTERNALtransfer_encoding_octet__aligned_descr_, p_coding);
339 break;
340 case ALT_arbitrary:
341 ec_1.set_msg("arbitrary': ");
342 new_tlv=field_arbitrary->BER_encode_TLV(EXTERNALtransfer_encoding_arbitrary_descr_, p_coding);
343 break;
344 case UNBOUND_VALUE:
345 new_tlv=BER_encode_chk_bound(FALSE);
346 break;
347 default:
348 TTCN_EncDec_ErrorContext::error_internal("Unknown selection.");
349 new_tlv = NULL;
350 break;
351 }
352 return ASN_BER_V2TLV(new_tlv, p_td, p_coding);
353 }
354
355 boolean EXTERNALtransfer_encoding::BER_decode_set_selection(const ASN_BER_TLV_t& p_tlv)
356 {
357 clean_up();
358 union_selection=ALT_single__ASN1__type;
359 field_single__ASN1__type=new ASN_ANY;
360 if(field_single__ASN1__type->BER_decode_isMyMsg(EXTERNALtransfer_encoding_single__ASN1__type_descr_, p_tlv))
361 return TRUE;
362 delete field_single__ASN1__type;
363 union_selection=ALT_octet__aligned;
364 field_octet__aligned=new OCTETSTRING;
365 if(field_octet__aligned->BER_decode_isMyMsg(EXTERNALtransfer_encoding_octet__aligned_descr_, p_tlv))
366 return TRUE;
367 delete field_octet__aligned;
368 union_selection=ALT_arbitrary;
369 field_arbitrary=new BITSTRING;
370 if(field_arbitrary->BER_decode_isMyMsg(EXTERNALtransfer_encoding_arbitrary_descr_, p_tlv))
371 return TRUE;
372 delete field_arbitrary;
373 union_selection=UNBOUND_VALUE;
374 return FALSE;
375 }
376
377 boolean EXTERNALtransfer_encoding::BER_decode_isMyMsg(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv)
378 {
379 if(p_td.ber->n_tags==0) {
380 EXTERNALtransfer_encoding tmp_type;
381 return tmp_type.BER_decode_set_selection(p_tlv);
382 }
383 else return Base_Type::BER_decode_isMyMsg(p_td, p_tlv);
384 }
385
386 boolean EXTERNALtransfer_encoding::BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form)
387 {
388 BER_chk_descr(p_td);
389 ASN_BER_TLV_t stripped_tlv;
390 BER_decode_strip_tags(*p_td.ber, p_tlv, L_form, stripped_tlv);
391 TTCN_EncDec_ErrorContext ec_0("While decoding 'EXTERNALtransfer.encoding' type: ");
392 ASN_BER_TLV_t tmp_tlv;
393 if(!BER_decode_TLV_CHOICE(*p_td.ber, stripped_tlv, L_form, tmp_tlv) || !BER_decode_CHOICE_selection(BER_decode_set_selection(tmp_tlv), tmp_tlv))
394 return FALSE;
395 TTCN_EncDec_ErrorContext ec_1("Alternative '");
396 TTCN_EncDec_ErrorContext ec_2;
397 switch (union_selection) {
398 case ALT_single__ASN1__type:
399 ec_2.set_msg("single-ASN1-type': ");
400 field_single__ASN1__type->BER_decode_TLV(EXTERNALtransfer_encoding_single__ASN1__type_descr_, tmp_tlv, L_form);
401 break;
402 case ALT_octet__aligned:
403 ec_2.set_msg("octet-aligned': ");
404 field_octet__aligned->BER_decode_TLV(EXTERNALtransfer_encoding_octet__aligned_descr_, tmp_tlv, L_form);
405 break;
406 case ALT_arbitrary:
407 ec_2.set_msg("arbitrary': ");
408 field_arbitrary->BER_decode_TLV(EXTERNALtransfer_encoding_arbitrary_descr_, tmp_tlv, L_form);
409 break;
410 default:
411 return FALSE;
412 }
413 return TRUE;
414 }
415
416 int EXTERNALtransfer_encoding::XER_encode(const XERdescriptor_t& p_td,
af710487 417 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const
970ed795
EL
418 {
419 int indenting = !is_canonical(flavor);
420 int exer = is_exer(flavor);
421 int encoded_length=(int)p_buf.get_len();
422 if (indenting) do_indent(p_buf, indent);
423 p_buf.put_c('<');
424 if (exer) write_ns_prefix(p_td, p_buf);
425 p_buf.put_s((size_t)p_td.namelens[exer] - 1 + indenting, (const unsigned char*)p_td.names[exer]);
426
427 ++indent;
428 switch (union_selection) {
429 case ALT_single__ASN1__type:
af710487 430 field_single__ASN1__type->XER_encode(EXTERNAL_encoding_singleASN_xer_, p_buf, flavor, indent, 0);
970ed795
EL
431 break;
432 case ALT_octet__aligned:
af710487 433 field_octet__aligned ->XER_encode(EXTERNAL_encoding_octet_aligned_xer_, p_buf, flavor, indent, 0);
970ed795
EL
434 break;
435 case ALT_arbitrary:
af710487 436 field_arbitrary ->XER_encode(EXTERNAL_encoding_arbitrary_xer_, p_buf, flavor, indent, 0);
970ed795
EL
437 break;
438 case UNBOUND_VALUE:
439 TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND,
440 "Encoding an unbound value");
441 break;
442 default:
443 TTCN_EncDec_ErrorContext::error_internal("Unknown selection.");
444 // TODO something at all ?
445 break;
446 }
447
448 if (indenting) do_indent(p_buf, --indent);
449 p_buf.put_c('<');
450 p_buf.put_c('/');
451 if (exer) write_ns_prefix(p_td, p_buf);
452 p_buf.put_s((size_t)p_td.namelens[exer] - 1 + indenting, (const unsigned char*)p_td.names[exer]);
453 return (int)p_buf.get_len() - encoded_length;
454 }
455
456 int EXTERNALtransfer_encoding::XER_decode(const XERdescriptor_t& p_td,
feade998 457 XmlReaderWrap& reader, unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*)
970ed795
EL
458 {
459 int exer = is_exer(flavor);
460 int success = reader.Ok(), type, depth = -1;
461 for (; success==1; success = reader.Read()) {
462 type = reader.NodeType();
463 if (type == XML_READER_TYPE_ELEMENT) {
464 verify_name(reader, p_td, exer);
465 depth = reader.Depth();
466 break;
467 }
468 } // next
469
470 const char * name = 0;
471 for (success = reader.Read(); success == 1; success = reader.Read()) {
472 type = reader.NodeType();
473 if (XML_READER_TYPE_ELEMENT == type) break;
474 else if (XML_READER_TYPE_END_ELEMENT == type) goto bail;
475 }
476 name = (const char*)reader.Name();
477
478 switch (*name) {
479 case 's': // single-ASN1-type
feade998 480 single__ASN1__type().XER_decode(EXTERNAL_encoding_singleASN_xer_, reader, flavor, flavor2, 0);
970ed795
EL
481 break;
482
483 case 'o': // octet-aligned
feade998 484 octet__aligned().XER_decode(EXTERNAL_encoding_octet_aligned_xer_, reader, flavor, flavor2, 0);
970ed795
EL
485 break;
486
487 case 'a': // arbitrary
feade998 488 arbitrary().XER_decode(EXTERNAL_encoding_arbitrary_xer_, reader, flavor, flavor2, 0);
970ed795
EL
489 break;
490
491 default:
492 TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG,
493 "Doh!"); // FIXME error method and text
494 break;
495 }
496
497 for (success = reader.Read(); success==1; success = reader.Read()) {
498 type = reader.NodeType();
499 if (XML_READER_TYPE_END_ELEMENT == type) {
500 verify_end(reader, p_td, depth, exer);
501 reader.Read(); // one last time
502 break;
503 }
504 }
505 bail:
506 return 0; // FIXME return value
507 }
508
509 /******************** EXTERNALtransfer class ********************/
510
511 ASN_BER_TLV_t* EXTERNALtransfer::BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const
512 {
513 BER_chk_descr(p_td);
514 ASN_BER_TLV_t *new_tlv=ASN_BER_TLV_t::construct(NULL);
515 TTCN_EncDec_ErrorContext ec_0("Component '");
516 TTCN_EncDec_ErrorContext ec_1;
517 ec_1.set_msg("direct-reference': ");
518 new_tlv->add_TLV(field_direct__reference.BER_encode_TLV(OBJID_descr_, p_coding));
519 ec_1.set_msg("indirect-reference': ");
520 new_tlv->add_TLV(field_indirect__reference.BER_encode_TLV(INTEGER_descr_, p_coding));
521 ec_1.set_msg("data-value-descriptor': ");
522 new_tlv->add_TLV(field_data__value__descriptor.BER_encode_TLV(ObjectDescriptor_descr_, p_coding));
523 ec_1.set_msg("encoding': ");
524 new_tlv->add_TLV(field_encoding.BER_encode_TLV(EXTERNALtransfer_encoding_descr_, p_coding));
525 new_tlv=ASN_BER_V2TLV(new_tlv, p_td, p_coding);
526 return new_tlv;
527 }
528
529 boolean EXTERNALtransfer::BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form)
530 {
531 BER_chk_descr(p_td);
532 ASN_BER_TLV_t stripped_tlv;
533 BER_decode_strip_tags(*p_td.ber, p_tlv, L_form, stripped_tlv);
534 TTCN_EncDec_ErrorContext ec_0("While decoding 'EXTERNALtransfer' type: ");
535 stripped_tlv.chk_constructed_flag(TRUE);
536 size_t V_pos=0;
537 ASN_BER_TLV_t tmp_tlv;
538 boolean tlv_present=FALSE;
539 {
540 TTCN_EncDec_ErrorContext ec_1("Component '");
541 TTCN_EncDec_ErrorContext ec_2;
542 ec_2.set_msg("direct-reference': ");
543 if(!tlv_present) tlv_present=BER_decode_constdTLV_next(stripped_tlv, V_pos, L_form, tmp_tlv);
544 if(!tlv_present) field_direct__reference=OMIT_VALUE;
545 else {
546 field_direct__reference.BER_decode_TLV(OBJID_descr_, tmp_tlv, L_form);
547 if(field_direct__reference.ispresent()) tlv_present=FALSE;
548 }
549 ec_2.set_msg("indirect-reference': ");
550 if(!tlv_present) tlv_present=BER_decode_constdTLV_next(stripped_tlv, V_pos, L_form, tmp_tlv);
551 if(!tlv_present) field_indirect__reference=OMIT_VALUE;
552 else {
553 field_indirect__reference.BER_decode_TLV(INTEGER_descr_, tmp_tlv, L_form);
554 if(field_indirect__reference.ispresent()) tlv_present=FALSE;
555 }
556 ec_2.set_msg("data-value-descriptor': ");
557 if(!tlv_present) tlv_present=BER_decode_constdTLV_next(stripped_tlv, V_pos, L_form, tmp_tlv);
558 if(!tlv_present) field_data__value__descriptor=OMIT_VALUE;
559 else {
560 field_data__value__descriptor.BER_decode_TLV(ObjectDescriptor_descr_, tmp_tlv, L_form);
561 if(field_data__value__descriptor.ispresent()) tlv_present=FALSE;
562 }
563 ec_2.set_msg("encoding': ");
564 if(!tlv_present) tlv_present=BER_decode_constdTLV_next(stripped_tlv, V_pos, L_form, tmp_tlv);
565 if(!tlv_present) return FALSE;
566 field_encoding.BER_decode_TLV(EXTERNALtransfer_encoding_descr_, tmp_tlv, L_form);
567 tlv_present=FALSE;
568 }
569 BER_decode_constdTLV_end(stripped_tlv, V_pos, L_form, tmp_tlv, tlv_present);
570 return TRUE;
571 }
572
573 int EXTERNALtransfer::XER_encode(const XERdescriptor_t& p_td,
af710487 574 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const
970ed795
EL
575 {
576 int indenting = !is_canonical(flavor);
577 int exer = is_exer(flavor);
578 int encoded_length=(int)p_buf.get_len();
579 if (indenting) do_indent(p_buf, indent);
580 p_buf.put_c('<');
581 if (exer) write_ns_prefix(p_td, p_buf);
582 p_buf.put_s((size_t)p_td.namelens[exer] - 1 + indenting, (const unsigned char*)p_td.names[exer]);
583
584 ++indent;
af710487 585 field_direct__reference .XER_encode(EXTERNAL_direct_reference_xer_ , p_buf, flavor, indent, 0);
586 field_indirect__reference .XER_encode(EXTERNAL_indirect_reference_xer_ , p_buf, flavor, indent, 0);
587 field_data__value__descriptor.XER_encode(EXTERNAL_data_value_descriptor_xer_, p_buf, flavor, indent, 0);
588 field_encoding .XER_encode(EXTERNAL_encoding_xer_ , p_buf, flavor, indent, 0);
970ed795
EL
589
590 if (indenting) do_indent(p_buf, --indent);
591 p_buf.put_c('<');
592 p_buf.put_c('/');
593 if (exer) write_ns_prefix(p_td, p_buf);
594 p_buf.put_s((size_t)p_td.namelens[exer] - 1 + indenting, (const unsigned char*)p_td.names[exer]);
595 return (int)p_buf.get_len() - encoded_length;
596 }
597
af710487 598 int EXTERNALtransfer::XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
feade998 599 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*)
970ed795
EL
600 {
601 int exer = is_exer(flavor);
602 int success = reader.Ok(), depth = -1;
603 for (; success == 1; success = reader.Read()) {
604 int type = reader.NodeType();
605 if (XML_READER_TYPE_ELEMENT == type) {
606 verify_name(reader, p_td, exer);
607 depth = reader.Depth();
608 reader.Read();
609 break;
610 }
611 }
612
feade998 613 field_direct__reference .XER_decode(EXTERNAL_direct_reference_xer_ , reader, flavor, flavor2, 0);
614 field_indirect__reference .XER_decode(EXTERNAL_indirect_reference_xer_ , reader, flavor, flavor2, 0);
615 field_data__value__descriptor.XER_decode(EXTERNAL_data_value_descriptor_xer_, reader, flavor, flavor2, 0);
616 field_encoding .XER_decode(EXTERNAL_encoding_xer_ , reader, flavor, flavor2, 0);
970ed795
EL
617
618 for (success = reader.Read(); success == 1; success = reader.Read()) {
619 int type = reader.NodeType();
620 if (XML_READER_TYPE_END_ELEMENT == type) {
621 verify_end(reader, p_td, depth, exer);
622 reader.Read(); // one more time
623 break;
624 }
625 }
626 return 1; // decode successful
627 }
628} // end of anonymous namespace
629
630/*
631 * And this is the EXTERNAL type stuff.
632 */
633
634/**
635 * This is written by hand, do not delete it! :)
636 */
637ASN_BER_TLV_t* EXTERNAL::BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const
638{
639 EXTERNALtransfer v_tmpmfr;
640 v_tmpmfr.load(*this);
641 return v_tmpmfr.BER_encode_TLV(p_td, p_coding);
642}
643
644/** Load information from an EXTERNALtransfer
645 *
646 * @param x pointer to an EXTERNALtransfer. It is of type void* because
647 * <anonymous-namespace>::EXTERNALtransfer can not appear in the header.
648 *
649 * Called by XER_decode() */
650void EXTERNAL::transfer(void *x)
651{
652 EXTERNALtransfer & v_tmpmfr = *(EXTERNALtransfer*)x;
653 if (v_tmpmfr.direct__reference().ispresent()) {
654 if (v_tmpmfr.indirect__reference().ispresent()) {
655 EXTERNAL_identification_context__negotiation& v_tmpjsz =
656 field_identification.context__negotiation();
657 v_tmpjsz.presentation__context__id() = v_tmpmfr.indirect__reference()();
658 v_tmpjsz.transfer__syntax() = v_tmpmfr.direct__reference()();
659 } else {
660 field_identification.syntax() = v_tmpmfr.direct__reference()();
661 }
662 } else {
663 if (v_tmpmfr.indirect__reference().ispresent()) {
664 field_identification.presentation__context__id() =
665 v_tmpmfr.indirect__reference()();
666 } else {
667 TTCN_EncDec_ErrorContext::warning("Neither direct-reference nor "
668 "indirect-reference is present.");
669 }
670 }
671 switch (field_identification.get_selection()) {
672 case EXTERNAL_identification::ALT_syntaxes:
673 case EXTERNAL_identification::ALT_transfer__syntax:
674 case EXTERNAL_identification::ALT_fixed:
675 TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG,
676 "EXTERNAL type does not allow the syntaxes, transfer-syntax or fixed");
677 break;
678
679 default:
680 break; // rest are OK
681 }
682
683 field_data__value__descriptor = v_tmpmfr.data__value__descriptor();
684 const EXTERNALtransfer_encoding& v_tmpjsz = v_tmpmfr.encoding();
685 switch (v_tmpjsz.get_selection()) {
686 case EXTERNALtransfer_encoding::ALT_single__ASN1__type:
687 field_data__value = v_tmpjsz.single__ASN1__type();
688 break;
689 case EXTERNALtransfer_encoding::ALT_octet__aligned:
690 field_data__value = v_tmpjsz.octet__aligned();
691 break;
692 case EXTERNALtransfer_encoding::ALT_arbitrary:
693 field_data__value = bit2oct(v_tmpjsz.arbitrary());
694 break;
695 default:
696 TTCN_EncDec_ErrorContext::error_internal("Unknown selection for field "
697 "`encoding' in EXTERNAL type.");
698 } // switch
699}
700
701/**
702 * This is written by hand, do not delete it! :)
703 */
704boolean EXTERNAL::BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, unsigned L_form)
705{
706 EXTERNALtransfer v_tmpmfr;
707 if(!v_tmpmfr.BER_decode_TLV(p_td, p_tlv, L_form))
708 return FALSE;
709 transfer(&v_tmpmfr);
710 return TRUE;
711}
712
713int EXTERNAL::XER_encode(const XERdescriptor_t& p_td,
af710487 714 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const
970ed795
EL
715{
716 if(!is_bound()) {
717 TTCN_EncDec_ErrorContext::error
718 (TTCN_EncDec::ET_UNBOUND, "Encoding an unbound value.");
719 }
720 EXTERNALtransfer xfer;
721 xfer.load(*this);
af710487 722 return xfer.XER_encode(p_td, p_buf, flavor, indent, 0);
970ed795
EL
723}
724
725int EXTERNAL::XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
feade998 726 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*)
970ed795
EL
727{
728 EXTERNALtransfer xfer;
feade998 729 xfer.XER_decode(p_td, reader, flavor, flavor2, 0);
970ed795
EL
730 transfer(&xfer);
731 return 1; // decode successful
732}
733
734/* generated stuff */
735
736void EXTERNAL_identification::clean_up()
737{
738 switch (union_selection) {
739 case ALT_syntaxes:
740 delete field_syntaxes;
741 break;
742 case ALT_syntax:
743 delete field_syntax;
744 break;
745 case ALT_presentation__context__id:
746 delete field_presentation__context__id;
747 break;
748 case ALT_context__negotiation:
749 delete field_context__negotiation;
750 break;
751 case ALT_transfer__syntax:
752 delete field_transfer__syntax;
753 break;
754 case ALT_fixed:
755 delete field_fixed;
756 break;
757 default:
758 break;
759 }
760 union_selection = UNBOUND_VALUE;
761}
762
763void EXTERNAL_identification::copy_value(const EXTERNAL_identification& other_value)
764{
765 switch (other_value.union_selection) {
766 case ALT_syntaxes:
767 field_syntaxes = new EXTERNAL_identification_syntaxes(*other_value.field_syntaxes);
768 break;
769 case ALT_syntax:
770 field_syntax = new OBJID(*other_value.field_syntax);
771 break;
772 case ALT_presentation__context__id:
773 field_presentation__context__id = new INTEGER(*other_value.field_presentation__context__id);
774 break;
775 case ALT_context__negotiation:
776 field_context__negotiation = new EXTERNAL_identification_context__negotiation(*other_value.field_context__negotiation);
777 break;
778 case ALT_transfer__syntax:
779 field_transfer__syntax = new OBJID(*other_value.field_transfer__syntax);
780 break;
781 case ALT_fixed:
782 field_fixed = new ASN_NULL(*other_value.field_fixed);
783 break;
784 default:
785 TTCN_error("Assignment of an unbound union value of type EXTERNAL.identification.");
786 }
787 union_selection = other_value.union_selection;
788}
789
790EXTERNAL_identification::EXTERNAL_identification()
791{
792 union_selection = UNBOUND_VALUE;
793}
794
795EXTERNAL_identification::EXTERNAL_identification(const EXTERNAL_identification& other_value)
796: Base_Type(other_value)
797{
798 copy_value(other_value);
799}
800
801EXTERNAL_identification::~EXTERNAL_identification()
802{
803 clean_up();
804}
805
806EXTERNAL_identification& EXTERNAL_identification::operator=(const EXTERNAL_identification& other_value)
807{
808 if (this != &other_value) {
809 clean_up();
810 copy_value(other_value);
811 }
812 return *this;
813}
814
815boolean EXTERNAL_identification::operator==(const EXTERNAL_identification& other_value) const
816{
817 if (union_selection == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of union type EXTERNAL.identification.");
818 if (other_value.union_selection == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of union type EXTERNAL.identification.");
819 if (union_selection != other_value.union_selection) return FALSE;
820 switch (union_selection) {
821 case ALT_syntaxes:
822 return *field_syntaxes == *other_value.field_syntaxes;
823 case ALT_syntax:
824 return *field_syntax == *other_value.field_syntax;
825 case ALT_presentation__context__id:
826 return *field_presentation__context__id == *other_value.field_presentation__context__id;
827 case ALT_context__negotiation:
828 return *field_context__negotiation == *other_value.field_context__negotiation;
829 case ALT_transfer__syntax:
830 return *field_transfer__syntax == *other_value.field_transfer__syntax;
831 case ALT_fixed:
832 return *field_fixed == *other_value.field_fixed;
833 default:
834 return FALSE;
835 }
836}
837
838EXTERNAL_identification_syntaxes& EXTERNAL_identification::syntaxes()
839{
840 if (union_selection != ALT_syntaxes) {
841 clean_up();
842 field_syntaxes = new EXTERNAL_identification_syntaxes;
843 union_selection = ALT_syntaxes;
844 }
845 return *field_syntaxes;
846}
847
848const EXTERNAL_identification_syntaxes& EXTERNAL_identification::syntaxes() const
849{
850 if (union_selection != ALT_syntaxes) TTCN_error("Using non-selected field syntaxes in a value of union type EXTERNAL.identification.");
851 return *field_syntaxes;
852}
853
854OBJID& EXTERNAL_identification::syntax()
855{
856 if (union_selection != ALT_syntax) {
857 clean_up();
858 field_syntax = new OBJID;
859 union_selection = ALT_syntax;
860 }
861 return *field_syntax;
862}
863
864const OBJID& EXTERNAL_identification::syntax() const
865{
866 if (union_selection != ALT_syntax) TTCN_error("Using non-selected field syntax in a value of union type EXTERNAL.identification.");
867 return *field_syntax;
868}
869
870INTEGER& EXTERNAL_identification::presentation__context__id()
871{
872 if (union_selection != ALT_presentation__context__id) {
873 clean_up();
874 field_presentation__context__id = new INTEGER;
875 union_selection = ALT_presentation__context__id;
876 }
877 return *field_presentation__context__id;
878}
879
880const INTEGER& EXTERNAL_identification::presentation__context__id() const
881{
882 if (union_selection != ALT_presentation__context__id) TTCN_error("Using non-selected field presentation_context_id in a value of union type EXTERNAL.identification.");
883 return *field_presentation__context__id;
884}
885
886EXTERNAL_identification_context__negotiation& EXTERNAL_identification::context__negotiation()
887{
888 if (union_selection != ALT_context__negotiation) {
889 clean_up();
890 field_context__negotiation = new EXTERNAL_identification_context__negotiation;
891 union_selection = ALT_context__negotiation;
892 }
893 return *field_context__negotiation;
894}
895
896const EXTERNAL_identification_context__negotiation& EXTERNAL_identification::context__negotiation() const
897{
898 if (union_selection != ALT_context__negotiation) TTCN_error("Using non-selected field context_negotiation in a value of union type EXTERNAL.identification.");
899 return *field_context__negotiation;
900}
901
902OBJID& EXTERNAL_identification::transfer__syntax()
903{
904 if (union_selection != ALT_transfer__syntax) {
905 clean_up();
906 field_transfer__syntax = new OBJID;
907 union_selection = ALT_transfer__syntax;
908 }
909 return *field_transfer__syntax;
910}
911
912const OBJID& EXTERNAL_identification::transfer__syntax() const
913{
914 if (union_selection != ALT_transfer__syntax) TTCN_error("Using non-selected field transfer_syntax in a value of union type EXTERNAL.identification.");
915 return *field_transfer__syntax;
916}
917
918ASN_NULL& EXTERNAL_identification::fixed()
919{
920 if (union_selection != ALT_fixed) {
921 clean_up();
922 field_fixed = new ASN_NULL;
923 union_selection = ALT_fixed;
924 }
925 return *field_fixed;
926}
927
928const ASN_NULL& EXTERNAL_identification::fixed() const
929{
930 if (union_selection != ALT_fixed) TTCN_error("Using non-selected field fixed in a value of union type EXTERNAL.identification.");
931 return *field_fixed;
932}
933
934boolean EXTERNAL_identification::ischosen(union_selection_type checked_selection) const
935{
936 if (checked_selection == UNBOUND_VALUE) TTCN_error("Internal error: Performing ischosen() operation on an invalid field of union type EXTERNAL.identification.");
937 if (union_selection == UNBOUND_VALUE) TTCN_error("Internal error: Performing ischosen() operation on an unbound value of union type EXTERNAL.identification.");
938 return union_selection == checked_selection;
939}
940
941boolean EXTERNAL_identification::is_value() const
942{
943 switch (union_selection) {
944 case ALT_syntaxes:
945 return field_syntaxes->is_value();
946 case ALT_syntax:
947 return field_syntax->is_value();
948 case ALT_presentation__context__id:
949 return field_presentation__context__id->is_value();
950 case ALT_context__negotiation:
951 return field_context__negotiation->is_value();
952 case ALT_transfer__syntax:
953 return field_transfer__syntax->is_value();
954 case ALT_fixed:
955 return field_fixed->is_value();
956 default:
957 return FALSE;
958 }
959}
960
961void EXTERNAL_identification::log() const
962{
963 switch (union_selection) {
964 case ALT_syntaxes:
965 TTCN_Logger::log_event_str("{ syntaxes := ");
966 field_syntaxes->log();
967 TTCN_Logger::log_event_str(" }");
968 break;
969 case ALT_syntax:
970 TTCN_Logger::log_event_str("{ syntax := ");
971 field_syntax->log();
972 TTCN_Logger::log_event_str(" }");
973 break;
974 case ALT_presentation__context__id:
975 TTCN_Logger::log_event_str("{ presentation_context_id := ");
976 field_presentation__context__id->log();
977 TTCN_Logger::log_event_str(" }");
978 break;
979 case ALT_context__negotiation:
980 TTCN_Logger::log_event_str("{ context_negotiation := ");
981 field_context__negotiation->log();
982 TTCN_Logger::log_event_str(" }");
983 break;
984 case ALT_transfer__syntax:
985 TTCN_Logger::log_event_str("{ transfer_syntax := ");
986 field_transfer__syntax->log();
987 TTCN_Logger::log_event_str(" }");
988 break;
989 case ALT_fixed:
990 TTCN_Logger::log_event_str("{ fixed := ");
991 field_fixed->log();
992 TTCN_Logger::log_event_str(" }");
993 break;
994 default:
995 TTCN_Logger::log_event_str("<unbound>");
996 break;
997 }
998}
999
1000void EXTERNAL_identification::set_param(Module_Param& param) {
1001 param.basic_check(Module_Param::BC_VALUE, "union value");
3abe9331 1002 Module_Param_Ptr mp = &param;
1003 if (param.get_type() == Module_Param::MP_Reference) {
1004 mp = param.get_referenced_param();
1005 }
1006 if (mp->get_type()==Module_Param::MP_Value_List && mp->get_size()==0) return;
1007 if (mp->get_type()!=Module_Param::MP_Assignment_List) {
970ed795
EL
1008 param.error("union value with field name was expected");
1009 }
3abe9331 1010 Module_Param* mp_last = mp->get_elem(mp->get_size()-1);
970ed795
EL
1011 if (!strcmp(mp_last->get_id()->get_name(), "syntaxes")) {
1012 syntaxes().set_param(*mp_last);
1013 return;
1014 }
1015 if (!strcmp(mp_last->get_id()->get_name(), "syntax")) {
1016 syntax().set_param(*mp_last);
1017 return;
1018 }
1019 if (!strcmp(mp_last->get_id()->get_name(), "presentation_context_id")) {
1020 presentation__context__id().set_param(*mp_last);
1021 return;
1022 }
1023 if (!strcmp(mp_last->get_id()->get_name(), "context_negotiation")) {
1024 context__negotiation().set_param(*mp_last);
1025 return;
1026 }
1027 if (!strcmp(mp_last->get_id()->get_name(), "transfer_syntax")) {
1028 transfer__syntax().set_param(*mp_last);
1029 return;
1030 }
1031 if (!strcmp(mp_last->get_id()->get_name(), "fixed")) {
1032 fixed().set_param(*mp_last);
1033 return;
1034 }
1035 mp_last->error("Field %s does not exist in type EXTERNAL.identification.", mp_last->get_id()->get_name());
1036}
1037
3abe9331 1038Module_Param* EXTERNAL_identification::get_param(Module_Param_Name& param_name) const
1039{
1040 if (!is_bound()) {
1041 return new Module_Param_Unbound();
1042 }
1043 Module_Param* mp_field = NULL;
1044
1045 switch(get_selection()) {
1046 case ALT_syntaxes:
1047 mp_field = field_syntaxes->get_param(param_name);
1048 mp_field->set_id(new Module_Param_FieldName(mcopystr("syntaxes")));
1049 break;
1050 case ALT_syntax:
1051 mp_field = field_syntax->get_param(param_name);
1052 mp_field->set_id(new Module_Param_FieldName(mcopystr("syntax")));
1053 break;
1054 case ALT_presentation__context__id:
1055 mp_field = field_presentation__context__id->get_param(param_name);
1056 mp_field->set_id(new Module_Param_FieldName(mcopystr("presentation_context_id")));
1057 break;
1058 case ALT_context__negotiation:
1059 mp_field = field_context__negotiation->get_param(param_name);
1060 mp_field->set_id(new Module_Param_FieldName(mcopystr("context_negotiation")));
1061 break;
1062 case ALT_transfer__syntax:
1063 mp_field = field_transfer__syntax->get_param(param_name);
1064 mp_field->set_id(new Module_Param_FieldName(mcopystr("transfer_syntax")));
1065 break;
1066 case ALT_fixed:
1067 mp_field = field_fixed->get_param(param_name);
1068 mp_field->set_id(new Module_Param_FieldName(mcopystr("fixed")));
1069 break;
1070 default:
1071 break;
1072 }
1073 Module_Param_Assignment_List* mp = new Module_Param_Assignment_List();
1074 mp->add_elem(mp_field);
1075 return mp;
1076}
1077
970ed795
EL
1078void EXTERNAL_identification_template::set_param(Module_Param& param)
1079{
1080 param.basic_check(Module_Param::BC_TEMPLATE, "union template");
3abe9331 1081 Module_Param_Ptr mp = &param;
1082 if (param.get_type() == Module_Param::MP_Reference) {
1083 mp = param.get_referenced_param();
1084 }
1085 switch (mp->get_type()) {
970ed795
EL
1086 case Module_Param::MP_Omit:
1087 *this = OMIT_VALUE;
1088 break;
1089 case Module_Param::MP_Any:
1090 *this = ANY_VALUE;
1091 break;
1092 case Module_Param::MP_AnyOrNone:
1093 *this = ANY_OR_OMIT;
1094 break;
1095 case Module_Param::MP_List_Template:
3abe9331 1096 case Module_Param::MP_ComplementList_Template: {
1097 EXTERNAL_identification_template temp;
1098 temp.set_type(mp->get_type() == Module_Param::MP_List_Template ?
1099 VALUE_LIST : COMPLEMENTED_LIST, mp->get_size());
1100 for (size_t i=0; i<mp->get_size(); i++) {
1101 temp.list_item(i).set_param(*mp->get_elem(i));
1102 }
1103 *this = temp;
1104 break; }
970ed795 1105 case Module_Param::MP_Value_List:
3abe9331 1106 if (mp->get_size()==0) break;
970ed795
EL
1107 param.type_error("union template", "EXTERNAL.identification");
1108 break;
1109 case Module_Param::MP_Assignment_List: {
3abe9331 1110 Module_Param* mp_last = mp->get_elem(mp->get_size()-1);
970ed795
EL
1111 if (!strcmp(mp_last->get_id()->get_name(), "syntaxes")) {
1112 syntaxes().set_param(*mp_last);
1113 break;
1114 }
1115 if (!strcmp(mp_last->get_id()->get_name(), "syntax")) {
1116 syntax().set_param(*mp_last);
1117 break;
1118 }
1119 if (!strcmp(mp_last->get_id()->get_name(), "presentation_context_id")) {
1120 presentation__context__id().set_param(*mp_last);
1121 break;
1122 }
1123 if (!strcmp(mp_last->get_id()->get_name(), "context_negotiation")) {
1124 context__negotiation().set_param(*mp_last);
1125 break;
1126 }
1127 if (!strcmp(mp_last->get_id()->get_name(), "transfer_syntax")) {
1128 transfer__syntax().set_param(*mp_last);
1129 break;
1130 }
1131 if (!strcmp(mp_last->get_id()->get_name(), "fixed")) {
1132 fixed().set_param(*mp_last);
1133 break;
1134 }
1135 mp_last->error("Field %s does not exist in type EXTERNAL.identification.", mp_last->get_id()->get_name());
1136 } break;
1137 default:
1138 param.type_error("union template", "EXTERNAL.identification");
1139 }
3abe9331 1140 is_ifpresent = param.get_ifpresent() || mp->get_ifpresent();
1141}
1142
1143Module_Param* EXTERNAL_identification_template::get_param(Module_Param_Name& param_name) const
1144{
1145 Module_Param* mp = NULL;
1146 switch (template_selection) {
1147 case UNINITIALIZED_TEMPLATE:
1148 mp = new Module_Param_Unbound();
1149 break;
1150 case OMIT_VALUE:
1151 mp = new Module_Param_Omit();
1152 break;
1153 case ANY_VALUE:
1154 mp = new Module_Param_Any();
1155 break;
1156 case ANY_OR_OMIT:
1157 mp = new Module_Param_AnyOrNone();
1158 break;
1159 case SPECIFIC_VALUE: {
1160 Module_Param* mp_field = NULL;
1161 switch(single_value.union_selection) {
1162 case EXTERNAL_identification::ALT_syntaxes:
1163 mp_field = single_value.field_syntaxes->get_param(param_name);
1164 mp_field->set_id(new Module_Param_FieldName(mcopystr("syntaxes")));
1165 break;
1166 case EXTERNAL_identification::ALT_syntax:
1167 mp_field = single_value.field_syntax->get_param(param_name);
1168 mp_field->set_id(new Module_Param_FieldName(mcopystr("syntax")));
1169 break;
1170 case EXTERNAL_identification::ALT_presentation__context__id:
1171 mp_field = single_value.field_presentation__context__id->get_param(param_name);
1172 mp_field->set_id(new Module_Param_FieldName(mcopystr("presentation_context_id")));
1173 break;
1174 case EXTERNAL_identification::ALT_context__negotiation:
1175 mp_field = single_value.field_context__negotiation->get_param(param_name);
1176 mp_field->set_id(new Module_Param_FieldName(mcopystr("context_negotiation")));
1177 break;
1178 case EXTERNAL_identification::ALT_transfer__syntax:
1179 mp_field = single_value.field_transfer__syntax->get_param(param_name);
1180 mp_field->set_id(new Module_Param_FieldName(mcopystr("transfer_syntax")));
1181 break;
1182 case EXTERNAL_identification::ALT_fixed:
1183 mp_field = single_value.field_fixed->get_param(param_name);
1184 mp_field->set_id(new Module_Param_FieldName(mcopystr("fixed")));
1185 break;
1186 default:
1187 break;
1188 }
1189 mp = new Module_Param_Assignment_List();
1190 mp->add_elem(mp_field);
1191 break; }
1192 case VALUE_LIST:
1193 case COMPLEMENTED_LIST: {
1194 if (template_selection == VALUE_LIST) {
1195 mp = new Module_Param_List_Template();
1196 }
1197 else {
1198 mp = new Module_Param_ComplementList_Template();
1199 }
1200 for (size_t i = 0; i < value_list.n_values; ++i) {
1201 mp->add_elem(value_list.list_value[i].get_param(param_name));
1202 }
1203 break; }
1204 default:
1205 break;
1206 }
1207 if (is_ifpresent) {
1208 mp->set_ifpresent();
1209 }
1210 return mp;
970ed795
EL
1211}
1212
1213void EXTERNAL_identification::encode_text(Text_Buf& text_buf) const
1214{
1215 text_buf.push_int(union_selection);
1216 switch (union_selection) {
1217 case ALT_syntaxes:
1218 field_syntaxes->encode_text(text_buf);
1219 break;
1220 case ALT_syntax:
1221 field_syntax->encode_text(text_buf);
1222 break;
1223 case ALT_presentation__context__id:
1224 field_presentation__context__id->encode_text(text_buf);
1225 break;
1226 case ALT_context__negotiation:
1227 field_context__negotiation->encode_text(text_buf);
1228 break;
1229 case ALT_transfer__syntax:
1230 field_transfer__syntax->encode_text(text_buf);
1231 break;
1232 case ALT_fixed:
1233 field_fixed->encode_text(text_buf);
1234 break;
1235 default:
1236 TTCN_error("Text encoder: Encoding an unbound value of union type EXTERNAL.identification.");
1237 }
1238}
1239
1240void EXTERNAL_identification::decode_text(Text_Buf& text_buf)
1241{
1242 switch ((union_selection_type)text_buf.pull_int().get_val()) {
1243 case ALT_syntaxes:
1244 syntaxes().decode_text(text_buf);
1245 break;
1246 case ALT_syntax:
1247 syntax().decode_text(text_buf);
1248 break;
1249 case ALT_presentation__context__id:
1250 presentation__context__id().decode_text(text_buf);
1251 break;
1252 case ALT_context__negotiation:
1253 context__negotiation().decode_text(text_buf);
1254 break;
1255 case ALT_transfer__syntax:
1256 transfer__syntax().decode_text(text_buf);
1257 break;
1258 case ALT_fixed:
1259 fixed().decode_text(text_buf);
1260 break;
1261 default:
1262 TTCN_error("Text decoder: Unrecognized union selector was received for type EXTERNAL.identification.");
1263 }
1264}
1265
1266
1267void EXTERNAL_identification_template::clean_up()
1268{
1269 switch (template_selection) {
1270 case SPECIFIC_VALUE:
1271 switch (single_value.union_selection) {
1272 case EXTERNAL_identification::ALT_syntaxes:
1273 delete single_value.field_syntaxes;
1274 break;
1275 case EXTERNAL_identification::ALT_syntax:
1276 delete single_value.field_syntax;
1277 break;
1278 case EXTERNAL_identification::ALT_presentation__context__id:
1279 delete single_value.field_presentation__context__id;
1280 break;
1281 case EXTERNAL_identification::ALT_context__negotiation:
1282 delete single_value.field_context__negotiation;
1283 break;
1284 case EXTERNAL_identification::ALT_transfer__syntax:
1285 delete single_value.field_transfer__syntax;
1286 break;
1287 case EXTERNAL_identification::ALT_fixed:
1288 delete single_value.field_fixed;
1289 break;
1290 default:
1291 break;
1292 }
1293 break;
1294 case VALUE_LIST:
1295 case COMPLEMENTED_LIST:
1296 delete [] value_list.list_value;
1297 break;
1298 default:
1299 break;
1300 }
1301 template_selection = UNINITIALIZED_TEMPLATE;
1302}
1303
1304void EXTERNAL_identification_template::copy_value(const EXTERNAL_identification& other_value)
1305{
1306 single_value.union_selection = other_value.get_selection();
1307 switch (single_value.union_selection) {
1308 case EXTERNAL_identification::ALT_syntaxes:
1309 single_value.field_syntaxes = new EXTERNAL_identification_syntaxes_template(other_value.syntaxes());
1310 break;
1311 case EXTERNAL_identification::ALT_syntax:
1312 single_value.field_syntax = new OBJID_template(other_value.syntax());
1313 break;
1314 case EXTERNAL_identification::ALT_presentation__context__id:
1315 single_value.field_presentation__context__id = new INTEGER_template(other_value.presentation__context__id());
1316 break;
1317 case EXTERNAL_identification::ALT_context__negotiation:
1318 single_value.field_context__negotiation = new EXTERNAL_identification_context__negotiation_template(other_value.context__negotiation());
1319 break;
1320 case EXTERNAL_identification::ALT_transfer__syntax:
1321 single_value.field_transfer__syntax = new OBJID_template(other_value.transfer__syntax());
1322 break;
1323 case EXTERNAL_identification::ALT_fixed:
1324 single_value.field_fixed = new ASN_NULL_template(other_value.fixed());
1325 break;
1326 default:
1327 TTCN_error("Initializing a template with an unbound value of type EXTERNAL.identification.");
1328 }
1329 set_selection(SPECIFIC_VALUE);
1330}
1331
1332void EXTERNAL_identification_template::copy_template(const EXTERNAL_identification_template& other_value)
1333{
1334 switch (other_value.template_selection) {
1335 case SPECIFIC_VALUE:
1336 single_value.union_selection = other_value.single_value.union_selection;
1337 switch (single_value.union_selection) {
1338 case EXTERNAL_identification::ALT_syntaxes:
1339 single_value.field_syntaxes = new EXTERNAL_identification_syntaxes_template(*other_value.single_value.field_syntaxes);
1340 break;
1341 case EXTERNAL_identification::ALT_syntax:
1342 single_value.field_syntax = new OBJID_template(*other_value.single_value.field_syntax);
1343 break;
1344 case EXTERNAL_identification::ALT_presentation__context__id:
1345 single_value.field_presentation__context__id = new INTEGER_template(*other_value.single_value.field_presentation__context__id);
1346 break;
1347 case EXTERNAL_identification::ALT_context__negotiation:
1348 single_value.field_context__negotiation = new EXTERNAL_identification_context__negotiation_template(*other_value.single_value.field_context__negotiation);
1349 break;
1350 case EXTERNAL_identification::ALT_transfer__syntax:
1351 single_value.field_transfer__syntax = new OBJID_template(*other_value.single_value.field_transfer__syntax);
1352 break;
1353 case EXTERNAL_identification::ALT_fixed:
1354 single_value.field_fixed = new ASN_NULL_template(*other_value.single_value.field_fixed);
1355 break;
1356 default:
1357 TTCN_error("Internal error: Invalid union selector in a specific value when copying a template of type EXTERNAL.identification.");
1358 }
1359 break;
1360 case OMIT_VALUE:
1361 case ANY_VALUE:
1362 case ANY_OR_OMIT:
1363 break;
1364 case VALUE_LIST:
1365 case COMPLEMENTED_LIST:
1366 value_list.n_values = other_value.value_list.n_values;
1367 value_list.list_value = new EXTERNAL_identification_template[value_list.n_values];
1368 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
1369 value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]);
1370 break;
1371 default:
1372 TTCN_error("Copying an uninitialized template of union type EXTERNAL.identification.");
1373 }
1374 set_selection(other_value);
1375}
1376
1377EXTERNAL_identification_template::EXTERNAL_identification_template()
1378{
1379}
1380
1381EXTERNAL_identification_template::EXTERNAL_identification_template(template_sel other_value)
1382 : Base_Template(other_value)
1383{
1384 check_single_selection(other_value);
1385}
1386
1387EXTERNAL_identification_template::EXTERNAL_identification_template(const EXTERNAL_identification& other_value)
1388{
1389 copy_value(other_value);
1390}
1391
1392EXTERNAL_identification_template::EXTERNAL_identification_template(const OPTIONAL<EXTERNAL_identification>& other_value)
1393{
1394 switch (other_value.get_selection()) {
1395 case OPTIONAL_PRESENT:
1396 copy_value((const EXTERNAL_identification&)other_value);
1397 break;
1398 case OPTIONAL_OMIT:
1399 set_selection(OMIT_VALUE);
1400 break;
1401 default:
1402 TTCN_error("Creating a template of union type EXTERNAL.identification from an unbound optional field.");
1403 }
1404}
1405
1406EXTERNAL_identification_template::EXTERNAL_identification_template(const EXTERNAL_identification_template& other_value)
1407: Base_Template()
1408{
1409 copy_template(other_value);
1410}
1411
1412EXTERNAL_identification_template::~EXTERNAL_identification_template()
1413{
1414 clean_up();
1415}
1416
1417EXTERNAL_identification_template& EXTERNAL_identification_template::operator=(template_sel other_value)
1418{
1419 check_single_selection(other_value);
1420 clean_up();
1421 set_selection(other_value);
1422 return *this;
1423}
1424
1425EXTERNAL_identification_template& EXTERNAL_identification_template::operator=(const EXTERNAL_identification& other_value)
1426{
1427 clean_up();
1428 copy_value(other_value);
1429 return *this;
1430}
1431
1432EXTERNAL_identification_template& EXTERNAL_identification_template::operator=(const OPTIONAL<EXTERNAL_identification>& other_value)
1433{
1434 clean_up();
1435 switch (other_value.get_selection()) {
1436 case OPTIONAL_PRESENT:
1437 copy_value((const EXTERNAL_identification&)other_value);
1438 break;
1439 case OPTIONAL_OMIT:
1440 set_selection(OMIT_VALUE);
1441 break;
1442 default:
1443 TTCN_error("Assignment of an unbound optional field to a template of union type EXTERNAL.identification.");
1444 }
1445 return *this;
1446}
1447
1448EXTERNAL_identification_template& EXTERNAL_identification_template::operator=(const EXTERNAL_identification_template& other_value)
1449{
1450 if (&other_value != this) {
1451 clean_up();
1452 copy_template(other_value);
1453 }
1454 return *this;
1455}
1456
3abe9331 1457boolean EXTERNAL_identification_template::match(const EXTERNAL_identification& other_value,
1458 boolean /* legacy */) const
970ed795
EL
1459{
1460 switch (template_selection) {
1461 case ANY_VALUE:
1462 case ANY_OR_OMIT:
1463 return TRUE;
1464 case OMIT_VALUE:
1465 return FALSE;
1466 case SPECIFIC_VALUE:
1467 {
1468 EXTERNAL_identification::union_selection_type value_selection = other_value.get_selection();
1469 if (value_selection == EXTERNAL_identification::UNBOUND_VALUE) return FALSE;
1470 if (value_selection != single_value.union_selection) return FALSE;
1471 switch (value_selection) {
1472 case EXTERNAL_identification::ALT_syntaxes:
1473 return single_value.field_syntaxes->match(other_value.syntaxes());
1474 case EXTERNAL_identification::ALT_syntax:
1475 return single_value.field_syntax->match(other_value.syntax());
1476 case EXTERNAL_identification::ALT_presentation__context__id:
1477 return single_value.field_presentation__context__id->match(other_value.presentation__context__id());
1478 case EXTERNAL_identification::ALT_context__negotiation:
1479 return single_value.field_context__negotiation->match(other_value.context__negotiation());
1480 case EXTERNAL_identification::ALT_transfer__syntax:
1481 return single_value.field_transfer__syntax->match(other_value.transfer__syntax());
1482 case EXTERNAL_identification::ALT_fixed:
1483 return single_value.field_fixed->match(other_value.fixed());
1484 default:
1485 TTCN_error("Internal error: Invalid selector in a specific value when matching a template of union type EXTERNAL.identification.");
1486 }
1487 }
1488 break; // should never get here
1489 case VALUE_LIST:
1490 case COMPLEMENTED_LIST:
1491 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
1492 if (value_list.list_value[list_count].match(other_value)) return template_selection == VALUE_LIST;
1493 return template_selection == COMPLEMENTED_LIST;
1494 default:
1495 TTCN_error ("Matching an uninitialized template of union type EXTERNAL.identification.");
1496 }
1497 return FALSE;
1498}
1499
1500EXTERNAL_identification EXTERNAL_identification_template::valueof() const
1501{
1502 if (template_selection != SPECIFIC_VALUE || is_ifpresent)
1503 TTCN_error("Performing valueof or send operation on a non-specific template of union type EXTERNAL.identification.");
1504 EXTERNAL_identification ret_val;
1505 switch (single_value.union_selection) {
1506 case EXTERNAL_identification::ALT_syntaxes:
1507 ret_val.syntaxes() = single_value.field_syntaxes->valueof();
1508 break;
1509 case EXTERNAL_identification::ALT_syntax:
1510 ret_val.syntax() = single_value.field_syntax->valueof();
1511 break;
1512 case EXTERNAL_identification::ALT_presentation__context__id:
1513 ret_val.presentation__context__id() = single_value.field_presentation__context__id->valueof();
1514 break;
1515 case EXTERNAL_identification::ALT_context__negotiation:
1516 ret_val.context__negotiation() = single_value.field_context__negotiation->valueof();
1517 break;
1518 case EXTERNAL_identification::ALT_transfer__syntax:
1519 ret_val.transfer__syntax() = single_value.field_transfer__syntax->valueof();
1520 break;
1521 case EXTERNAL_identification::ALT_fixed:
1522 ret_val.fixed() = single_value.field_fixed->valueof();
1523 break;
1524 default:
1525 TTCN_error("Internal error: Invalid selector in a specific value when performing valueof operation on a template of union type EXTERNAL.identification.");
1526 }
1527 return ret_val;
1528}
1529
1530EXTERNAL_identification_template& EXTERNAL_identification_template::list_item(unsigned int list_index) const
1531{
1532 if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST) TTCN_error("Internal error: Accessing a list element of a non-list template of union type EXTERNAL.identification.");
1533 if (list_index >= value_list.n_values) TTCN_error("Internal error: Index overflow in a value list template of union type EXTERNAL.identification.");
1534 return value_list.list_value[list_index];
1535}
1536void EXTERNAL_identification_template::set_type(template_sel template_type, unsigned int list_length)
1537{
1538 if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST) TTCN_error ("Internal error: Setting an invalid list for a template of union type EXTERNAL.identification.");
1539 clean_up();
1540 set_selection(template_type);
1541 value_list.n_values = list_length;
1542 value_list.list_value = new EXTERNAL_identification_template[list_length];
1543}
1544
1545EXTERNAL_identification_syntaxes_template& EXTERNAL_identification_template::syntaxes()
1546{
1547 if (template_selection != SPECIFIC_VALUE || single_value.union_selection != EXTERNAL_identification::ALT_syntaxes) {
1548 template_sel old_selection = template_selection;
1549 clean_up();
1550 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) single_value.field_syntaxes = new EXTERNAL_identification_syntaxes_template(ANY_VALUE);
1551 else single_value.field_syntaxes = new EXTERNAL_identification_syntaxes_template;
1552 single_value.union_selection = EXTERNAL_identification::ALT_syntaxes;
1553 set_selection(SPECIFIC_VALUE);
1554 }
1555 return *single_value.field_syntaxes;
1556}
1557
1558const EXTERNAL_identification_syntaxes_template& EXTERNAL_identification_template::syntaxes() const
1559{
1560 if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field syntaxes in a non-specific template of union type EXTERNAL.identification.");
1561 if (single_value.union_selection != EXTERNAL_identification::ALT_syntaxes) TTCN_error("Accessing non-selected field syntaxes in a template of union type EXTERNAL.identification.");
1562 return *single_value.field_syntaxes;
1563}
1564
1565OBJID_template& EXTERNAL_identification_template::syntax()
1566{
1567 if (template_selection != SPECIFIC_VALUE || single_value.union_selection != EXTERNAL_identification::ALT_syntax) {
1568 template_sel old_selection = template_selection;
1569 clean_up();
1570 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) single_value.field_syntax = new OBJID_template(ANY_VALUE);
1571 else single_value.field_syntax = new OBJID_template;
1572 single_value.union_selection = EXTERNAL_identification::ALT_syntax;
1573 set_selection(SPECIFIC_VALUE);
1574 }
1575 return *single_value.field_syntax;
1576}
1577
1578const OBJID_template& EXTERNAL_identification_template::syntax() const
1579{
1580 if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field syntax in a non-specific template of union type EXTERNAL.identification.");
1581 if (single_value.union_selection != EXTERNAL_identification::ALT_syntax) TTCN_error("Accessing non-selected field syntax in a template of union type EXTERNAL.identification.");
1582 return *single_value.field_syntax;
1583}
1584
1585INTEGER_template& EXTERNAL_identification_template::presentation__context__id()
1586{
1587 if (template_selection != SPECIFIC_VALUE || single_value.union_selection != EXTERNAL_identification::ALT_presentation__context__id) {
1588 template_sel old_selection = template_selection;
1589 clean_up();
1590 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) single_value.field_presentation__context__id = new INTEGER_template(ANY_VALUE);
1591 else single_value.field_presentation__context__id = new INTEGER_template;
1592 single_value.union_selection = EXTERNAL_identification::ALT_presentation__context__id;
1593 set_selection(SPECIFIC_VALUE);
1594 }
1595 return *single_value.field_presentation__context__id;
1596}
1597
1598const INTEGER_template& EXTERNAL_identification_template::presentation__context__id() const
1599{
1600 if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field presentation_context_id in a non-specific template of union type EXTERNAL.identification.");
1601 if (single_value.union_selection != EXTERNAL_identification::ALT_presentation__context__id) TTCN_error("Accessing non-selected field presentation_context_id in a template of union type EXTERNAL.identification.");
1602 return *single_value.field_presentation__context__id;
1603}
1604
1605EXTERNAL_identification_context__negotiation_template& EXTERNAL_identification_template::context__negotiation()
1606{
1607 if (template_selection != SPECIFIC_VALUE || single_value.union_selection != EXTERNAL_identification::ALT_context__negotiation) {
1608 template_sel old_selection = template_selection;
1609 clean_up();
1610 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) single_value.field_context__negotiation = new EXTERNAL_identification_context__negotiation_template(ANY_VALUE);
1611 else single_value.field_context__negotiation = new EXTERNAL_identification_context__negotiation_template;
1612 single_value.union_selection = EXTERNAL_identification::ALT_context__negotiation;
1613 set_selection(SPECIFIC_VALUE);
1614 }
1615 return *single_value.field_context__negotiation;
1616}
1617
1618const EXTERNAL_identification_context__negotiation_template& EXTERNAL_identification_template::context__negotiation() const
1619{
1620 if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field context_negotiation in a non-specific template of union type EXTERNAL.identification.");
1621 if (single_value.union_selection != EXTERNAL_identification::ALT_context__negotiation) TTCN_error("Accessing non-selected field context_negotiation in a template of union type EXTERNAL.identification.");
1622 return *single_value.field_context__negotiation;
1623}
1624
1625OBJID_template& EXTERNAL_identification_template::transfer__syntax()
1626{
1627 if (template_selection != SPECIFIC_VALUE || single_value.union_selection != EXTERNAL_identification::ALT_transfer__syntax) {
1628 template_sel old_selection = template_selection;
1629 clean_up();
1630 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) single_value.field_transfer__syntax = new OBJID_template(ANY_VALUE);
1631 else single_value.field_transfer__syntax = new OBJID_template;
1632 single_value.union_selection = EXTERNAL_identification::ALT_transfer__syntax;
1633 set_selection(SPECIFIC_VALUE);
1634 }
1635 return *single_value.field_transfer__syntax;
1636}
1637
1638const OBJID_template& EXTERNAL_identification_template::transfer__syntax() const
1639{
1640 if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field transfer_syntax in a non-specific template of union type EXTERNAL.identification.");
1641 if (single_value.union_selection != EXTERNAL_identification::ALT_transfer__syntax) TTCN_error("Accessing non-selected field transfer_syntax in a template of union type EXTERNAL.identification.");
1642 return *single_value.field_transfer__syntax;
1643}
1644
1645ASN_NULL_template& EXTERNAL_identification_template::fixed()
1646{
1647 if (template_selection != SPECIFIC_VALUE || single_value.union_selection != EXTERNAL_identification::ALT_fixed) {
1648 template_sel old_selection = template_selection;
1649 clean_up();
1650 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) single_value.field_fixed = new ASN_NULL_template(ANY_VALUE);
1651 else single_value.field_fixed = new ASN_NULL_template;
1652 single_value.union_selection = EXTERNAL_identification::ALT_fixed;
1653 set_selection(SPECIFIC_VALUE);
1654 }
1655 return *single_value.field_fixed;
1656}
1657
1658const ASN_NULL_template& EXTERNAL_identification_template::fixed() const
1659{
1660 if (template_selection != SPECIFIC_VALUE) TTCN_error("Accessing field fixed in a non-specific template of union type EXTERNAL.identification.");
1661 if (single_value.union_selection != EXTERNAL_identification::ALT_fixed) TTCN_error("Accessing non-selected field fixed in a template of union type EXTERNAL.identification.");
1662 return *single_value.field_fixed;
1663}
1664
1665boolean EXTERNAL_identification_template::ischosen(EXTERNAL_identification::union_selection_type checked_selection) const
1666{
1667 if (checked_selection == EXTERNAL_identification::UNBOUND_VALUE) TTCN_error("Internal error: Performing ischosen() operation on an invalid field of union type EXTERNAL.identification.");
1668 switch (template_selection) {
1669 case SPECIFIC_VALUE:
1670 if (single_value.union_selection == EXTERNAL_identification::UNBOUND_VALUE) TTCN_error("Internal error: Invalid selector in a specific value when performing ischosen() operation on a template of union type EXTERNAL.identification.");
1671 return single_value.union_selection == checked_selection;
1672 case VALUE_LIST:
1673 {
1674 if (value_list.n_values < 1)
1675 TTCN_error("Internal error: Performing ischosen() operation on a template of union type EXTERNAL.identification containing an empty list.");
1676 boolean ret_val = value_list.list_value[0].ischosen(checked_selection);
1677 boolean all_same = TRUE;
1678 for (unsigned int list_count = 1; list_count < value_list.n_values; list_count++) {
1679 if (value_list.list_value[list_count].ischosen(checked_selection) != ret_val) {
1680 all_same = FALSE;
1681 break;
1682 }
1683 }
1684 if (all_same) return ret_val;
1685 }
1686 // FIXME really no break?
1687 case ANY_VALUE:
1688 case ANY_OR_OMIT:
1689 case OMIT_VALUE:
1690 case COMPLEMENTED_LIST:
1691 TTCN_error("Performing ischosen() operation on a template of union type EXTERNAL.identification, which does not determine unambiguously the chosen field of the matching values.");
1692 default:
1693 TTCN_error("Performing ischosen() operation on an uninitialized template of union type EXTERNAL.identification");
1694 }
1695 return FALSE;
1696}
1697
1698void EXTERNAL_identification_template::log() const
1699{
1700 switch (template_selection) {
1701 case SPECIFIC_VALUE:
1702 switch (single_value.union_selection) {
1703 case EXTERNAL_identification::ALT_syntaxes:
1704 TTCN_Logger::log_event_str("{ syntaxes := ");
1705 single_value.field_syntaxes->log();
1706 TTCN_Logger::log_event_str(" }");
1707 break;
1708 case EXTERNAL_identification::ALT_syntax:
1709 TTCN_Logger::log_event_str("{ syntax := ");
1710 single_value.field_syntax->log();
1711 TTCN_Logger::log_event_str(" }");
1712 break;
1713 case EXTERNAL_identification::ALT_presentation__context__id:
1714 TTCN_Logger::log_event_str("{ presentation_context_id := ");
1715 single_value.field_presentation__context__id->log();
1716 TTCN_Logger::log_event_str(" }");
1717 break;
1718 case EXTERNAL_identification::ALT_context__negotiation:
1719 TTCN_Logger::log_event_str("{ context_negotiation := ");
1720 single_value.field_context__negotiation->log();
1721 TTCN_Logger::log_event_str(" }");
1722 break;
1723 case EXTERNAL_identification::ALT_transfer__syntax:
1724 TTCN_Logger::log_event_str("{ transfer_syntax := ");
1725 single_value.field_transfer__syntax->log();
1726 TTCN_Logger::log_event_str(" }");
1727 break;
1728 case EXTERNAL_identification::ALT_fixed:
1729 TTCN_Logger::log_event_str("{ fixed := ");
1730 single_value.field_fixed->log();
1731 TTCN_Logger::log_event_str(" }");
1732 break;
1733 default:
1734 TTCN_Logger::log_event_str("<invalid selector>");
1735 break;
1736 }
1737 break;
1738 case COMPLEMENTED_LIST:
1739 TTCN_Logger::log_event_str("complement ");
1740 // no break
1741 case VALUE_LIST:
1742 TTCN_Logger::log_char('(');
1743 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) {
1744 if (list_count > 0) TTCN_Logger::log_event_str(", ");
1745 value_list.list_value[list_count].log();
1746 }
1747 TTCN_Logger::log_char(')');
1748 break;
1749 default:
1750 log_generic();
1751 break;
1752 }
1753 log_ifpresent();
1754}
1755
3abe9331 1756void EXTERNAL_identification_template::log_match(const EXTERNAL_identification& match_value,
1757 boolean /* legacy */) const
970ed795
EL
1758{
1759 if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){
1760 if(match(match_value)){
1761 TTCN_Logger::print_logmatch_buffer();
1762 TTCN_Logger::log_event_str(" matched ");
1763 }
1764 return;
1765 }
1766 if (template_selection == SPECIFIC_VALUE && single_value.union_selection == match_value.get_selection()) {
1767 switch (single_value.union_selection) {
1768 case EXTERNAL_identification::ALT_syntaxes:
1769 if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){
1770 TTCN_Logger::log_logmatch_info(".syntaxes");
1771 single_value.field_syntaxes->log_match(match_value.syntaxes());
1772 }else{
1773 TTCN_Logger::log_event_str("{ syntaxes := ");
1774 single_value.field_syntaxes->log_match(match_value.syntaxes());
1775 TTCN_Logger::log_event_str(" }");
1776 }
1777 break;
1778 case EXTERNAL_identification::ALT_syntax:
1779 if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){
1780 TTCN_Logger::log_logmatch_info(".syntax");
1781 single_value.field_syntax->log_match(match_value.syntax());
1782 }else{
1783 TTCN_Logger::log_event_str("{ syntax := ");
1784 single_value.field_syntax->log_match(match_value.syntax());
1785 TTCN_Logger::log_event_str(" }");
1786 }
1787 break;
1788 case EXTERNAL_identification::ALT_presentation__context__id:
1789 if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){
1790 TTCN_Logger::log_logmatch_info(".presentation_context_id");
1791 single_value.field_presentation__context__id->log_match(match_value.presentation__context__id());
1792 }else{
1793 TTCN_Logger::log_event_str("{ presentation_context_id := ");
1794 single_value.field_presentation__context__id->log_match(match_value.presentation__context__id());
1795 TTCN_Logger::log_event_str(" }");
1796 }
1797 break;
1798 case EXTERNAL_identification::ALT_context__negotiation:
1799 if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){
1800 TTCN_Logger::log_logmatch_info(".context_negotiation");
1801 single_value.field_context__negotiation->log_match(match_value.context__negotiation());
1802 }else{
1803 TTCN_Logger::log_event_str("{ context_negotiation := ");
1804 single_value.field_context__negotiation->log_match(match_value.context__negotiation());
1805 TTCN_Logger::log_event_str(" }");
1806 }
1807 break;
1808 case EXTERNAL_identification::ALT_transfer__syntax:
1809 if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){
1810 TTCN_Logger::log_logmatch_info(".transfer_syntax");
1811 single_value.field_transfer__syntax->log_match(match_value.transfer__syntax());
1812 }else{
1813 TTCN_Logger::log_event_str("{ transfer_syntax := ");
1814 single_value.field_transfer__syntax->log_match(match_value.transfer__syntax());
1815 TTCN_Logger::log_event_str(" }");
1816 }
1817 break;
1818 case EXTERNAL_identification::ALT_fixed:
1819 if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){
1820 TTCN_Logger::log_logmatch_info(".fixed");
1821 single_value.field_fixed->log_match(match_value.fixed());
1822 }else{
1823 TTCN_Logger::log_event_str("{ fixed := ");
1824 single_value.field_fixed->log_match(match_value.fixed());
1825 TTCN_Logger::log_event_str(" }");
1826 }
1827 break;
1828 default:
1829 TTCN_Logger::print_logmatch_buffer();
1830 TTCN_Logger::log_event_str("<invalid selector>");
1831 break;
1832 }
1833 } else {
1834 TTCN_Logger::print_logmatch_buffer();
1835 match_value.log();
1836 TTCN_Logger::log_event_str(" with ");
1837 log();
1838 if (match(match_value)) TTCN_Logger::log_event_str(" matched");
1839 else TTCN_Logger::log_event_str(" unmatched");
1840 }
1841}
1842
1843void EXTERNAL_identification_template::encode_text(Text_Buf& text_buf) const
1844{
1845 encode_text_base(text_buf);
1846 switch (template_selection) {
1847 case SPECIFIC_VALUE:
1848 text_buf.push_int(single_value.union_selection);
1849 switch (single_value.union_selection) {
1850 case EXTERNAL_identification::ALT_syntaxes:
1851 single_value.field_syntaxes->encode_text(text_buf);
1852 break;
1853 case EXTERNAL_identification::ALT_syntax:
1854 single_value.field_syntax->encode_text(text_buf);
1855 break;
1856 case EXTERNAL_identification::ALT_presentation__context__id:
1857 single_value.field_presentation__context__id->encode_text(text_buf);
1858 break;
1859 case EXTERNAL_identification::ALT_context__negotiation:
1860 single_value.field_context__negotiation->encode_text(text_buf);
1861 break;
1862 case EXTERNAL_identification::ALT_transfer__syntax:
1863 single_value.field_transfer__syntax->encode_text(text_buf);
1864 break;
1865 case EXTERNAL_identification::ALT_fixed:
1866 single_value.field_fixed->encode_text(text_buf);
1867 break;
1868 default:
1869 TTCN_error("Internal error: Invalid selector in a specific value when encoding a template of union type EXTERNAL.identification.");
1870 }
1871 break;
1872 case OMIT_VALUE:
1873 case ANY_VALUE:
1874 case ANY_OR_OMIT:
1875 break;
1876 case VALUE_LIST:
1877 case COMPLEMENTED_LIST:
1878 text_buf.push_int(value_list.n_values);
1879 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
1880 value_list.list_value[list_count].encode_text(text_buf);
1881 break;
1882 default:
1883 TTCN_error("Text encoder: Encoding an uninitialized template of type EXTERNAL.identification.");
1884 }
1885}
1886
1887void EXTERNAL_identification_template::decode_text(Text_Buf& text_buf)
1888{
1889 clean_up();
1890 decode_text_base(text_buf);
1891 switch (template_selection) {
1892 case SPECIFIC_VALUE:
1893 {
1894 single_value.union_selection = EXTERNAL_identification::UNBOUND_VALUE;
1895 EXTERNAL_identification::union_selection_type new_selection = (EXTERNAL_identification::union_selection_type)text_buf.pull_int().get_val();
1896 switch (new_selection) {
1897 case EXTERNAL_identification::ALT_syntaxes:
1898 single_value.field_syntaxes = new EXTERNAL_identification_syntaxes_template;
1899 single_value.field_syntaxes->decode_text(text_buf);
1900 break;
1901 case EXTERNAL_identification::ALT_syntax:
1902 single_value.field_syntax = new OBJID_template;
1903 single_value.field_syntax->decode_text(text_buf);
1904 break;
1905 case EXTERNAL_identification::ALT_presentation__context__id:
1906 single_value.field_presentation__context__id = new INTEGER_template;
1907 single_value.field_presentation__context__id->decode_text(text_buf);
1908 break;
1909 case EXTERNAL_identification::ALT_context__negotiation:
1910 single_value.field_context__negotiation = new EXTERNAL_identification_context__negotiation_template;
1911 single_value.field_context__negotiation->decode_text(text_buf);
1912 break;
1913 case EXTERNAL_identification::ALT_transfer__syntax:
1914 single_value.field_transfer__syntax = new OBJID_template;
1915 single_value.field_transfer__syntax->decode_text(text_buf);
1916 break;
1917 case EXTERNAL_identification::ALT_fixed:
1918 single_value.field_fixed = new ASN_NULL_template;
1919 single_value.field_fixed->decode_text(text_buf);
1920 break;
1921 default:
1922 TTCN_error("Text decoder: Unrecognized union selector was received for a template of type EXTERNAL.identification.");
1923 }
1924 single_value.union_selection = new_selection;
1925 }
1926 break;
1927 case OMIT_VALUE:
1928 case ANY_VALUE:
1929 case ANY_OR_OMIT:
1930 break;
1931 case VALUE_LIST:
1932 case COMPLEMENTED_LIST:
1933 value_list.n_values = text_buf.pull_int().get_val();
1934 value_list.list_value = new EXTERNAL_identification_template[value_list.n_values];
1935 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
1936 value_list.list_value[list_count].decode_text(text_buf);
1937 break;
1938 default:
1939 TTCN_error("Text decoder: Unrecognized selector was received in a template of type EXTERNAL.identification.");
1940 }
1941}
1942
3abe9331 1943boolean EXTERNAL_identification_template::is_present(boolean legacy /* = FALSE */) const
970ed795
EL
1944{
1945 if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;
3abe9331 1946 return !match_omit(legacy);
970ed795
EL
1947}
1948
3abe9331 1949boolean EXTERNAL_identification_template::match_omit(boolean legacy /* = FALSE */) const
970ed795
EL
1950{
1951 if (is_ifpresent) return TRUE;
1952 switch (template_selection) {
1953 case OMIT_VALUE:
1954 case ANY_OR_OMIT:
1955 return TRUE;
1956 case VALUE_LIST:
1957 case COMPLEMENTED_LIST:
3abe9331 1958 if (legacy) {
1959 for (unsigned int i=0; i<value_list.n_values; i++)
1960 if (value_list.list_value[i].match_omit())
1961 return template_selection==VALUE_LIST;
1962 return template_selection==COMPLEMENTED_LIST;
1963 } // else fall through
970ed795
EL
1964 default:
1965 return FALSE;
1966 }
1967 return FALSE;
1968}
1969
1970#ifndef TITAN_RUNTIME_2
3abe9331 1971void EXTERNAL_identification_template::check_restriction(template_res t_res, const char* t_name,
1972 boolean legacy /* = FALSE */) const
970ed795
EL
1973{
1974 if (template_selection==UNINITIALIZED_TEMPLATE) return;
1975 switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {
1976 case TR_VALUE:
1977 if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;
1978 break;
1979 case TR_OMIT:
1980 if (!is_ifpresent && (template_selection==OMIT_VALUE ||
1981 template_selection==SPECIFIC_VALUE)) return;
1982 break;
1983 case TR_PRESENT:
3abe9331 1984 if (!match_omit(legacy)) return;
970ed795
EL
1985 break;
1986 default:
1987 return;
1988 }
1989 TTCN_error("Restriction `%s' on template of type %s violated.",
1990 get_res_name(t_res), t_name ? t_name : "EXTERNAL.identification");
1991}
1992#endif
1993
1994EXTERNAL_identification_syntaxes::EXTERNAL_identification_syntaxes()
1995{
1996}
1997
1998EXTERNAL_identification_syntaxes::EXTERNAL_identification_syntaxes(const OBJID& par_abstract,
1999 const OBJID& par_transfer)
2000 : field_abstract(par_abstract),
2001 field_transfer(par_transfer)
2002{
2003}
2004
2005boolean EXTERNAL_identification_syntaxes::operator==(const EXTERNAL_identification_syntaxes& other_value) const
2006{
2007 return field_abstract==other_value.field_abstract
2008 && field_transfer==other_value.field_transfer;
2009}
2010
2011int EXTERNAL_identification_syntaxes::size_of() const
2012{
2013 int ret_val = 2;
2014 return ret_val;
2015}
2016
2017void EXTERNAL_identification_syntaxes::log() const
2018{
2019 TTCN_Logger::log_event_str("{ abstract := ");
2020 field_abstract.log();
2021 TTCN_Logger::log_event_str(", transfer := ");
2022 field_transfer.log();
2023 TTCN_Logger::log_event_str(" }");
2024}
2025
2026boolean EXTERNAL_identification_syntaxes::is_bound() const
2027{
2028 if(field_abstract.is_bound()) return TRUE;
2029 if(field_transfer.is_bound()) return TRUE;
2030 return FALSE;
2031}
2032
2033boolean EXTERNAL_identification_syntaxes::is_value() const
2034{
2035 if(!field_abstract.is_value()) return FALSE;
2036 if(!field_transfer.is_value()) return FALSE;
2037 return TRUE;
2038}
2039
2040void EXTERNAL_identification_syntaxes::clean_up()
2041{
2042 field_abstract.clean_up();
2043 field_transfer.clean_up();
2044}
2045
2046void EXTERNAL_identification_syntaxes::set_param(Module_Param& param)
2047{
2048 param.basic_check(Module_Param::BC_VALUE, "record value");
3abe9331 2049 Module_Param_Ptr mp = &param;
2050 if (param.get_type() == Module_Param::MP_Reference) {
2051 mp = param.get_referenced_param();
2052 }
2053 switch (mp->get_type()) {
970ed795 2054 case Module_Param::MP_Value_List:
3abe9331 2055 if (mp->get_size()==0) return;
2056 if (2!=mp->get_size()) {
2057 param.error("record value of type EXTERNAL.identification.syntaxes has 2 fields but list value has %d fields", (int)mp->get_size());
970ed795 2058 }
3abe9331 2059 if (mp->get_elem(0)->get_type()!=Module_Param::MP_NotUsed) abstract().set_param(*mp->get_elem(0));
2060 if (mp->get_elem(1)->get_type()!=Module_Param::MP_NotUsed) transfer().set_param(*mp->get_elem(1));
970ed795
EL
2061 break;
2062 case Module_Param::MP_Assignment_List: {
3abe9331 2063 Vector<bool> value_used(mp->get_size());
2064 value_used.resize(mp->get_size(), false);
2065 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2066 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2067 if (!strcmp(curr_param->get_id()->get_name(), "abstract")) {
2068 abstract().set_param(*curr_param);
2069 value_used[val_idx]=true;
2070 }
2071 }
3abe9331 2072 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2073 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2074 if (!strcmp(curr_param->get_id()->get_name(), "transfer")) {
2075 transfer().set_param(*curr_param);
2076 value_used[val_idx]=true;
2077 }
2078 }
3abe9331 2079 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) if (!value_used[val_idx]) {
2080 mp->get_elem(val_idx)->error("Non existent field name in type EXTERNAL.identification.syntaxes: %s", mp->get_elem(val_idx)->get_id()->get_name());
970ed795
EL
2081 break;
2082 }
2083 } break;
2084 default:
2085 param.type_error("record value", "EXTERNAL.identification.syntaxes");
2086 }
2087}
2088
3abe9331 2089Module_Param* EXTERNAL_identification_syntaxes::get_param(Module_Param_Name& param_name) const
2090{
2091 if (!is_bound()) {
2092 return new Module_Param_Unbound();
2093 }
2094 Module_Param* mp_field_abstract = field_abstract.get_param(param_name);
2095 mp_field_abstract->set_id(new Module_Param_FieldName(mcopystr("abstract")));
2096 Module_Param* mp_field_transfer = field_transfer.get_param(param_name);
2097 mp_field_transfer->set_id(new Module_Param_FieldName(mcopystr("transfer")));
2098 Module_Param_Assignment_List* mp = new Module_Param_Assignment_List();
2099 mp->add_elem(mp_field_abstract);
2100 mp->add_elem(mp_field_transfer);
2101 return mp;
2102}
2103
2104void EXTERNAL_identification_syntaxes::encode_text(Text_Buf& text_buf) const
2105{
2106 field_abstract.encode_text(text_buf);
2107 field_transfer.encode_text(text_buf);
2108}
2109
2110void EXTERNAL_identification_syntaxes::decode_text(Text_Buf& text_buf)
2111{
2112 field_abstract.decode_text(text_buf);
2113 field_transfer.decode_text(text_buf);
2114}
2115
2116struct EXTERNAL_identification_syntaxes_template::single_value_struct {
2117 OBJID_template field_abstract;
2118 OBJID_template field_transfer;
2119};
2120
970ed795
EL
2121void EXTERNAL_identification_syntaxes_template::set_param(Module_Param& param)
2122{
2123 param.basic_check(Module_Param::BC_TEMPLATE, "record template");
3abe9331 2124 Module_Param_Ptr mp = &param;
2125 if (param.get_type() == Module_Param::MP_Reference) {
2126 mp = param.get_referenced_param();
2127 }
2128 switch (mp->get_type()) {
970ed795
EL
2129 case Module_Param::MP_Omit:
2130 *this = OMIT_VALUE;
2131 break;
2132 case Module_Param::MP_Any:
2133 *this = ANY_VALUE;
2134 break;
2135 case Module_Param::MP_AnyOrNone:
2136 *this = ANY_OR_OMIT;
2137 break;
2138 case Module_Param::MP_List_Template:
3abe9331 2139 case Module_Param::MP_ComplementList_Template: {
2140 EXTERNAL_identification_syntaxes_template temp;
2141 temp.set_type(mp->get_type() == Module_Param::MP_List_Template ?
2142 VALUE_LIST : COMPLEMENTED_LIST, mp->get_size());
2143 for (size_t i=0; i<mp->get_size(); i++) {
2144 temp.list_item(i).set_param(*mp->get_elem(i));
2145 }
2146 *this = temp;
2147 break; }
970ed795 2148 case Module_Param::MP_Value_List:
3abe9331 2149 if (mp->get_size()==0) break;
2150 if (2!=mp->get_size()) {
2151 param.error("record template of type EXTERNAL.identification.syntaxes has 2 fields but list value has %d fields", (int)mp->get_size());
970ed795 2152 }
3abe9331 2153 if (mp->get_elem(0)->get_type()!=Module_Param::MP_NotUsed) abstract().set_param(*mp->get_elem(0));
2154 if (mp->get_elem(1)->get_type()!=Module_Param::MP_NotUsed) transfer().set_param(*mp->get_elem(1));
970ed795
EL
2155 break;
2156 case Module_Param::MP_Assignment_List: {
3abe9331 2157 Vector<bool> value_used(mp->get_size());
2158 value_used.resize(mp->get_size(), false);
2159 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2160 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2161 if (!strcmp(curr_param->get_id()->get_name(), "abstract")) {
2162 abstract().set_param(*curr_param);
2163 value_used[val_idx]=true;
2164 }
2165 }
3abe9331 2166 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2167 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2168 if (!strcmp(curr_param->get_id()->get_name(), "transfer")) {
2169 transfer().set_param(*curr_param);
2170 value_used[val_idx]=true;
2171 }
2172 }
3abe9331 2173 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) if (!value_used[val_idx]) {
2174 mp->get_elem(val_idx)->error("Non existent field name in type EXTERNAL.identification.syntaxes: %s", mp->get_elem(val_idx)->get_id()->get_name());
970ed795
EL
2175 break;
2176 }
2177 } break;
2178 default:
2179 param.type_error("record template", "EXTERNAL.identification.syntaxes");
2180 }
3abe9331 2181 is_ifpresent = param.get_ifpresent() || mp->get_ifpresent();
970ed795
EL
2182}
2183
3abe9331 2184Module_Param* EXTERNAL_identification_syntaxes_template::get_param(Module_Param_Name& param_name) const
970ed795 2185{
3abe9331 2186 Module_Param* mp = NULL;
2187 switch (template_selection) {
2188 case UNINITIALIZED_TEMPLATE:
2189 mp = new Module_Param_Unbound();
2190 break;
2191 case OMIT_VALUE:
2192 mp = new Module_Param_Omit();
2193 break;
2194 case ANY_VALUE:
2195 mp = new Module_Param_Any();
2196 break;
2197 case ANY_OR_OMIT:
2198 mp = new Module_Param_AnyOrNone();
2199 break;
2200 case SPECIFIC_VALUE: {
2201 Module_Param* mp_field_abstract = single_value->field_abstract.get_param(param_name);
2202 mp_field_abstract->set_id(new Module_Param_FieldName(mcopystr("abstract")));
2203 Module_Param* mp_field_transfer = single_value->field_transfer.get_param(param_name);
2204 mp_field_transfer->set_id(new Module_Param_FieldName(mcopystr("transfer")));
2205 mp = new Module_Param_Assignment_List();
2206 mp->add_elem(mp_field_abstract);
2207 mp->add_elem(mp_field_transfer);
2208 break; }
2209 case VALUE_LIST:
2210 case COMPLEMENTED_LIST: {
2211 if (template_selection == VALUE_LIST) {
2212 mp = new Module_Param_List_Template();
2213 }
2214 else {
2215 mp = new Module_Param_ComplementList_Template();
2216 }
2217 for (size_t i = 0; i < value_list.n_values; ++i) {
2218 mp->add_elem(value_list.list_value[i].get_param(param_name));
2219 }
2220 break; }
2221 default:
2222 break;
2223 }
2224 if (is_ifpresent) {
2225 mp->set_ifpresent();
2226 }
2227 return mp;
970ed795
EL
2228}
2229
970ed795
EL
2230void EXTERNAL_identification_syntaxes_template::clean_up()
2231{
2232 switch (template_selection) {
2233 case SPECIFIC_VALUE:
2234 delete single_value;
2235 break;
2236 case VALUE_LIST:
2237 case COMPLEMENTED_LIST:
2238 delete [] value_list.list_value;
2239 break;
2240 default:
2241 break;
2242 }
2243 template_selection = UNINITIALIZED_TEMPLATE;
2244}
2245
2246void EXTERNAL_identification_syntaxes_template::set_specific()
2247{
2248 if (template_selection != SPECIFIC_VALUE) {
2249 template_sel old_selection = template_selection;
2250 clean_up();
2251 single_value = new single_value_struct;
2252 set_selection(SPECIFIC_VALUE);
2253 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) {
2254 single_value->field_abstract = ANY_VALUE;
2255 single_value->field_transfer = ANY_VALUE;
2256 }
2257 }
2258}
2259
2260void EXTERNAL_identification_syntaxes_template::copy_value(const EXTERNAL_identification_syntaxes& other_value)
2261{
2262 single_value = new single_value_struct;
2263 single_value->field_abstract = other_value.abstract();
2264 single_value->field_transfer = other_value.transfer();
2265 set_selection(SPECIFIC_VALUE);
2266}
2267
2268void EXTERNAL_identification_syntaxes_template::copy_template(const EXTERNAL_identification_syntaxes_template& other_value)
2269{
2270 switch (other_value.template_selection) {
2271 case SPECIFIC_VALUE:
2272 single_value = new single_value_struct(*other_value.single_value);
2273 break;
2274 case OMIT_VALUE:
2275 case ANY_VALUE:
2276 case ANY_OR_OMIT:
2277 break;
2278 case VALUE_LIST:
2279 case COMPLEMENTED_LIST:
2280 value_list.n_values = other_value.value_list.n_values;
2281 value_list.list_value = new EXTERNAL_identification_syntaxes_template[value_list.n_values];
2282 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
2283 value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]);
2284 break;
2285 default:
2286 TTCN_error("Copying an uninitialized/unsupported template of type EXTERNAL.identification.syntaxes.");
2287 }
2288 set_selection(other_value);
2289}
2290
2291EXTERNAL_identification_syntaxes_template::EXTERNAL_identification_syntaxes_template()
2292{
2293}
2294
2295EXTERNAL_identification_syntaxes_template::EXTERNAL_identification_syntaxes_template(template_sel other_value)
2296 : Base_Template(other_value)
2297{
2298 check_single_selection(other_value);
2299}
2300
2301EXTERNAL_identification_syntaxes_template::EXTERNAL_identification_syntaxes_template(const EXTERNAL_identification_syntaxes& other_value)
2302{
2303 copy_value(other_value);
2304}
2305
2306EXTERNAL_identification_syntaxes_template::EXTERNAL_identification_syntaxes_template(const OPTIONAL<EXTERNAL_identification_syntaxes>& other_value)
2307{
2308 switch (other_value.get_selection()) {
2309 case OPTIONAL_PRESENT:
2310 copy_value((const EXTERNAL_identification_syntaxes&)other_value);
2311 break;
2312 case OPTIONAL_OMIT:
2313 set_selection(OMIT_VALUE);
2314 break;
2315 default:
2316 TTCN_error("Creating a template of type EXTERNAL.identification.syntaxes from an unbound optional field.");
2317 }
2318}
2319
2320EXTERNAL_identification_syntaxes_template::EXTERNAL_identification_syntaxes_template(const EXTERNAL_identification_syntaxes_template& other_value)
2321: Base_Template()
2322{
2323 copy_template(other_value);
2324}
2325
2326EXTERNAL_identification_syntaxes_template::~EXTERNAL_identification_syntaxes_template()
2327{
2328 clean_up();
2329}
2330
2331EXTERNAL_identification_syntaxes_template& EXTERNAL_identification_syntaxes_template::operator=(template_sel other_value)
2332{
2333 check_single_selection(other_value);
2334 clean_up();
2335 set_selection(other_value);
2336 return *this;
2337}
2338
2339EXTERNAL_identification_syntaxes_template& EXTERNAL_identification_syntaxes_template::operator=(const EXTERNAL_identification_syntaxes& other_value)
2340{
2341 clean_up();
2342 copy_value(other_value);
2343 return *this;
2344}
2345
2346EXTERNAL_identification_syntaxes_template& EXTERNAL_identification_syntaxes_template::operator=(const OPTIONAL<EXTERNAL_identification_syntaxes>& other_value)
2347{
2348 clean_up();
2349 switch (other_value.get_selection()) {
2350 case OPTIONAL_PRESENT:
2351 copy_value((const EXTERNAL_identification_syntaxes&)other_value);
2352 break;
2353 case OPTIONAL_OMIT:
2354 set_selection(OMIT_VALUE);
2355 break;
2356 default:
2357 TTCN_error("Assignment of an unbound optional field to a template of type EXTERNAL.identification.syntaxes.");
2358 }
2359 return *this;
2360}
2361
2362EXTERNAL_identification_syntaxes_template& EXTERNAL_identification_syntaxes_template::operator=(const EXTERNAL_identification_syntaxes_template& other_value)
2363{
2364 if (&other_value != this) {
2365 clean_up();
2366 copy_template(other_value);
2367 }
2368 return *this;
2369}
2370
3abe9331 2371boolean EXTERNAL_identification_syntaxes_template::match(const EXTERNAL_identification_syntaxes& other_value,
2372 boolean /* legacy */) const
970ed795
EL
2373{
2374 switch (template_selection) {
2375 case ANY_VALUE:
2376 case ANY_OR_OMIT:
2377 return TRUE;
2378 case OMIT_VALUE:
2379 return FALSE;
2380 case SPECIFIC_VALUE:
2381 if (!other_value.abstract().is_bound()) return FALSE;
2382 if (!single_value->field_abstract.match(other_value.abstract())) return FALSE;
2383 if (!other_value.transfer().is_bound()) return FALSE;
2384 if (!single_value->field_transfer.match(other_value.transfer())) return FALSE;
2385 return TRUE;
2386 case VALUE_LIST:
2387 case COMPLEMENTED_LIST:
2388 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
2389 if (value_list.list_value[list_count].match(other_value)) return template_selection == VALUE_LIST;
2390 return template_selection == COMPLEMENTED_LIST;
2391 default:
2392 TTCN_error("Matching an uninitialized/unsupported template of type EXTERNAL.identification.syntaxes.");
2393 }
2394 return FALSE;
2395}
2396
2397EXTERNAL_identification_syntaxes EXTERNAL_identification_syntaxes_template::valueof() const
2398{
2399 if (template_selection != SPECIFIC_VALUE || is_ifpresent)
2400 TTCN_error("Performing valueof or send operation on a non-specific template of type EXTERNAL.identification.syntaxes.");
2401 EXTERNAL_identification_syntaxes ret_val;
2402 ret_val.abstract() = single_value->field_abstract.valueof();
2403 ret_val.transfer() = single_value->field_transfer.valueof();
2404 return ret_val;
2405}
2406
2407void EXTERNAL_identification_syntaxes_template::set_type(template_sel template_type, unsigned int list_length)
2408{
2409 if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST)
2410 TTCN_error("Setting an invalid list for a template of type EXTERNAL.identification.syntaxes.");
2411 clean_up();
2412 set_selection(template_type);
2413 value_list.n_values = list_length;
2414 value_list.list_value = new EXTERNAL_identification_syntaxes_template[list_length];
2415}
2416
2417EXTERNAL_identification_syntaxes_template& EXTERNAL_identification_syntaxes_template::list_item(unsigned int list_index) const
2418{
2419 if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST)
2420 TTCN_error("Accessing a list element of a non-list template of type EXTERNAL.identification.syntaxes.");
2421 if (list_index >= value_list.n_values)
2422 TTCN_error("Index overflow in a value list template of type EXTERNAL.identification.syntaxes.");
2423 return value_list.list_value[list_index];
2424}
2425
2426OBJID_template& EXTERNAL_identification_syntaxes_template::abstract()
2427{
2428 set_specific();
2429 return single_value->field_abstract;
2430}
2431
2432const OBJID_template& EXTERNAL_identification_syntaxes_template::abstract() const
2433{
2434 if (template_selection != SPECIFIC_VALUE)
2435 TTCN_error("Accessing field abstract of a non-specific template of type EXTERNAL.identification.syntaxes.");
2436 return single_value->field_abstract;
2437}
2438
2439OBJID_template& EXTERNAL_identification_syntaxes_template::transfer()
2440{
2441 set_specific();
2442 return single_value->field_transfer;
2443}
2444
2445const OBJID_template& EXTERNAL_identification_syntaxes_template::transfer() const
2446{
2447 if (template_selection != SPECIFIC_VALUE)
2448 TTCN_error("Accessing field transfer of a non-specific template of type EXTERNAL.identification.syntaxes.");
2449 return single_value->field_transfer;
2450}
2451
2452int EXTERNAL_identification_syntaxes_template::size_of() const
2453{
2454 switch (template_selection)
2455 {
2456 case SPECIFIC_VALUE:
2457 {
2458 int ret_val = 2;
2459 return ret_val;
2460 }
2461 case VALUE_LIST:
2462 {
2463 if (value_list.n_values<1)
2464 TTCN_error("Internal error: Performing sizeof() operation on a template of type EXTERNAL.identification.syntaxes containing an empty list.");
2465 int item_size = value_list.list_value[0].size_of();
2466 for (unsigned int i = 1; i < value_list.n_values; i++)
2467 {
2468 if (value_list.list_value[i].size_of()!=item_size)
2469 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.syntaxes containing a value list with different sizes.");
2470 }
2471 return item_size;
2472 }
2473 case OMIT_VALUE:
2474 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.syntaxes containing omit value.");
2475 case ANY_VALUE:
2476 case ANY_OR_OMIT:
2477 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.syntaxes containing */? value.");
2478 case COMPLEMENTED_LIST:
2479 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.syntaxes containing complemented list.");
2480 default:
2481 TTCN_error("Performing sizeof() operation on an uninitialized/unsupported template of type EXTERNAL.identification.syntaxes.");
2482 }
2483 return 0;
2484}
2485
2486void EXTERNAL_identification_syntaxes_template::log() const
2487{
2488 switch (template_selection) {
2489 case SPECIFIC_VALUE:
2490 TTCN_Logger::log_event_str("{ abstract := ");
2491 single_value->field_abstract.log();
2492 TTCN_Logger::log_event_str(", transfer := ");
2493 single_value->field_transfer.log();
2494 TTCN_Logger::log_event_str(" }");
2495 break;
2496 case COMPLEMENTED_LIST:
2497 TTCN_Logger::log_event_str("complement ");
2498 // no break
2499 case VALUE_LIST:
2500 TTCN_Logger::log_char('(');
2501 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) {
2502 if (list_count > 0) TTCN_Logger::log_event_str(", ");
2503 value_list.list_value[list_count].log();
2504 }
2505 TTCN_Logger::log_char(')');
2506 break;
2507 default:
2508 log_generic();
2509 break;
2510 }
2511 log_ifpresent();
2512}
2513
3abe9331 2514void EXTERNAL_identification_syntaxes_template::log_match(const EXTERNAL_identification_syntaxes& match_value,
2515 boolean /* legacy */) const
970ed795
EL
2516{
2517 if (template_selection == SPECIFIC_VALUE) {
2518 TTCN_Logger::log_event_str("{ abstract := ");
2519 single_value->field_abstract.log_match(match_value.abstract());
2520 TTCN_Logger::log_event_str(", transfer := ");
2521 single_value->field_transfer.log_match(match_value.transfer());
2522 TTCN_Logger::log_event_str(" }");
2523 } else {
2524 match_value.log();
2525 TTCN_Logger::log_event_str(" with ");
2526 log();
2527 if (match(match_value)) TTCN_Logger::log_event_str(" matched");
2528 else TTCN_Logger::log_event_str(" unmatched");
2529 }
2530}
2531
2532void EXTERNAL_identification_syntaxes_template::encode_text(Text_Buf& text_buf) const
2533{
2534 encode_text_base(text_buf);
2535 switch (template_selection) {
2536 case SPECIFIC_VALUE:
2537 single_value->field_abstract.encode_text(text_buf);
2538 single_value->field_transfer.encode_text(text_buf);
2539 break;
2540 case OMIT_VALUE:
2541 case ANY_VALUE:
2542 case ANY_OR_OMIT:
2543 break;
2544 case VALUE_LIST:
2545 case COMPLEMENTED_LIST:
2546 text_buf.push_int(value_list.n_values);
2547 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
2548 value_list.list_value[list_count].encode_text(text_buf);
2549 break;
2550 default:
2551 TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of type EXTERNAL.identification.syntaxes.");
2552 }
2553}
2554
2555void EXTERNAL_identification_syntaxes_template::decode_text(Text_Buf& text_buf)
2556{
2557 clean_up();
2558 decode_text_base(text_buf);
2559 switch (template_selection) {
2560 case SPECIFIC_VALUE:
2561 single_value = new single_value_struct;
2562 single_value->field_abstract.decode_text(text_buf);
2563 single_value->field_transfer.decode_text(text_buf);
2564 break;
2565 case OMIT_VALUE:
2566 case ANY_VALUE:
2567 case ANY_OR_OMIT:
2568 break;
2569 case VALUE_LIST:
2570 case COMPLEMENTED_LIST:
2571 value_list.n_values = text_buf.pull_int().get_val();
2572 value_list.list_value = new EXTERNAL_identification_syntaxes_template[value_list.n_values];
2573 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
2574 value_list.list_value[list_count].decode_text(text_buf);
2575 break;
2576 default:
2577 TTCN_error("Text decoder: An unknown/unsupported selection was received in a template of type EXTERNAL.identification.syntaxes.");
2578 }
2579}
2580
3abe9331 2581boolean EXTERNAL_identification_syntaxes_template::is_present(boolean legacy /* = FALSE */) const
970ed795
EL
2582{
2583 if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;
3abe9331 2584 return !match_omit(legacy);
970ed795
EL
2585}
2586
3abe9331 2587boolean EXTERNAL_identification_syntaxes_template::match_omit(boolean legacy /* = FALSE */) const
970ed795
EL
2588{
2589 if (is_ifpresent) return TRUE;
2590 switch (template_selection) {
2591 case OMIT_VALUE:
2592 case ANY_OR_OMIT:
2593 return TRUE;
2594 case VALUE_LIST:
2595 case COMPLEMENTED_LIST:
3abe9331 2596 if (legacy) {
2597 for (unsigned int i=0; i<value_list.n_values; i++)
2598 if (value_list.list_value[i].match_omit())
2599 return template_selection==VALUE_LIST;
2600 return template_selection==COMPLEMENTED_LIST;
2601 } // else fall through
970ed795
EL
2602 default:
2603 return FALSE;
2604 }
2605 return FALSE;
2606}
2607
2608#ifndef TITAN_RUNTIME_2
3abe9331 2609void EXTERNAL_identification_syntaxes_template::check_restriction(template_res t_res, const char* t_name,
2610 boolean legacy /* = FALSE */) const
970ed795
EL
2611{
2612 if (template_selection==UNINITIALIZED_TEMPLATE) return;
2613 switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {
2614 case TR_VALUE:
2615 if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;
2616 break;
2617 case TR_OMIT:
2618 if (!is_ifpresent && (template_selection==OMIT_VALUE ||
2619 template_selection==SPECIFIC_VALUE)) return;
2620 break;
2621 case TR_PRESENT:
3abe9331 2622 if (!match_omit(legacy)) return;
970ed795
EL
2623 break;
2624 default:
2625 return;
2626 }
2627 TTCN_error("Restriction `%s' on template of type %s violated.",
2628 get_res_name(t_res), t_name ? t_name : "EXTERNAL.identification.syntaxes");
2629}
2630#endif
2631
2632EXTERNAL_identification_context__negotiation::EXTERNAL_identification_context__negotiation()
2633{
2634}
2635
2636EXTERNAL_identification_context__negotiation::EXTERNAL_identification_context__negotiation(const INTEGER& par_presentation__context__id,
2637 const OBJID& par_transfer__syntax)
2638 : field_presentation__context__id(par_presentation__context__id),
2639 field_transfer__syntax(par_transfer__syntax)
2640{
2641}
2642
2643boolean EXTERNAL_identification_context__negotiation::operator==(const EXTERNAL_identification_context__negotiation& other_value) const
2644{
2645 return field_presentation__context__id==other_value.field_presentation__context__id
2646 && field_transfer__syntax==other_value.field_transfer__syntax;
2647}
2648
2649int EXTERNAL_identification_context__negotiation::size_of() const
2650{
2651 int ret_val = 2;
2652 return ret_val;
2653}
2654
2655void EXTERNAL_identification_context__negotiation::log() const
2656{
2657 TTCN_Logger::log_event_str("{ presentation_context_id := ");
2658 field_presentation__context__id.log();
2659 TTCN_Logger::log_event_str(", transfer_syntax := ");
2660 field_transfer__syntax.log();
2661 TTCN_Logger::log_event_str(" }");
2662}
2663
2664boolean EXTERNAL_identification_context__negotiation::is_bound() const
2665{
2666 if(field_presentation__context__id.is_bound()) return TRUE;
2667 if(field_transfer__syntax.is_bound()) return TRUE;
2668 return FALSE;
2669}
2670
2671boolean EXTERNAL_identification_context__negotiation::is_value() const
2672{
2673 if(!field_presentation__context__id.is_value()) return FALSE;
2674 if(!field_transfer__syntax.is_value()) return FALSE;
2675 return TRUE;
2676}
2677
2678void EXTERNAL_identification_context__negotiation::clean_up()
2679{
2680 field_presentation__context__id.clean_up();
2681 field_transfer__syntax.clean_up();
2682}
2683
2684void EXTERNAL_identification_context__negotiation::set_param(Module_Param& param)
2685{
2686 param.basic_check(Module_Param::BC_VALUE, "record value");
3abe9331 2687 Module_Param_Ptr mp = &param;
2688 if (param.get_type() == Module_Param::MP_Reference) {
2689 mp = param.get_referenced_param();
2690 }
2691 switch (mp->get_type()) {
970ed795 2692 case Module_Param::MP_Value_List:
3abe9331 2693 if (mp->get_size()==0) return;
2694 if (2!=mp->get_size()) {
2695 param.error("record value of type EXTERNAL.identification.context-negotiation has 2 fields but list value has %d fields", (int)mp->get_size());
970ed795 2696 }
3abe9331 2697 if (mp->get_elem(0)->get_type()!=Module_Param::MP_NotUsed) presentation__context__id().set_param(*mp->get_elem(0));
2698 if (mp->get_elem(1)->get_type()!=Module_Param::MP_NotUsed) transfer__syntax().set_param(*mp->get_elem(1));
970ed795
EL
2699 break;
2700 case Module_Param::MP_Assignment_List: {
3abe9331 2701 Vector<bool> value_used(mp->get_size());
2702 value_used.resize(mp->get_size(), false);
2703 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2704 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2705 if (!strcmp(curr_param->get_id()->get_name(), "presentation_context_id")) {
2706 presentation__context__id().set_param(*curr_param);
2707 value_used[val_idx]=true;
2708 }
2709 }
3abe9331 2710 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2711 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2712 if (!strcmp(curr_param->get_id()->get_name(), "transfer_syntax")) {
2713 transfer__syntax().set_param(*curr_param);
2714 value_used[val_idx]=true;
2715 }
2716 }
3abe9331 2717 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) if (!value_used[val_idx]) {
2718 mp->get_elem(val_idx)->error("Non existent field name in type EXTERNAL.identification.context-negotiation: %s", mp->get_elem(val_idx)->get_id()->get_name());
970ed795
EL
2719 break;
2720 }
2721 } break;
2722 default:
2723 param.type_error("record value", "EXTERNAL.identification.context-negotiation");
2724 }
2725}
2726
3abe9331 2727Module_Param* EXTERNAL_identification_context__negotiation::get_param(Module_Param_Name& param_name) const
2728{
2729 if (!is_bound()) {
2730 return new Module_Param_Unbound();
2731 }
2732 Module_Param* mp_field_presentation_context_id = field_presentation__context__id.get_param(param_name);
2733 mp_field_presentation_context_id->set_id(new Module_Param_FieldName(mcopystr("presentation_context_id")));
2734 Module_Param* mp_field_transfer_syntax = field_transfer__syntax.get_param(param_name);
2735 mp_field_transfer_syntax->set_id(new Module_Param_FieldName(mcopystr("transfer_syntax")));
2736 Module_Param_Assignment_List* mp = new Module_Param_Assignment_List();
2737 mp->add_elem(mp_field_presentation_context_id);
2738 mp->add_elem(mp_field_transfer_syntax);
2739 return mp;
2740}
2741
2742void EXTERNAL_identification_context__negotiation::encode_text(Text_Buf& text_buf) const
2743{
2744 field_presentation__context__id.encode_text(text_buf);
2745 field_transfer__syntax.encode_text(text_buf);
2746}
2747
2748void EXTERNAL_identification_context__negotiation::decode_text(Text_Buf& text_buf)
2749{
2750 field_presentation__context__id.decode_text(text_buf);
2751 field_transfer__syntax.decode_text(text_buf);
2752}
2753
2754struct EXTERNAL_identification_context__negotiation_template::single_value_struct {
2755 INTEGER_template field_presentation__context__id;
2756 OBJID_template field_transfer__syntax;
2757};
2758
970ed795
EL
2759void EXTERNAL_identification_context__negotiation_template::set_param(Module_Param& param)
2760{
2761 param.basic_check(Module_Param::BC_TEMPLATE, "record template");
3abe9331 2762 Module_Param_Ptr mp = &param;
2763 if (param.get_type() == Module_Param::MP_Reference) {
2764 mp = param.get_referenced_param();
2765 }
2766 switch (mp->get_type()) {
970ed795
EL
2767 case Module_Param::MP_Omit:
2768 *this = OMIT_VALUE;
2769 break;
2770 case Module_Param::MP_Any:
2771 *this = ANY_VALUE;
2772 break;
2773 case Module_Param::MP_AnyOrNone:
2774 *this = ANY_OR_OMIT;
2775 break;
2776 case Module_Param::MP_List_Template:
3abe9331 2777 case Module_Param::MP_ComplementList_Template: {
2778 EXTERNAL_identification_context__negotiation_template temp;
2779 temp.set_type(mp->get_type() == Module_Param::MP_List_Template ?
2780 VALUE_LIST : COMPLEMENTED_LIST, mp->get_size());
2781 for (size_t i=0; i<mp->get_size(); i++) {
2782 temp.list_item(i).set_param(*mp->get_elem(i));
2783 }
2784 *this = temp;
2785 break; }
970ed795 2786 case Module_Param::MP_Value_List:
3abe9331 2787 if (mp->get_size()==0) break;
2788 if (2!=mp->get_size()) {
2789 param.error("record template of type EXTERNAL.identification.context-negotiation has 2 fields but list value has %d fields", (int)mp->get_size());
970ed795 2790 }
3abe9331 2791 if (mp->get_elem(0)->get_type()!=Module_Param::MP_NotUsed) presentation__context__id().set_param(*mp->get_elem(0));
2792 if (mp->get_elem(1)->get_type()!=Module_Param::MP_NotUsed) transfer__syntax().set_param(*mp->get_elem(1));
970ed795
EL
2793 break;
2794 case Module_Param::MP_Assignment_List: {
3abe9331 2795 Vector<bool> value_used(mp->get_size());
2796 value_used.resize(mp->get_size(), false);
2797 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2798 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2799 if (!strcmp(curr_param->get_id()->get_name(), "presentation_context_id")) {
2800 presentation__context__id().set_param(*curr_param);
2801 value_used[val_idx]=true;
2802 }
2803 }
3abe9331 2804 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
2805 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
2806 if (!strcmp(curr_param->get_id()->get_name(), "transfer_syntax")) {
2807 transfer__syntax().set_param(*curr_param);
2808 value_used[val_idx]=true;
2809 }
2810 }
3abe9331 2811 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) if (!value_used[val_idx]) {
2812 mp->get_elem(val_idx)->error("Non existent field name in type EXTERNAL.identification.context-negotiation: %s", mp->get_elem(val_idx)->get_id()->get_name());
970ed795
EL
2813 break;
2814 }
2815 } break;
2816 default:
2817 param.type_error("record template", "EXTERNAL.identification.context-negotiation");
2818 }
3abe9331 2819 is_ifpresent = param.get_ifpresent() || mp->get_ifpresent();
970ed795
EL
2820}
2821
3abe9331 2822Module_Param* EXTERNAL_identification_context__negotiation_template::get_param(Module_Param_Name& param_name) const
970ed795 2823{
3abe9331 2824 Module_Param* mp = NULL;
2825 switch (template_selection) {
2826 case UNINITIALIZED_TEMPLATE:
2827 mp = new Module_Param_Unbound();
2828 break;
2829 case OMIT_VALUE:
2830 mp = new Module_Param_Omit();
2831 break;
2832 case ANY_VALUE:
2833 mp = new Module_Param_Any();
2834 break;
2835 case ANY_OR_OMIT:
2836 mp = new Module_Param_AnyOrNone();
2837 break;
2838 case SPECIFIC_VALUE: {
2839 Module_Param* mp_field_presentation_context_id = single_value->field_presentation__context__id.get_param(param_name);
2840 mp_field_presentation_context_id->set_id(new Module_Param_FieldName(mcopystr("presentation_context_id")));
2841 Module_Param* mp_field_transfer_syntax = single_value->field_transfer__syntax.get_param(param_name);
2842 mp_field_transfer_syntax->set_id(new Module_Param_FieldName(mcopystr("transfer_syntax")));
2843 mp = new Module_Param_Assignment_List();
2844 mp->add_elem(mp_field_presentation_context_id);
2845 mp->add_elem(mp_field_transfer_syntax);
2846 break; }
2847 case VALUE_LIST:
2848 case COMPLEMENTED_LIST: {
2849 if (template_selection == VALUE_LIST) {
2850 mp = new Module_Param_List_Template();
2851 }
2852 else {
2853 mp = new Module_Param_ComplementList_Template();
2854 }
2855 for (size_t i = 0; i < value_list.n_values; ++i) {
2856 mp->add_elem(value_list.list_value[i].get_param(param_name));
2857 }
2858 break; }
2859 default:
2860 break;
2861 }
2862 if (is_ifpresent) {
2863 mp->set_ifpresent();
2864 }
2865 return mp;
970ed795
EL
2866}
2867
970ed795
EL
2868void EXTERNAL_identification_context__negotiation_template::clean_up()
2869{
2870 switch (template_selection) {
2871 case SPECIFIC_VALUE:
2872 delete single_value;
2873 break;
2874 case VALUE_LIST:
2875 case COMPLEMENTED_LIST:
2876 delete [] value_list.list_value;
2877 break;
2878 default:
2879 break;
2880 }
2881 template_selection = UNINITIALIZED_TEMPLATE;
2882}
2883
2884void EXTERNAL_identification_context__negotiation_template::set_specific()
2885{
2886 if (template_selection != SPECIFIC_VALUE) {
2887 template_sel old_selection = template_selection;
2888 clean_up();
2889 single_value = new single_value_struct;
2890 set_selection(SPECIFIC_VALUE);
2891 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) {
2892 single_value->field_presentation__context__id = ANY_VALUE;
2893 single_value->field_transfer__syntax = ANY_VALUE;
2894 }
2895 }
2896}
2897
2898void EXTERNAL_identification_context__negotiation_template::copy_value(const EXTERNAL_identification_context__negotiation& other_value)
2899{
2900 single_value = new single_value_struct;
2901 single_value->field_presentation__context__id = other_value.presentation__context__id();
2902 single_value->field_transfer__syntax = other_value.transfer__syntax();
2903 set_selection(SPECIFIC_VALUE);
2904}
2905
2906void EXTERNAL_identification_context__negotiation_template::copy_template(const EXTERNAL_identification_context__negotiation_template& other_value)
2907{
2908 switch (other_value.template_selection) {
2909 case SPECIFIC_VALUE:
2910 single_value = new single_value_struct(*other_value.single_value);
2911 break;
2912 case OMIT_VALUE:
2913 case ANY_VALUE:
2914 case ANY_OR_OMIT:
2915 break;
2916 case VALUE_LIST:
2917 case COMPLEMENTED_LIST:
2918 value_list.n_values = other_value.value_list.n_values;
2919 value_list.list_value = new EXTERNAL_identification_context__negotiation_template[value_list.n_values];
2920 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
2921 value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]);
2922 break;
2923 default:
2924 TTCN_error("Copying an uninitialized/unsupported template of type EXTERNAL.identification.context-negotiation.");
2925 }
2926 set_selection(other_value);
2927}
2928
2929EXTERNAL_identification_context__negotiation_template::EXTERNAL_identification_context__negotiation_template()
2930{
2931}
2932
2933EXTERNAL_identification_context__negotiation_template::EXTERNAL_identification_context__negotiation_template(template_sel other_value)
2934 : Base_Template(other_value)
2935{
2936 check_single_selection(other_value);
2937}
2938
2939EXTERNAL_identification_context__negotiation_template::EXTERNAL_identification_context__negotiation_template(const EXTERNAL_identification_context__negotiation& other_value)
2940{
2941 copy_value(other_value);
2942}
2943
2944EXTERNAL_identification_context__negotiation_template::EXTERNAL_identification_context__negotiation_template(const OPTIONAL<EXTERNAL_identification_context__negotiation>& other_value)
2945{
2946 switch (other_value.get_selection()) {
2947 case OPTIONAL_PRESENT:
2948 copy_value((const EXTERNAL_identification_context__negotiation&)other_value);
2949 break;
2950 case OPTIONAL_OMIT:
2951 set_selection(OMIT_VALUE);
2952 break;
2953 default:
2954 TTCN_error("Creating a template of type EXTERNAL.identification.context-negotiation from an unbound optional field.");
2955 }
2956}
2957
2958EXTERNAL_identification_context__negotiation_template::EXTERNAL_identification_context__negotiation_template(const EXTERNAL_identification_context__negotiation_template& other_value)
2959: Base_Template()
2960{
2961 copy_template(other_value);
2962}
2963
2964EXTERNAL_identification_context__negotiation_template::~EXTERNAL_identification_context__negotiation_template()
2965{
2966 clean_up();
2967}
2968
2969EXTERNAL_identification_context__negotiation_template& EXTERNAL_identification_context__negotiation_template::operator=(template_sel other_value)
2970{
2971 check_single_selection(other_value);
2972 clean_up();
2973 set_selection(other_value);
2974 return *this;
2975}
2976
2977EXTERNAL_identification_context__negotiation_template& EXTERNAL_identification_context__negotiation_template::operator=(const EXTERNAL_identification_context__negotiation& other_value)
2978{
2979 clean_up();
2980 copy_value(other_value);
2981 return *this;
2982}
2983
2984EXTERNAL_identification_context__negotiation_template& EXTERNAL_identification_context__negotiation_template::operator=(const OPTIONAL<EXTERNAL_identification_context__negotiation>& other_value)
2985{
2986 clean_up();
2987 switch (other_value.get_selection()) {
2988 case OPTIONAL_PRESENT:
2989 copy_value((const EXTERNAL_identification_context__negotiation&)other_value);
2990 break;
2991 case OPTIONAL_OMIT:
2992 set_selection(OMIT_VALUE);
2993 break;
2994 default:
2995 TTCN_error("Assignment of an unbound optional field to a template of type EXTERNAL.identification.context-negotiation.");
2996 }
2997 return *this;
2998}
2999
3000EXTERNAL_identification_context__negotiation_template& EXTERNAL_identification_context__negotiation_template::operator=(const EXTERNAL_identification_context__negotiation_template& other_value)
3001{
3002 if (&other_value != this) {
3003 clean_up();
3004 copy_template(other_value);
3005 }
3006 return *this;
3007}
3008
3abe9331 3009boolean EXTERNAL_identification_context__negotiation_template::match(const EXTERNAL_identification_context__negotiation& other_value,
3010 boolean /* legacy */) const
970ed795
EL
3011{
3012 switch (template_selection) {
3013 case ANY_VALUE:
3014 case ANY_OR_OMIT:
3015 return TRUE;
3016 case OMIT_VALUE:
3017 return FALSE;
3018 case SPECIFIC_VALUE:
3019 if (!other_value.presentation__context__id().is_bound()) return FALSE;
3020 if (!single_value->field_presentation__context__id.match(other_value.presentation__context__id())) return FALSE;
3021 if (!other_value.transfer__syntax().is_bound()) return FALSE;
3022 if (!single_value->field_transfer__syntax.match(other_value.transfer__syntax())) return FALSE;
3023 return TRUE;
3024 case VALUE_LIST:
3025 case COMPLEMENTED_LIST:
3026 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
3027 if (value_list.list_value[list_count].match(other_value)) return template_selection == VALUE_LIST;
3028 return template_selection == COMPLEMENTED_LIST;
3029 default:
3030 TTCN_error("Matching an uninitialized/unsupported template of type EXTERNAL.identification.context-negotiation.");
3031 }
3032 return FALSE;
3033}
3034
3035EXTERNAL_identification_context__negotiation EXTERNAL_identification_context__negotiation_template::valueof() const
3036{
3037 if (template_selection != SPECIFIC_VALUE || is_ifpresent)
3038 TTCN_error("Performing valueof or send operation on a non-specific template of type EXTERNAL.identification.context-negotiation.");
3039 EXTERNAL_identification_context__negotiation ret_val;
3040 ret_val.presentation__context__id() = single_value->field_presentation__context__id.valueof();
3041 ret_val.transfer__syntax() = single_value->field_transfer__syntax.valueof();
3042 return ret_val;
3043}
3044
3045void EXTERNAL_identification_context__negotiation_template::set_type(template_sel template_type, unsigned int list_length)
3046{
3047 if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST)
3048 TTCN_error("Setting an invalid list for a template of type EXTERNAL.identification.context-negotiation.");
3049 clean_up();
3050 set_selection(template_type);
3051 value_list.n_values = list_length;
3052 value_list.list_value = new EXTERNAL_identification_context__negotiation_template[list_length];
3053}
3054
3055EXTERNAL_identification_context__negotiation_template& EXTERNAL_identification_context__negotiation_template::list_item(unsigned int list_index) const
3056{
3057 if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST)
3058 TTCN_error("Accessing a list element of a non-list template of type EXTERNAL.identification.context-negotiation.");
3059 if (list_index >= value_list.n_values)
3060 TTCN_error("Index overflow in a value list template of type EXTERNAL.identification.context-negotiation.");
3061 return value_list.list_value[list_index];
3062}
3063
3064INTEGER_template& EXTERNAL_identification_context__negotiation_template::presentation__context__id()
3065{
3066 set_specific();
3067 return single_value->field_presentation__context__id;
3068}
3069
3070const INTEGER_template& EXTERNAL_identification_context__negotiation_template::presentation__context__id() const
3071{
3072 if (template_selection != SPECIFIC_VALUE)
3073 TTCN_error("Accessing field presentation_context_id of a non-specific template of type EXTERNAL.identification.context-negotiation.");
3074 return single_value->field_presentation__context__id;
3075}
3076
3077OBJID_template& EXTERNAL_identification_context__negotiation_template::transfer__syntax()
3078{
3079 set_specific();
3080 return single_value->field_transfer__syntax;
3081}
3082
3083const OBJID_template& EXTERNAL_identification_context__negotiation_template::transfer__syntax() const
3084{
3085 if (template_selection != SPECIFIC_VALUE)
3086 TTCN_error("Accessing field transfer_syntax of a non-specific template of type EXTERNAL.identification.context-negotiation.");
3087 return single_value->field_transfer__syntax;
3088}
3089
3090int EXTERNAL_identification_context__negotiation_template::size_of() const
3091{
3092 switch (template_selection)
3093 {
3094 case SPECIFIC_VALUE:
3095 {
3096 int ret_val = 2;
3097 return ret_val;
3098 }
3099 case VALUE_LIST:
3100 {
3101 if (value_list.n_values<1)
3102 TTCN_error("Internal error: Performing sizeof() operation on a template of type EXTERNAL.identification.context-negotiation containing an empty list.");
3103 int item_size = value_list.list_value[0].size_of();
3104 for (unsigned int i = 1; i < value_list.n_values; i++)
3105 {
3106 if (value_list.list_value[i].size_of()!=item_size)
3107 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.context-negotiation containing a value list with different sizes.");
3108 }
3109 return item_size;
3110 }
3111 case OMIT_VALUE:
3112 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.context-negotiation containing omit value.");
3113 case ANY_VALUE:
3114 case ANY_OR_OMIT:
3115 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.context-negotiation containing */? value.");
3116 case COMPLEMENTED_LIST:
3117 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL.identification.context-negotiation containing complemented list.");
3118 default:
3119 TTCN_error("Performing sizeof() operation on an uninitialized/unsupported template of type EXTERNAL.identification.context-negotiation.");
3120 }
3121 return 0;
3122}
3123
3124void EXTERNAL_identification_context__negotiation_template::log() const
3125{
3126 switch (template_selection) {
3127 case SPECIFIC_VALUE:
3128 TTCN_Logger::log_event_str("{ presentation_context_id := ");
3129 single_value->field_presentation__context__id.log();
3130 TTCN_Logger::log_event_str(", transfer_syntax := ");
3131 single_value->field_transfer__syntax.log();
3132 TTCN_Logger::log_event_str(" }");
3133 break;
3134 case COMPLEMENTED_LIST:
3135 TTCN_Logger::log_event_str("complement ");
3136 // no break
3137 case VALUE_LIST:
3138 TTCN_Logger::log_char('(');
3139 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) {
3140 if (list_count > 0) TTCN_Logger::log_event_str(", ");
3141 value_list.list_value[list_count].log();
3142 }
3143 TTCN_Logger::log_char(')');
3144 break;
3145 default:
3146 log_generic();
3147 break;
3148 }
3149 log_ifpresent();
3150}
3151
3abe9331 3152void EXTERNAL_identification_context__negotiation_template::log_match(const EXTERNAL_identification_context__negotiation& match_value,
3153 boolean /* legacy */) const
970ed795
EL
3154{
3155 if (template_selection == SPECIFIC_VALUE) {
3156 TTCN_Logger::log_event_str("{ presentation_context_id := ");
3157 single_value->field_presentation__context__id.log_match(match_value.presentation__context__id());
3158 TTCN_Logger::log_event_str(", transfer_syntax := ");
3159 single_value->field_transfer__syntax.log_match(match_value.transfer__syntax());
3160 TTCN_Logger::log_event_str(" }");
3161 } else {
3162 match_value.log();
3163 TTCN_Logger::log_event_str(" with ");
3164 log();
3165 if (match(match_value)) TTCN_Logger::log_event_str(" matched");
3166 else TTCN_Logger::log_event_str(" unmatched");
3167 }
3168}
3169
3170void EXTERNAL_identification_context__negotiation_template::encode_text(Text_Buf& text_buf) const
3171{
3172 encode_text_base(text_buf);
3173 switch (template_selection) {
3174 case SPECIFIC_VALUE:
3175 single_value->field_presentation__context__id.encode_text(text_buf);
3176 single_value->field_transfer__syntax.encode_text(text_buf);
3177 break;
3178 case OMIT_VALUE:
3179 case ANY_VALUE:
3180 case ANY_OR_OMIT:
3181 break;
3182 case VALUE_LIST:
3183 case COMPLEMENTED_LIST:
3184 text_buf.push_int(value_list.n_values);
3185 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
3186 value_list.list_value[list_count].encode_text(text_buf);
3187 break;
3188 default:
3189 TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of type EXTERNAL.identification.context-negotiation.");
3190 }
3191}
3192
3193void EXTERNAL_identification_context__negotiation_template::decode_text(Text_Buf& text_buf)
3194{
3195 clean_up();
3196 decode_text_base(text_buf);
3197 switch (template_selection) {
3198 case SPECIFIC_VALUE:
3199 single_value = new single_value_struct;
3200 single_value->field_presentation__context__id.decode_text(text_buf);
3201 single_value->field_transfer__syntax.decode_text(text_buf);
3202 break;
3203 case OMIT_VALUE:
3204 case ANY_VALUE:
3205 case ANY_OR_OMIT:
3206 break;
3207 case VALUE_LIST:
3208 case COMPLEMENTED_LIST:
3209 value_list.n_values = text_buf.pull_int().get_val();
3210 value_list.list_value = new EXTERNAL_identification_context__negotiation_template[value_list.n_values];
3211 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
3212 value_list.list_value[list_count].decode_text(text_buf);
3213 break;
3214 default:
3215 TTCN_error("Text decoder: An unknown/unsupported selection was received in a template of type EXTERNAL.identification.context-negotiation.");
3216 }
3217}
3218
3abe9331 3219boolean EXTERNAL_identification_context__negotiation_template::is_present(boolean legacy /* = FALSE */) const
970ed795
EL
3220{
3221 if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;
3abe9331 3222 return !match_omit(legacy);
970ed795
EL
3223}
3224
3abe9331 3225boolean EXTERNAL_identification_context__negotiation_template::match_omit(boolean legacy /* = FALSE */) const
970ed795
EL
3226{
3227 if (is_ifpresent) return TRUE;
3228 switch (template_selection) {
3229 case OMIT_VALUE:
3230 case ANY_OR_OMIT:
3231 return TRUE;
3232 case VALUE_LIST:
3233 case COMPLEMENTED_LIST:
3abe9331 3234 if (legacy) {
3235 for (unsigned int i=0; i<value_list.n_values; i++)
3236 if (value_list.list_value[i].match_omit())
3237 return template_selection==VALUE_LIST;
3238 return template_selection==COMPLEMENTED_LIST;
3239 } // else fall through
970ed795
EL
3240 default:
3241 return FALSE;
3242 }
3243 return FALSE;
3244}
3245
3246#ifndef TITAN_RUNTIME_2
3abe9331 3247void EXTERNAL_identification_context__negotiation_template::check_restriction(template_res t_res, const char* t_name,
3248 boolean legacy /* = FALSE */) const
970ed795
EL
3249{
3250 if (template_selection==UNINITIALIZED_TEMPLATE) return;
3251 switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {
3252 case TR_VALUE:
3253 if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;
3254 break;
3255 case TR_OMIT:
3256 if (!is_ifpresent && (template_selection==OMIT_VALUE ||
3257 template_selection==SPECIFIC_VALUE)) return;
3258 break;
3259 case TR_PRESENT:
3abe9331 3260 if (!match_omit(legacy)) return;
970ed795
EL
3261 break;
3262 default:
3263 return;
3264 }
3265 TTCN_error("Restriction `%s' on template of type %s violated.",
3266 get_res_name(t_res), t_name ? t_name : "EXTERNAL.identification.context-negotiation");
3267}
3268#endif
3269
3270EXTERNAL::EXTERNAL()
3271{
3272}
3273
3274EXTERNAL::EXTERNAL(const EXTERNAL_identification& par_identification,
3275 const OPTIONAL<UNIVERSAL_CHARSTRING>& par_data__value__descriptor,
3276 const OCTETSTRING& par_data__value)
3277 : field_identification(par_identification),
3278 field_data__value__descriptor(par_data__value__descriptor),
3279 field_data__value(par_data__value)
3280{
3281}
3282
3283boolean EXTERNAL::operator==(const EXTERNAL& other_value) const
3284{
3285 return field_identification==other_value.field_identification
3286 && field_data__value__descriptor==other_value.field_data__value__descriptor
3287 && field_data__value==other_value.field_data__value;
3288}
3289
3290int EXTERNAL::size_of() const
3291{
3292 int ret_val = 2;
3293 if (field_data__value__descriptor.ispresent()) ret_val++;
3294 return ret_val;
3295}
3296
3297void EXTERNAL::log() const
3298{
3299 TTCN_Logger::log_event_str("{ identification := ");
3300 field_identification.log();
3301 TTCN_Logger::log_event_str(", data_value_descriptor := ");
3302 field_data__value__descriptor.log();
3303 TTCN_Logger::log_event_str(", data_value := ");
3304 field_data__value.log();
3305 TTCN_Logger::log_event_str(" }");
3306}
3307
3308boolean EXTERNAL::is_bound() const
3309{
3310 if(field_identification.is_bound()) return TRUE;
3311 if(OPTIONAL_OMIT == field_data__value__descriptor.get_selection() || field_data__value__descriptor.is_bound()) return TRUE;
3312 if(field_data__value.is_bound()) return TRUE;
3313 return FALSE;
3314}
3315
3316boolean EXTERNAL::is_value() const
3317{
3318 if(!field_identification.is_value()) return FALSE;
3319 if(OPTIONAL_OMIT != field_data__value__descriptor.get_selection() && !field_data__value__descriptor.is_value()) return FALSE;
3320 if(!field_data__value.is_value()) return FALSE;
3321 return TRUE;
3322}
3323
3324void EXTERNAL::clean_up()
3325{
3326 field_identification.clean_up();
3327 field_data__value__descriptor.clean_up();
3328 field_data__value.clean_up();
3329}
3330
3331void EXTERNAL::set_param(Module_Param& param)
3332{
3333 param.basic_check(Module_Param::BC_VALUE, "record value");
3abe9331 3334 Module_Param_Ptr mp = &param;
3335 if (param.get_type() == Module_Param::MP_Reference) {
3336 mp = param.get_referenced_param();
3337 }
3338 switch (mp->get_type()) {
970ed795 3339 case Module_Param::MP_Value_List:
3abe9331 3340 if (mp->get_size()==0) return;
3341 if (3!=mp->get_size()) {
3342 param.error("record value of type EXTERNAL has 3 fields but list value has %d fields", (int)mp->get_size());
970ed795 3343 }
3abe9331 3344 if (mp->get_elem(0)->get_type()!=Module_Param::MP_NotUsed) identification().set_param(*mp->get_elem(0));
3345 if (mp->get_elem(1)->get_type()!=Module_Param::MP_NotUsed) data__value__descriptor().set_param(*mp->get_elem(1));
3346 if (mp->get_elem(2)->get_type()!=Module_Param::MP_NotUsed) data__value().set_param(*mp->get_elem(2));
970ed795
EL
3347 break;
3348 case Module_Param::MP_Assignment_List: {
3abe9331 3349 Vector<bool> value_used(mp->get_size());
3350 value_used.resize(mp->get_size(), false);
3351 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
3352 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
3353 if (!strcmp(curr_param->get_id()->get_name(), "identification")) {
3354 identification().set_param(*curr_param);
3355 value_used[val_idx]=true;
3356 }
3357 }
3abe9331 3358 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
3359 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
3360 if (!strcmp(curr_param->get_id()->get_name(), "data_value_descriptor")) {
3361 data__value__descriptor().set_param(*curr_param);
3362 value_used[val_idx]=true;
3363 }
3364 }
3abe9331 3365 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
3366 Module_Param* const curr_param = mp->get_elem(val_idx);
970ed795
EL
3367 if (!strcmp(curr_param->get_id()->get_name(), "data_value")) {
3368 data__value().set_param(*curr_param);
3369 value_used[val_idx]=true;
3370 }
3371 }
3abe9331 3372 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) if (!value_used[val_idx]) {
3373 mp->get_elem(val_idx)->error("Non existent field name in type EXTERNAL: %s", mp->get_elem(val_idx)->get_id()->get_name());
970ed795
EL
3374 break;
3375 }
3376 } break;
3377 default:
3378 param.type_error("record value", "EXTERNAL");
3379 }
3380}
3381
3abe9331 3382Module_Param* EXTERNAL::get_param(Module_Param_Name& param_name) const
970ed795 3383{
3abe9331 3384 if (!is_bound()) {
3385 return new Module_Param_Unbound();
970ed795 3386 }
3abe9331 3387 Module_Param* mp_field_identification = field_identification.get_param(param_name);
3388 mp_field_identification->set_id(new Module_Param_FieldName(mcopystr("identification")));
3389 Module_Param* mp_field_data_value_descriptor = field_data__value__descriptor.get_param(param_name);
3390 mp_field_data_value_descriptor->set_id(new Module_Param_FieldName(mcopystr("data_value_descriptor")));
3391 Module_Param* mp_field_data_value = field_data__value.get_param(param_name);
3392 mp_field_data_value->set_id(new Module_Param_FieldName(mcopystr("data_value")));
3393 Module_Param_Assignment_List* mp = new Module_Param_Assignment_List();
3394 mp->add_elem(mp_field_identification);
3395 mp->add_elem(mp_field_data_value_descriptor);
3396 mp->add_elem(mp_field_data_value);
3397 return mp;
970ed795
EL
3398}
3399
3400void EXTERNAL::encode_text(Text_Buf& text_buf) const
3401{
3402 field_identification.encode_text(text_buf);
3403 field_data__value__descriptor.encode_text(text_buf);
3404 field_data__value.encode_text(text_buf);
3405}
3406
3407void EXTERNAL::decode_text(Text_Buf& text_buf)
3408{
3409 field_identification.decode_text(text_buf);
3410 field_data__value__descriptor.decode_text(text_buf);
3411 field_data__value.decode_text(text_buf);
3412}
3413
3414void EXTERNAL::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, TTCN_EncDec::coding_t p_coding, ...) const
3415{
3416 va_list pvar;
3417 va_start(pvar, p_coding);
3418 switch(p_coding) {
3419 case TTCN_EncDec::CT_BER: {
3420 TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name);
3421 unsigned BER_coding=va_arg(pvar, unsigned);
3422 BER_encode_chk_coding(BER_coding);
3423 ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding);
3424 tlv->put_in_buffer(p_buf);
3425 ASN_BER_TLV_t::destruct(tlv);
3426 break;}
3427 case TTCN_EncDec::CT_RAW: {
3428 TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name);
3429 TTCN_EncDec_ErrorContext::error_internal
3430 ("No RAW descriptor available for type '%s'.", p_td.name);
3431 break;}
3432 case TTCN_EncDec::CT_TEXT: {
3433 TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name);
3434 TTCN_EncDec_ErrorContext::error_internal
3435 ("No TEXT descriptor available for type '%s'.", p_td.name);
3436 break;}
3437 case TTCN_EncDec::CT_XER: {
3438 TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name);
3439 unsigned XER_coding=va_arg(pvar, unsigned);
af710487 3440 XER_encode(*p_td.xer, p_buf, XER_coding, 0, 0);
970ed795
EL
3441 break;}
3442 case TTCN_EncDec::CT_JSON: {
3443 TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name);
3444 TTCN_EncDec_ErrorContext::error_internal
3445 ("No JSON descriptor available for type '%s'.", p_td.name);
3446 break;}
3447 default:
3448 TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name);
3449 }
3450 va_end(pvar);
3451}
3452
3453void EXTERNAL::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, TTCN_EncDec::coding_t p_coding, ...)
3454{
3455 va_list pvar;
3456 va_start(pvar, p_coding);
3457 switch(p_coding) {
3458 case TTCN_EncDec::CT_BER: {
3459 TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name);
3460 unsigned L_form=va_arg(pvar, unsigned);
3461 ASN_BER_TLV_t tlv;
3462 BER_decode_str2TLV(p_buf, tlv, L_form);
3463 BER_decode_TLV(p_td, tlv, L_form);
3464 if(tlv.isComplete) p_buf.increase_pos(tlv.get_len());
3465 break;}
3466 case TTCN_EncDec::CT_RAW: {
3467 TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name);
3468 TTCN_EncDec_ErrorContext::error_internal
3469 ("No RAW descriptor available for type '%s'.", p_td.name);
3470 break;}
3471 case TTCN_EncDec::CT_TEXT: {
3472 TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name);
3473 TTCN_EncDec_ErrorContext::error_internal
3474 ("No TEXT descriptor available for type '%s'.", p_td.name);
3475 break;}
3476 case TTCN_EncDec::CT_XER: {
3477 TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
3478 unsigned XER_coding=va_arg(pvar, unsigned);
3479 XmlReaderWrap reader(p_buf);
3480 int success = reader.Read();
3481 for (; success==1; success=reader.Read()) {
3482 int type = reader.NodeType();
3483 if (type==XML_READER_TYPE_ELEMENT)
3484 break;
3485 }
feade998 3486 XER_decode(*p_td.xer, reader, XER_coding, XER_NONE, 0);
970ed795
EL
3487 size_t bytes = reader.ByteConsumed();
3488 p_buf.set_pos(bytes);
3489 break;}
3490 case TTCN_EncDec::CT_JSON: {
3491 TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name);
3492 TTCN_EncDec_ErrorContext::error_internal
3493 ("No JSON descriptor available for type '%s'.", p_td.name);
3494 break;}
3495 default:
3496 TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name);
3497 }
3498 va_end(pvar);
3499}
3500
3501struct EXTERNAL_template::single_value_struct {
3502 EXTERNAL_identification_template field_identification;
3503 UNIVERSAL_CHARSTRING_template field_data__value__descriptor;
3504 OCTETSTRING_template field_data__value;
3505};
3506
3abe9331 3507void EXTERNAL_template::set_param(Module_Param& param)
3508{
3509 param.basic_check(Module_Param::BC_TEMPLATE, "record template");
3510 Module_Param_Ptr mp = &param;
3511 if (param.get_type() == Module_Param::MP_Reference) {
3512 mp = param.get_referenced_param();
3513 }
3514 switch (mp->get_type()) {
3515 case Module_Param::MP_Omit:
3516 *this = OMIT_VALUE;
3517 break;
3518 case Module_Param::MP_Any:
3519 *this = ANY_VALUE;
3520 break;
3521 case Module_Param::MP_AnyOrNone:
3522 *this = ANY_OR_OMIT;
3523 break;
3524 case Module_Param::MP_List_Template:
3525 case Module_Param::MP_ComplementList_Template: {
3526 EXTERNAL_template temp;
3527 temp.set_type(mp->get_type() == Module_Param::MP_List_Template ?
3528 VALUE_LIST : COMPLEMENTED_LIST, mp->get_size());
3529 for (size_t i=0; i<mp->get_size(); i++) {
3530 temp.list_item(i).set_param(*mp->get_elem(i));
3531 }
3532 *this = temp;
3533 break; }
3534 case Module_Param::MP_Value_List:
3535 if (mp->get_size()==0) break;
3536 if (3!=mp->get_size()) {
3537 param.error("record template of type EXTERNAL has 3 fields but list value has %d fields", (int)mp->get_size());
3538 }
3539 if (mp->get_elem(0)->get_type()!=Module_Param::MP_NotUsed) identification().set_param(*mp->get_elem(0));
3540 if (mp->get_elem(1)->get_type()!=Module_Param::MP_NotUsed) data__value__descriptor().set_param(*mp->get_elem(1));
3541 if (mp->get_elem(2)->get_type()!=Module_Param::MP_NotUsed) data__value().set_param(*mp->get_elem(2));
3542 break;
3543 case Module_Param::MP_Assignment_List: {
3544 Vector<bool> value_used(mp->get_size());
3545 value_used.resize(mp->get_size(), false);
3546 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
3547 Module_Param* const curr_param = mp->get_elem(val_idx);
3548 if (!strcmp(curr_param->get_id()->get_name(), "identification")) {
3549 identification().set_param(*curr_param);
3550 value_used[val_idx]=true;
3551 }
3552 }
3553 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
3554 Module_Param* const curr_param = mp->get_elem(val_idx);
3555 if (!strcmp(curr_param->get_id()->get_name(), "data_value_descriptor")) {
3556 data__value__descriptor().set_param(*curr_param);
3557 value_used[val_idx]=true;
3558 }
3559 }
3560 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) {
3561 Module_Param* const curr_param = mp->get_elem(val_idx);
3562 if (!strcmp(curr_param->get_id()->get_name(), "data_value")) {
3563 data__value().set_param(*curr_param);
3564 value_used[val_idx]=true;
3565 }
3566 }
3567 for (size_t val_idx=0; val_idx<mp->get_size(); val_idx++) if (!value_used[val_idx]) {
3568 mp->get_elem(val_idx)->error("Non existent field name in type EXTERNAL: %s", mp->get_elem(val_idx)->get_id()->get_name());
3569 break;
3570 }
3571 } break;
3572 default:
3573 param.type_error("record template", "EXTERNAL");
3574 }
3575 is_ifpresent = param.get_ifpresent() || mp->get_ifpresent();
3576}
3577
3578Module_Param* EXTERNAL_template::get_param(Module_Param_Name& param_name) const
3579{
3580 Module_Param* mp = NULL;
3581 switch (template_selection) {
3582 case UNINITIALIZED_TEMPLATE:
3583 mp = new Module_Param_Unbound();
3584 break;
3585 case OMIT_VALUE:
3586 mp = new Module_Param_Omit();
3587 break;
3588 case ANY_VALUE:
3589 mp = new Module_Param_Any();
3590 break;
3591 case ANY_OR_OMIT:
3592 mp = new Module_Param_AnyOrNone();
3593 break;
3594 case SPECIFIC_VALUE: {
3595 Module_Param* mp_field_identification = single_value->field_identification.get_param(param_name);
3596 mp_field_identification->set_id(new Module_Param_FieldName(mcopystr("identification")));
3597 Module_Param* mp_field_data_value_descriptor = single_value->field_data__value__descriptor.get_param(param_name);
3598 mp_field_data_value_descriptor->set_id(new Module_Param_FieldName(mcopystr("data_value_descriptor")));
3599 Module_Param* mp_field_string_value = single_value->field_data__value.get_param(param_name);
3600 mp_field_string_value->set_id(new Module_Param_FieldName(mcopystr("data_value")));
3601 mp = new Module_Param_Assignment_List();
3602 mp->add_elem(mp_field_identification);
3603 mp->add_elem(mp_field_data_value_descriptor);
3604 mp->add_elem(mp_field_string_value);
3605 break; }
3606 case VALUE_LIST:
3607 case COMPLEMENTED_LIST: {
3608 if (template_selection == VALUE_LIST) {
3609 mp = new Module_Param_List_Template();
3610 }
3611 else {
3612 mp = new Module_Param_ComplementList_Template();
3613 }
3614 for (size_t i = 0; i < value_list.n_values; ++i) {
3615 mp->add_elem(value_list.list_value[i].get_param(param_name));
3616 }
3617 break; }
3618 default:
3619 break;
3620 }
3621 if (is_ifpresent) {
3622 mp->set_ifpresent();
3623 }
3624 return mp;
3625}
3626
970ed795
EL
3627void EXTERNAL_template::clean_up()
3628{
3629 switch (template_selection) {
3630 case SPECIFIC_VALUE:
3631 delete single_value;
3632 break;
3633 case VALUE_LIST:
3634 case COMPLEMENTED_LIST:
3635 delete [] value_list.list_value;
3636 break;
3637 default:
3638 break;
3639 }
3640 template_selection = UNINITIALIZED_TEMPLATE;
3641}
3642
3643void EXTERNAL_template::set_specific()
3644{
3645 if (template_selection != SPECIFIC_VALUE) {
3646 template_sel old_selection = template_selection;
3647 clean_up();
3648 single_value = new single_value_struct;
3649 set_selection(SPECIFIC_VALUE);
3650 if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) {
3651 single_value->field_identification = ANY_VALUE;
3652 single_value->field_data__value__descriptor = ANY_OR_OMIT;
3653 single_value->field_data__value = ANY_VALUE;
3654 }
3655 }
3656}
3657
3658void EXTERNAL_template::copy_value(const EXTERNAL& other_value)
3659{
3660 single_value = new single_value_struct;
3661 single_value->field_identification = other_value.identification();
3662 if (other_value.data__value__descriptor().ispresent()) single_value->field_data__value__descriptor = (const UNIVERSAL_CHARSTRING&)(other_value.data__value__descriptor());
3663 else single_value->field_data__value__descriptor = OMIT_VALUE;
3664 single_value->field_data__value = other_value.data__value();
3665 set_selection(SPECIFIC_VALUE);
3666}
3667
3668void EXTERNAL_template::copy_template(const EXTERNAL_template& other_value)
3669{
3670 switch (other_value.template_selection) {
3671 case SPECIFIC_VALUE:
3672 single_value = new single_value_struct(*other_value.single_value);
3673 break;
3674 case OMIT_VALUE:
3675 case ANY_VALUE:
3676 case ANY_OR_OMIT:
3677 break;
3678 case VALUE_LIST:
3679 case COMPLEMENTED_LIST:
3680 value_list.n_values = other_value.value_list.n_values;
3681 value_list.list_value = new EXTERNAL_template[value_list.n_values];
3682 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
3683 value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]);
3684 break;
3685 default:
3686 TTCN_error("Copying an uninitialized/unsupported template of type EXTERNAL.");
3687 }
3688 set_selection(other_value);
3689}
3690
3691EXTERNAL_template::EXTERNAL_template()
3692{
3693}
3694
3695EXTERNAL_template::EXTERNAL_template(template_sel other_value)
3696 : Base_Template(other_value)
3697{
3698 check_single_selection(other_value);
3699}
3700
3701EXTERNAL_template::EXTERNAL_template(const EXTERNAL& other_value)
3702{
3703 copy_value(other_value);
3704}
3705
3706EXTERNAL_template::EXTERNAL_template(const OPTIONAL<EXTERNAL>& other_value)
3707{
3708 switch (other_value.get_selection()) {
3709 case OPTIONAL_PRESENT:
3710 copy_value((const EXTERNAL&)other_value);
3711 break;
3712 case OPTIONAL_OMIT:
3713 set_selection(OMIT_VALUE);
3714 break;
3715 default:
3716 TTCN_error("Creating a template of type EXTERNAL from an unbound optional field.");
3717 }
3718}
3719
3720EXTERNAL_template::EXTERNAL_template(const EXTERNAL_template& other_value)
3721: Base_Template()
3722{
3723 copy_template(other_value);
3724}
3725
3726EXTERNAL_template::~EXTERNAL_template()
3727{
3728 clean_up();
3729}
3730
3731EXTERNAL_template& EXTERNAL_template::operator=(template_sel other_value)
3732{
3733 check_single_selection(other_value);
3734 clean_up();
3735 set_selection(other_value);
3736 return *this;
3737}
3738
3739EXTERNAL_template& EXTERNAL_template::operator=(const EXTERNAL& other_value)
3740{
3741 clean_up();
3742 copy_value(other_value);
3743 return *this;
3744}
3745
3746EXTERNAL_template& EXTERNAL_template::operator=(const OPTIONAL<EXTERNAL>& other_value)
3747{
3748 clean_up();
3749 switch (other_value.get_selection()) {
3750 case OPTIONAL_PRESENT:
3751 copy_value((const EXTERNAL&)other_value);
3752 break;
3753 case OPTIONAL_OMIT:
3754 set_selection(OMIT_VALUE);
3755 break;
3756 default:
3757 TTCN_error("Assignment of an unbound optional field to a template of type EXTERNAL.");
3758 }
3759 return *this;
3760}
3761
3762EXTERNAL_template& EXTERNAL_template::operator=(const EXTERNAL_template& other_value)
3763{
3764 if (&other_value != this) {
3765 clean_up();
3766 copy_template(other_value);
3767 }
3768 return *this;
3769}
3770
3abe9331 3771boolean EXTERNAL_template::match(const EXTERNAL& other_value,
3772 boolean /* legacy */) const
970ed795
EL
3773{
3774 switch (template_selection) {
3775 case ANY_VALUE:
3776 case ANY_OR_OMIT:
3777 return TRUE;
3778 case OMIT_VALUE:
3779 return FALSE;
3780 case SPECIFIC_VALUE:
3781 if (!other_value.identification().is_bound()) return FALSE;
3782 if (!single_value->field_identification.match(other_value.identification())) return FALSE;
3783 if (!other_value.data__value__descriptor().is_bound()) return FALSE;
3784 if (other_value.data__value__descriptor().ispresent() ? !single_value->field_data__value__descriptor.match((const UNIVERSAL_CHARSTRING&)other_value.data__value__descriptor()) : !single_value->field_data__value__descriptor.match_omit()) return FALSE;
3785 if (!other_value.data__value().is_bound()) return FALSE;
3786 if (!single_value->field_data__value.match(other_value.data__value())) return FALSE;
3787 return TRUE;
3788 case VALUE_LIST:
3789 case COMPLEMENTED_LIST:
3790 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
3791 if (value_list.list_value[list_count].match(other_value)) return template_selection == VALUE_LIST;
3792 return template_selection == COMPLEMENTED_LIST;
3793 default:
3794 TTCN_error("Matching an uninitialized/unsupported template of type EXTERNAL.");
3795 }
3796 return FALSE;
3797}
3798
3799EXTERNAL EXTERNAL_template::valueof() const
3800{
3801 if (template_selection != SPECIFIC_VALUE || is_ifpresent)
3802 TTCN_error("Performing valueof or send operation on a non-specific template of type EXTERNAL.");
3803 EXTERNAL ret_val;
3804 ret_val.identification() = single_value->field_identification.valueof();
3805 if (single_value->field_data__value__descriptor.is_omit()) ret_val.data__value__descriptor() = OMIT_VALUE;
3806 else ret_val.data__value__descriptor() = single_value->field_data__value__descriptor.valueof();
3807 ret_val.data__value() = single_value->field_data__value.valueof();
3808 return ret_val;
3809}
3810
3811void EXTERNAL_template::set_type(template_sel template_type, unsigned int list_length)
3812{
3813 if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST)
3814 TTCN_error("Setting an invalid list for a template of type EXTERNAL.");
3815 clean_up();
3816 set_selection(template_type);
3817 value_list.n_values = list_length;
3818 value_list.list_value = new EXTERNAL_template[list_length];
3819}
3820
3821EXTERNAL_template& EXTERNAL_template::list_item(unsigned int list_index) const
3822{
3823 if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST)
3824 TTCN_error("Accessing a list element of a non-list template of type EXTERNAL.");
3825 if (list_index >= value_list.n_values)
3826 TTCN_error("Index overflow in a value list template of type EXTERNAL.");
3827 return value_list.list_value[list_index];
3828}
3829
3830EXTERNAL_identification_template& EXTERNAL_template::identification()
3831{
3832 set_specific();
3833 return single_value->field_identification;
3834}
3835
3836const EXTERNAL_identification_template& EXTERNAL_template::identification() const
3837{
3838 if (template_selection != SPECIFIC_VALUE)
3839 TTCN_error("Accessing field identification of a non-specific template of type EXTERNAL.");
3840 return single_value->field_identification;
3841}
3842
3843UNIVERSAL_CHARSTRING_template& EXTERNAL_template::data__value__descriptor()
3844{
3845 set_specific();
3846 return single_value->field_data__value__descriptor;
3847}
3848
3849const UNIVERSAL_CHARSTRING_template& EXTERNAL_template::data__value__descriptor() const
3850{
3851 if (template_selection != SPECIFIC_VALUE)
3852 TTCN_error("Accessing field data_value_descriptor of a non-specific template of type EXTERNAL.");
3853 return single_value->field_data__value__descriptor;
3854}
3855
3856OCTETSTRING_template& EXTERNAL_template::data__value()
3857{
3858 set_specific();
3859 return single_value->field_data__value;
3860}
3861
3862const OCTETSTRING_template& EXTERNAL_template::data__value() const
3863{
3864 if (template_selection != SPECIFIC_VALUE)
3865 TTCN_error("Accessing field data_value of a non-specific template of type EXTERNAL.");
3866 return single_value->field_data__value;
3867}
3868
3869int EXTERNAL_template::size_of() const
3870{
3871 switch (template_selection)
3872 {
3873 case SPECIFIC_VALUE:
3874 {
3875 int ret_val = 2;
3876 if (single_value->field_data__value__descriptor.is_present()) ret_val++;
3877 return ret_val;
3878 }
3879 case VALUE_LIST:
3880 {
3881 if (value_list.n_values<1)
3882 TTCN_error("Internal error: Performing sizeof() operation on a template of type EXTERNAL containing an empty list.");
3883 int item_size = value_list.list_value[0].size_of();
3884 for (unsigned int i = 1; i < value_list.n_values; i++)
3885 {
3886 if (value_list.list_value[i].size_of()!=item_size)
3887 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL containing a value list with different sizes.");
3888 }
3889 return item_size;
3890 }
3891 case OMIT_VALUE:
3892 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL containing omit value.");
3893 case ANY_VALUE:
3894 case ANY_OR_OMIT:
3895 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL containing */? value.");
3896 case COMPLEMENTED_LIST:
3897 TTCN_error("Performing sizeof() operation on a template of type EXTERNAL containing complemented list.");
3898 default:
3899 TTCN_error("Performing sizeof() operation on an uninitialized/unsupported template of type EXTERNAL.");
3900 }
3901 return 0;
3902}
3903
3904void EXTERNAL_template::log() const
3905{
3906 switch (template_selection) {
3907 case SPECIFIC_VALUE:
3908 TTCN_Logger::log_event_str("{ identification := ");
3909 single_value->field_identification.log();
3910 TTCN_Logger::log_event_str(", data_value_descriptor := ");
3911 single_value->field_data__value__descriptor.log();
3912 TTCN_Logger::log_event_str(", data_value := ");
3913 single_value->field_data__value.log();
3914 TTCN_Logger::log_event_str(" }");
3915 break;
3916 case COMPLEMENTED_LIST:
3917 TTCN_Logger::log_event_str("complement ");
3918 // no break
3919 case VALUE_LIST:
3920 TTCN_Logger::log_char('(');
3921 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++) {
3922 if (list_count > 0) TTCN_Logger::log_event_str(", ");
3923 value_list.list_value[list_count].log();
3924 }
3925 TTCN_Logger::log_char(')');
3926 break;
3927 default:
3928 log_generic();
3929 break;
3930 }
3931 log_ifpresent();
3932}
3933
3abe9331 3934void EXTERNAL_template::log_match(const EXTERNAL& match_value,
3935 boolean /* legacy */) const
970ed795
EL
3936{
3937 if (template_selection == SPECIFIC_VALUE) {
3938 TTCN_Logger::log_event_str("{ identification := ");
3939 single_value->field_identification.log_match(match_value.identification());
3940 TTCN_Logger::log_event_str(", data_value_descriptor := ");
3941 if (match_value.data__value__descriptor().ispresent()) single_value->field_data__value__descriptor.log_match(match_value.data__value__descriptor());
3942 else {
3943 single_value->field_data__value__descriptor.log();
3944 if (single_value->field_data__value__descriptor.match_omit()) TTCN_Logger::log_event_str(" matched");
3945 else TTCN_Logger::log_event_str(" unmatched");
3946 }
3947 TTCN_Logger::log_event_str(", data_value := ");
3948 single_value->field_data__value.log_match(match_value.data__value());
3949 TTCN_Logger::log_event_str(" }");
3950 } else {
3951 match_value.log();
3952 TTCN_Logger::log_event_str(" with ");
3953 log();
3954 if (match(match_value)) TTCN_Logger::log_event_str(" matched");
3955 else TTCN_Logger::log_event_str(" unmatched");
3956 }
3957}
3958
3959void EXTERNAL_template::encode_text(Text_Buf& text_buf) const
3960{
3961 encode_text_base(text_buf);
3962 switch (template_selection) {
3963 case SPECIFIC_VALUE:
3964 single_value->field_identification.encode_text(text_buf);
3965 single_value->field_data__value__descriptor.encode_text(text_buf);
3966 single_value->field_data__value.encode_text(text_buf);
3967 break;
3968 case OMIT_VALUE:
3969 case ANY_VALUE:
3970 case ANY_OR_OMIT:
3971 break;
3972 case VALUE_LIST:
3973 case COMPLEMENTED_LIST:
3974 text_buf.push_int(value_list.n_values);
3975 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
3976 value_list.list_value[list_count].encode_text(text_buf);
3977 break;
3978 default:
3979 TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of type EXTERNAL.");
3980 }
3981}
3982
3983void EXTERNAL_template::decode_text(Text_Buf& text_buf)
3984{
3985 clean_up();
3986 decode_text_base(text_buf);
3987 switch (template_selection) {
3988 case SPECIFIC_VALUE:
3989 single_value = new single_value_struct;
3990 single_value->field_identification.decode_text(text_buf);
3991 single_value->field_data__value__descriptor.decode_text(text_buf);
3992 single_value->field_data__value.decode_text(text_buf);
3993 break;
3994 case OMIT_VALUE:
3995 case ANY_VALUE:
3996 case ANY_OR_OMIT:
3997 break;
3998 case VALUE_LIST:
3999 case COMPLEMENTED_LIST:
4000 value_list.n_values = text_buf.pull_int().get_val();
4001 value_list.list_value = new EXTERNAL_template[value_list.n_values];
4002 for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
4003 value_list.list_value[list_count].decode_text(text_buf);
4004 break;
4005 default:
4006 TTCN_error("Text decoder: An unknown/unsupported selection was received in a template of type EXTERNAL.");
4007 }
4008}
4009
3abe9331 4010boolean EXTERNAL_template::is_present(boolean legacy /* = FALSE */) const
970ed795
EL
4011{
4012 if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;
3abe9331 4013 return !match_omit(legacy);
970ed795
EL
4014}
4015
3abe9331 4016boolean EXTERNAL_template::match_omit(boolean legacy /* = FALSE */) const
970ed795
EL
4017{
4018 if (is_ifpresent) return TRUE;
4019 switch (template_selection) {
4020 case OMIT_VALUE:
4021 case ANY_OR_OMIT:
4022 return TRUE;
4023 case VALUE_LIST:
4024 case COMPLEMENTED_LIST:
3abe9331 4025 if (legacy) {
4026 // legacy behavior: 'omit' can appear in the value/complement list
4027 for (unsigned int i=0; i<value_list.n_values; i++)
4028 if (value_list.list_value[i].match_omit())
4029 return template_selection==VALUE_LIST;
4030 return template_selection==COMPLEMENTED_LIST;
4031 }
4032 // else fall through
970ed795
EL
4033 default:
4034 return FALSE;
4035 }
4036 return FALSE;
4037}
4038
4039#ifndef TITAN_RUNTIME_2
3abe9331 4040void EXTERNAL_template::check_restriction(template_res t_res, const char* t_name,
4041 boolean legacy /* = FALSE */) const
970ed795
EL
4042{
4043 if (template_selection==UNINITIALIZED_TEMPLATE) return;
4044 switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {
4045 case TR_VALUE:
4046 if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;
4047 break;
4048 case TR_OMIT:
4049 if (!is_ifpresent && (template_selection==OMIT_VALUE ||
4050 template_selection==SPECIFIC_VALUE)) return;
4051 break;
4052 case TR_PRESENT:
3abe9331 4053 if (!match_omit(legacy)) return;
970ed795
EL
4054 break;
4055 default:
4056 return;
4057 }
4058 TTCN_error("Restriction `%s' on template of type %s violated.",
4059 get_res_name(t_res), t_name ? t_name : "EXTERNAL");
4060}
4061#endif
This page took 0.1745 seconds and 5 git commands to generate.