2 * Copyright 2019 AT&T Intellectual Property
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
24 #include <asn_internal.h>
25 #include <constraints.h>
28 asn_generic_no_constraint(const asn_TYPE_descriptor_t *type_descriptor,
29 const void *struct_ptr,
30 asn_app_constraint_failed_f *cb, void *key) {
31 (void)type_descriptor; /* Unused argument */
32 (void)struct_ptr; /* Unused argument */
33 (void)cb; /* Unused argument */
34 (void)key; /* Unused argument */
36 /* Nothing to check */
41 asn_generic_unknown_constraint(const asn_TYPE_descriptor_t *type_descriptor,
42 const void *struct_ptr,
43 asn_app_constraint_failed_f *cb, void *key) {
44 (void)type_descriptor; /* Unused argument */
45 (void)struct_ptr; /* Unused argument */
46 (void)cb; /* Unused argument */
47 (void)key; /* Unused argument */
49 /* Unknown how to check */
54 const asn_TYPE_descriptor_t *failed_type;
55 const void *failed_struct_ptr;
61 _asn_i_ctfailcb(void *key, const asn_TYPE_descriptor_t *td, const void *sptr,
62 const char *fmt, ...) {
63 struct errbufDesc *arg = key;
68 arg->failed_type = td;
69 arg->failed_struct_ptr = sptr;
76 vlen = vsnprintf(arg->errbuf, maxlen, fmt, ap);
79 arg->errbuf[maxlen-1] = '\0'; /* Ensuring libc correctness */
80 arg->errlen = maxlen - 1; /* Not counting termination */
82 } else if(vlen >= 0) {
83 arg->errbuf[vlen] = '\0'; /* Ensuring libc correctness */
84 arg->errlen = vlen; /* Not counting termination */
87 * The libc on this system is broken.
89 vlen = sizeof("<broken vsnprintf>") - 1;
91 arg->errlen = vlen < maxlen ? vlen : maxlen;
92 memcpy(arg->errbuf, "<broken vsnprintf>", arg->errlen);
93 arg->errbuf[arg->errlen] = 0;
100 asn_check_constraints(const asn_TYPE_descriptor_t *type_descriptor,
101 const void *struct_ptr, char *errbuf, size_t *errlen) {
102 struct errbufDesc arg;
106 arg.failed_struct_ptr = 0;
108 arg.errlen = errlen ? *errlen : 0;
110 ret = type_descriptor->encoding_constraints.general_constraints(
111 type_descriptor, struct_ptr, _asn_i_ctfailcb, &arg);
112 if(ret == -1 && errlen) *errlen = arg.errlen;