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