Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #ifndef _ASN1_CONSTRAINTS_VALIDATOR_H_ |
| 6 | #define _ASN1_CONSTRAINTS_VALIDATOR_H_ |
| 7 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 8 | #include <asn_system.h> /* Platform-dependent types */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 10 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | * Validate the structure according to the ASN.1 constraints. |
| 14 | * If errbuf and errlen are given, they shall be pointing to the appropriate |
| 15 | * buffer space and its length before calling this function. Alternatively, |
| 16 | * they could be passed as NULL's. If constraints validation fails, |
| 17 | * errlen will contain the actual number of bytes taken from the errbuf |
| 18 | * to encode an error message (properly 0-terminated). |
| 19 | */ |
| 20 | int |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 21 | asn_check_constraints(struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 22 | const void *struct_ptr, /* Target language's structure */ |
| 23 | char *errbuf, /* Returned error description */ |
| 24 | size_t *errlen /* Length of the error description */ |
| 25 | ); |
| 26 | |
| 27 | /* |
| 28 | * Generic type for constraint checking callback, |
| 29 | * associated with every type descriptor. |
| 30 | */ |
| 31 | typedef int (asn_constr_check_f)( |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 32 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | const void *struct_ptr, |
| 34 | asn_app_consume_bytes_f *optional_app_errlog, /* Log the error */ |
| 35 | void *optional_app_key /* Opaque key passed to app_errlog */ |
| 36 | ); |
| 37 | |
| 38 | /******************************* |
| 39 | * INTERNALLY USEFUL FUNCTIONS * |
| 40 | *******************************/ |
| 41 | |
| 42 | asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */ |
| 43 | asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */ |
| 44 | |
| 45 | /* |
| 46 | * Invoke the callback with a complete error message. |
| 47 | */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 48 | /* Preprocessor may not support variable args macros, so act strangely */ |
Lev Walkin | f2de171 | 2004-08-11 09:25:09 +0000 | [diff] [blame] | 49 | #define _ASN_ERRLOG if(app_errlog) _asn_i_log_error |
Lev Walkin | f2de171 | 2004-08-11 09:25:09 +0000 | [diff] [blame] | 50 | |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 51 | void _asn_i_log_error(asn_app_consume_bytes_f *, void *key, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 52 | const char *fmt, ...) __attribute__ ((format(printf, 3, 4))); |
| 53 | |
| 54 | #endif /* _ASN1_CONSTRAINTS_VALIDATOR_H_ */ |