constr_SEQUENCE.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
8 
11 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
13 #else
14  0,
15 #endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
18 #if !defined(ASN_DISABLE_BER_SUPPORT)
21 #else
22  0,
23  0,
24 #endif /* !defined(ASN_DISABLE_BER_SUPPORT) */
25 #if !defined(ASN_DISABLE_XER_SUPPORT)
28 #else
29  0,
30  0,
31 #endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
32 #if !defined(ASN_DISABLE_JER_SUPPORT)
35 #else
36  0,
37  0,
38 #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
39 #if !defined(ASN_DISABLE_OER_SUPPORT)
42 #else
43  0,
44  0,
45 #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
46 #if !defined(ASN_DISABLE_UPER_SUPPORT)
49 #else
50  0,
51  0,
52 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */
53 #if !defined(ASN_DISABLE_APER_SUPPORT)
56 #else
57  0,
58  0,
59 #endif /* !defined(ASN_DISABLE_APER_SUPPORT) */
60 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
62 #else
63  0,
64 #endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
65  0 /* Use generic outmost tag fetcher */
66 };
67 
68 void
69 SEQUENCE_free(const asn_TYPE_descriptor_t *td, void *sptr,
70  enum asn_struct_free_method method) {
71  size_t edx;
72  const asn_SEQUENCE_specifics_t *specs;
73  asn_struct_ctx_t *ctx; /* Decoder context */
74 
75  if(!td || !sptr)
76  return;
77 
78  specs = (const asn_SEQUENCE_specifics_t *)td->specifics;
79 
80  ASN_DEBUG("Freeing %s as SEQUENCE", td->name);
81 
82  for(edx = 0; edx < td->elements_count; edx++) {
83  asn_TYPE_member_t *elm = &td->elements[edx];
84  void *memb_ptr;
85  if(elm->flags & ATF_POINTER) {
86  memb_ptr = *(void **)((char *)sptr + elm->memb_offset);
87  if(memb_ptr)
88  ASN_STRUCT_FREE(*elm->type, memb_ptr);
89  } else {
90  memb_ptr = (void *)((char *)sptr + elm->memb_offset);
91  ASN_STRUCT_FREE_CONTENTS_ONLY(*elm->type, memb_ptr);
92  }
93  }
94 
95  /* Clean parsing context */
96  ctx = (asn_struct_ctx_t *)((char *)sptr + specs->ctx_offset);
97  FREEMEM(ctx->ptr);
98 
99  switch(method) {
101  FREEMEM(sptr);
102  break;
104  break;
106  memset(
107  sptr, 0,
108  ((const asn_SEQUENCE_specifics_t *)(td->specifics))->struct_size);
109  break;
110  }
111 }
112 
113 int
114 SEQUENCE_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
115  asn_app_constraint_failed_f *ctfailcb, void *app_key) {
116  size_t edx;
117 
118  if(!sptr) {
119  ASN__CTFAIL(app_key, td, sptr,
120  "%s: value not given (%s:%d)",
121  td->name, __FILE__, __LINE__);
122  return -1;
123  }
124 
125  /*
126  * Iterate over structure members and check their validity.
127  */
128  for(edx = 0; edx < td->elements_count; edx++) {
129  asn_TYPE_member_t *elm = &td->elements[edx];
130  const void *memb_ptr;
131  asn_constr_check_f *constr;
132  int ret;
133 
134  if(elm->flags & ATF_POINTER) {
135  memb_ptr = *(const void * const *)((const char *)sptr + elm->memb_offset);
136  if(!memb_ptr) {
137  if(elm->optional)
138  continue;
139  ASN__CTFAIL(app_key, td, sptr,
140  "%s: mandatory element %s absent (%s:%d)",
141  td->name, elm->name, __FILE__, __LINE__);
142  return -1;
143  }
144  } else {
145  memb_ptr = (const void *)((const char *)sptr + elm->memb_offset);
146  }
147 
149  if(!constr)
151 
152  ret = constr(elm->type, memb_ptr, ctfailcb, app_key);
153  if(ret) return ret;
154  }
155 
156  return 0;
157 }
158 
159 int
160 SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
161  const void *bptr) {
162  size_t edx;
163 
164  for(edx = 0; edx < td->elements_count; edx++) {
165  asn_TYPE_member_t *elm = &td->elements[edx];
166  const void *amemb;
167  const void *bmemb;
168  int ret;
169 
170  if(elm->flags & ATF_POINTER) {
171  amemb =
172  *(const void *const *)((const char *)aptr + elm->memb_offset);
173  bmemb =
174  *(const void *const *)((const char *)bptr + elm->memb_offset);
175  if(!amemb) {
176  if(!bmemb) continue;
177  if(elm->default_value_cmp
178  && elm->default_value_cmp(bmemb) == 0) {
179  /* A is absent, but B is present and equal to DEFAULT */
180  continue;
181  }
182  return -1;
183  } else if(!bmemb) {
184  if(elm->default_value_cmp
185  && elm->default_value_cmp(amemb) == 0) {
186  /* B is absent, but A is present and equal to DEFAULT */
187  continue;
188  }
189  return 1;
190  }
191  } else {
192  amemb = (const void *)((const char *)aptr + elm->memb_offset);
193  bmemb = (const void *)((const char *)bptr + elm->memb_offset);
194  }
195 
196  ret = elm->type->op->compare_struct(elm->type, amemb, bmemb);
197  if(ret != 0) return ret;
198  }
199 
200  return 0;
201 }
202 
203 int
204 SEQUENCE_copy(const asn_TYPE_descriptor_t *td, void **aptr,
205  const void *bptr) {
206  if(!td) return -1;
207 
208  const asn_SEQUENCE_specifics_t *specs =
209  (const asn_SEQUENCE_specifics_t *)td->specifics;
210  size_t edx;
211  void *st = *aptr; /* Target structure */
212 
213  if(!bptr) {
214  if(st) {
215  SEQUENCE_free(td, st, 0);
216  *aptr = 0;
217  }
218  return 0;
219  }
220 
221  /*
222  * Create the target structure if it is not present already.
223  */
224  if(st == 0) {
225  st = *aptr = CALLOC(1, specs->struct_size);
226  if(st == 0) return -1;
227  }
228 
229  for(edx = 0; edx < td->elements_count; edx++) {
230  asn_TYPE_member_t *elm = &td->elements[edx];
231  void *amemb;
232  void **amembp;
233  const void *bmemb;
234  int ret;
235 
236  if(elm->flags & ATF_POINTER) {
237  /* Member is a pointer to another structure */
238  amembp = (void **)((char *)st + elm->memb_offset);
239  bmemb = *(const void* const*)((const char*)bptr + elm->memb_offset);
240  } else {
241  amemb = (char *)st + elm->memb_offset;
242  amembp = &amemb;
243  bmemb = (const void*)((const char*)bptr + elm->memb_offset);
244  }
245 
246  ret = elm->type->op->copy_struct(elm->type, amembp, bmemb);
247  if(ret != 0) return ret;
248  }
249 
250  return 0;
251 }
ASN_STRUCT_FREE
#define ASN_STRUCT_FREE(asn_DEF, ptr)
Definition: constr_TYPE.h:102
asn_struct_ctx_s
Definition: constr_TYPE.h:29
asn_TYPE_operation_s
Definition: constr_TYPE.h:184
SEQUENCE_decode_uper
per_type_decoder_f SEQUENCE_decode_uper
Definition: constr_SEQUENCE.h:79
SEQUENCE_free
void SEQUENCE_free(const asn_TYPE_descriptor_t *td, void *sptr, enum asn_struct_free_method method)
Definition: constr_SEQUENCE.c:69
SEQUENCE_compare
int SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr)
Definition: constr_SEQUENCE.c:160
SEQUENCE_encode_der
der_type_encoder_f SEQUENCE_encode_der
Definition: constr_SEQUENCE.h:60
ASFM_FREE_UNDERLYING
@ ASFM_FREE_UNDERLYING
Definition: constr_TYPE.h:92
asn_TYPE_member_s::memb_offset
unsigned memb_offset
Definition: constr_TYPE.h:275
SEQUENCE_random_fill
asn_random_fill_f SEQUENCE_random_fill
Definition: constr_SEQUENCE.h:88
asn_app_constraint_failed_f
void() asn_app_constraint_failed_f(void *application_specific_key, const struct asn_TYPE_descriptor_s *type_descriptor_which_failed, const void *structure_which_failed_ptr, const char *error_message_format,...) CC_PRINTFLIKE(4
Definition: asn_application.h:167
asn_SEQUENCE_specifics_s::struct_size
unsigned struct_size
Definition: constr_SEQUENCE.h:18
asn_TYPE_descriptor_s::elements_count
unsigned elements_count
Definition: constr_TYPE.h:253
asn_TYPE_descriptor_s::name
const char * name
Definition: constr_TYPE.h:225
CALLOC
#define CALLOC(nmemb, size)
Definition: asn_internal.h:37
SEQUENCE_decode_xer
xer_type_decoder_f SEQUENCE_decode_xer
Definition: constr_SEQUENCE.h:64
SEQUENCE_encode_uper
per_type_encoder_f SEQUENCE_encode_uper
Definition: constr_SEQUENCE.h:80
ASFM_FREE_UNDERLYING_AND_RESET
@ ASFM_FREE_UNDERLYING_AND_RESET
Definition: constr_TYPE.h:93
ASFM_FREE_EVERYTHING
@ ASFM_FREE_EVERYTHING
Definition: constr_TYPE.h:91
SEQUENCE_decode_oer
oer_type_decoder_f SEQUENCE_decode_oer
Definition: constr_SEQUENCE.h:74
asn_TYPE_operation_s::copy_struct
asn_struct_copy_f * copy_struct
Definition: constr_TYPE.h:188
FREEMEM
#define FREEMEM(ptr)
Definition: asn_internal.h:40
SEQUENCE_decode_ber
ber_type_decoder_f SEQUENCE_decode_ber
Definition: constr_SEQUENCE.h:59
SEQUENCE_constraint
int SEQUENCE_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, asn_app_constraint_failed_f *ctfailcb, void *app_key)
Definition: constr_SEQUENCE.c:114
ATF_POINTER
@ ATF_POINTER
Definition: constr_TYPE.h:268
SEQUENCE_encode_aper
per_type_encoder_f SEQUENCE_encode_aper
Definition: constr_SEQUENCE.h:84
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
asn_TYPE_member_s::type
asn_TYPE_descriptor_t * type
Definition: constr_TYPE.h:278
asn_TYPE_descriptor_s::specifics
const void * specifics
Definition: constr_TYPE.h:259
SEQUENCE_copy
int SEQUENCE_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr)
Definition: constr_SEQUENCE.c:204
asn_SEQUENCE_specifics_s::ctx_offset
unsigned ctx_offset
Definition: constr_SEQUENCE.h:19
asn_TYPE_member_s::name
const char * name
Definition: constr_TYPE.h:283
SEQUENCE_encode_xer
xer_type_encoder_f SEQUENCE_encode_xer
Definition: constr_SEQUENCE.h:65
asn_TYPE_descriptor_s::op
asn_TYPE_operation_t * op
Definition: constr_TYPE.h:232
asn_struct_free_method
asn_struct_free_method
Definition: constr_TYPE.h:90
SEQUENCE_decode_jer
jer_type_decoder_f SEQUENCE_decode_jer
Definition: constr_SEQUENCE.h:69
SEQUENCE_print
asn_struct_print_f SEQUENCE_print
Definition: constr_SEQUENCE.h:50
asn_TYPE_operation_s::compare_struct
asn_struct_compare_f * compare_struct
Definition: constr_TYPE.h:187
asn_constr_check_f
int() asn_constr_check_f(const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr, asn_app_constraint_failed_f *optional_callback, void *optional_app_key)
Definition: constraints.h:41
asn_SEQUENCE_specifics_s
Definition: constr_SEQUENCE.h:14
asn_internal.h
ASN__CTFAIL
#define ASN__CTFAIL
Definition: constraints.h:57
SEQUENCE_decode_aper
per_type_decoder_f SEQUENCE_decode_aper
Definition: constr_SEQUENCE.h:83
asn_TYPE_descriptor_s::elements
struct asn_TYPE_member_s * elements
Definition: constr_TYPE.h:252
asn_encoding_constraints_s::general_constraints
asn_constr_check_f * general_constraints
Definition: constr_TYPE.h:218
SEQUENCE_encode_oer
oer_type_encoder_f SEQUENCE_encode_oer
Definition: constr_SEQUENCE.h:75
constr_SEQUENCE.h
asn_OP_SEQUENCE
asn_TYPE_operation_t asn_OP_SEQUENCE
Definition: constr_SEQUENCE.c:9
asn_struct_ctx_s::ptr
void * ptr
Definition: constr_TYPE.h:33
asn_TYPE_member_s
Definition: constr_TYPE.h:272
asn_TYPE_descriptor_s::encoding_constraints
asn_encoding_constraints_t encoding_constraints
Definition: constr_TYPE.h:247
asn_TYPE_member_s::flags
enum asn_TYPE_flags_e flags
Definition: constr_TYPE.h:273
asn_TYPE_member_s::default_value_cmp
int(* default_value_cmp)(const void *sptr)
Definition: constr_TYPE.h:281
ASN_STRUCT_FREE_CONTENTS_ONLY
#define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr)
Definition: constr_TYPE.h:123
SEQUENCE_encode_jer
jer_type_encoder_f SEQUENCE_encode_jer
Definition: constr_SEQUENCE.h:70
asn_TYPE_member_s::encoding_constraints
asn_encoding_constraints_t encoding_constraints
Definition: constr_TYPE.h:280
asn_TYPE_member_s::optional
unsigned optional
Definition: constr_TYPE.h:274


etsi_its_cam_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:21:23