blob: aefaefdb718a315c68ec88f0ebcc49a4912d8b77 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkina9cc46e2004-09-22 16:06:28 +00005#include <asn_internal.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00006#include <constr_TYPE.h>
7#include <errno.h>
8
Lev Walkina9cc46e2004-09-22 16:06:28 +00009/*
10 * Version of the ASN.1 infrastructure shipped with compiler.
11 */
12int get_asn1c_environment_version() { return ASN1C_ENVIRONMENT_VERSION; }
13
Lev Walkinf15320b2004-06-03 03:38:44 +000014static asn_app_consume_bytes_f _print2fp;
15
16/*
17 * Return the outmost tag of the type.
18 */
19ber_tlv_tag_t
Wim Lewis14e6b162014-07-23 16:06:01 -070020asn_TYPE_outmost_tag(const asn_TYPE_descriptor_t *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000021 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag) {
22
23 if(tag_mode)
24 return tag;
25
26 if(type_descriptor->tags_count)
27 return type_descriptor->tags[0];
28
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080029 return type_descriptor->op->outmost_tag(type_descriptor, struct_ptr, 0, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000030}
31
32/*
33 * Print the target language's structure in human readable form.
34 */
35int
Lev Walkincf573ec2017-11-07 04:20:52 -080036asn_fprint(FILE *stream, const asn_TYPE_descriptor_t *td,
37 const void *struct_ptr) {
38 if(!stream) stream = stdout;
39 if(!td || !struct_ptr) {
40 errno = EINVAL;
41 return -1;
Lev Walkinf15320b2004-06-03 03:38:44 +000042 }
43
44 /* Invoke type-specific printer */
Lev Walkincf573ec2017-11-07 04:20:52 -080045 if(td->op->print_struct(td, struct_ptr, 1, _print2fp, stream)) {
46 return -1;
47 }
Lev Walkinf15320b2004-06-03 03:38:44 +000048
Lev Walkincf573ec2017-11-07 04:20:52 -080049 /* Terminate the output */
50 if(_print2fp("\n", 1, stream)) {
51 return -1;
52 }
Lev Walkinf15320b2004-06-03 03:38:44 +000053
Lev Walkincf573ec2017-11-07 04:20:52 -080054 return fflush(stream);
Lev Walkinf15320b2004-06-03 03:38:44 +000055}
56
57/* Dump the data into the specified stdio stream */
58static int
59_print2fp(const void *buffer, size_t size, void *app_key) {
Lev Walkinc2346572004-08-11 09:07:36 +000060 FILE *stream = (FILE *)app_key;
Lev Walkinf15320b2004-06-03 03:38:44 +000061
62 if(fwrite(buffer, 1, size, stream) != size)
63 return -1;
64
65 return 0;
66}
67
Lev Walkin7a5e3022004-08-11 08:32:04 +000068
69/*
70 * Some compilers do not support variable args macros.
71 * This function is a replacement of ASN_DEBUG() macro.
72 */
Lev Walkineb1b9ba2004-08-11 11:51:15 +000073void ASN_DEBUG_f(const char *fmt, ...);
Lev Walkin7a5e3022004-08-11 08:32:04 +000074void ASN_DEBUG_f(const char *fmt, ...) {
75 va_list ap;
76 va_start(ap, fmt);
77 vfprintf(stderr, fmt, ap);
78 fprintf(stderr, "\n");
79 va_end(ap);
80}