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
4fd7318e
Commit
4fd7318e
authored
Oct 21, 2004
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ber_codec_prim -> asn_codecs_prim
parent
c698ee5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
295 additions
and
0 deletions
+295
-0
skeletons/asn_codecs_prim.c
skeletons/asn_codecs_prim.c
+262
-0
skeletons/asn_codecs_prim.h
skeletons/asn_codecs_prim.h
+33
-0
No files found.
skeletons/
ber_codec
_prim.c
→
skeletons/
asn_codecs
_prim.c
View file @
4fd7318e
...
...
@@ -3,7 +3,7 @@
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
#include <
ber_codec
_prim.h>
#include <
asn_codecs
_prim.h>
#include <assert.h>
#include <errno.h>
...
...
@@ -131,3 +131,132 @@ ASN__PRIMITIVE_TYPE_free(asn_TYPE_descriptor_t *td, void *sptr,
FREEMEM
(
st
);
}
/*
* Local internal type passed around as an argument.
*/
struct
xdp_arg_s
{
ASN__PRIMITIVE_TYPE_t
*
sptr
;
ssize_t
(
*
prim_body_decode
)(
ASN__PRIMITIVE_TYPE_t
*
sptr
,
void
*
chunk_buf
,
size_t
chunk_size
);
int
decoded_something
;
int
want_more
;
};
static
int
xer_decode__unexpected_tag
(
void
*
key
,
void
*
chunk_buf
,
size_t
chunk_size
)
{
struct
xdp_arg_s
*
arg
=
(
struct
xdp_arg_s
*
)
key
;
ssize_t
decoded
;
if
(
arg
->
decoded_something
)
{
/*
* Decoding was done once already. Prohibit doing it again.
*/
return
-
1
;
}
decoded
=
arg
->
prim_body_decode
(
arg
->
sptr
,
chunk_buf
,
chunk_size
);
if
(
decoded
<
0
)
{
return
-
1
;
}
else
{
/* Tag decoded successfully */
arg
->
decoded_something
=
1
;
return
0
;
}
}
static
ssize_t
xer_decode__body
(
void
*
key
,
void
*
chunk_buf
,
size_t
chunk_size
,
int
have_more
)
{
struct
xdp_arg_s
*
arg
=
(
struct
xdp_arg_s
*
)
key
;
ssize_t
decoded
;
if
(
arg
->
decoded_something
)
{
/*
* Decoding was done once already. Prohibit doing it again.
*/
return
-
1
;
}
if
(
!
have_more
)
{
/*
* If we've received something like "1", we can't really
* tell whether it is really `1` or `123`, until we know
* that there is no more data coming.
* The have_more argument will be set to 1 once something
* like this is available to the caller of this callback:
* "1<tag_start..."
*/
arg
->
want_more
=
1
;
return
-
1
;
}
decoded
=
arg
->
prim_body_decode
(
arg
->
sptr
,
chunk_buf
,
chunk_size
);
if
(
decoded
<
0
)
{
return
-
1
;
}
else
{
arg
->
decoded_something
=
1
;
return
decoded
;
}
}
asn_dec_rval_t
xer_decode_primitive
(
asn_codec_ctx_t
*
opt_codec_ctx
,
asn_TYPE_descriptor_t
*
td
,
ASN__PRIMITIVE_TYPE_t
**
sptr
,
const
char
*
opt_mname
,
void
*
buf_ptr
,
size_t
size
,
ssize_t
(
*
prim_body_decode
)(
ASN__PRIMITIVE_TYPE_t
*
sptr
,
void
*
chunk_buf
,
size_t
chunk_size
)
)
{
const
char
*
xml_tag
=
opt_mname
?
opt_mname
:
td
->
xml_tag
;
asn_struct_ctx_t
s_ctx
;
struct
xdp_arg_s
s_arg
;
asn_dec_rval_t
rc
;
/*
* Create the structure if does not exist.
*/
if
(
!*
sptr
)
{
*
sptr
=
CALLOC
(
1
,
sizeof
(
ASN__PRIMITIVE_TYPE_t
));
if
(
!*
sptr
)
{
asn_dec_rval_t
rval
;
rval
.
code
=
RC_FAIL
;
rval
.
consumed
=
0
;
return
rval
;
}
}
memset
(
&
s_ctx
,
0
,
sizeof
(
s_ctx
));
s_arg
.
sptr
=
*
sptr
;
s_arg
.
prim_body_decode
=
prim_body_decode
;
s_arg
.
decoded_something
=
0
;
s_arg
.
want_more
=
0
;
rc
=
xer_decode_general
(
opt_codec_ctx
,
&
s_ctx
,
&
s_arg
,
xml_tag
,
buf_ptr
,
size
,
xer_decode__unexpected_tag
,
xer_decode__body
);
switch
(
rc
.
code
)
{
case
RC_OK
:
if
(
!
s_arg
.
decoded_something
)
{
/* Opportunity has come and gone. Where's the result? */
rc
.
code
=
RC_FAIL
;
rc
.
consumed
=
0
;
}
break
;
case
RC_WMORE
:
/*
* Redo the whole thing later.
* We don't have a context to save intermediate parsing state.
*/
rc
.
consumed
=
0
;
break
;
case
RC_FAIL
:
rc
.
consumed
=
0
;
if
(
s_arg
.
want_more
)
rc
.
code
=
RC_WMORE
;
break
;
}
return
rc
;
}
skeletons/
ber_codec
_prim.h
→
skeletons/
asn_codecs
_prim.h
View file @
4fd7318e
...
...
@@ -2,8 +2,8 @@
* Copyright (c) 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef
_BER_CODEC_of_PRIMITIVE_TYPE_H_
#define
_BER_CODEC_of_PRIMITIVE_TYPE_H_
#ifndef
ASN_CODECS_PRIM_H
#define
ASN_CODECS_PRIM_H
#include <asn_application.h>
...
...
@@ -16,4 +16,18 @@ asn_struct_free_f ASN__PRIMITIVE_TYPE_free;
ber_type_decoder_f
ber_decode_primitive
;
der_type_encoder_f
der_encode_primitive
;
#endif
/* _BER_CODEC_of_PRIMITIVE_TYPE_H_ */
/*
* Specific function to decode simple primitive values
* (INTEGER, ENUMERATED, REAL, OBJECT IDENTIFIER, etc).
* Also see xer_decode_general() in xer_decoder.h
*/
asn_dec_rval_t
xer_decode_primitive
(
asn_codec_ctx_t
*
opt_codec_ctx
,
asn_TYPE_descriptor_t
*
type_descriptor
,
ASN__PRIMITIVE_TYPE_t
**
struct_ptr
,
const
char
*
opt_mname
,
void
*
buf_ptr
,
size_t
size
,
ssize_t
(
*
prim_body_decode
)(
ASN__PRIMITIVE_TYPE_t
*
struct_ptr
,
void
*
chunk_buf
,
size_t
chunk_size
)
);
#endif
/* ASN_CODECS_PRIM_H */
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