EBOOK-TOOLS
epublib.h
Go to the documentation of this file.
1#ifndef EPUBLIB_H
2#define EPUBLIB_H 1
3// generally needed includes
4#include <stdlib.h>
5#include <string.h>
6#include <errno.h>
7
8// For opening the zip file
9#include <zip.h>
10#include <zlib.h>
11
12// For parsing xml
13#include <libxml/xmlreader.h>
14
15// For list stuff
16#include "linklist.h"
17#include "epub_shared.h"
18
19// General definitions
20#ifdef _WIN32
21# define PATH_SEPARATOR '\\'
22#else
23# define PATH_SEPARATOR '/'
24#endif
25
26#ifdef __GNUC__
27# define PRINTF_FORMAT(si, ftc) __attribute__ ((format (printf, si, ftc)))
28#else
29# define PRINTF_FORMAT(si, ftc)
30#endif
31
32// MSVC-specific definitions
33#ifdef _MSC_VER
34# define strdup _strdup
35#endif
36
37///////////////////////////////////////////////////////////
38// OCF definions
39///////////////////////////////////////////////////////////
40#define METAINFO_DIR "META-INF"
41#define MIMETYPE_FILENAME "mimetype"
42#define CONTAINER_FILENAME "container.xml"
43#define MANIFEST_FILENAME "manifest.xml"
44#define METADATA_FILENAME "metadata.xml"
45#define SIGNATURES_FILENAME "signatures.xml"
46#define ENCRYPTION_FILENAME "encryption.xml"
47#define RIGHTS_FILENAME "rights.xml"
48
49// An OCF root
50struct root {
51 xmlChar *mediatype; // media type (mime)
52 xmlChar *fullpath; // full path to the root
53};
54
55
56struct ocf {
57 char *datapath; // The path that the data files relative to
58 char *filename; // The ebook filename
59 struct zip *arch; // The epub zip
60 char *mimetype; // For debugging
61 listPtr roots; // list of OCF roots
62 struct epub *epub; // back pointer
63};
64
65struct meta {
66 xmlChar *name;
67 xmlChar *content;
68};
69
70struct id {
71 xmlChar *id;
72 xmlChar *scheme;
73 xmlChar *string;
74};
75
76struct date {
77 xmlChar *date;
78 xmlChar *event;
79};
80
81struct creator {
82 xmlChar *name;
83 xmlChar *fileAs;
84 xmlChar *role;
85};
86
87struct metadata {
104};
105
106struct manifest {
107 xmlChar *nspace;
108 xmlChar *modules;
109 xmlChar *id;
110 xmlChar *href;
111 xmlChar *type;
112 xmlChar *fallback;
113 xmlChar *fbStyle;
114
115};
116
117struct guide {
118 xmlChar *type;
119 xmlChar *title;
120 xmlChar *href;
121};
122
123struct site {
124 xmlChar *title;
125 xmlChar *href;
126};
127
128struct tour {
129 xmlChar *id;
130 xmlChar *title;
132};
133
134// Struct for navLabel and navInfo
135struct tocLabel {
136 xmlChar *lang;
137 xmlChar *dir;
138 xmlChar *text;
139};
140
141// struct for navPoint, pageTarget, navTarget
142struct tocItem {
143 xmlChar *id;
144 xmlChar *src;
145 xmlChar *class;
146 xmlChar *type; //pages
148 int depth;
150 int value;
151};
152
153// struct for navMap, pageList, navList
155 xmlChar *id;
156 xmlChar *class;
157 listPtr info; //tocLabel
158 listPtr label; //tocLabel
159 listPtr items; //tocItem
160};
161
162// General toc struct
163struct toc {
168};
169
170struct spine {
171 xmlChar *idref;
172 int linear; //bool
173};
174
175struct opf {
176 char *name;
177 xmlChar *tocName;
178 struct epub *epub;
180 struct toc *toc; // must in opf 2.0
184
185 // might be NULL
188};
189
190struct epuberr {
191 char lastStr[1025];
192 const char *str;
193 int len;
194 int type; /* for str: 0 = lastStr, 1 = external */
195};
196extern const char _epub_error_oom[];
197#define _epub_err_set_const_str(_err, _err_string) \
198 do { \
199 (_err)->str = _err_string; \
200 (_err)->type = 1; \
201 } while (0)
202#define _epub_err_set_str(_err, _err_string, _err_string_len) \
203 do { \
204 strncpy((_err)->lastStr, _err_string, _err_string_len); \
205 (_err)->len = _err_string_len; \
206 (_err)->str = (_err)->lastStr; \
207 (_err)->type = 0; \
208 } while (0)
209#define _epub_err_set_oom(_epub_err) _epub_err_set_const_str(_epub_err, _epub_error_oom)
210
211// general structs
212struct epub {
213 struct ocf *ocf;
214 struct opf *opf;
216 int debug;
217
218};
219
220enum {
227
228struct eiterator {
230 struct epub *epub;
231 int opt;
233 char *cache;
234};
235
236struct tit_info {
237 char *label;
238 int depth;
239 char *link;
240};
241
242struct titerator {
244 struct epub *epub;
245 int opt;
248 int valid;
249};
250
251// Ocf functions
252struct ocf *_ocf_parse(struct epub *epub, const char *filename);
253void _ocf_dump(struct ocf *ocf);
254void _ocf_close(struct ocf *ocf);
255struct zip *_ocf_open(struct ocf *ocf, const char *fileName);
256int _ocf_get_file(struct ocf *ocf, const char *filename, char **fileStr);
257int _ocf_get_data_file(struct ocf *ocf, const char *filename, char **fileStr);
258int _ocf_check_file(struct ocf *ocf, const char *filename);
259char *_ocf_root_by_type(struct ocf *ocf, const char *type);
260char *_ocf_root_fullpath_by_type(struct ocf *ocf, const char *type);
261
262// Parsing ocf
265
266// parsing opf
267struct opf *_opf_parse(struct epub *epub, char *opfStr);
268void _opf_dump(struct opf *opf);
269void _opf_close(struct opf *opf);
270
271void _opf_parse_metadata(struct opf *opf, xmlTextReaderPtr reader);
272void _opf_parse_spine(struct opf *opf, xmlTextReaderPtr reader);
273void _opf_parse_manifest(struct opf *opf, xmlTextReaderPtr reader);
274void _opf_parse_guide(struct opf *opf, xmlTextReaderPtr reader);
275void _opf_parse_tours(struct opf *opf, xmlTextReaderPtr reader);
276
277// parse toc
278void _opf_parse_toc(struct opf *opf, char *tocStr, int size);
279void _opf_parse_navlist(struct opf *opf, xmlTextReaderPtr reader);
280void _opf_parse_navmap(struct opf *opf, xmlTextReaderPtr reader);
281void _opf_parse_pagelist(struct opf *opf, xmlTextReaderPtr reader);
282struct tocLabel *_opf_parse_navlabel(struct opf *opf, xmlTextReaderPtr reader);
284void _opf_free_toc(struct toc *toc);
287
288xmlChar *_opf_label_get_by_lang(struct opf *opf, listPtr label, char *lang);
290
291struct manifest *_opf_manifest_get_by_id(struct opf *opf, xmlChar* id);
292
293// epub functions
294struct epub *epub_open(const char *filename, int debug);
295void _epub_print_debug(struct epub *epub, int debug, const char *format, ...) PRINTF_FORMAT(3, 4);
297
298// List operations
299void _list_free_root(struct root *data);
300
301void _list_free_creator(struct creator *data);
303void _list_free_id(struct id *id);
305
310
313
314int _list_cmp_root_by_mediatype(struct root *root1, struct root *root2);
315int _list_cmp_manifest_by_id(struct manifest *m1, struct manifest *m2);
316int _list_cmp_toc_by_playorder(struct tocItem *t1, struct tocItem *t2);
317int _list_cmp_label_by_lang(struct tocLabel *t1, struct tocLabel *t2);
318
320
321void _list_dump_string(char *string);
322void _list_dump_creator(struct creator *data);
324void _list_dump_id(struct id *id);
326
330
331#endif /* epublib_h */
eiterator_type
Ebook Iterator types.
Definition: epub_shared.h:39
titerator_type
Ebook Table Of Content Iterator types.
Definition: epub_shared.h:49
#define PRINTF_FORMAT(si, ftc)
Definition: epublib.h:29
int _ocf_check_file(struct ocf *ocf, const char *filename)
@ DEBUG_VERBOSE
Definition: epublib.h:225
@ DEBUG_ERROR
Definition: epublib.h:222
@ DEBUG_INFO
Definition: epublib.h:224
@ DEBUG_WARNING
Definition: epublib.h:223
@ DEBUG_NONE
Definition: epublib.h:221
int _ocf_parse_container(struct ocf *ocf)
void _opf_parse_metadata(struct opf *opf, xmlTextReaderPtr reader)
char * _ocf_root_fullpath_by_type(struct ocf *ocf, const char *type)
void _ocf_close(struct ocf *ocf)
void _opf_parse_pagelist(struct opf *opf, xmlTextReaderPtr reader)
void _list_free_guide(struct guide *guide)
void _opf_dump(struct opf *opf)
void _list_free_manifest(struct manifest *manifest)
struct epub * epub_open(const char *filename, int debug)
void _list_free_tours(struct tour *tour)
void _list_free_creator(struct creator *data)
void _list_dump_guide(struct guide *guide)
struct tocLabel * _opf_parse_navlabel(struct opf *opf, xmlTextReaderPtr reader)
void _list_free_id(struct id *id)
void _opf_parse_manifest(struct opf *opf, xmlTextReaderPtr reader)
struct zip * _ocf_open(struct ocf *ocf, const char *fileName)
int _ocf_get_data_file(struct ocf *ocf, const char *filename, char **fileStr)
void _list_free_date(struct date *date)
void _opf_parse_spine(struct opf *opf, xmlTextReaderPtr reader)
int _list_cmp_root_by_mediatype(struct root *root1, struct root *root2)
void _list_free_root(struct root *data)
void _opf_close(struct opf *opf)
int _list_cmp_label_by_lang(struct tocLabel *t1, struct tocLabel *t2)
void _opf_free_toc_category(struct tocCategory *tc)
void _list_free_toc_item(struct tocItem *ti)
int _ocf_get_file(struct ocf *ocf, const char *filename, char **fileStr)
void _list_free_toc_label(struct tocLabel *tl)
void _epub_print_debug(struct epub *epub, int debug, const char *format,...) PRINTF_FORMAT(3
void _list_free_meta(struct meta *meta)
void _opf_free_toc(struct toc *toc)
int _list_cmp_manifest_by_id(struct manifest *m1, struct manifest *m2)
void _list_free_spine(struct spine *spine)
void _opf_parse_guide(struct opf *opf, xmlTextReaderPtr reader)
void _list_dump_id(struct id *id)
void _list_dump_root(struct root *root)
void _ocf_dump(struct ocf *ocf)
const char _epub_error_oom[]
void _list_dump_meta(struct meta *meta)
struct manifest * _opf_manifest_get_by_id(struct opf *opf, xmlChar *id)
void _list_dump_tour(struct tour *tour)
xmlChar * _opf_label_get_by_lang(struct opf *opf, listPtr label, char *lang)
int _ocf_parse_mimetype(struct ocf *ocf)
void _opf_parse_navlist(struct opf *opf, xmlTextReaderPtr reader)
void char * epub_last_errStr(struct epub *epub)
struct ocf * _ocf_parse(struct epub *epub, const char *filename)
char * _ocf_root_by_type(struct ocf *ocf, const char *type)
struct opf * _opf_parse(struct epub *epub, char *opfStr)
struct toc * _opf_init_toc()
void _list_dump_string(char *string)
void _opf_parse_navmap(struct opf *opf, xmlTextReaderPtr reader)
xmlChar * _opf_label_get_by_doc_lang(struct opf *opf, listPtr label)
void _opf_parse_toc(struct opf *opf, char *tocStr, int size)
void _list_dump_spine(struct spine *spine)
int _list_cmp_toc_by_playorder(struct tocItem *t1, struct tocItem *t2)
void _opf_parse_tours(struct opf *opf, xmlTextReaderPtr reader)
struct tocCategory * _opf_init_toc_category()
void _list_dump_date(struct date *date)
void _list_dump_creator(struct creator *data)
xmlChar * role
Definition: epublib.h:84
xmlChar * fileAs
Definition: epublib.h:83
xmlChar * name
Definition: epublib.h:82
Definition: epublib.h:76
xmlChar * event
Definition: epublib.h:78
xmlChar * date
Definition: epublib.h:77
private iterator struct
Definition: epublib.h:228
int opt
Definition: epublib.h:231
struct epub * epub
Definition: epublib.h:230
listnodePtr curr
Definition: epublib.h:232
char * cache
Definition: epublib.h:233
enum eiterator_type type
Definition: epublib.h:229
private struct containting information about the epub file
Definition: epublib.h:212
struct epuberr error
Definition: epublib.h:215
int debug
Definition: epublib.h:216
struct opf * opf
Definition: epublib.h:214
struct ocf * ocf
Definition: epublib.h:213
int type
Definition: epublib.h:194
const char * str
Definition: epublib.h:192
int len
Definition: epublib.h:193
char lastStr[1025]
Definition: epublib.h:191
Definition: epublib.h:117
xmlChar * type
Definition: epublib.h:118
xmlChar * title
Definition: epublib.h:119
xmlChar * href
Definition: epublib.h:120
Definition: epublib.h:70
xmlChar * scheme
Definition: epublib.h:72
xmlChar * id
Definition: epublib.h:71
xmlChar * string
Definition: epublib.h:73
xmlChar * fallback
Definition: epublib.h:112
xmlChar * nspace
Definition: epublib.h:107
xmlChar * fbStyle
Definition: epublib.h:113
xmlChar * id
Definition: epublib.h:109
xmlChar * type
Definition: epublib.h:111
xmlChar * modules
Definition: epublib.h:108
xmlChar * href
Definition: epublib.h:110
Definition: epublib.h:65
xmlChar * content
Definition: epublib.h:67
xmlChar * name
Definition: epublib.h:66
listPtr relation
Definition: epublib.h:100
listPtr description
Definition: epublib.h:94
listPtr lang
Definition: epublib.h:99
listPtr meta
Definition: epublib.h:103
listPtr id
Definition: epublib.h:88
listPtr date
Definition: epublib.h:95
listPtr publisher
Definition: epublib.h:93
listPtr format
Definition: epublib.h:97
listPtr rights
Definition: epublib.h:102
listPtr type
Definition: epublib.h:96
listPtr coverage
Definition: epublib.h:101
listPtr subject
Definition: epublib.h:92
listPtr source
Definition: epublib.h:98
listPtr title
Definition: epublib.h:89
listPtr creator
Definition: epublib.h:90
listPtr contrib
Definition: epublib.h:91
Definition: epublib.h:56
struct epub * epub
Definition: epublib.h:62
struct zip * arch
Definition: epublib.h:59
listPtr roots
Definition: epublib.h:61
char * datapath
Definition: epublib.h:57
char * filename
Definition: epublib.h:58
char * mimetype
Definition: epublib.h:60
Definition: epublib.h:175
listPtr spine
Definition: epublib.h:182
listPtr guide
Definition: epublib.h:186
struct metadata * metadata
Definition: epublib.h:179
listPtr manifest
Definition: epublib.h:181
int linearCount
Definition: epublib.h:183
struct epub * epub
Definition: epublib.h:178
struct toc * toc
Definition: epublib.h:180
xmlChar * tocName
Definition: epublib.h:177
char * name
Definition: epublib.h:176
listPtr tours
Definition: epublib.h:187
Definition: epublib.h:50
xmlChar * mediatype
Definition: epublib.h:51
xmlChar * fullpath
Definition: epublib.h:52
Definition: epublib.h:123
xmlChar * href
Definition: epublib.h:125
xmlChar * title
Definition: epublib.h:124
Definition: epublib.h:170
int linear
Definition: epublib.h:172
xmlChar * idref
Definition: epublib.h:171
char * label
Definition: epublib.h:237
int depth
Definition: epublib.h:238
char * link
Definition: epublib.h:239
enum titerator_type type
Definition: epublib.h:243
struct epub * epub
Definition: epublib.h:244
listnodePtr next
Definition: epublib.h:246
int valid
Definition: epublib.h:248
int opt
Definition: epublib.h:245
struct tit_info cache
Definition: epublib.h:247
xmlChar * id
Definition: epublib.h:155
listPtr info
Definition: epublib.h:157
listPtr label
Definition: epublib.h:158
listPtr items
Definition: epublib.h:159
int playOrder
Definition: epublib.h:149
listPtr label
Definition: epublib.h:147
int value
Definition: epublib.h:150
xmlChar * src
Definition: epublib.h:144
xmlChar * id
Definition: epublib.h:143
int depth
Definition: epublib.h:148
xmlChar * type
Definition: epublib.h:146
xmlChar * lang
Definition: epublib.h:136
xmlChar * dir
Definition: epublib.h:137
xmlChar * text
Definition: epublib.h:138
Definition: epublib.h:163
listPtr playOrder
Definition: epublib.h:167
struct tocCategory * navMap
Definition: epublib.h:164
struct tocCategory * pageList
Definition: epublib.h:165
struct tocCategory * navList
Definition: epublib.h:166
Definition: epublib.h:128
listPtr sites
Definition: epublib.h:131
xmlChar * title
Definition: epublib.h:130
xmlChar * id
Definition: epublib.h:129