vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
vlm | af68ef5 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2004, 2006 Lev Walkin <vlm@lionet.info>. All rights reserved. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #ifndef _ASN1_CONSTRAINTS_VALIDATOR_H_ |
| 6 | #define _ASN1_CONSTRAINTS_VALIDATOR_H_ |
| 7 | |
vlm | 9de248e | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 8 | #include <asn_system.h> /* Platform-dependent types */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
vlm | fa67ddc | 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). |
vlm | af68ef5 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 23 | * |
| 24 | * RETURN VALUES: |
| 25 | * This function returns 0 in case all ASN.1 constraints are met |
| 26 | * and -1 if one or more constraints were failed. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 27 | */ |
| 28 | int |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 29 | asn_check_constraints(struct asn_TYPE_descriptor_s *type_descriptor, |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 30 | const void *struct_ptr, /* Target language's structure */ |
| 31 | char *errbuf, /* Returned error description */ |
| 32 | size_t *errlen /* Length of the error description */ |
| 33 | ); |
| 34 | |
vlm | af68ef5 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 35 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 36 | /* |
| 37 | * Generic type for constraint checking callback, |
| 38 | * associated with every type descriptor. |
| 39 | */ |
| 40 | typedef int (asn_constr_check_f)( |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 41 | struct asn_TYPE_descriptor_s *type_descriptor, |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 42 | const void *struct_ptr, |
vlm | af68ef5 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 43 | asn_app_constraint_failed_f *optional_callback, /* Log the error */ |
| 44 | void *optional_app_key /* Opaque key passed to a callback */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 45 | ); |
| 46 | |
| 47 | /******************************* |
| 48 | * INTERNALLY USEFUL FUNCTIONS * |
| 49 | *******************************/ |
| 50 | |
| 51 | asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */ |
| 52 | asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */ |
| 53 | |
| 54 | /* |
| 55 | * Invoke the callback with a complete error message. |
| 56 | */ |
vlm | af68ef5 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 57 | #define _ASN_CTFAIL if(ctfailcb) ctfailcb |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 58 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 59 | #ifdef __cplusplus |
| 60 | } |
| 61 | #endif |
| 62 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 63 | #endif /* _ASN1_CONSTRAINTS_VALIDATOR_H_ */ |