| APT2 Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#include <apt.h>
AptControlSection;
AptControlSection * apt_control_section_new (const gchar *section,
gssize length,
const gchar **next);
void apt_control_section_unref (AptControlSection *section);
AptControlSection * apt_control_section_ref (AptControlSection *section);
const gchar * apt_control_section_get (AptControlSection *section,
const gchar *name);
GList * apt_control_section_get_keys (AptControlSection *section);
gsize apt_control_section_get_size (AptControlSection *section);
GList * apt_control_section_get_values (AptControlSection *section);
const gchar * apt_control_section_get_raw (AptControlSection *section,
const gchar *name,
gboolean complete,
gsize *length);
gboolean apt_control_section_has_key (AptControlSection *section,
const gchar *name);
const gchar * apt_control_section_raw (AptControlSection *section,
gsize *size);
AptControlFile;
AptControlFile * apt_control_file_new (const gchar *file,
GError **error);
AptControlFile * apt_control_file_new_for_data (const gchar *data,
gsize length);
void apt_control_file_free (AptControlFile *file);
AptControlSection * apt_control_file_step (AptControlFile *file);
AptControlSection * apt_control_file_jump (AptControlFile *file,
goffset offset);
goffset apt_control_file_get_offset (AptControlFile *file);
This section explains the control file parser of APT2. A control file is a file consisting of multiple RFC 822-style header sections. Those files are widely used in the Debian project for packaging purposes and other stuff as well.
typedef struct _AptControlSection AptControlSection;
AptControlSection is an opaque data type and may only be accessed using the following functions.
AptControlSection * apt_control_section_new (const gchar *section,gssize length,const gchar **next);
Parses a RFC 822 header section. In case multiple fields with the same name exist, only the last one will be available. Any newlines in front of a section are ignored.
|
The section that shall be parsed. |
|
The length of section. It may be longer than the to be parsed
section, it only exists to not read outside of the string. |
|
If not NULL, it will be set to the beginning of the body
of the RFC-822 message; that is, (for our use) the next section. |
Returns : |
An AptControlSection containing the section. |
void apt_control_section_unref (AptControlSection *section);
Decrements the reference count of section by one. If the reference count
drops to 0, the memory used by section is freed.
|
An AptControlSection |
AptControlSection * apt_control_section_ref (AptControlSection *section);
Increments the reference count of section by one.
|
An AptControlSection |
Returns : |
section. |
const gchar * apt_control_section_get (AptControlSection *section,const gchar *name);
Looks up the name in the hash table and returns the value of the field, excluding whitespace at the beginning and the end.
|
An AptControlSection |
|
The name of the field that shall be looked up. |
Returns : |
The stripped value as a string or NULL if the key is not
set. |
GList * apt_control_section_get_keys (AptControlSection *section);
Gets a list of all keys contained in this section.
|
An AptControlSection |
Returns : |
A GList containing the keys of this section. The data in this
list is owned by the section and must not be modified. If the
list is no longer needed, call g_list_free() on it. |
gsize apt_control_section_get_size (AptControlSection *section);
Gets the number of fields in this section.
|
An AptControlSection |
Returns : |
The number of fields in this section. |
GList * apt_control_section_get_values (AptControlSection *section);
Gets a list of all values contained in this section.
|
An AptControlSection |
Returns : |
A GList containing the values of this section. The data in
this list is owned by the section and must not be modified.
If the list is no longer needed, call g_list_free() on it. |
const gchar * apt_control_section_get_raw (AptControlSection *section,const gchar *name,gboolean complete,gsize *length);
Looks up the name in the hash table and returns the value of the field,
or (if complete is TRUE) the complete field. This function is preferred
over apt_control_section_get(), because it does not require string
duplication.
|
An AptControlSection |
|
The name of the field that shall be looked up. |
|
Return the complete field, including the field name. |
|
Return location for the length of the return value; or NULL
if the length is not needed (e.g. for passing to atoi()). |
Returns : |
The field as a string or NULL if the key is not
set. The returned string is not nul-terminated. |
gboolean apt_control_section_has_key (AptControlSection *section,const gchar *name);
Checks whether section contains the field name.
|
An AptControlSection |
|
The name of the option |
Returns : |
TRUE if section contains name, FALSE otherwise. |
const gchar * apt_control_section_raw (AptControlSection *section,gsize *size);
Gets the raw section data for the current section. This is useful if a section should be displayed. In most cases, the returned data is not null-terminated.
|
An AptControlSection |
|
A pointer to the gsize holding the size of the section. |
Returns : |
The raw section data, not null-terminated. |
typedef struct _AptControlFile AptControlFile;
An opaque data structure that may only be accessed using the following functions.
Thread-safe: No
AptControlFile * apt_control_file_new (const gchar *file,GError **error);
Creates a new AptControlFile for parsing file.
|
The name of the file that should be parsed. |
|
Location to store an error. |
Returns : |
A newly allocated AptControlFile or NULL if an error
occurs. |
AptControlFile * apt_control_file_new_for_data (const gchar *data,gsize length);
Creates a new AptControlFile for parsing data.
|
The data that shall be parsed. Must be kept around for the life-time of the object and will not be copied. |
|
The length of data or 0 if data is null terminated. |
Returns : |
A newly allocated AptControlFile. |
void apt_control_file_free (AptControlFile *file);
Free the memory used by file.
|
An AptControlFile |
AptControlSection * apt_control_file_step (AptControlFile *file);
Advances to the next section in the file and returns that section as a
AptControlSection as returned by apt_control_section_new().
|
An AptControlFile |
Returns : |
A newly allocated AptControlSection. |
AptControlSection * apt_control_file_jump (AptControlFile *file,goffset offset);
Parse the header section at offset. This moves the internal file
pointer to the given offset, it should thus not be mixed with calls
to apt_control_file_step().
|
An AptControlFile |
|
The offset at which the section begins. |
Returns : |
A newly allocated GHashTable or NULL if there are no
more sections. |
goffset apt_control_file_get_offset (AptControlFile *file);
Gets the absolute offset at which the current section is located.
|
An AptControlFile |
Returns : |
The offset of the current section. |