Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
3be4919d
Commit
3be4919d
authored
Nov 11, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make -pdu=auto a default
parent
5f4dbb75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
36 deletions
+75
-36
libasn1compiler/asn1c_save.c
libasn1compiler/asn1c_save.c
+20
-3
skeletons/converter-example.c
skeletons/converter-example.c
+55
-33
No files found.
libasn1compiler/asn1c_save.c
View file @
3be4919d
...
@@ -617,12 +617,16 @@ generate_pdu_collection(arg_t *arg) {
...
@@ -617,12 +617,16 @@ generate_pdu_collection(arg_t *arg) {
abuf_printf
(
buf
,
"/*
\n
* Generated by asn1c-"
VERSION
abuf_printf
(
buf
,
"/*
\n
* Generated by asn1c-"
VERSION
" (http://lionet.info/asn1c)
\n
*/
\n\n
"
);
" (http://lionet.info/asn1c)
\n
*/
\n\n
"
);
abuf_printf
(
buf
,
"struct asn_TYPE_descriptor_s;
\t
"
"/* Forward declaration */
\n\n
"
);
TQ_FOR
(
mod
,
&
(
arg
->
asn
->
modules
),
mod_next
)
{
TQ_FOR
(
mod
,
&
(
arg
->
asn
->
modules
),
mod_next
)
{
TQ_FOR
(
arg
->
expr
,
&
(
mod
->
members
),
next
)
{
TQ_FOR
(
arg
->
expr
,
&
(
mod
->
members
),
next
)
{
if
(
include_type_to_pdu_collection
(
arg
)
==
TI_NOT_INCLUDED
)
continue
;
if
(
include_type_to_pdu_collection
(
arg
)
==
TI_NOT_INCLUDED
)
continue
;
abuf_printf
(
buf
,
abuf_printf
(
buf
,
"extern
asn_TYPE_descriptor_t
"
"extern
struct asn_TYPE_descriptor_s
"
"asn_DEF_%s;
\n
"
,
"asn_DEF_%s;
\n
"
,
asn1c_make_identifier
(
0
,
arg
->
expr
,
NULL
));
asn1c_make_identifier
(
0
,
arg
->
expr
,
NULL
));
}
}
...
@@ -724,10 +728,19 @@ asn1c__pdu_type_lookup(const char *typename) {
...
@@ -724,10 +728,19 @@ asn1c__pdu_type_lookup(const char *typename) {
static
int
static
int
need_to_generate_pdu_collection
(
arg_t
*
arg
)
{
need_to_generate_pdu_collection
(
arg_t
*
arg
)
{
/* If -pdu=all or -pdu=auto are given, we need to generate one. */
if
(
arg
->
flags
&
(
A1C_PDU_ALL
|
A1C_PDU_AUTO
))
if
(
arg
->
flags
&
(
A1C_PDU_ALL
|
A1C_PDU_AUTO
))
return
1
;
return
1
;
if
(
arg
->
flags
&
A1C_PDU_TYPE
)
return
(
pduTypes
>
1
)
?
1
:
0
;
/*
* If no -pdu=... flags were given, need to do it, too,
* effectively producing -pdu=auto.
*/
if
(
!
(
arg
->
flags
&
(
A1C_PDU_ALL
|
A1C_PDU_AUTO
|
A1C_PDU_TYPE
)))
return
1
;
if
(
arg
->
flags
&
A1C_PDU_TYPE
)
{
return
(
pduTypes
>
1
)
?
1
:
0
;
}
return
0
;
return
0
;
}
}
...
@@ -757,7 +770,11 @@ include_type_to_pdu_collection(arg_t *arg) {
...
@@ -757,7 +770,11 @@ include_type_to_pdu_collection(arg_t *arg) {
}
}
if
((
arg
->
flags
&
A1C_PDU_ALL
)
if
((
arg
->
flags
&
A1C_PDU_ALL
)
/* -pdu=auto */
||
((
arg
->
flags
&
A1C_PDU_AUTO
)
&&
!
arg
->
expr
->
_type_referenced
)
||
((
arg
->
flags
&
A1C_PDU_AUTO
)
&&
!
arg
->
expr
->
_type_referenced
)
/* No -pdu=... whatsoever, act as if -pdu=auto */
||
(
!
(
arg
->
flags
&
(
A1C_PDU_ALL
|
A1C_PDU_AUTO
|
A1C_PDU_TYPE
))
&&
!
arg
->
expr
->
_type_referenced
)
||
asn1c__pdu_type_lookup
(
arg
->
expr
->
Identifier
))
{
||
asn1c__pdu_type_lookup
(
arg
->
expr
->
Identifier
))
{
return
1
;
return
1
;
}
}
...
...
skeletons/converter-example.c
View file @
3be4919d
...
@@ -23,24 +23,26 @@
...
@@ -23,24 +23,26 @@
#include <asn_internal.h>
/* for ASN__DEFAULT_STACK_MAX */
#include <asn_internal.h>
/* for ASN__DEFAULT_STACK_MAX */
/* Convert "Type" defined by -DPDU into "asn_DEF_Type" */
/* Convert "Type" defined by -DPDU into "asn_DEF_Type" */
#ifdef PDU
#ifndef NO_ASN_PDU
#ifndef PDU
#error Define -DPDU to compile this sample converter.
#error `asn1c -pdu=...` adds it automatically.
#endif
#ifdef ASN_PDU_COLLECTION
/* Generated by asn1c: -pdu=... */
extern
asn_TYPE_descriptor_t
*
asn_pdu_collection
[];
#endif
#define ASN_DEF_PDU(t) asn_DEF_ ## t
#define ASN_DEF_PDU(t) asn_DEF_ ## t
#define DEF_PDU_Type(t) ASN_DEF_PDU(t)
#define DEF_PDU_Type(t) ASN_DEF_PDU(t)
#define PDU_Type DEF_PDU_Type(PDU)
#define PDU_Type DEF_PDU_Type(PDU)
extern
asn_TYPE_descriptor_t
PDU_Type
;
/* ASN.1 type to be decoded */
extern
asn_TYPE_descriptor_t
PDU_Type
;
/* ASN.1 type to be decoded */
#define PDU_Type_Ptr (&PDU_Type)
#define PDU_Type_Ptr (&PDU_Type)
#else
/*
NO_ASN_
PDU */
#else
/*
!
PDU */
#define PDU_Type_Ptr NULL
#define PDU_Type_Ptr NULL
#endif
/* NO_ASN_PDU */
#endif
/* PDU */
#ifdef ASN_PDU_COLLECTION
/* Generated by asn1c -pdu=... */
extern
asn_TYPE_descriptor_t
*
asn_pdu_collection
[];
#endif
#ifndef NO_ASN_PDU
#if !defined(PDU) && !defined(ASN_PDU_COLLECTION)
#error Define -DPDU to compile this example converter.
#error `asn1c -pdu=...` adds necessary flags automatically.
#endif
#endif
/*
/*
* Open file and parse its contens.
* Open file and parse its contens.
...
@@ -190,7 +192,8 @@ ats_by_name(const char *name, const asn_TYPE_descriptor_t *td,
...
@@ -190,7 +192,8 @@ ats_by_name(const char *name, const asn_TYPE_descriptor_t *td,
int
int
main
(
int
ac
,
char
*
av
[])
{
main
(
int
ac
,
char
*
av
[])
{
FILE
*
binary_out
;
FILE
*
binary_out
;
static
asn_TYPE_descriptor_t
*
pduType
=
PDU_Type_Ptr
;
asn_TYPE_descriptor_t
*
pduType
=
PDU_Type_Ptr
;
asn_TYPE_descriptor_t
*
anyPduType
=
PDU_Type_Ptr
;
ssize_t
suggested_bufsize
=
8192
;
/* close or equal to stdio buffer */
ssize_t
suggested_bufsize
=
8192
;
/* close or equal to stdio buffer */
int
number_of_iterations
=
1
;
int
number_of_iterations
=
1
;
int
num
;
int
num
;
...
@@ -199,22 +202,27 @@ main(int ac, char *av[]) {
...
@@ -199,22 +202,27 @@ main(int ac, char *av[]) {
enum
asn_transfer_syntax
isyntax
=
ATS_INVALID
;
enum
asn_transfer_syntax
isyntax
=
ATS_INVALID
;
enum
asn_transfer_syntax
osyntax
=
ATS_BASIC_XER
;
enum
asn_transfer_syntax
osyntax
=
ATS_BASIC_XER
;
#ifndef PDU
if
(
!
anyPduType
)
{
if
(
!
pduType
)
{
#ifdef ASN_PDU_COLLECTION
fprintf
(
stderr
,
"No -DPDU defined during compilation.
\n
"
);
anyPduType
=
asn_pdu_collection
[
0
];
#ifdef NO_ASN_PDU
if
(
!
anyPduType
)
{
exit
(
0
);
fprintf
(
stderr
,
"Empty PDU collection, no reference PDU to choose from.
\n
"
);
exit
(
EX_SOFTWARE
);
}
#else
#else
fprintf
(
stderr
,
"Either asn1c -pdu=... or cc -DPDU should be used.
\n
"
);
exit
(
EX_SOFTWARE
);
exit
(
EX_SOFTWARE
);
#endif
#endif
}
}
#endif
/* Figure out if specialty decoder needs to be default */
/* Figure out if a specialty decoder needs to be default */
if
(
ats_by_name
(
"oer"
,
pduType
,
input_encodings
))
#ifndef ASN_DISABLE_OER_SUPPORT
isyntax
=
ATS_BASIC_OER
;
isyntax
=
ATS_BASIC_OER
;
if
(
ats_by_name
(
"per"
,
pduType
,
input_encodings
))
#endif
isyntax
=
ATS_UNALIGNED_BASIC_PER
;
#ifndef ASN_DISABLE_PER_SUPPORT
isyntax
=
ATS_UNALIGNED_BASIC_PER
;
#endif
/*
/*
* Pocess the command-line argments.
* Pocess the command-line argments.
...
@@ -222,7 +230,7 @@ main(int ac, char *av[]) {
...
@@ -222,7 +230,7 @@ main(int ac, char *av[]) {
while
((
ch
=
getopt
(
ac
,
av
,
"i:o:1b:cdn:p:hs:"
JUNKOPT
RANDOPT
))
!=
-
1
)
while
((
ch
=
getopt
(
ac
,
av
,
"i:o:1b:cdn:p:hs:"
JUNKOPT
RANDOPT
))
!=
-
1
)
switch
(
ch
)
{
switch
(
ch
)
{
case
'i'
:
case
'i'
:
sel
=
ats_by_name
(
optarg
,
p
duType
,
input_encodings
);
sel
=
ats_by_name
(
optarg
,
anyP
duType
,
input_encodings
);
if
(
sel
)
{
if
(
sel
)
{
isyntax
=
sel
->
syntax
;
isyntax
=
sel
->
syntax
;
}
else
{
}
else
{
...
@@ -232,7 +240,7 @@ main(int ac, char *av[]) {
...
@@ -232,7 +240,7 @@ main(int ac, char *av[]) {
}
}
break
;
break
;
case
'o'
:
case
'o'
:
sel
=
ats_by_name
(
optarg
,
p
duType
,
output_encodings
);
sel
=
ats_by_name
(
optarg
,
anyP
duType
,
output_encodings
);
if
(
sel
)
{
if
(
sel
)
{
osyntax
=
sel
->
syntax
;
osyntax
=
sel
->
syntax
;
}
else
{
}
else
{
...
@@ -283,19 +291,23 @@ main(int ac, char *av[]) {
...
@@ -283,19 +291,23 @@ main(int ac, char *av[]) {
asn_TYPE_descriptor_t
**
pdu
=
asn_pdu_collection
;
asn_TYPE_descriptor_t
**
pdu
=
asn_pdu_collection
;
while
(
*
pdu
&&
strcmp
((
*
pdu
)
->
name
,
optarg
))
pdu
++
;
while
(
*
pdu
&&
strcmp
((
*
pdu
)
->
name
,
optarg
))
pdu
++
;
if
(
*
pdu
)
{
pduType
=
*
pdu
;
break
;
}
if
(
*
pdu
)
{
pduType
=
*
pdu
;
break
;
}
fprintf
(
stderr
,
"-p %s: Unrecognized PDU
\n
"
,
optarg
);
fprintf
(
stderr
,
"-p %s: Unrecognized PDU. Try '-p list'.
\n
"
,
optarg
);
exit
(
EX_USAGE
);
exit
(
EX_USAGE
);
}
}
#else
/* Without -pdu=auto there's just a single type */
#else
/* Without -pdu=auto there's just a single type */
if
(
strcmp
(
optarg
,
"list"
)
==
0
)
{
if
(
strcmp
(
optarg
,
"list"
)
==
0
)
{
fprintf
(
stderr
,
"Available PDU types:
\n
"
);
fprintf
(
stderr
,
"Available PDU types:
\n
"
);
printf
(
"%s
\n
"
,
pduType
->
name
);
if
(
pduType
)
{
printf
(
"%s
\n
"
,
pduType
->
name
);
}
exit
(
0
);
exit
(
0
);
}
else
if
(
optarg
[
0
]
>=
'A'
&&
optarg
[
0
]
<=
'Z'
)
{
}
else
if
(
optarg
[
0
]
>=
'A'
&&
optarg
[
0
]
<=
'Z'
)
{
if
(
strcmp
(
optarg
,
pduType
->
name
)
==
0
)
{
if
(
pduType
&&
strcmp
(
optarg
,
pduType
->
name
)
==
0
)
{
break
;
break
;
}
}
fprintf
(
stderr
,
"-p %s: Unrecognized PDU
\n
"
,
optarg
);
fprintf
(
stderr
,
"-p %s: Unrecognized PDU. Try '-p list'.
\n
"
,
optarg
);
exit
(
EX_USAGE
);
exit
(
EX_USAGE
);
}
}
#endif
/* ASN_PDU_COLLECTION */
#endif
/* ASN_PDU_COLLECTION */
...
@@ -342,21 +354,21 @@ main(int ac, char *av[]) {
...
@@ -342,21 +354,21 @@ main(int ac, char *av[]) {
fprintf
(
stderr
,
"Usage: %s [options] <datafile> ...
\n
"
,
av
[
0
]);
fprintf
(
stderr
,
"Usage: %s [options] <datafile> ...
\n
"
,
av
[
0
]);
fprintf
(
stderr
,
"Where options are:
\n
"
);
fprintf
(
stderr
,
"Where options are:
\n
"
);
for
(
sel
=
input_encodings
;
sel
->
name
;
sel
++
)
{
for
(
sel
=
input_encodings
;
sel
->
name
;
sel
++
)
{
if
(
ats_by_name
(
sel
->
name
,
p
duType
,
sel
))
{
if
(
ats_by_name
(
sel
->
name
,
anyP
duType
,
sel
))
{
fprintf
(
stderr
,
" -i%s %s%s
\n
"
,
sel
->
name
,
fprintf
(
stderr
,
" -i%s %s%s
\n
"
,
sel
->
name
,
sel
->
full_name
,
sel
->
full_name
,
(
sel
->
syntax
==
isyntax
)
?
" (DEFAULT)"
:
""
);
(
sel
->
syntax
==
isyntax
)
?
" (DEFAULT)"
:
""
);
}
}
}
}
for
(
sel
=
output_encodings
;
sel
->
name
;
sel
++
)
{
for
(
sel
=
output_encodings
;
sel
->
name
;
sel
++
)
{
if
(
ats_by_name
(
sel
->
name
,
p
duType
,
sel
))
{
if
(
ats_by_name
(
sel
->
name
,
anyP
duType
,
sel
))
{
fprintf
(
stderr
,
" -o%s%s %s%s
\n
"
,
sel
->
name
,
fprintf
(
stderr
,
" -o%s%s %s%s
\n
"
,
sel
->
name
,
strlen
(
sel
->
name
)
>
3
?
""
:
" "
,
strlen
(
sel
->
name
)
>
3
?
""
:
" "
,
sel
->
full_name
,
sel
->
full_name
,
(
sel
->
syntax
==
osyntax
)
?
" (DEFAULT)"
:
""
);
(
sel
->
syntax
==
osyntax
)
?
" (DEFAULT)"
:
""
);
}
}
}
}
if
(
p
duType
->
op
->
uper_decoder
)
{
if
(
anyP
duType
->
op
->
uper_decoder
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
" -per-nopad Assume PER PDUs are not padded (-iper)
\n
"
);
" -per-nopad Assume PER PDUs are not padded (-iper)
\n
"
);
}
}
...
@@ -384,6 +396,16 @@ main(int ac, char *av[]) {
...
@@ -384,6 +396,16 @@ main(int ac, char *av[]) {
ac
-=
optind
;
ac
-=
optind
;
av
+=
optind
;
av
+=
optind
;
if
(
!
pduType
)
{
#ifdef NO_ASN_PDU
fprintf
(
stderr
,
"No -DPDU defined during compilation.
\n
"
);
exit
(
0
);
#else
fprintf
(
stderr
,
"Use '-p <Type>' or '-p list' to select ASN.1 type.
\n
"
);
exit
(
EX_USAGE
);
#endif
/* NO_ASN_PDU */
}
if
(
ac
<
1
&&
isyntax
!=
ATS_RANDOM
)
{
if
(
ac
<
1
&&
isyntax
!=
ATS_RANDOM
)
{
fprintf
(
stderr
,
"%s: No input files specified. "
fprintf
(
stderr
,
"%s: No input files specified. "
"Try '-h' for more information
\n
"
,
"Try '-h' for more information
\n
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment