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