1 #include <asn_internal.h>
\r
2 #include <constraints.h>
\r
5 asn_generic_no_constraint(const asn_TYPE_descriptor_t *type_descriptor,
\r
6 const void *struct_ptr,
\r
7 asn_app_constraint_failed_f *cb, void *key) {
\r
8 (void)type_descriptor; /* Unused argument */
\r
9 (void)struct_ptr; /* Unused argument */
\r
10 (void)cb; /* Unused argument */
\r
11 (void)key; /* Unused argument */
\r
13 /* Nothing to check */
\r
18 asn_generic_unknown_constraint(const asn_TYPE_descriptor_t *type_descriptor,
\r
19 const void *struct_ptr,
\r
20 asn_app_constraint_failed_f *cb, void *key) {
\r
21 (void)type_descriptor; /* Unused argument */
\r
22 (void)struct_ptr; /* Unused argument */
\r
23 (void)cb; /* Unused argument */
\r
24 (void)key; /* Unused argument */
\r
26 /* Unknown how to check */
\r
31 const asn_TYPE_descriptor_t *failed_type;
\r
32 const void *failed_struct_ptr;
\r
38 _asn_i_ctfailcb(void *key, const asn_TYPE_descriptor_t *td, const void *sptr,
\r
39 const char *fmt, ...) {
\r
40 struct errbufDesc *arg = key;
\r
45 arg->failed_type = td;
\r
46 arg->failed_struct_ptr = sptr;
\r
48 maxlen = arg->errlen;
\r
53 vlen = vsnprintf(arg->errbuf, maxlen, fmt, ap);
\r
55 if(vlen >= maxlen) {
\r
56 arg->errbuf[maxlen-1] = '\0'; /* Ensuring libc correctness */
\r
57 arg->errlen = maxlen - 1; /* Not counting termination */
\r
59 } else if(vlen >= 0) {
\r
60 arg->errbuf[vlen] = '\0'; /* Ensuring libc correctness */
\r
61 arg->errlen = vlen; /* Not counting termination */
\r
64 * The libc on this system is broken.
\r
66 vlen = sizeof("<broken vsnprintf>") - 1;
\r
68 arg->errlen = vlen < maxlen ? vlen : maxlen;
\r
69 memcpy(arg->errbuf, "<broken vsnprintf>", arg->errlen);
\r
70 arg->errbuf[arg->errlen] = 0;
\r
77 asn_check_constraints(const asn_TYPE_descriptor_t *type_descriptor,
\r
78 const void *struct_ptr, char *errbuf, size_t *errlen) {
\r
79 struct errbufDesc arg;
\r
82 arg.failed_type = 0;
\r
83 arg.failed_struct_ptr = 0;
\r
84 arg.errbuf = errbuf;
\r
85 arg.errlen = errlen ? *errlen : 0;
\r
87 ret = type_descriptor->encoding_constraints.general_constraints(
\r
88 type_descriptor, struct_ptr, _asn_i_ctfailcb, &arg);
\r
89 if(ret == -1 && errlen) *errlen = arg.errlen;
\r