root/openpgpsdk/trunk/src/packet-parse.h

Revision 96 (checked in by ben, 8 years ago)

Finish when the data finishes.

  • Property svn:keywords set to Id
Line 
1 /** \file packet-parse.h
2  * Parser for OpenPGP packets - headers.
3  *
4  * $Id$
5  */
6
7 #ifndef OPS_PACKET_PARSE_H
8 #define OPS_PACKET_PARSE_H
9
10 #include "types.h"
11 #include "packet.h"
12
13 typedef struct ops_region
14     {
15     struct ops_region *parent;
16     unsigned length;
17     unsigned length_read;
18     unsigned last_read; /*!< length of last read, only valid in deepest child */
19     ops_boolean_t indeterminate:1;
20     } ops_region_t;
21
22 /** Return values for #ops_packet_reader_t. */
23 enum ops_reader_ret_t
24     {
25     OPS_R_OK            =0,     /*!< success */
26     OPS_R_EOF           =1,     /*!< reached end of file, no data has been returned */
27     OPS_R_EARLY_EOF     =2,     /*!< could not read the requested amount of bytes and OPS_RETURN_LENGTH was not set and at least 1 byte was read */
28     OPS_R_PARTIAL_READ  =3,     /*!< if OPS_RETURN_LENGTH is set and the buffer was not filled */
29     };
30
31 typedef enum
32     {
33     OPS_RELEASE_MEMORY,
34     OPS_KEEP_MEMORY
35     } ops_parse_callback_return_t;
36
37 typedef ops_parse_callback_return_t
38 ops_packet_parse_callback_t(const ops_parser_content_t *content,void *arg);
39 typedef ops_reader_ret_t ops_packet_reader_t(unsigned char *dest,
40                                              unsigned *plength,
41                                              ops_reader_flags_t flags,
42                                              void *arg);
43
44 typedef struct
45     {
46     unsigned char ss_raw[256/8];
47     unsigned char ss_parsed[256/8];
48
49     ops_packet_parse_callback_t *cb;
50     void *cb_arg;
51
52     ops_packet_reader_t *reader;
53     void *reader_arg;
54
55     unsigned accumulate:1;      /*!< accumulate packet data */
56     unsigned char *accumulated; /*!< the accumulated data */
57     unsigned asize;     /*!< size of the buffer */
58     unsigned alength;   /*!< used buffer */
59     } ops_parse_options_t;
60
61 int ops_parse(ops_parse_options_t *opt);
62 void ops_parse_and_validate(ops_parse_options_t *opt);
63
64 enum ops_parse_type_t
65     {
66     OPS_PARSE_RAW,
67     OPS_PARSE_PARSED,
68     OPS_PARSE_IGNORE
69     };
70
71 #define ops_parse_options_init(opt) memset(opt,'\0',sizeof *opt)
72
73 void ops_parse_options(ops_parse_options_t *opt,ops_content_tag_t tag,
74                        ops_parse_type_t type);
75
76 int ops_limited_read(unsigned char *dest,unsigned length,
77                      ops_region_t *region,ops_parse_options_t *opt);
78
79 /* vim:set textwidth=120: */
80 /* vim:set ts=8: */
81
82 #endif
83
Note: See TracBrowser for help on using the browser.