blob: d8434e4eaf94ff20efcdb7e0d1b77abf4ba99463 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
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 Walkindc06f6b2004-10-20 15:50:55 +00008#include <asn_system.h> /* Platform-dependent types */
Lev Walkinf15320b2004-06-03 03:38:44 +00009
Lev Walkin5e033762004-09-29 13:26:15 +000010struct asn_TYPE_descriptor_s; /* Forward declaration */
Lev Walkinf15320b2004-06-03 03:38:44 +000011
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 */
20int
Lev Walkin5e033762004-09-29 13:26:15 +000021asn_check_constraints(struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000022 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 */
31typedef int (asn_constr_check_f)(
Lev Walkin5e033762004-09-29 13:26:15 +000032 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000033 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
42asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */
43asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */
44
45/*
46 * Invoke the callback with a complete error message.
47 */
Lev Walkin8e8078a2004-09-26 13:10:40 +000048/* Preprocessor may not support variable args macros, so act strangely */
Lev Walkinf2de1712004-08-11 09:25:09 +000049#define _ASN_ERRLOG if(app_errlog) _asn_i_log_error
Lev Walkinf2de1712004-08-11 09:25:09 +000050
Lev Walkin8e8078a2004-09-26 13:10:40 +000051void _asn_i_log_error(asn_app_consume_bytes_f *, void *key,
Lev Walkinf15320b2004-06-03 03:38:44 +000052 const char *fmt, ...) __attribute__ ((format(printf, 3, 4)));
53
54#endif /* _ASN1_CONSTRAINTS_VALIDATOR_H_ */