blob: dfc0759f7510a768114282d9479b24af3af5ca27 [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
8#include <asn_types.h> /* System-dependent types */
9
10struct asn1_TYPE_descriptor_s; /* Forward declaration */
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 */
20int
21asn_check_constraints(struct asn1_TYPE_descriptor_s *type_descriptor,
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 */
31typedef int (asn_constr_check_f)(
32 struct asn1_TYPE_descriptor_s *type_descriptor,
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
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 Walkinf2de1712004-08-11 09:25:09 +000048#ifdef __GNUC__
Lev Walkinba4e5182004-08-11 09:44:13 +000049#define _ASN_ERRLOG(app_errlog, app_key, fmt, args...) do { \
50 if(app_errlog) \
51 _asn_i_log_error(app_errlog, \
52 app_key, fmt, ##args); \
Lev Walkinf2de1712004-08-11 09:25:09 +000053} while(0);
54#else /* Preprocessor does not support variable args macros */
55#define _ASN_ERRLOG if(app_errlog) _asn_i_log_error
56#endif
57
58extern void _asn_i_log_error(asn_app_consume_bytes_f *, void *key,
Lev Walkinf15320b2004-06-03 03:38:44 +000059 const char *fmt, ...) __attribute__ ((format(printf, 3, 4)));
60
61#endif /* _ASN1_CONSTRAINTS_VALIDATOR_H_ */