Read OpenPGP packets
[Core API]


Functions

ops_boolean_t ops_limited_read (unsigned char *dest, size_t length, ops_region_t *region, ops_error_t **errors, ops_reader_info_t *rinfo, ops_parse_cb_info_t *cbinfo)
 Read bytes from a region within the packet.
ops_boolean_t ops_stacked_limited_read (void *dest, unsigned length, ops_region_t *region, ops_error_t **errors, ops_reader_info_t *rinfo, ops_parse_cb_info_t *cbinfo)
 Call ops_limited_read on next in stack.
int ops_parse (ops_parse_info_t *pinfo)
 Parse packets from an input stream until EOF or error.
int ops_parse_and_print_errors (ops_parse_info_t *pinfo)
 Parse packets and print any errors.
void ops_parse_options (ops_parse_info_t *pinfo, ops_content_tag_t tag, ops_parse_type_t type)
 Specifies whether one or more signature subpacket types should be returned parsed; or raw; or ignored.
ops_parse_info_tops_parse_info_new (void)
 Creates a new zero-ed ops_parse_info_t struct.
void ops_parse_info_delete (ops_parse_info_t *pinfo)
 Free ops_parse_info_t struct and its contents.
ops_reader_info_tops_parse_get_rinfo (ops_parse_info_t *pinfo)
 Returns the parse_info's reader_info.
void ops_parse_cb_set (ops_parse_info_t *pinfo, ops_parse_cb_t *cb, void *arg)
 Sets the parse_info's callback This is used when adding the first callback in a stack of callbacks.
void ops_parse_cb_push (ops_parse_info_t *pinfo, ops_parse_cb_t *cb, void *arg)
 Adds a further callback to a stack of callbacks.
void * ops_parse_cb_get_arg (ops_parse_cb_info_t *cbinfo)
 Returns callback's arg.
void * ops_parse_cb_get_errors (ops_parse_cb_info_t *cbinfo)
 Returns callback's errors.
ops_parse_cb_return_t ops_parse_cb (const ops_parser_content_t *content, ops_parse_cb_info_t *cbinfo)
 Calls the parse_cb_info's callback if present.
ops_parse_cb_return_t ops_parse_stacked_cb (const ops_parser_content_t *content, ops_parse_cb_info_t *cbinfo)
 Calls the next callback in the stack.
ops_error_tops_parse_info_get_errors (ops_parse_info_t *pinfo)
 Returns the parse_info's errors.

Function Documentation

ops_boolean_t ops_limited_read unsigned char *  dest,
size_t  length,
ops_region_t region,
ops_error_t **  errors,
ops_reader_info_t rinfo,
ops_parse_cb_info_t cbinfo
 

Read bytes from a region within the packet.

Read length bytes into the buffer pointed to by *dest. Make sure we do not read over the packet boundary. Updates the Packet Tag's ops_ptag_t::length_read.

If length would make us read over the packet boundary, or if reading fails, we call the callback with an error.

Note that if the region is indeterminate, this can return a short read - check region->last_read for the length. EOF is indicated by a success return and region->last_read == 0 in this case (for a region of known length, EOF is an error).

This function makes sure to respect packet boundaries.

Parameters:
dest The destination buffer
length How many bytes to read
region Pointer to packet region
errors Error stack
rinfo Reader info
cbinfo Callback info
Returns:
ops_true on success, ops_false on error

int ops_parse ops_parse_info_t pinfo  ) 
 

Parse packets from an input stream until EOF or error.

Setup the necessary parsing configuration in "pinfo" before calling ops_parse().

That information includes :

  • a "reader" function to be used to get the data to be parsed

  • a "callback" function to be called when this library has identified a parseable object within the data

  • whether the calling function wants the signature subpackets returned raw, parsed or not at all.

After returning, pinfo->errors holds any errors encountered while parsing.

Parameters:
pinfo Parsing configuration
Returns:
1 on success in all packets, 0 on error in any packet
See also:
Core API Overview

ops_print_errors(), ops_parse_and_print_errors()

Example code
ops_parse_cb_t* example_callback();
void example()
 {
 int fd=0;
 ops_parse_info_t *pinfo=NULL;
 char *filename="pubring.gpg";

 // setup pinfo to read from file with example callback
 fd=ops_setup_file_read(&pinfo, filename, NULL, example_callback, ops_false);

 // specify how we handle signature subpackets
 ops_parse_options(pinfo, OPS_PTAG_SS_ALL, OPS_PARSE_PARSED);
 
 if (!ops_parse(pinfo))
   ops_print_errors(pinfo->errors);

 ops_teardown_file_read(pinfo,fd);
 }

int ops_parse_and_print_errors ops_parse_info_t pinfo  ) 
 

Parse packets and print any errors.

Parameters:
pinfo Parsing configuration
Returns:
1 on success in all packets, 0 on error in any packet
See also:
Core API Overview

ops_parse()

ops_parse_cb_return_t ops_parse_cb const ops_parser_content_t content,
ops_parse_cb_info_t cbinfo
 

Calls the parse_cb_info's callback if present.

Returns:
Return value from callback, if present; else OPS_FINISHED

void ops_parse_cb_push ops_parse_info_t pinfo,
ops_parse_cb_t *  cb,
void *  arg
 

Adds a further callback to a stack of callbacks.

See also:
ops_parse_cb_set()

void ops_parse_cb_set ops_parse_info_t pinfo,
ops_parse_cb_t *  cb,
void *  arg
 

Sets the parse_info's callback This is used when adding the first callback in a stack of callbacks.

See also:
ops_parse_cb_push()

ops_reader_info_t* ops_parse_get_rinfo ops_parse_info_t pinfo  ) 
 

Returns the parse_info's reader_info.

Returns:
Pointer to the reader_info inside the parse_info

void ops_parse_info_delete ops_parse_info_t pinfo  ) 
 

Free ops_parse_info_t struct and its contents.

See also:
ops_parse_info_new()

ops_error_t* ops_parse_info_get_errors ops_parse_info_t pinfo  ) 
 

Returns the parse_info's errors.

Returns:
parse_info's errors

ops_parse_info_t* ops_parse_info_new void   ) 
 

Creates a new zero-ed ops_parse_info_t struct.

See also:
ops_parse_info_delete()

void ops_parse_options ops_parse_info_t pinfo,
ops_content_tag_t  tag,
ops_parse_type_t  type
 

Specifies whether one or more signature subpacket types should be returned parsed; or raw; or ignored.

Parameters:
pinfo Pointer to previously allocated structure
tag Packet tag. OPS_PTAG_SS_ALL for all SS tags; or one individual signature subpacket tag
type Parse type
Todo:
Make all packet types optional, not just subpackets

ops_parse_cb_return_t ops_parse_stacked_cb const ops_parser_content_t content,
ops_parse_cb_info_t cbinfo
 

Calls the next callback in the stack.

Returns:
Return value from callback


Generated on Fri May 24 00:00:03 2013 for OpenPGP:SDK by  doxygen 1.4.6