blob: 51fad8ed5f10e8f7d790b1472e87e4148e3f87ae [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 Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkin5e033762004-09-29 13:26:15 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
Lev Walkinf15320b2004-06-03 03:38:44 +000015
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 */
24int
Lev Walkin5e033762004-09-29 13:26:15 +000025asn_check_constraints(struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000026 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 */
35typedef int (asn_constr_check_f)(
Lev Walkin5e033762004-09-29 13:26:15 +000036 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000037 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
46asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */
47asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */
48
49/*
50 * Invoke the callback with a complete error message.
51 */
Lev Walkin8e8078a2004-09-26 13:10:40 +000052/* Preprocessor may not support variable args macros, so act strangely */
Lev Walkinf2de1712004-08-11 09:25:09 +000053#define _ASN_ERRLOG if(app_errlog) _asn_i_log_error
Lev Walkinf2de1712004-08-11 09:25:09 +000054
Lev Walkin8e8078a2004-09-26 13:10:40 +000055void _asn_i_log_error(asn_app_consume_bytes_f *, void *key,
Lev Walkinf15320b2004-06-03 03:38:44 +000056 const char *fmt, ...) __attribute__ ((format(printf, 3, 4)));
57
Lev Walkin21b41ac2005-07-24 09:03:44 +000058#ifdef __cplusplus
59}
60#endif
61
Lev Walkinf15320b2004-06-03 03:38:44 +000062#endif /* _ASN1_CONSTRAINTS_VALIDATOR_H_ */