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