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