blob: 0a8ee2819d910cee4b0fad688d89eb4a39d1f7f9 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkina9cc46e2004-09-22 16:06:28 +00005#include <asn_internal.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00006#include <constr_SET_OF.h>
7#include <asn_SET_OF.h>
8
9/*
10 * Number of bytes left for this structure.
11 * (ctx->left) indicates the number of bytes _transferred_ for the structure.
12 * (size) contains the number of bytes in the buffer passed.
13 */
Lev Walkinec1ffd42004-08-18 04:53:32 +000014#define LEFT ((size<(size_t)ctx->left)?size:(size_t)ctx->left)
Lev Walkinf15320b2004-06-03 03:38:44 +000015
16/*
17 * If the subprocessor function returns with an indication that it wants
18 * more data, it may well be a fatal decoding problem, because the
19 * size is constrained by the <TLV>'s L, even if the buffer size allows
20 * reading more data.
21 * For example, consider the buffer containing the following TLVs:
22 * <T:5><L:1><V> <T:6>...
23 * The TLV length clearly indicates that one byte is expected in V, but
24 * if the V processor returns with "want more data" even if the buffer
25 * contains way more data than the V processor have seen.
26 */
Lev Walkind9bd7752004-06-05 08:17:50 +000027#define SIZE_VIOLATION (ctx->left != -1 && (size_t)ctx->left <= size)
Lev Walkinf15320b2004-06-03 03:38:44 +000028
29/*
30 * This macro "eats" the part of the buffer which is definitely "consumed",
31 * i.e. was correctly converted into local representation or rightfully skipped.
32 */
33#define ADVANCE(num_bytes) do { \
34 size_t num = num_bytes; \
Lev Walkin4ce78ca2004-08-25 01:34:11 +000035 ptr = ((char *)ptr) + num; \
Lev Walkinf15320b2004-06-03 03:38:44 +000036 size -= num; \
37 if(ctx->left >= 0) \
38 ctx->left -= num; \
39 consumed_myself += num; \
40 } while(0)
41
42/*
43 * Switch to the next phase of parsing.
44 */
45#define NEXT_PHASE(ctx) do { \
46 ctx->phase++; \
47 ctx->step = 0; \
48 } while(0)
49#define PHASE_OUT(ctx) do { ctx->phase = 10; } while(0)
50
51/*
52 * Return a standardized complex structure.
53 */
54#define RETURN(_code) do { \
55 rval.code = _code; \
56 rval.consumed = consumed_myself;\
57 return rval; \
58 } while(0)
59
60/*
61 * The decoder of the SET OF type.
62 */
63ber_dec_rval_t
Lev Walkin449f8322004-08-20 13:23:42 +000064SET_OF_decode_ber(asn1_TYPE_descriptor_t *td,
Lev Walkinf15320b2004-06-03 03:38:44 +000065 void **struct_ptr, void *ptr, size_t size, int tag_mode) {
66 /*
67 * Bring closer parts of structure description.
68 */
Lev Walkin449f8322004-08-20 13:23:42 +000069 asn1_SET_OF_specifics_t *specs = (asn1_SET_OF_specifics_t *)td->specifics;
70 asn1_TYPE_member_t *element = td->elements; /* Single one */
Lev Walkinf15320b2004-06-03 03:38:44 +000071
72 /*
73 * Parts of the structure being constructed.
74 */
75 void *st = *struct_ptr; /* Target structure. */
76 ber_dec_ctx_t *ctx; /* Decoder context */
77
78 ber_tlv_tag_t tlv_tag; /* T from TLV */
79 //ber_tlv_len_t tlv_len; /* L from TLV */
80 ber_dec_rval_t rval; /* Return code from subparsers */
81
82 ssize_t consumed_myself = 0; /* Consumed bytes from ptr */
83
Lev Walkin449f8322004-08-20 13:23:42 +000084 ASN_DEBUG("Decoding %s as SET OF", td->name);
Lev Walkinf15320b2004-06-03 03:38:44 +000085
86 /*
87 * Create the target structure if it is not present already.
88 */
89 if(st == 0) {
90 st = *struct_ptr = CALLOC(1, specs->struct_size);
91 if(st == 0) {
92 RETURN(RC_FAIL);
93 }
94 }
95
96 /*
97 * Restore parsing context.
98 */
Lev Walkin4d9528c2004-08-11 08:10:13 +000099 ctx = (ber_dec_ctx_t *)((char *)st + specs->ctx_offset);
Lev Walkinf15320b2004-06-03 03:38:44 +0000100
101 /*
102 * Start to parse where left previously
103 */
104 switch(ctx->phase) {
105 case 0:
106 /*
107 * PHASE 0.
108 * Check that the set of tags associated with given structure
109 * perfectly fits our expectations.
110 */
111
Lev Walkin449f8322004-08-20 13:23:42 +0000112 rval = ber_check_tags(td, ctx, ptr, size,
Lev Walkinf15320b2004-06-03 03:38:44 +0000113 tag_mode, &ctx->left, 0);
114 if(rval.code != RC_OK) {
115 ASN_DEBUG("%s tagging check failed: %d",
Lev Walkin449f8322004-08-20 13:23:42 +0000116 td->name, rval.code);
Lev Walkinf15320b2004-06-03 03:38:44 +0000117 consumed_myself += rval.consumed;
118 RETURN(rval.code);
119 }
120
121 if(ctx->left >= 0)
122 ctx->left += rval.consumed; /* ?Substracted below! */
123 ADVANCE(rval.consumed);
124
125 ASN_DEBUG("Structure consumes %ld bytes, "
126 "buffer %ld", (long)ctx->left, (long)size);
127
128 NEXT_PHASE(ctx);
129 /* Fall through */
130 case 1:
131 /*
132 * PHASE 1.
133 * From the place where we've left it previously,
134 * try to decode the next item.
135 */
136 for(;; ctx->step = 0) {
137 ssize_t tag_len; /* Length of TLV's T */
138
139 if(ctx->step & 1)
140 goto microphase2;
141
142 /*
143 * MICROPHASE 1: Synchronize decoding.
144 */
145
146 if(ctx->left == 0) {
Lev Walkin449f8322004-08-20 13:23:42 +0000147 ASN_DEBUG("End of SET OF %s", td->name);
Lev Walkinf15320b2004-06-03 03:38:44 +0000148 /*
149 * No more things to decode.
150 * Exit out of here.
151 */
152 PHASE_OUT(ctx);
153 RETURN(RC_OK);
154 }
155
156 /*
157 * Fetch the T from TLV.
158 */
159 tag_len = ber_fetch_tag(ptr, LEFT, &tlv_tag);
160 switch(tag_len) {
161 case 0: if(!SIZE_VIOLATION) RETURN(RC_WMORE);
162 /* Fall through */
163 case -1: RETURN(RC_FAIL);
164 }
165
166 if(ctx->left < 0 && ((uint8_t *)ptr)[0] == 0) {
167 if(LEFT < 2) {
168 if(SIZE_VIOLATION)
169 RETURN(RC_FAIL);
170 else
171 RETURN(RC_WMORE);
172 } else if(((uint8_t *)ptr)[1] == 0) {
173 /*
174 * Found the terminator of the
175 * indefinite length structure.
176 */
177 break;
178 }
179 }
180
181 /* Outmost tag may be unknown and cannot be fetched/compared */
Lev Walkind9bd7752004-06-05 08:17:50 +0000182 if(element->tag != (ber_tlv_tag_t)-1) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000183 if(BER_TAGS_EQUAL(tlv_tag, element->tag)) {
184 /*
185 * The new list member of expected type has arrived.
186 */
187 } else {
188 ASN_DEBUG("Unexpected tag %s fixed SET OF %s",
Lev Walkin449f8322004-08-20 13:23:42 +0000189 ber_tlv_tag_string(tlv_tag), td->name);
Lev Walkinf15320b2004-06-03 03:38:44 +0000190 ASN_DEBUG("%s SET OF has tag %s",
Lev Walkin449f8322004-08-20 13:23:42 +0000191 td->name, ber_tlv_tag_string(element->tag));
Lev Walkinf15320b2004-06-03 03:38:44 +0000192 RETURN(RC_FAIL);
193 }
194 }
195
196 /*
197 * MICROPHASE 2: Invoke the member-specific decoder.
198 */
199 ctx->step |= 1; /* Confirm entering next microphase */
200 microphase2:
201
202 /*
203 * Invoke the member fetch routine according to member's type
204 */
Lev Walkinc2346572004-08-11 09:07:36 +0000205 rval = element->type->ber_decoder(element->type,
Lev Walkinf15320b2004-06-03 03:38:44 +0000206 &ctx->ptr, ptr, LEFT, 0);
207 ASN_DEBUG("In %s SET OF %s code %d consumed %d",
Lev Walkin449f8322004-08-20 13:23:42 +0000208 td->name, element->type->name,
Lev Walkinf15320b2004-06-03 03:38:44 +0000209 rval.code, (int)rval.consumed);
210 switch(rval.code) {
211 case RC_OK:
212 {
Lev Walkinc2346572004-08-11 09:07:36 +0000213 A_SET_OF(void) *list;
214 (void *)list = st;
Lev Walkinf15320b2004-06-03 03:38:44 +0000215 if(ASN_SET_ADD(list, ctx->ptr) != 0)
216 RETURN(RC_FAIL);
217 else
218 ctx->ptr = 0;
219 }
220 break;
221 case RC_WMORE: /* More data expected */
222 if(!SIZE_VIOLATION) {
223 ADVANCE(rval.consumed);
224 RETURN(RC_WMORE);
225 }
226 /* Fall through */
227 case RC_FAIL: /* Fatal error */
228 RETURN(RC_FAIL);
229 } /* switch(rval) */
230
231 ADVANCE(rval.consumed);
232 } /* for(all list members) */
233
234 NEXT_PHASE(ctx);
235 case 2:
236 /*
237 * Read in all "end of content" TLVs.
238 */
239 while(ctx->left < 0) {
240 if(LEFT < 2) {
241 if(LEFT > 0 && ((char *)ptr)[0] != 0) {
242 /* Unexpected tag */
243 RETURN(RC_FAIL);
244 } else {
245 RETURN(RC_WMORE);
246 }
247 }
248 if(((char *)ptr)[0] == 0
249 && ((char *)ptr)[1] == 0) {
250 ADVANCE(2);
251 ctx->left++;
252 } else {
253 RETURN(RC_FAIL);
254 }
255 }
256
257 PHASE_OUT(ctx);
258 }
259
260 RETURN(RC_OK);
261}
262
263/*
264 * Internally visible buffer holding a single encoded element.
265 */
266struct _el_buffer {
267 uint8_t *buf;
268 size_t length;
269 size_t size;
270};
271/* Append bytes to the above structure */
272static int _el_addbytes(const void *buffer, size_t size, void *el_buf_ptr) {
Lev Walkinc2346572004-08-11 09:07:36 +0000273 struct _el_buffer *el_buf = (struct _el_buffer *)el_buf_ptr;
Lev Walkinf15320b2004-06-03 03:38:44 +0000274
275 if(el_buf->length + size > el_buf->size)
276 return -1;
277
278 memcpy(el_buf->buf + el_buf->length, buffer, size);
279
280 el_buf->length += size;
281 return 0;
282}
283static int _el_buf_cmp(const void *ap, const void *bp) {
Lev Walkinc2346572004-08-11 09:07:36 +0000284 const struct _el_buffer *a = (const struct _el_buffer *)ap;
285 const struct _el_buffer *b = (const struct _el_buffer *)bp;
Lev Walkinf15320b2004-06-03 03:38:44 +0000286 int ret;
287 size_t common_len;
288
289 if(a->length < b->length)
290 common_len = a->length;
291 else
292 common_len = b->length;
293
294 ret = memcmp(a->buf, b->buf, common_len);
295 if(ret == 0) {
296 if(a->length < b->length)
297 ret = -1;
298 else if(a->length > b->length)
299 ret = 1;
300 }
301
302 return ret;
303}
304
305/*
306 * The DER encoder of the SET OF type.
307 */
Lev Walkina9cc46e2004-09-22 16:06:28 +0000308asn_enc_rval_t
Lev Walkin449f8322004-08-20 13:23:42 +0000309SET_OF_encode_der(asn1_TYPE_descriptor_t *td, void *ptr,
Lev Walkinf15320b2004-06-03 03:38:44 +0000310 int tag_mode, ber_tlv_tag_t tag,
311 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkin449f8322004-08-20 13:23:42 +0000312 asn1_TYPE_member_t *elm = td->elements;
Lev Walkinf15320b2004-06-03 03:38:44 +0000313 asn1_TYPE_descriptor_t *elm_type = elm->type;
314 der_type_encoder_f *der_encoder = elm_type->der_encoder;
Lev Walkinc2346572004-08-11 09:07:36 +0000315 A_SET_OF(void) *list;
Lev Walkinf15320b2004-06-03 03:38:44 +0000316 size_t computed_size = 0;
317 ssize_t encoding_size = 0;
318 struct _el_buffer *encoded_els;
319 size_t max_encoded_len = 1;
Lev Walkina9cc46e2004-09-22 16:06:28 +0000320 asn_enc_rval_t erval;
Lev Walkinf15320b2004-06-03 03:38:44 +0000321 int ret;
322 int edx;
323
Lev Walkin449f8322004-08-20 13:23:42 +0000324 ASN_DEBUG("Estimating size for SET OF %s", td->name);
Lev Walkinf15320b2004-06-03 03:38:44 +0000325
326 /*
327 * Gather the length of the underlying members sequence.
328 */
Lev Walkinc2346572004-08-11 09:07:36 +0000329 (void *)list = ptr;
Lev Walkinf15320b2004-06-03 03:38:44 +0000330 for(edx = 0; edx < list->count; edx++) {
331 void *memb_ptr = list->array[edx];
332 erval = der_encoder(elm_type, memb_ptr, 0, elm->tag, 0, 0);
333 if(erval.encoded == -1)
334 return erval;
335 computed_size += erval.encoded;
336
337 /* Compute maximum encoding's size */
Lev Walkind9bd7752004-06-05 08:17:50 +0000338 if(max_encoded_len < (size_t)erval.encoded)
Lev Walkinf15320b2004-06-03 03:38:44 +0000339 max_encoded_len = erval.encoded;
340 }
341
342 /*
343 * Encode the TLV for the sequence itself.
344 */
Lev Walkin449f8322004-08-20 13:23:42 +0000345 encoding_size = der_write_tags(td, computed_size, tag_mode, tag,
Lev Walkinf15320b2004-06-03 03:38:44 +0000346 cb, app_key);
347 if(encoding_size == -1) {
348 erval.encoded = -1;
Lev Walkin449f8322004-08-20 13:23:42 +0000349 erval.failed_type = td;
Lev Walkinf15320b2004-06-03 03:38:44 +0000350 erval.structure_ptr = ptr;
351 return erval;
352 }
353 computed_size += encoding_size;
354
355 if(!cb) {
356 erval.encoded = computed_size;
357 return erval;
358 }
359
360 /*
361 * DER mandates dynamic sorting of the SET OF elements
362 * according to their encodings. Build an array of the
363 * encoded elements.
364 */
Lev Walkinc2346572004-08-11 09:07:36 +0000365 (void *)encoded_els = MALLOC(list->count * sizeof(encoded_els[0]));
Lev Walkinf15320b2004-06-03 03:38:44 +0000366 if(encoded_els == NULL) {
367 erval.encoded = -1;
Lev Walkin449f8322004-08-20 13:23:42 +0000368 erval.failed_type = td;
Lev Walkinf15320b2004-06-03 03:38:44 +0000369 erval.structure_ptr = ptr;
370 return erval;
371 }
372
Lev Walkin449f8322004-08-20 13:23:42 +0000373 ASN_DEBUG("Encoding members of %s SET OF", td->name);
Lev Walkinf15320b2004-06-03 03:38:44 +0000374
375 /*
376 * Encode all members.
377 */
378 for(edx = 0; edx < list->count; edx++) {
379 void *memb_ptr = list->array[edx];
380 struct _el_buffer *encoded_el = &encoded_els[edx];
381
382 /*
383 * Prepare space for encoding.
384 */
Lev Walkinc2346572004-08-11 09:07:36 +0000385 encoded_el->buf = (uint8_t *)MALLOC(max_encoded_len);
Lev Walkinf15320b2004-06-03 03:38:44 +0000386 if(encoded_el->buf) {
387 encoded_el->length = 0;
388 encoded_el->size = max_encoded_len;
389 } else {
390 for(edx--; edx >= 0; edx--)
391 FREEMEM(encoded_els[edx].buf);
392 FREEMEM(encoded_els);
393 erval.encoded = -1;
Lev Walkin449f8322004-08-20 13:23:42 +0000394 erval.failed_type = td;
Lev Walkinf15320b2004-06-03 03:38:44 +0000395 erval.structure_ptr = ptr;
396 return erval;
397 }
398
399 /*
400 * Encode the member into the prepared space.
401 */
402 erval = der_encoder(elm_type, memb_ptr, 0, elm->tag,
403 _el_addbytes, encoded_el);
404 if(erval.encoded == -1) {
405 for(; edx >= 0; edx--)
406 FREEMEM(encoded_els[edx].buf);
407 FREEMEM(encoded_els);
408 return erval;
409 }
410 encoding_size += erval.encoded;
411 }
412
413 /*
414 * Sort the encoded elements according to their encoding.
415 */
416 qsort(encoded_els, list->count, sizeof(encoded_els[0]), _el_buf_cmp);
417
418 /*
419 * Report encoded elements to the application.
420 * Dispose of temporary sorted members table.
421 */
422 ret = 0;
423 for(edx = 0; edx < list->count; edx++) {
424 struct _el_buffer *encoded_el = &encoded_els[edx];
425 /* Report encoded chunks to the application */
426 if(ret == 0
427 && cb(encoded_el->buf, encoded_el->length, app_key) == -1)
428 ret = -1;
429 FREEMEM(encoded_el->buf);
430 }
431 FREEMEM(encoded_els);
432
Lev Walkind9bd7752004-06-05 08:17:50 +0000433 if(ret || computed_size != (size_t)encoding_size) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000434 /*
435 * Standard callback failed, or
436 * encoded size is not equal to the computed size.
437 */
438 erval.encoded = -1;
Lev Walkin449f8322004-08-20 13:23:42 +0000439 erval.failed_type = td;
Lev Walkinf15320b2004-06-03 03:38:44 +0000440 erval.structure_ptr = ptr;
441 } else {
442 erval.encoded = computed_size;
443 }
444
445 return erval;
446}
447
Lev Walkina9cc46e2004-09-22 16:06:28 +0000448asn_enc_rval_t
449SET_OF_encode_xer(asn1_TYPE_descriptor_t *td, void *sptr,
450 int ilevel, enum xer_encoder_flags_e flags,
451 asn_app_consume_bytes_f *cb, void *app_key) {
452 asn_enc_rval_t er;
453 asn1_SET_OF_specifics_t *specs=(asn1_SET_OF_specifics_t *)td->specifics;
454 asn1_TYPE_member_t *element = td->elements;
455 A_SET_OF(void) *list;
456 const char *mname = specs->as_XMLValueList
457 ? 0 : ((*element->name) ? element->name : element->type->name);
458 size_t mlen = mname ? strlen(mname) : 0;
459 int xcan = (flags & XER_F_CANONICAL);
460 int i;
461
462 if(!sptr) _ASN_ENCODE_FAILED;
463
464 er.encoded = 0;
465
466 (void *)list = sptr;
467 for(i = 0; i < list->count; i++) {
468 asn_enc_rval_t tmper;
469
470 void *memb_ptr = list->array[i];
471 if(!memb_ptr) continue;
472
473 if(mname) {
474 if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel);
475 _ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
476 }
477
478 tmper = element->type->xer_encoder(element->type, memb_ptr,
479 ilevel + 1, flags, cb, app_key);
480 if(tmper.encoded == -1) return tmper;
481
482 if(mname) {
483 _ASN_CALLBACK3("</", 2, mname, mlen, ">", 1);
484 er.encoded += 5;
485 }
486
487 er.encoded += (2 * mlen) + tmper.encoded;
488 }
489
490 if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1);
491
492 return er;
493}
494
Lev Walkinf15320b2004-06-03 03:38:44 +0000495int
496SET_OF_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
497 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkin449f8322004-08-20 13:23:42 +0000498 asn1_TYPE_member_t *element = td->elements;
Lev Walkinc2346572004-08-11 09:07:36 +0000499 const A_SET_OF(void) *list;
Lev Walkinf15320b2004-06-03 03:38:44 +0000500 int ret;
501 int i;
502
503 if(!sptr) return cb("<absent>", 8, app_key);
504
505 /* Dump preamble */
506 if(cb(td->name, strlen(td->name), app_key)
507 || cb(" ::= {\n", 7, app_key))
508 return -1;
509
Lev Walkin8ee15932004-08-11 09:34:42 +0000510 (const void *)list = sptr;
Lev Walkinf15320b2004-06-03 03:38:44 +0000511 for(i = 0; i < list->count; i++) {
512 const void *memb_ptr = list->array[i];
513 if(!memb_ptr) continue;
514
515 /* Indentation */
516 for(ret = 0; ret < ilevel; ret++) cb(" ", 1, app_key);
517
518 ret = element->type->print_struct(element->type, memb_ptr,
519 ilevel + 4, cb, app_key);
520 if(ret) return ret;
521
522 ret = cb("\n", 1, app_key);
523 if(ret) return ret;
524 }
525
526 /* Indentation */
527 for(ret = 0; ret < ilevel - 4; ret++) cb(" ", 1, app_key);
528
529 return cb("}", 1, app_key);
530}
531
532void
533SET_OF_free(asn1_TYPE_descriptor_t *td, void *ptr, int contents_only) {
534 if(td && ptr) {
Lev Walkin449f8322004-08-20 13:23:42 +0000535 asn1_TYPE_member_t *element = td->elements;
Lev Walkinc2346572004-08-11 09:07:36 +0000536 A_SET_OF(void) *list;
Lev Walkinf15320b2004-06-03 03:38:44 +0000537 int i;
538
539 /*
540 * Could not use set_of_empty() because of (*free)
541 * incompatibility.
542 */
Lev Walkinc2346572004-08-11 09:07:36 +0000543 (void *)list = ptr;
Lev Walkinf15320b2004-06-03 03:38:44 +0000544 for(i = 0; i < list->count; i++) {
545 void *memb_ptr = list->array[i];
546 if(memb_ptr)
547 element->type->free_struct(element->type, memb_ptr, 0);
548 }
Lev Walkin246a2af2004-07-15 10:51:26 +0000549 list->count = 0; /* No meaningful elements left */
550
551 asn_set_empty(list); /* Remove (list->array) */
Lev Walkinf15320b2004-06-03 03:38:44 +0000552
553 if(!contents_only) {
554 FREEMEM(ptr);
555 }
556 }
557}
558
559int
560SET_OF_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
561 asn_app_consume_bytes_f *app_errlog, void *app_key) {
Lev Walkin449f8322004-08-20 13:23:42 +0000562 asn1_TYPE_member_t *element = td->elements;
563 asn_constr_check_f *constr;
Lev Walkinc2346572004-08-11 09:07:36 +0000564 const A_SET_OF(void) *list;
Lev Walkinf15320b2004-06-03 03:38:44 +0000565 int i;
566
567 if(!sptr) {
Lev Walkinba4e5182004-08-11 09:44:13 +0000568 _ASN_ERRLOG(app_errlog, app_key,
Lev Walkin16835b62004-08-22 13:47:59 +0000569 "%s: value not given (%s:%d)",
570 td->name, __FILE__, __LINE__);
Lev Walkinf15320b2004-06-03 03:38:44 +0000571 return -1;
572 }
573
Lev Walkin8ee15932004-08-11 09:34:42 +0000574 (const void *)list = sptr;
Lev Walkin449f8322004-08-20 13:23:42 +0000575
576 constr = element->memb_constraints;
577 if(!constr) constr = element->type->check_constraints;
578
579 /*
580 * Iterate over the members of an array.
581 * Validate each in turn, until one fails.
582 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000583 for(i = 0; i < list->count; i++) {
584 const void *memb_ptr = list->array[i];
Lev Walkin449f8322004-08-20 13:23:42 +0000585 int ret;
586
Lev Walkinf15320b2004-06-03 03:38:44 +0000587 if(!memb_ptr) continue;
Lev Walkin449f8322004-08-20 13:23:42 +0000588
589 ret = constr(element->type, memb_ptr, app_errlog, app_key);
590 if(ret) return ret;
Lev Walkinf15320b2004-06-03 03:38:44 +0000591 }
592
Lev Walkin449f8322004-08-20 13:23:42 +0000593 /*
594 * Cannot inherit it eralier:
595 * need to make sure we get the updated version.
596 */
597 if(!element->memb_constraints)
598 element->memb_constraints = element->type->check_constraints;
599
Lev Walkinf15320b2004-06-03 03:38:44 +0000600 return 0;
601}