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

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

Mostly working again.

  • 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 */  /* XXX: How do we tell how many? */
28     };
29
30 typedef enum
31     {
32     OPS_RELEASE_MEMORY,
33     OPS_KEEP_MEMORY
34     } ops_parse_callback_return_t;
35
36 typedef ops_parse_callback_return_t
37 ops_packet_parse_callback_t(const ops_parser_content_t *content,void *arg);
38 typedef ops_reader_ret_t ops_packet_reader_t(unsigned char *dest,
39                                              unsigned *plength,
40                                              ops_reader_flags_t flags,
41                                              void *arg);
42
43 typedef struct
44     {
45     unsigned char ss_raw[256/8];
46     unsigned char ss_parsed[256/8];
47
48     ops_packet_parse_callback_t *cb;
49     void *cb_arg;
50
51     ops_packet_reader_t *reader;
52     void *reader_arg;
53
54     unsigned accumulate:1;      /*!< accumulate packet data */
55     unsigned char *accumulated; /*!< the accumulated data */
56     unsigned asize;     /*!< size of the buffer */
57     unsigned alength;   /*!< used buffer */
58     } ops_parse_options_t;
59
60 int ops_parse(ops_parse_options_t *opt);
61 void ops_parse_and_validate(ops_parse_options_t *opt);
62
63 enum ops_parse_type_t
64     {
65     OPS_PARSE_RAW,
66     OPS_PARSE_PARSED,
67     OPS_PARSE_IGNORE
68     };
69
70 #define ops_parse_options_init(opt) memset(opt,'\0',sizeof *opt)
71
72 void ops_parse_options(ops_parse_options_t *opt,ops_content_tag_t tag,
73                        ops_parse_type_t type);
74
75 int ops_limited_read(unsigned char *dest,unsigned length,
76                      ops_region_t *region,ops_parse_options_t *opt);
77
78 /* vim:set textwidth=120: */
79 /* vim:set ts=8: */
80
81 #endif
82
Note: See TracBrowser for help on using the browser.