yEnc blocks

yEnc blocks — Streaming framed yEnc readers and writers

Functions

Types and Values

Description

These APIs handle single-part and multipart blocks, bounded input lines, filenames, size validation and CRC-32 trailers. They do not assemble files, interpret MIME or undo NNTP dot-stuffing. Filenames are untrusted metadata, never filesystem paths. Instances are not thread-safe.

Functions

g_mime_yenc_options_new ()

GMimeYencOptions *
g_mime_yenc_options_new (void);

Returns

options with the default limits and encoding.

[transfer full]


g_mime_yenc_options_clone ()

GMimeYencOptions *
g_mime_yenc_options_clone (GMimeYencOptions *options);

Parameters

options

options, or NULL for defaults.

[nullable]

Returns

an independent copy.

[transfer full]


g_mime_yenc_options_free ()

void
g_mime_yenc_options_free (GMimeYencOptions *options);

Parameters

options

options to free

 

g_mime_yenc_options_get_max_line_length ()

guint
g_mime_yenc_options_get_max_line_length
                               (GMimeYencOptions *options);

Parameters

options

options

 

Returns

the maximum control, payload or scanned-text line length.


g_mime_yenc_options_set_max_line_length ()

void
g_mime_yenc_options_set_max_line_length
                               (GMimeYencOptions *options,
                                guint length);

Parameters

options

options

 

length

a byte count from 1 through G_MAXINT - 2, excluding the newline

 

g_mime_yenc_options_get_max_decoded_size ()

gint64
g_mime_yenc_options_get_max_decoded_size
                               (GMimeYencOptions *options);

Parameters

options

options

 

Returns

the maximum decoded size of an individual block, not the entire multipart file.


g_mime_yenc_options_set_max_decoded_size ()

void
g_mime_yenc_options_set_max_decoded_size
                               (GMimeYencOptions *options,
                                gint64 size);

Parameters

options

options

 

size

a nonnegative block size limit; zero permits only empty blocks

 

g_mime_yenc_options_get_filename_charset ()

const char *
g_mime_yenc_options_get_filename_charset
                               (GMimeYencOptions *options);

Parameters

options

options

 

Returns

the charset used to convert filenames to and from UTF-8.

[transfer none]


g_mime_yenc_options_set_filename_charset ()

gboolean
g_mime_yenc_options_set_filename_charset
                               (GMimeYencOptions *options,
                                const char *charset,
                                GError **error);

The format does not declare a charset. The default ISO-8859-1 preserves every filename byte. Conversion errors are reported without replacement.

Parameters

options

options

 

charset

a supported charset name

 

error

return location for an error

 

Returns

whether the charset was accepted, without changing it on failure.


g_mime_yenc_options_get_newline_format ()

GMimeNewLineFormat
g_mime_yenc_options_get_newline_format
                               (GMimeYencOptions *options);

Parameters

options

options

 

Returns

the writer's newline format.


g_mime_yenc_options_set_newline_format ()

void
g_mime_yenc_options_set_newline_format
                               (GMimeYencOptions *options,
                                GMimeNewLineFormat format);

Parameters

options

options

 

format

DOS (CRLF) or Unix (LF)

 

g_mime_yenc_header_new ()

GMimeYencHeader *
g_mime_yenc_header_new (const char *filename,
                        gint64 size,
                        guint line_length,
                        guint part_number,
                        guint total_parts,
                        gint64 begin,
                        gint64 end,
                        GError **error);

Multipart ranges must fall within the file size. A total part count, when specified, must include the part number. Filenames are metadata, not paths.

Parameters

filename

a nonempty UTF-8 filename without CR, LF or surrounding ASCII spaces

 

size

the entire file size, nonnegative

 

line_length

the nominal payload line length, normally 128; writers support 60 through 998

 

part_number

the part number, or zero for a single-part block

 

total_parts

the total part count, or zero if unspecified

 

begin

the one-based inclusive range start, or zero for a single-part block

 

end

the one-based inclusive range end, or zero for a single-part block

 

error

return location for an error

 

Returns

immutable metadata, or NULL if invalid.

[transfer full][nullable]


g_mime_yenc_header_get_filename ()

const char *
g_mime_yenc_header_get_filename (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the untrusted UTF-8 filename.

[transfer none]


g_mime_yenc_header_get_size ()

gint64
g_mime_yenc_header_get_size (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the entire file size.


g_mime_yenc_header_get_line_length ()

guint
g_mime_yenc_header_get_line_length (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the nominal payload line length, excluding the newline.


g_mime_yenc_header_get_part_number ()

guint
g_mime_yenc_header_get_part_number (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the part number, or zero for single-part blocks.


g_mime_yenc_header_get_total_parts ()

guint
g_mime_yenc_header_get_total_parts (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the total part count, or zero if unspecified.


g_mime_yenc_header_get_begin ()

gint64
g_mime_yenc_header_get_begin (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the one-based inclusive range start, or zero for single-part blocks.


g_mime_yenc_header_get_end ()

gint64
g_mime_yenc_header_get_end (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the one-based inclusive range end, or zero for single-part blocks.


g_mime_yenc_header_get_decoded_size ()

gint64
g_mime_yenc_header_get_decoded_size (GMimeYencHeader *header);

Parameters

header

block metadata

 

Returns

the decoded size of this block, derived from the multipart range when applicable.


g_mime_yenc_reader_new ()

GMimeYencReader *
g_mime_yenc_reader_new (GMimeStream *stream,
                        GMimeYencOptions *options);

Takes an independent snapshot of the options and retains a stream reference.

Parameters

stream

the source stream, not necessarily seekable

 

options

options, or NULL for defaults.

[nullable]

Returns

a streaming yEnc reader.

[transfer full]


g_mime_yenc_reader_read_next ()

gboolean
g_mime_yenc_reader_read_next (GMimeYencReader *reader,
                              GError **error);

Skips surrounding text, respecting the line limit even outside blocks. Decode the current block before calling again. Clean EOF is not an error.

Parameters

reader

a yEnc reader

 

error

return location for an error

 

Returns

TRUE if a block was found; FALSE at EOF or on error.


g_mime_yenc_reader_decode_to ()

gboolean
g_mime_yenc_reader_decode_to (GMimeYencReader *reader,
                              GMimeStream *destination,
                              GError **error);

Leaves the destination open and unflushed. Discard its output on failure. Missing checksums are accepted; present block checksums are verified. Whole-file checksums of partial ranges are unverified metadata.

Parameters

reader

a yEnc reader with a pending block

 

destination

a stream distinct from the source

 

error

return location for an error

 

Returns

whether the block was decoded and validated successfully.


g_mime_yenc_reader_get_header ()

GMimeYencHeader *
g_mime_yenc_reader_get_header (GMimeYencReader *reader);

Parameters

reader

a yEnc reader

 

Returns

the current header, or NULL before reading or after clean EOF.

[transfer none][nullable]


g_mime_yenc_reader_get_decoded_size ()

gint64
g_mime_yenc_reader_get_decoded_size (GMimeYencReader *reader);

Parameters

reader

a yEnc reader

 

Returns

the decoded byte count, which does not imply successful validation.


g_mime_yenc_reader_get_checksum ()

gboolean
g_mime_yenc_reader_get_checksum (GMimeYencReader *reader,
                                 guint32 *checksum);

Parameters

reader

a yEnc reader

 

checksum

the computed finalized block CRC-32, or zero if unavailable.

[out]

Returns

whether decoding and validation completed successfully.


g_mime_yenc_reader_get_expected_checksum ()

gboolean
g_mime_yenc_reader_get_expected_checksum
                               (GMimeYencReader *reader,
                                guint32 *checksum);

For partial ranges this checksum is unverified metadata.

Parameters

reader

a yEnc reader

 

checksum

the advertised whole-file CRC-32, or zero if unavailable.

[out]

Returns

whether a whole-file checksum was present after successful decoding.


g_mime_yenc_reader_get_expected_part_checksum ()

gboolean
g_mime_yenc_reader_get_expected_part_checksum
                               (GMimeYencReader *reader,
                                guint32 *checksum);

Parameters

reader

a yEnc reader

 

checksum

the advertised part CRC-32, or zero if unavailable.

[out]

Returns

whether a part checksum was present and verified after successful decoding.


g_mime_yenc_writer_new ()

GMimeYencWriter *
g_mime_yenc_writer_new (GMimeStream *stream,
                        GMimeYencOptions *options);

Takes an independent snapshot of the options and retains a stream reference.

Parameters

stream

the destination, not necessarily seekable

 

options

options, or NULL for defaults.

[nullable]

Returns

a streaming yEnc writer.

[transfer full]


g_mime_yenc_writer_write ()

gboolean
g_mime_yenc_writer_write (GMimeYencWriter *writer,
                          GMimeYencHeader *header,
                          GMimeStream *source,
                          const guint32 *file_checksum,
                          guint32 *checksum,
                          GError **error);

Writes framing, payload and a trailer. Leaves the source open and does not flush the destination. A partial range's supplied whole-file checksum is emitted without verification. For a whole-file block it must match. Validation before output does not invalidate the writer; size, checksum or I/O failures once writing begins do invalidate it.

Parameters

writer

a yEnc writer

 

header

the block metadata

 

source

exactly this block's decoded bytes, distinct from the destination

 

file_checksum

an optional finalized whole-file CRC-32.

[in][nullable]

checksum

the finalized block CRC-32, or zero on failure.

[out][optional]

error

return location for an error

 

Returns

whether the complete block was written successfully.

Types and Values

GMimeYencOptions

typedef struct _GMimeYencOptions GMimeYencOptions;

Boxed options copied by readers and writers. Defaults are CRLF output, ISO-8859-1 filenames, a 16384-byte line limit excluding the newline, and a 1 GiB decoded-block limit. Readers accept CRLF and LF independently of the output newline setting. Filename conversion never substitutes bytes.


GMimeYencHeader

typedef struct _GMimeYencHeader GMimeYencHeader;

Immutable block metadata. Multipart ranges are one-based and inclusive; the size is the entire file size, not the current part size. Metadata alone does not imply that content has been validated.


GMimeYencReader

typedef struct _GMimeYencReader GMimeYencReader;

Call g_mime_yenc_reader_read_next() followed by g_mime_yenc_reader_decode_to() for each block. Decode to a GMimeStreamNull to discard a block while still validating it. Do not access the source directly: the reader buffers beyond the current block.

Output is provisional until decoding succeeds. A parsing or I/O failure invalidates the reader. Stream references are retained, not explicitly closed; non-seekable sources are supported.


GMimeYencWriter

typedef struct _GMimeYencWriter GMimeYencWriter;

Writes complete blocks without buffering entire files. Each source must contain exactly the declared block size at its current position; multipart sources contain only the indicated range. A failed write may leave partial output and invalidates the writer. Stream references are retained, not explicitly closed. No MIME headers or NNTP framing are generated.