00001 #ifndef EPUBLIB_H
00002 #define EPUBLIB_H 1
00003
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <errno.h>
00007
00008
00009 #include <zip.h>
00010 #include <zlib.h>
00011
00012
00013 #include <libxml/xmlreader.h>
00014
00015
00016 #include "linklist.h"
00017 #include "epub_shared.h"
00018
00019
00020 #ifdef _WIN32
00021 # define PATH_SEPARATOR '\\'
00022 #else
00023 # define PATH_SEPARATOR '/'
00024 #endif
00025
00026 #ifdef __GNUC__
00027 # define PRINTF_FORMAT(si, ftc) __attribute__ ((format (printf, si, ftc)))
00028 #else
00029 # define PRINTF_FORMAT(si, ftc)
00030 #endif
00031
00032
00033 #ifdef _MSC_VER
00034 # define strdup _strdup
00035 #endif
00036
00037
00038
00039
00040 #define METAINFO_DIR "META-INF"
00041 #define MIMETYPE_FILENAME "mimetype"
00042 #define CONTAINER_FILENAME "container.xml"
00043 #define MANIFEST_FILENAME "manifest.xml"
00044 #define METADATA_FILENAME "metadata.xml"
00045 #define SIGNATURES_FILENAME "signatures.xml"
00046 #define ENCRYPTION_FILENAME "encryption.xml"
00047 #define RIGHTS_FILENAME "rights.xml"
00048
00049
00050 struct root {
00051 xmlChar *mediatype;
00052 xmlChar *fullpath;
00053 };
00054
00055
00056 struct ocf {
00057 char *datapath;
00058 char *filename;
00059 struct zip *arch;
00060 char *mimetype;
00061 listPtr roots;
00062 struct epub *epub;
00063 };
00064
00065 struct meta {
00066 xmlChar *name;
00067 xmlChar *content;
00068 };
00069
00070 struct id {
00071 xmlChar *id;
00072 xmlChar *scheme;
00073 xmlChar *string;
00074 };
00075
00076 struct date {
00077 xmlChar *date;
00078 xmlChar *event;
00079 };
00080
00081 struct creator {
00082 xmlChar *name;
00083 xmlChar *fileAs;
00084 xmlChar *role;
00085 };
00086
00087 struct metadata {
00088 listPtr id;
00089 listPtr title;
00090 listPtr creator;
00091 listPtr contrib;
00092 listPtr subject;
00093 listPtr publisher;
00094 listPtr description;
00095 listPtr date;
00096 listPtr type;
00097 listPtr format;
00098 listPtr source;
00099 listPtr lang;
00100 listPtr relation;
00101 listPtr coverage;
00102 listPtr rights;
00103 listPtr meta;
00104 };
00105
00106 struct manifest {
00107 xmlChar *nspace;
00108 xmlChar *modules;
00109 xmlChar *id;
00110 xmlChar *href;
00111 xmlChar *type;
00112 xmlChar *fallback;
00113 xmlChar *fbStyle;
00114
00115 };
00116
00117 struct guide {
00118 xmlChar *type;
00119 xmlChar *title;
00120 xmlChar *href;
00121 };
00122
00123 struct site {
00124 xmlChar *title;
00125 xmlChar *href;
00126 };
00127
00128 struct tour {
00129 xmlChar *id;
00130 xmlChar *title;
00131 listPtr sites;
00132 };
00133
00134
00135 struct tocLabel {
00136 xmlChar *lang;
00137 xmlChar *dir;
00138 xmlChar *text;
00139 };
00140
00141
00142 struct tocItem {
00143 xmlChar *id;
00144 xmlChar *src;
00145 xmlChar *class;
00146 xmlChar *type;
00147 listPtr label;
00148 int depth;
00149 int playOrder;
00150 int value;
00151 };
00152
00153
00154 struct tocCategory {
00155 xmlChar *id;
00156 xmlChar *class;
00157 listPtr info;
00158 listPtr label;
00159 listPtr items;
00160 };
00161
00162
00163 struct toc {
00164 struct tocCategory *navMap;
00165 struct tocCategory *pageList;
00166 struct tocCategory *navList;
00167 listPtr playOrder;
00168 };
00169
00170 struct spine {
00171 xmlChar *idref;
00172 int linear;
00173 };
00174
00175 struct opf {
00176 char *name;
00177 xmlChar *tocName;
00178 struct epub *epub;
00179 struct metadata *metadata;
00180 struct toc *toc;
00181 listPtr manifest;
00182 listPtr spine;
00183 int linearCount;
00184
00185
00186 listPtr guide;
00187 listPtr tours;
00188 };
00189
00190 struct epuberr {
00191 char lastStr[1025];
00192 const char *str;
00193 int len;
00194 int type;
00195 };
00196 extern const char _epub_error_oom[];
00197 #define _epub_err_set_const_str(_err, _err_string) \
00198 do { \
00199 (_err)->str = _err_string; \
00200 (_err)->type = 1; \
00201 } while (0)
00202 #define _epub_err_set_str(_err, _err_string, _err_string_len) \
00203 do { \
00204 strncpy((_err)->lastStr, _err_string, _err_string_len); \
00205 (_err)->len = _err_string_len; \
00206 (_err)->str = (_err)->lastStr; \
00207 (_err)->type = 0; \
00208 } while (0)
00209 #define _epub_err_set_oom(_epub_err) _epub_err_set_const_str(_epub_err, _epub_error_oom)
00210
00211
00212 struct epub {
00213 struct ocf *ocf;
00214 struct opf *opf;
00215 struct epuberr error;
00216 int debug;
00217
00218 };
00219
00220 enum {
00221 DEBUG_NONE,
00222 DEBUG_ERROR,
00223 DEBUG_WARNING,
00224 DEBUG_INFO,
00225 DEBUG_VERBOSE
00226 };
00227
00228 struct eiterator {
00229 enum eiterator_type type;
00230 struct epub *epub;
00231 int opt;
00232 listnodePtr curr;
00233 char *cache;
00234 };
00235
00236 struct tit_info {
00237 char *label;
00238 int depth;
00239 char *link;
00240 };
00241
00242 struct titerator {
00243 enum titerator_type type;
00244 struct epub *epub;
00245 int opt;
00246 listnodePtr next;
00247 struct tit_info cache;
00248 int valid;
00249 };
00250
00251
00252 struct ocf *_ocf_parse(struct epub *epub, const char *filename);
00253 void _ocf_dump(struct ocf *ocf);
00254 void _ocf_close(struct ocf *ocf);
00255 struct zip *_ocf_open(struct ocf *ocf, const char *fileName);
00256 int _ocf_get_file(struct ocf *ocf, const char *filename, char **fileStr);
00257 int _ocf_get_data_file(struct ocf *ocf, const char *filename, char **fileStr);
00258 int _ocf_check_file(struct ocf *ocf, const char *filename);
00259 char *_ocf_root_by_type(struct ocf *ocf, const char *type);
00260 char *_ocf_root_fullpath_by_type(struct ocf *ocf, const char *type);
00261
00262
00263 int _ocf_parse_container(struct ocf *ocf);
00264 int _ocf_parse_mimetype(struct ocf *ocf);
00265
00266
00267 struct opf *_opf_parse(struct epub *epub, char *opfStr);
00268 void _opf_dump(struct opf *opf);
00269 void _opf_close(struct opf *opf);
00270
00271 void _opf_parse_metadata(struct opf *opf, xmlTextReaderPtr reader);
00272 void _opf_parse_spine(struct opf *opf, xmlTextReaderPtr reader);
00273 void _opf_parse_manifest(struct opf *opf, xmlTextReaderPtr reader);
00274 void _opf_parse_guide(struct opf *opf, xmlTextReaderPtr reader);
00275 void _opf_parse_tours(struct opf *opf, xmlTextReaderPtr reader);
00276
00277
00278 void _opf_parse_toc(struct opf *opf, char *tocStr, int size);
00279 void _opf_parse_navlist(struct opf *opf, xmlTextReaderPtr reader);
00280 void _opf_parse_navmap(struct opf *opf, xmlTextReaderPtr reader);
00281 void _opf_parse_pagelist(struct opf *opf, xmlTextReaderPtr reader);
00282 struct tocLabel *_opf_parse_navlabel(struct opf *opf, xmlTextReaderPtr reader);
00283 void _opf_free_toc_category(struct tocCategory *tc);
00284 void _opf_free_toc(struct toc *toc);
00285 struct toc *_opf_init_toc();
00286 struct tocCategory *_opf_init_toc_category();
00287
00288 xmlChar *_opf_label_get_by_lang(struct opf *opf, listPtr label, char *lang);
00289 xmlChar *_opf_label_get_by_doc_lang(struct opf *opf, listPtr label);
00290
00291 struct manifest *_opf_manifest_get_by_id(struct opf *opf, xmlChar* id);
00292
00293
00294 struct epub *epub_open(const char *filename, int debug);
00295 void _epub_print_debug(struct epub *epub, int debug, const char *format, ...) PRINTF_FORMAT(3, 4);
00296 char *epub_last_errStr(struct epub *epub);
00297
00298
00299 void _list_free_root(struct root *data);
00300
00301 void _list_free_creator(struct creator *data);
00302 void _list_free_date(struct date *date);
00303 void _list_free_id(struct id *id);
00304 void _list_free_meta(struct meta *meta);
00305
00306 void _list_free_spine(struct spine *spine);
00307 void _list_free_manifest(struct manifest *manifest);
00308 void _list_free_guide(struct guide *guide);
00309 void _list_free_tours(struct tour *tour);
00310
00311 void _list_free_toc_label(struct tocLabel *tl);
00312 void _list_free_toc_item(struct tocItem *ti);
00313
00314 int _list_cmp_root_by_mediatype(struct root *root1, struct root *root2);
00315 int _list_cmp_manifest_by_id(struct manifest *m1, struct manifest *m2);
00316 int _list_cmp_toc_by_playorder(struct tocItem *t1, struct tocItem *t2);
00317 int _list_cmp_label_by_lang(struct tocLabel *t1, struct tocLabel *t2);
00318
00319 void _list_dump_root(struct root *root);
00320
00321 void _list_dump_string(char *string);
00322 void _list_dump_creator(struct creator *data);
00323 void _list_dump_date(struct date *date);
00324 void _list_dump_id(struct id *id);
00325 void _list_dump_meta(struct meta *meta);
00326
00327 void _list_dump_spine(struct spine *spine);
00328 void _list_dump_guide(struct guide *guide);
00329 void _list_dump_tour(struct tour *tour);
00330
00331 #endif