libmobi
C library for handling MOBI format ebook documents
|
Functions for handling OPF structures. More...
#include <stdlib.h>
#include <string.h>
#include "opf.h"
#include "xmlwriter.h"
#include "index.h"
#include "util.h"
#include "parse_rawml.h"
#include "debug.h"
Macros | |
#define | _GNU_SOURCE 1 |
#define | __USE_BSD /* for strdup on linux/glibc */ |
#define | mobi_opf_copy_tagtype(mobidata, struct_type, struct_element, member_name) |
Copy text data from EXTH record to "member_name" member of a structure with given type. More... | |
#define | mobi_opf_set_tagtype(struct_type, struct_element, member_name, string) |
Set "member_name" member of a structure with given type to string value. More... | |
#define | mobi_free_opf_struct_2el(struct_array, struct_member1, struct_member2) |
Macro to free generic OPF structure with two members. More... | |
#define | mobi_free_opf_struct_3el(struct_array, struct_member1, struct_member2, struct_member3) |
Macro to free generic OPF structure with three members. More... | |
Functions | |
bool | mobi_is_guide_type (const char *type) |
Check if type is valid OPF guide element. More... | |
MOBI_RET | mobi_build_opf_guide (OPF *opf, const MOBIRawml *rawml) |
Reconstruct guide part of the OPF file. More... | |
MOBI_RET | mobi_write_ncx_level (xmlTextWriterPtr writer, const NCX *ncx, const size_t level, const size_t from, const size_t to, size_t *seq) |
Write <navPoint> entries for given ncx level. More... | |
MOBI_RET | mobi_xml_write_meta (xmlTextWriterPtr writer, const char *name, const char *content) |
Write element <meta name="name" content="content"> to XML buffer. More... | |
MOBI_RET | mobi_opf_add_to_rawml (const char *opf_xml, MOBIRawml *rawml) |
Add reconstruced opf part to rawml. More... | |
MOBI_RET | mobi_ncx_add_to_rawml (const char *ncx_xml, MOBIRawml *rawml) |
Add reconstruced ncx part to rawml. More... | |
MOBI_RET | mobi_write_ncx_header (xmlTextWriterPtr writer, const OPF *opf, uint32_t maxlevel) |
Write ncx header. More... | |
MOBI_RET | mobi_write_ncx (MOBIRawml *rawml, const NCX *ncx, const OPF *opf, uint32_t maxlevel) |
Build ncx document using libxml2 and append it to rawml. More... | |
void | mobi_free_ncx (NCX *ncx, size_t count) |
Free array of ncx entries. More... | |
MOBI_RET | mobi_build_ncx (MOBIRawml *rawml, const OPF *opf) |
Parse ncx index, recreate ncx document and append it to rawml. More... | |
void | mobi_opf_set_item (OPFmeta **meta, const char *name, const char *content) |
Set values for attributes of OPF manifest tag. More... | |
MOBI_RET | mobi_get_opf_from_exth (OPFmetadata *metadata, const MOBIData *m) |
Copy text data from EXTH record to OPFmetadata tags structure. More... | |
MOBI_RET | mobi_build_opf_metadata (OPF *opf, const MOBIData *m, const MOBIRawml *rawml) |
Recreate OPF structure. More... | |
MOBI_RET | mobi_xml_write_element_ns (xmlTextWriterPtr writer, const char *name, const char **content, const char *ns) |
Write array of xml elements of given name to XML buffer. More... | |
MOBI_RET | mobi_xml_write_dcmeta (xmlTextWriterPtr writer, const char *name, const char **content) |
Write array of Dublin Core elements of given name to XML buffer. More... | |
MOBI_RET | mobi_xml_write_xmeta (xmlTextWriterPtr writer, const char *name, const char **content) |
Write array of custom MOBI elements of given name to XML buffer. More... | |
MOBI_RET | mobi_xml_write_opfmeta (xmlTextWriterPtr writer, const OPFmeta **meta) |
Write array of <meta> elements to XML buffer. More... | |
MOBI_RET | mobi_xml_write_reference (xmlTextWriterPtr writer, const OPFreference **reference) |
Write array of <referenece> elements to XML buffer. More... | |
MOBI_RET | mobi_xml_write_item (xmlTextWriterPtr writer, const char *id, const char *href, const char *media_type) |
Write single element to XML buffer. More... | |
MOBI_RET | mobi_xml_write_spine (xmlTextWriterPtr writer, const MOBIRawml *rawml) |
Write opf <spine> part to XML buffer. More... | |
MOBI_RET | mobi_xml_write_manifest (xmlTextWriterPtr writer, const MOBIRawml *rawml) |
Write all manifest elements to XML buffer. More... | |
MOBI_RET | mobi_xml_write_dcmeta_identifier (xmlTextWriterPtr writer, const OPFidentifier **identifier) |
Write array of Dublin Core identifier elements to XML buffer. More... | |
MOBI_RET | mobi_xml_write_dcmeta_creator (xmlTextWriterPtr writer, const OPFcreator **creator, const char *name) |
Write array of Dublin Core creator/contributor elements to XML buffer. More... | |
MOBI_RET | mobi_xml_write_dcmeta_subject (xmlTextWriterPtr writer, const OPFsubject **subject) |
Write array of Dublin Core subject elements to XML buffer. More... | |
MOBI_RET | mobi_xml_write_dcmeta_date (xmlTextWriterPtr writer, const OPFdate **date) |
Write array of Dublin Core date elements to XML buffer. More... | |
MOBI_RET | mobi_xml_write_xmeta_srp (xmlTextWriterPtr writer, const OPFsrp **srp) |
Write array of custom srp elements to XML buffer. More... | |
void | mobi_free_opf_array (char **array) |
Free array of OPF sturcture members. More... | |
void | mobi_free_opf_metadata (OPFmetadata *metadata) |
Free OPF metadata structure and data. More... | |
void | mobi_free_opf_manifest (OPFmanifest *manifest) |
Free OPFmanifest structure and data. More... | |
void | mobi_free_opf_spine (OPFspine *spine) |
Free OPFspine structure and data. More... | |
void | mobi_free_opf_guide (OPFguide *guide) |
Free OPFguide structure and data. More... | |
void | mobi_free_opf (OPF *opf) |
Free OPF structure and data. More... | |
MOBI_RET | mobi_build_opf (MOBIRawml *rawml, const MOBIData *m) |
Recreate OPF structure. More... | |
Variables | |
const char * | mobi_guide_types [] |
Array of valid OPF guide types. More... | |
Functions for handling OPF structures.
Copyright (c) 2020 Bartek Fabiszewski http://www.fabiszewski.net
This file is part of libmobi. Licensed under LGPL, either version 3, or any later. See http://www.gnu.org/licenses/
#define mobi_free_opf_struct_2el | ( | struct_array, | |
struct_member1, | |||
struct_member2 | |||
) |
Macro to free generic OPF structure with two members.
[in] | struct_array | Structure name |
[in] | struct_member1 | Structure member 1 |
[in] | struct_member2 | Structure member 2 |
#define mobi_free_opf_struct_3el | ( | struct_array, | |
struct_member1, | |||
struct_member2, | |||
struct_member3 | |||
) |
Macro to free generic OPF structure with three members.
[in] | struct_array | Structure name |
[in] | struct_member1 | Structure member 1 |
[in] | struct_member2 | Structure member 2 |
[in] | struct_member3 | Structure member 3 |
#define mobi_opf_copy_tagtype | ( | mobidata, | |
struct_type, | |||
struct_element, | |||
member_name | |||
) |
Copy text data from EXTH record to "member_name" member of a structure with given type.
Data will copied from curr->data. It will allocate memory for the array of structures if not already allocated. It will find first array index that is not already used
[in] | mobidata | Mobidata structure |
[in] | struct_type | Structure type defined with typedef |
[in] | struct_element | Member member_name of this structure will be set to EXTH data |
[in] | member_name | Structure member name that will be modified |
#define mobi_opf_set_tagtype | ( | struct_type, | |
struct_element, | |||
member_name, | |||
string | |||
) |
Set "member_name" member of a structure with given type to string value.
It will allocate memory for the array of structures if not already allocated. It will find first array index that is not already used
[in] | struct_type | Structure type defined with typedef |
[in] | struct_element | Member member_name of this structure will be set to EXTH data |
[in] | member_name | Structure member name that will be modified |
[in] | string | String value that will be assigned to the structure memeber |
Recreate OPF structure.
This function will fill OPF structure with parsed index data and convert it to xml file. The file will be stored in MOBIRawml structure.
[in,out] | rawml | OPF xml file will be appended to rawml->markup linked list |
[in] | m | MOBIData structure containing document metadata |
Recreate OPF structure.
[in,out] | opf | Structure OPF->OPFmetadata will be filled with parsed data |
[in] | m | MOBIData structure containing document metadata |
[in] | rawml | MOBIRawml structure containing parsed records |
void mobi_free_ncx | ( | NCX * | ncx, |
size_t | count | ||
) |
Free array of ncx entries.
[in] | ncx | Array of NCX structures with ncx content |
[in] | count | Size of the array |
void mobi_free_opf_array | ( | char ** | array | ) |
Free array of OPF sturcture members.
[in] | array | Array |
void mobi_free_opf_guide | ( | OPFguide * | guide | ) |
void mobi_free_opf_manifest | ( | OPFmanifest * | manifest | ) |
Free OPFmanifest structure and data.
[in] | manifest | OPF opf->manifest structure |
void mobi_free_opf_metadata | ( | OPFmetadata * | metadata | ) |
void mobi_free_opf_spine | ( | OPFspine * | spine | ) |
MOBI_RET mobi_get_opf_from_exth | ( | OPFmetadata * | metadata, |
const MOBIData * | m | ||
) |
Copy text data from EXTH record to OPFmetadata tags structure.
[in,out] | metadata | Structure OPFmetadata will be filled with parsed data |
[in] | m | MOBIData structure with loaded data |
bool mobi_is_guide_type | ( | const char * | type | ) |
void mobi_opf_set_item | ( | OPFmeta ** | meta, |
const char * | name, | ||
const char * | content | ||
) |
Set values for attributes of OPF manifest tag.
It will allocate memory for the OPFitem members: id, href and media-type. It will find first array index that is not already used
[in,out] | meta | Array of OPFmeta structures to be filled with data |
[in] | name | Value of the name attribute |
[in] | content | Value of the content attribute |
MOBI_RET mobi_write_ncx_header | ( | xmlTextWriterPtr | writer, |
const OPF * | opf, | ||
uint32_t | maxlevel | ||
) |
Write ncx header.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | opf | OPF structure to fetch some data |
[in] | maxlevel | Value of dtb:depth attribute |
MOBI_RET mobi_write_ncx_level | ( | xmlTextWriterPtr | writer, |
const NCX * | ncx, | ||
const size_t | level, | ||
const size_t | from, | ||
const size_t | to, | ||
size_t * | seq | ||
) |
Write <navPoint> entries for given ncx level.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | ncx | Array of NCX structures with ncx content |
[in] | level | TOC level |
[in] | from | First entry in NCX array to copy from |
[in] | to | Last entry in NCX array to copy from |
[in] | seq | Sequential number for playOrder attribute |
MOBI_RET mobi_xml_write_dcmeta | ( | xmlTextWriterPtr | writer, |
const char * | name, | ||
const char ** | content | ||
) |
Write array of Dublin Core elements of given name to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | name | XML element name |
[in] | content | Array of XML element contents |
MOBI_RET mobi_xml_write_dcmeta_creator | ( | xmlTextWriterPtr | writer, |
const OPFcreator ** | creator, | ||
const char * | name | ||
) |
Write array of Dublin Core creator/contributor elements to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | creator | OPFcreator structure representing creator/contributor element |
[in] | name | OPF creator value |
MOBI_RET mobi_xml_write_dcmeta_date | ( | xmlTextWriterPtr | writer, |
const OPFdate ** | date | ||
) |
Write array of Dublin Core date elements to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | date | OPFdate structure representing date element |
MOBI_RET mobi_xml_write_dcmeta_identifier | ( | xmlTextWriterPtr | writer, |
const OPFidentifier ** | identifier | ||
) |
Write array of Dublin Core identifier elements to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | identifier | OPFidentifier structure representing identifier element |
MOBI_RET mobi_xml_write_dcmeta_subject | ( | xmlTextWriterPtr | writer, |
const OPFsubject ** | subject | ||
) |
Write array of Dublin Core subject elements to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | subject | OPFsubject structure representing subject element |
MOBI_RET mobi_xml_write_element_ns | ( | xmlTextWriterPtr | writer, |
const char * | name, | ||
const char ** | content, | ||
const char * | ns | ||
) |
Write array of xml elements of given name to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | name | XML element name |
[in] | content | Array of XML element contents |
[in] | ns | XML namespace string or NULL if empty |
MOBI_RET mobi_xml_write_item | ( | xmlTextWriterPtr | writer, |
const char * | id, | ||
const char * | href, | ||
const char * | media_type | ||
) |
Write single element to XML buffer.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | id | Attribute "id" |
[in] | href | Attribute "href" |
[in] | media_type | Attribute "media-type" |
MOBI_RET mobi_xml_write_manifest | ( | xmlTextWriterPtr | writer, |
const MOBIRawml * | rawml | ||
) |
Write all manifest elements to XML buffer.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | rawml | MOBIRawml structure containing parts metadata |
MOBI_RET mobi_xml_write_meta | ( | xmlTextWriterPtr | writer, |
const char * | name, | ||
const char * | content | ||
) |
Write element <meta name="name" content="content"> to XML buffer.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | name | Attribute name |
[in] | content | Attribute content |
MOBI_RET mobi_xml_write_opfmeta | ( | xmlTextWriterPtr | writer, |
const OPFmeta ** | meta | ||
) |
Write array of <meta> elements to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElement() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | meta | Array of OPFmeta structures |
MOBI_RET mobi_xml_write_reference | ( | xmlTextWriterPtr | writer, |
const OPFreference ** | reference | ||
) |
Write array of <referenece> elements to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElement() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | reference | Array of OPFreference structures |
MOBI_RET mobi_xml_write_spine | ( | xmlTextWriterPtr | writer, |
const MOBIRawml * | rawml | ||
) |
Write opf <spine> part to XML buffer.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | rawml | MOBIRawml structure containing parts metadata |
MOBI_RET mobi_xml_write_xmeta | ( | xmlTextWriterPtr | writer, |
const char * | name, | ||
const char ** | content | ||
) |
Write array of custom MOBI elements of given name to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | name | XML element name |
[in] | content | Array of XML element contents |
MOBI_RET mobi_xml_write_xmeta_srp | ( | xmlTextWriterPtr | writer, |
const OPFsrp ** | srp | ||
) |
Write array of custom srp elements to XML buffer.
Wrapper for libxml2 xmlTextWriterWriteElementNS() function. Writes xml element for each not-null entry in the input array.
[in,out] | writer | xmlTextWriterPtr to write to |
[in] | srp | OPFsrp structure representing srp element |
const char* mobi_guide_types[] |
Array of valid OPF guide types.
http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.6