libmobi
C library for handling MOBI format ebook documents
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mobi.h
Go to the documentation of this file.
1 
16 #ifndef libmobi_mobi_h
17 #define libmobi_mobi_h
18 
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include <time.h>
23 
25 #if defined (__CYGWIN__) || defined (__MINGW32__)
26 #define MOBI_EXPORT __attribute__((visibility("default"))) __declspec(dllexport) extern
27 #elif defined (_WIN32)
28 #define MOBI_EXPORT __declspec(dllexport)
29 #else
30 #define MOBI_EXPORT __attribute__((__visibility__("default")))
31 #endif
32 
37 #define MOBI_NOTSET UINT32_MAX
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43 
51  typedef enum {
53  MOBI_ERROR = 1,
62  MOBI_XML_ERR = 10,
67  } MOBI_RET;
68 
72  typedef enum {
73  EXTH_NUMERIC = 0,
74  EXTH_STRING = 1,
75  EXTH_BINARY = 2
76  } MOBIExthType;
77 
81  typedef enum {
82  EXTH_DRMSERVER = 1,
83  EXTH_DRMCOMMERCE = 2,
84  EXTH_DRMEBOOKBASE = 3,
85 
86  EXTH_TITLE = 99,
87  EXTH_AUTHOR = 100,
89  EXTH_IMPRINT = 102,
91  EXTH_ISBN = 104,
92  EXTH_SUBJECT = 105,
94  EXTH_REVIEW = 107,
96  EXTH_RIGHTS = 109,
98  EXTH_TYPE = 111,
99  EXTH_SOURCE = 112,
100  EXTH_ASIN = 113,
101  EXTH_VERSION = 114,
102  EXTH_SAMPLE = 115,
104  EXTH_ADULT = 117,
105  EXTH_PRICE = 118,
107  EXTH_KF8BOUNDARY = 121,
111  EXTH_COUNTRESOURCES = 125,
115  EXTH_KF8COVERURI = 129,
116  EXTH_RESCOFFSET = 131,
121  EXTH_THUMBOFFSET = 202,
122  EXTH_HASFAKECOVER = 203,
123  EXTH_CREATORSOFT = 204,
124  EXTH_CREATORMAJOR = 205,
125  EXTH_CREATORMINOR = 206,
126  EXTH_CREATORBUILD = 207,
127  EXTH_WATERMARK = 208,
128  EXTH_TAMPERKEYS = 209,
129 
130  EXTH_FONTSIGNATURE = 300,
131 
132  EXTH_CLIPPINGLIMIT = 401,
133  EXTH_PUBLISHERLIMIT = 402,
134  EXTH_UNK403 = 403,
135  EXTH_TTSDISABLE = 404,
136  EXTH_UNK405 = 405,
137  EXTH_RENTAL = 406,
138  EXTH_UNK407 = 407,
139  EXTH_UNK450 = 450,
140  EXTH_UNK451 = 451,
141  EXTH_UNK452 = 452,
142  EXTH_UNK453 = 453,
143 
144  EXTH_DOCTYPE = 501,
145  EXTH_LASTUPDATE = 502,
146  EXTH_UPDATEDTITLE = 503,
147  EXTH_ASIN504 = 504,
148  EXTH_TITLEFILEAS = 508,
149  EXTH_CREATORFILEAS = 517,
150  EXTH_PUBLISHERFILEAS = 522,
153  EXTH_CREATORSTRING = 526,
154  EXTH_PAGEDIR = 527,
156  EXTH_SORCEDESC = 529,
157  EXTH_DICTLANGIN = 531,
158  EXTH_DICTLANGOUT = 532,
159  EXTH_INPUTSOURCE = 534,
160  EXTH_CREATORBUILDREV = 535,
161  } MOBIExthTag;
162 
166  typedef enum {
168  /* markup */
174  /* images */
179  /* fonts */
182  /* media */
186  /* generic types */
191  } MOBIFiletype;
192 
196  typedef struct {
198  char extension[5];
199  char mime_type[30];
200  } MOBIFileMeta;
201 
208  typedef enum {
209  MOBI_CP1252 = 1252,
210  MOBI_UTF8 = 65001,
211  MOBI_UTF16 = 65002,
212  } MOBIEncoding;
223  typedef struct {
224  char name[33];
225  uint16_t attributes;
226  uint16_t version;
227  uint32_t ctime;
228  uint32_t mtime;
229  uint32_t btime;
230  uint32_t mod_num;
231  uint32_t appinfo_offset;
232  uint32_t sortinfo_offset;
233  char type[5];
234  char creator[5];
235  uint32_t uid;
236  uint32_t next_rec;
237  uint16_t rec_count;
238  } MOBIPdbHeader;
239 
243  typedef struct MOBIPdbRecord {
244  uint32_t offset;
245  size_t size;
246  uint8_t attributes;
247  uint32_t uid;
248  unsigned char *data;
249  struct MOBIPdbRecord *next;
250  } MOBIPdbRecord;
251 
255  typedef struct MOBIExthHeader {
256  uint32_t tag;
257  uint32_t size;
258  void *data;
260  } MOBIExthHeader;
261 
265  typedef struct {
268  char *name;
269  } MOBIExthMeta;
270 
274  typedef struct {
275  /* PalmDOC header (extended), offset 0, length 16 */
276  uint16_t compression_type;
277  /* uint16_t unused; // 2; 0 */
278  uint32_t text_length;
279  uint16_t text_record_count;
280  uint16_t text_record_size;
281  uint16_t encryption_type;
282  uint16_t unknown1;
284 
290  typedef struct {
291  /* MOBI header, offset 16 */
292  char mobi_magic[5];
293  uint32_t *header_length;
294  uint32_t *mobi_type;
296  uint32_t *uid;
297  uint32_t *version;
298  uint32_t *orth_index;
299  uint32_t *infl_index;
300  uint32_t *names_index;
301  uint32_t *keys_index;
302  uint32_t *extra0_index;
303  uint32_t *extra1_index;
304  uint32_t *extra2_index;
305  uint32_t *extra3_index;
306  uint32_t *extra4_index;
307  uint32_t *extra5_index;
308  uint32_t *non_text_index;
309  uint32_t *full_name_offset;
310  uint32_t *full_name_length;
311  uint32_t *locale;
312  uint32_t *dict_input_lang;
313  uint32_t *dict_output_lang;
314  uint32_t *min_version;
315  uint32_t *image_index;
316  uint32_t *huff_rec_index;
317  uint32_t *huff_rec_count;
318  uint32_t *datp_rec_index;
319  uint32_t *datp_rec_count;
320  uint32_t *exth_flags;
321  /* 32 unknown bytes 0? */
322  /* unknown2 */
323  /* unknown3 */
324  /* unknown4 */
325  /* unknown5 */
326  uint32_t *unknown6;
327  uint32_t *drm_offset;
328  uint32_t *drm_count;
329  uint32_t *drm_size;
330  uint32_t *drm_flags;
331  /* 8 unknown bytes 0? */
332  /* unknown7 */
333  /* unknown8 */
334  uint16_t *first_text_index;
335  uint16_t *last_text_index;
336  uint32_t *fdst_index;
337  //uint32_t *unknown9; /**< 196: */
338  uint32_t *fdst_section_count;
339  uint32_t *fcis_index;
340  uint32_t *fcis_count;
341  uint32_t *flis_index;
342  uint32_t *flis_count;
343  uint32_t *unknown10;
344  uint32_t *unknown11;
345  uint32_t *srcs_index;
346  uint32_t *srcs_count;
347  uint32_t *unknown12;
348  uint32_t *unknown13;
349  /* uint16_t fill 0 */
350  uint16_t *extra_flags;
351  uint32_t *ncx_index;
352  uint32_t *unknown14;
353  uint32_t *fragment_index;
354  uint32_t *unknown15;
355  uint32_t *skeleton_index;
356  uint32_t *datp_index;
357  uint32_t *unknown16;
358  uint32_t *guide_index;
359  uint32_t *unknown17;
360  uint32_t *unknown18;
361  uint32_t *unknown19;
362  uint32_t *unknown20;
363  char *full_name;
364  } MOBIMobiHeader;
365 
373  typedef struct MOBIData {
374  bool use_kf8;
376  unsigned char *drm_key;
382  struct MOBIData *next;
383  } MOBIData;
384  // end of raw_structs group
386 
398  typedef struct {
401  uint32_t *fdst_section_ends;
402  } MOBIFdst;
403 
407  typedef struct {
408  size_t tagid;
410  uint32_t *tagvalues;
411  } MOBIIndexTag;
412 
416  typedef struct {
417  char *label;
418  size_t tags_count;
420  } MOBIIndexEntry;
421 
425  typedef struct {
426  size_t type;
427  size_t entries_count;
430  size_t ordt_offset;
431  size_t ligt_offset;
437  } MOBIIndx;
438 
444  typedef struct MOBIPart {
445  size_t uid;
447  size_t size;
448  unsigned char *data;
449  struct MOBIPart *next;
450  } MOBIPart;
451 
455  typedef struct {
456  size_t version;
467  } MOBIRawml;
468  // end of parsed_structs group
470 
475  MOBI_EXPORT const char * mobi_version(void);
477  MOBI_EXPORT MOBI_RET mobi_load_filename(MOBIData *m, const char *path);
478 
480  MOBI_EXPORT void mobi_free(MOBIData *m);
481 
484 
486  MOBI_EXPORT MOBI_RET mobi_parse_rawml_opt(MOBIRawml *rawml, const MOBIData *m, bool parse_toc, bool parse_dict, bool reconstruct);
487 
488  MOBI_EXPORT MOBI_RET mobi_get_rawml(const MOBIData *m, char *text, size_t *len);
489  MOBI_EXPORT MOBI_RET mobi_dump_rawml(const MOBIData *m, FILE *file);
490  MOBI_EXPORT MOBI_RET mobi_decode_font_resource(unsigned char **decoded_font, size_t *decoded_size, MOBIPart *part);
491  MOBI_EXPORT MOBI_RET mobi_decode_audio_resource(unsigned char **decoded_resource, size_t *decoded_size, MOBIPart *part);
492  MOBI_EXPORT MOBI_RET mobi_decode_video_resource(unsigned char **decoded_resource, size_t *decoded_size, MOBIPart *part);
493  MOBI_EXPORT MOBI_RET mobi_get_embedded_source(unsigned char **data, size_t *size, const MOBIData *m);
494  MOBI_EXPORT MOBI_RET mobi_get_embedded_log(unsigned char **data, size_t *size, const MOBIData *m);
495 
496  MOBI_EXPORT MOBIPdbRecord * mobi_get_record_by_uid(const MOBIData *m, const size_t uid);
497  MOBI_EXPORT MOBIPdbRecord * mobi_get_record_by_seqnumber(const MOBIData *m, const size_t uid);
498  MOBI_EXPORT MOBIPart * mobi_get_flow_by_uid(const MOBIRawml *rawml, const size_t uid);
499  MOBI_EXPORT MOBIPart * mobi_get_flow_by_fid(const MOBIRawml *rawml, const char *fid);
500  MOBI_EXPORT MOBIPart * mobi_get_resource_by_uid(const MOBIRawml *rawml, const size_t uid);
501  MOBI_EXPORT MOBIPart * mobi_get_resource_by_fid(const MOBIRawml *rawml, const char *fid);
502  MOBI_EXPORT MOBIPart * mobi_get_part_by_uid(const MOBIRawml *rawml, const size_t uid);
503  MOBI_EXPORT MOBI_RET mobi_get_fullname(const MOBIData *m, char *fullname, const size_t len);
505  MOBI_EXPORT size_t mobi_get_text_maxsize(const MOBIData *m);
507  MOBI_EXPORT size_t mobi_get_kf8offset(const MOBIData *m);
509  MOBI_EXPORT size_t mobi_get_record_extrasize(const MOBIPdbRecord *record, const uint16_t flags);
510  MOBI_EXPORT size_t mobi_get_record_mb_extrasize(const MOBIPdbRecord *record, const uint16_t flags);
511  MOBI_EXPORT size_t mobi_get_fileversion(const MOBIData *m);
516  MOBI_EXPORT MOBI_RET mobi_add_exthrecord(MOBIData *m, const MOBIExthTag tag, const uint32_t size, const void *value);
519  MOBI_EXPORT uint32_t mobi_decode_exthvalue(const unsigned char *data, const size_t size);
520  MOBI_EXPORT char * mobi_decode_exthstring(const MOBIData *m, const unsigned char *data, const size_t size);
521  MOBI_EXPORT struct tm * mobi_pdbtime_to_time(const long pdb_time);
522  MOBI_EXPORT const char * mobi_get_locale_string(const uint32_t locale);
523  MOBI_EXPORT size_t mobi_get_locale_number(const char *locale_string);
524 
526  MOBI_EXPORT bool mobi_exists_fdst(const MOBIData *m);
530  MOBI_EXPORT bool mobi_exists_ncx(const MOBIData *m);
531  MOBI_EXPORT bool mobi_exists_orth(const MOBIData *m);
532  MOBI_EXPORT bool mobi_exists_infl(const MOBIData *m);
533  MOBI_EXPORT bool mobi_is_hybrid(const MOBIData *m);
534  MOBI_EXPORT bool mobi_is_encrypted(const MOBIData *m);
535  MOBI_EXPORT bool mobi_is_mobipocket(const MOBIData *m);
536  MOBI_EXPORT bool mobi_is_dictionary(const MOBIData *m);
537  MOBI_EXPORT bool mobi_is_kf8(const MOBIData *m);
538  MOBI_EXPORT bool mobi_is_rawml_kf8(const MOBIRawml *rawml);
541 
542  MOBI_EXPORT char * mobi_meta_get_title(const MOBIData *m);
543  MOBI_EXPORT char * mobi_meta_get_author(const MOBIData *m);
545  MOBI_EXPORT char * mobi_meta_get_imprint(const MOBIData *m);
547  MOBI_EXPORT char * mobi_meta_get_isbn(const MOBIData *m);
548  MOBI_EXPORT char * mobi_meta_get_subject(const MOBIData *m);
550  MOBI_EXPORT char * mobi_meta_get_review(const MOBIData *m);
553  MOBI_EXPORT char * mobi_meta_get_asin(const MOBIData *m);
555  MOBI_EXPORT MOBI_RET mobi_meta_set_title(MOBIData *m, const char *title);
556  MOBI_EXPORT MOBI_RET mobi_meta_add_title(MOBIData *m, const char *title);
558  MOBI_EXPORT MOBI_RET mobi_meta_set_author(MOBIData *m, const char *author);
559  MOBI_EXPORT MOBI_RET mobi_meta_add_author(MOBIData *m, const char *author);
561  MOBI_EXPORT MOBI_RET mobi_meta_set_publisher(MOBIData *m, const char *publisher);
562  MOBI_EXPORT MOBI_RET mobi_meta_add_publisher(MOBIData *m, const char *publisher);
564  MOBI_EXPORT MOBI_RET mobi_meta_set_imprint(MOBIData *m, const char *imprint);
565  MOBI_EXPORT MOBI_RET mobi_meta_add_imprint(MOBIData *m, const char *imprint);
567  MOBI_EXPORT MOBI_RET mobi_meta_set_description(MOBIData *m, const char *description);
568  MOBI_EXPORT MOBI_RET mobi_meta_add_description(MOBIData *m, const char *description);
570  MOBI_EXPORT MOBI_RET mobi_meta_set_isbn(MOBIData *m, const char *isbn);
571  MOBI_EXPORT MOBI_RET mobi_meta_add_isbn(MOBIData *m, const char *isbn);
573  MOBI_EXPORT MOBI_RET mobi_meta_set_subject(MOBIData *m, const char *subject);
574  MOBI_EXPORT MOBI_RET mobi_meta_add_subject(MOBIData *m, const char *subject);
576  MOBI_EXPORT MOBI_RET mobi_meta_set_publishdate(MOBIData *m, const char *publishdate);
577  MOBI_EXPORT MOBI_RET mobi_meta_add_publishdate(MOBIData *m, const char *publishdate);
579  MOBI_EXPORT MOBI_RET mobi_meta_set_review(MOBIData *m, const char *review);
580  MOBI_EXPORT MOBI_RET mobi_meta_add_review(MOBIData *m, const char *review);
582  MOBI_EXPORT MOBI_RET mobi_meta_set_contributor(MOBIData *m, const char *contributor);
583  MOBI_EXPORT MOBI_RET mobi_meta_add_contributor(MOBIData *m, const char *contributor);
585  MOBI_EXPORT MOBI_RET mobi_meta_set_copyright(MOBIData *m, const char *copyright);
586  MOBI_EXPORT MOBI_RET mobi_meta_add_copyright(MOBIData *m, const char *copyright);
588  MOBI_EXPORT MOBI_RET mobi_meta_set_asin(MOBIData *m, const char *asin);
589  MOBI_EXPORT MOBI_RET mobi_meta_add_asin(MOBIData *m, const char *asin);
591  MOBI_EXPORT MOBI_RET mobi_meta_set_language(MOBIData *m, const char *language);
592  MOBI_EXPORT MOBI_RET mobi_meta_add_language(MOBIData *m, const char *language);
594 
595  MOBI_EXPORT MOBI_RET mobi_drm_setkey(MOBIData *m, const char *pid);
596  MOBI_EXPORT MOBI_RET mobi_drm_setkey_serial(MOBIData *m, const char *serial);
599 
600  MOBI_EXPORT MOBI_RET mobi_write_file(FILE *file, MOBIData *m); // end of mobi_export group
602 
603 #ifdef __cplusplus
604 }
605 #endif
606 
607 #endif
MOBI_EXPORT MOBI_RET mobi_decode_audio_resource(unsigned char **decoded_resource, size_t *decoded_size, MOBIPart *part)
Decode audio resource.
Definition: util.c:2074
uint16_t encryption_type
Definition: mobi.h:281
struct MOBIPart MOBIPart
Reconstructed source file.
MOBIEncoding
Definition: mobi.h:208
MOBI_EXPORT MOBIRawml * mobi_init_rawml(const MOBIData *m)
Initialize and return MOBIRawml structure.
Definition: memory.c:228
MOBI_EXPORT MOBI_RET mobi_meta_delete_contributor(MOBIData *m)
Delete all contributor metadata.
Definition: meta.c:527
Definition: mobi.h:172
MOBI_EXPORT size_t mobi_get_first_resource_record(const MOBIData *m)
Get sequential number of first resource record (image/font etc)
Definition: util.c:2618
MOBI_EXPORT MOBI_RET mobi_meta_set_title(MOBIData *m, const char *title)
Set document title metadata.
Definition: meta.c:130
Definition: mobi.h:117
uint32_t * extra5_index
Definition: mobi.h:307
MOBI_EXPORT MOBI_RET mobi_decode_video_resource(unsigned char **decoded_resource, size_t *decoded_size, MOBIPart *part)
Decode video resource.
Definition: util.c:2127
Definition: mobi.h:170
Definition: mobi.h:103
MOBIFdst * fdst
Definition: mobi.h:457
MOBIEncoding encoding
Definition: mobi.h:428
MOBI_EXPORT bool mobi_exists_guide_indx(const MOBIData *m)
Check if guide INDX is present in the loaded file.
Definition: util.c:1931
uint32_t * non_text_index
Definition: mobi.h:308
Definition: mobi.h:96
uint32_t * unknown19
Definition: mobi.h:361
MOBI_EXPORT MOBI_RET mobi_get_embedded_log(unsigned char **data, size_t *size, const MOBIData *m)
Get embedded conversion log.
Definition: util.c:2217
uint32_t * fcis_index
Definition: mobi.h:339
MOBI_EXPORT MOBI_RET mobi_parse_rawml_opt(MOBIRawml *rawml, const MOBIData *m, bool parse_toc, bool parse_dict, bool reconstruct)
Parse raw records into html flow parts, markup parts, resources and indices. Individual stages of the...
Definition: parse_rawml.c:1974
MOBI_EXPORT MOBI_RET mobi_drm_decrypt(MOBIData *m)
Decrypt document.
Definition: encryption.c:766
uint32_t uid
Definition: mobi.h:247
size_t ordt_offset
Definition: mobi.h:430
MOBI_EXPORT MOBI_RET mobi_get_fullname(const MOBIData *m, char *fullname, const size_t len)
Get ebook full name stored in Record 0 at offset given in MOBI header.
Definition: util.c:747
MOBI_EXPORT MOBIData * mobi_init(void)
Initializer for MOBIData structure.
Definition: memory.c:25
uint32_t * min_version
Definition: mobi.h:314
uint32_t * unknown13
Definition: mobi.h:348
uint16_t text_record_size
Definition: mobi.h:280
Definition: mobi.h:184
MOBI_EXPORT struct tm * mobi_pdbtime_to_time(const long pdb_time)
Convert time values from palmdoc header to time tm struct.
Definition: util.c:1589
uint32_t * keys_index
Definition: mobi.h:301
MOBI_EXPORT MOBI_RET mobi_meta_add_language(MOBIData *m, const char *language)
Add document language code metadata.
Definition: meta.c:814
uint32_t * unknown10
Definition: mobi.h:343
MOBI_EXPORT MOBI_RET mobi_dump_rawml(const MOBIData *m, FILE *file)
Decompress text record to an open file descriptor.
Definition: util.c:1821
MOBI_RET
Error codes returned by functions.
Definition: mobi.h:51
MOBI_EXPORT const char * mobi_get_locale_string(const uint32_t locale)
Get pointer to locale tag for a given Mobipocket locale number.
Definition: util.c:644
MOBIIndx * skel
Definition: mobi.h:458
uint32_t * image_index
Definition: mobi.h:315
uint16_t version
Definition: mobi.h:226
Definition: mobi.h:66
uint32_t * names_index
Definition: mobi.h:300
size_t size
Definition: mobi.h:447
Reconstructed source file.
Definition: mobi.h:444
MOBIExthHeader * eh
Definition: mobi.h:380
unsigned char * drm_key
Definition: mobi.h:376
Definition: mobi.h:89
MOBI_EXPORT MOBI_RET mobi_load_filename(MOBIData *m, const char *path)
Read MOBI document from a path into MOBIData structure.
Definition: read.c:899
MOBI_EXPORT MOBI_RET mobi_meta_add_isbn(MOBIData *m, const char *isbn)
Add document isbn metadata.
Definition: meta.c:684
Definition: mobi.h:109
Definition: mobi.h:183
Parsed INDX record.
Definition: mobi.h:425
MOBI_EXPORT MOBI_RET mobi_meta_set_publisher(MOBIData *m, const char *publisher)
Set document publisher metadata.
Definition: meta.c:312
uint32_t * version
Definition: mobi.h:297
Metadata of file types.
Definition: mobi.h:196
size_t fdst_section_count
Definition: mobi.h:399
MOBI_EXPORT MOBI_RET mobi_drm_setkey_serial(MOBIData *m, const char *serial)
Store PID for encryption in MOBIData stucture. PID will be calculated from device serial number...
Definition: util.c:2888
uint32_t * fdst_section_ends
Definition: mobi.h:401
MOBI_EXPORT void mobi_free_rawml(MOBIRawml *rawml)
Free MOBIRawml structure allocated by mobi_init_rawml()
Definition: memory.c:414
uint32_t mtime
Definition: mobi.h:228
uint32_t * extra3_index
Definition: mobi.h:305
uint32_t next_rec
Definition: mobi.h:236
MOBI_EXPORT size_t mobi_get_kf8boundary_seqnumber(const MOBIData *m)
Get sequential number of KF8 Boundary record for KF7/KF8 hybrid file.
Definition: util.c:2724
uint16_t text_record_count
Definition: mobi.h:279
MOBI_EXPORT MOBI_RET mobi_meta_add_description(MOBIData *m, const char *description)
Add document description metadata.
Definition: meta.c:399
MOBIPdbHeader * ph
Definition: mobi.h:377
MOBI_EXPORT MOBI_RET mobi_meta_add_subject(MOBIData *m, const char *subject)
Add document subject metadata.
Definition: meta.c:228
MOBI_EXPORT MOBI_RET mobi_meta_add_author(MOBIData *m, const char *author)
Add document author metadata.
Definition: meta.c:171
MOBIFiletype type
Definition: mobi.h:446
MOBI_EXPORT char * mobi_meta_get_review(const MOBIData *m)
Get document review metadata.
Definition: meta.c:559
uint32_t * extra4_index
Definition: mobi.h:306
Definition: mobi.h:105
MOBI_EXPORT MOBI_RET mobi_meta_delete_asin(MOBIData *m)
Delete all asin metadata.
Definition: meta.c:755
uint32_t * srcs_index
Definition: mobi.h:345
MOBI_EXPORT MOBIFileMeta mobi_get_filemeta_by_type(const MOBIFiletype type)
Get MOBIFileMeta tag structure by MOBIFiletype type.
Definition: util.c:728
MOBIIndx * orth
Definition: mobi.h:462
Definition: mobi.h:90
uint32_t * infl_index
Definition: mobi.h:299
MOBI_EXPORT size_t mobi_get_fileversion(const MOBIData *m)
Get mobi file version.
Definition: util.c:2510
MOBI_EXPORT MOBI_RET mobi_meta_add_publishdate(MOBIData *m, const char *publishdate)
Add document publishdate metadata.
Definition: meta.c:342
MOBIExthType type
Definition: mobi.h:267
struct MOBIExthHeader * next
Definition: mobi.h:259
uint32_t * fdst_index
Definition: mobi.h:336
Definition: mobi.h:95
Definition: mobi.h:178
uint32_t * exth_flags
Definition: mobi.h:320
Definition: mobi.h:181
Definition: mobi.h:62
MOBIPart * markup
Definition: mobi.h:465
uint32_t * fdst_section_starts
Definition: mobi.h:400
uint32_t * uid
Definition: mobi.h:296
MOBIIndexTag * tags
Definition: mobi.h:419
uint16_t compression_type
Definition: mobi.h:276
MOBI_EXPORT bool mobi_is_kf8(const MOBIData *m)
Is file version 8 or above.
Definition: util.c:2540
uint32_t * guide_index
Definition: mobi.h:358
MOBI_EXPORT MOBIExthMeta mobi_get_exthtagmeta_by_tag(const MOBIExthTag tag)
Get MOBIExthMeta tag structure by MOBIExthTag tag id.
Definition: util.c:1385
MOBI_EXPORT MOBI_RET mobi_add_exthrecord(MOBIData *m, const MOBIExthTag tag, const uint32_t size, const void *value)
Add new EXTH record with given tag and value.
Definition: util.c:1139
uint32_t * datp_rec_index
Definition: mobi.h:318
uint32_t * unknown20
Definition: mobi.h:362
MOBI_EXPORT bool mobi_is_hybrid(const MOBIData *m)
Check if loaded MOBI data is KF7/KF8 hybrid file.
Definition: util.c:2437
uint32_t * unknown16
Definition: mobi.h:357
Definition: mobi.h:189
uint32_t * mobi_type
Definition: mobi.h:294
char * orth_index_name
Definition: mobi.h:436
MOBI_EXPORT size_t mobi_get_text_maxsize(const MOBIData *m)
Get maximal size of all uncompressed text records.
Definition: util.c:2590
uint32_t kf8_boundary_offset
Definition: mobi.h:375
uint32_t mod_num
Definition: mobi.h:230
MOBI_EXPORT MOBI_RET mobi_meta_set_description(MOBIData *m, const char *description)
Set document description metadata.
Definition: meta.c:426
MOBI_EXPORT MOBI_RET mobi_meta_set_author(MOBIData *m, const char *author)
Set document author metadata.
Definition: meta.c:198
MOBI header which follows Record 0 header.
Definition: mobi.h:290
uint32_t * datp_rec_count
Definition: mobi.h:319
MOBI_EXPORT char * mobi_meta_get_contributor(const MOBIData *m)
Get document contributor metadata.
Definition: meta.c:502
MOBI_EXPORT MOBI_RET mobi_meta_delete_publisher(MOBIData *m)
Delete all publisher metadata.
Definition: meta.c:299
Definition: mobi.h:113
Definition: mobi.h:112
MOBI_EXPORT const char * mobi_version(void)
Get libmobi version.
Definition: util.c:74
uint32_t * fcis_count
Definition: mobi.h:340
uint32_t * unknown18
Definition: mobi.h:360
MOBI_EXPORT MOBI_RET mobi_load_file(MOBIData *m, FILE *file)
Read MOBI document from file into MOBIData structure.
Definition: read.c:831
MOBI_EXPORT MOBIPart * mobi_get_resource_by_uid(const MOBIRawml *rawml, const size_t uid)
Get MOBIPart resource record with given unique id.
Definition: util.c:942
MOBI_EXPORT MOBI_RET mobi_meta_set_asin(MOBIData *m, const char *asin)
Set document asin metadata.
Definition: meta.c:768
Main structure containing reconstructed source parts and indices.
Definition: mobi.h:455
MOBI_EXPORT MOBI_RET mobi_meta_delete_copyright(MOBIData *m)
Delete all copyright metadata.
Definition: meta.c:641
uint32_t * unknown12
Definition: mobi.h:347
Definition: mobi.h:106
uint32_t uid
Definition: mobi.h:235
Definition: mobi.h:97
uint32_t * datp_index
Definition: mobi.h:356
uint16_t * last_text_index
Definition: mobi.h:335
MOBI_EXPORT MOBI_RET mobi_drm_setkey(MOBIData *m, const char *pid)
Store PID for encryption in MOBIData stucture.
Definition: util.c:2906
struct MOBIPart * next
Definition: mobi.h:449
#define MOBI_EXPORT
Visibility attributes for symbol export.
Definition: mobi.h:30
uint16_t rec_count
Definition: mobi.h:237
struct MOBIExthHeader MOBIExthHeader
Metadata and data of a EXTH record. All records form a linked list.
Definition: mobi.h:54
MOBI_EXPORT bool mobi_is_encrypted(const MOBIData *m)
Check if loaded document is encrypted.
Definition: util.c:2491
MOBI_EXPORT MOBI_RET mobi_meta_add_imprint(MOBIData *m, const char *imprint)
Add document imprint metadata.
Definition: meta.c:456
uint32_t * flis_index
Definition: mobi.h:341
MOBI_EXPORT MOBI_RET mobi_meta_delete_publishdate(MOBIData *m)
Delete all publishdate metadata.
Definition: meta.c:356
Definition: mobi.h:151
MOBI_EXPORT char * mobi_meta_get_language(const MOBIData *m)
Get document language code metadata.
Definition: meta.c:790
MOBIIndexEntry * entries
Definition: mobi.h:435
Header of the Record 0 meta-record.
Definition: mobi.h:274
Definition: mobi.h:177
Parsed FDST record.
Definition: mobi.h:398
uint32_t * orth_index
Definition: mobi.h:298
size_t total_entries_count
Definition: mobi.h:429
MOBI_EXPORT uint32_t mobi_decode_exthvalue(const unsigned char *data, const size_t size)
Decode big-endian value stored in EXTH record.
Definition: util.c:1405
MOBI_EXPORT size_t mobi_get_fdst_record_number(const MOBIData *m)
Get sequential number of FDST record.
Definition: util.c:1889
MOBI_EXPORT bool mobi_is_rawml_kf8(const MOBIRawml *rawml)
Is file version 8 or above.
Definition: util.c:2554
MOBI_EXPORT MOBI_RET mobi_parse_rawml(MOBIRawml *rawml, const MOBIData *m)
Parse raw records into html flow parts, markup parts, resources and indices.
Definition: parse_rawml.c:1959
Definition: mobi.h:98
MOBI_EXPORT MOBI_RET mobi_meta_delete_subject(MOBIData *m)
Delete all subject metadata.
Definition: meta.c:242
Definition: mobi.h:88
MOBI_EXPORT char * mobi_meta_get_title(const MOBIData *m)
Get document title metadata.
Definition: meta.c:72
MOBI_EXPORT bool mobi_exists_skel_indx(const MOBIData *m)
Check if skeleton INDX is present in the loaded file.
Definition: util.c:1848
Definition: mobi.h:173
MOBI_EXPORT MOBI_RET mobi_meta_set_subject(MOBIData *m, const char *subject)
Set document subject metadata.
Definition: meta.c:255
MOBIFiletype type
Definition: mobi.h:197
Definition: mobi.h:91
uint32_t size
Definition: mobi.h:257
Definition: mobi.h:120
uint32_t * header_length
Definition: mobi.h:293
MOBI_EXPORT bool mobi_exists_frag_indx(const MOBIData *m)
Check if fragments INDX is present in the loaded file.
Definition: util.c:1914
uint32_t offset
Definition: mobi.h:244
MOBI_EXPORT bool mobi_exists_orth(const MOBIData *m)
Check if orth INDX is present in the loaded file.
Definition: util.c:1965
MOBI_EXPORT MOBI_RET mobi_get_rawml(const MOBIData *m, char *text, size_t *len)
Decompress text to a text buffer.
Definition: util.c:1798
MOBI_EXPORT MOBIPdbRecord * mobi_get_record_by_seqnumber(const MOBIData *m, const size_t uid)
Get palm database record with given sequential number (first record has number 0) ...
Definition: util.c:1013
MOBI_EXPORT bool mobi_exists_fdst(const MOBIData *m)
Check if FDST record is present in the loaded file.
Definition: util.c:1865
uint32_t * srcs_count
Definition: mobi.h:346
MOBIMobiHeader * mh
Definition: mobi.h:379
MOBI_EXPORT MOBIPart * mobi_get_resource_by_fid(const MOBIRawml *rawml, const char *fid)
Find resource by flow id (fid) from kindle:embed:fid link. Flow fid is base32 encoded part uid...
Definition: util.c:969
Definition: mobi.h:144
uint32_t btime
Definition: mobi.h:229
struct MOBIPdbRecord MOBIPdbRecord
Metadata and data of a record. All records form a linked list.
Definition: mobi.h:94
MOBI_EXPORT MOBI_RET mobi_meta_add_contributor(MOBIData *m, const char *contributor)
Add document contributor metadata.
Definition: meta.c:513
MOBIIndx * ncx
Definition: mobi.h:461
uint16_t unknown1
Definition: mobi.h:282
MOBI_EXPORT MOBI_RET mobi_meta_set_copyright(MOBIData *m, const char *copyright)
Set document copyright metadata.
Definition: meta.c:654
MOBI_EXPORT size_t mobi_get_record_extrasize(const MOBIPdbRecord *record, const uint16_t flags)
Calculate the size of extra bytes at the end of text record.
Definition: read.c:480
Definition: mobi.h:53
uint32_t * huff_rec_index
Definition: mobi.h:316
MOBI_EXPORT MOBI_RET mobi_meta_delete_review(MOBIData *m)
Delete all review metadata.
Definition: meta.c:584
Definition: mobi.h:185
MOBI_EXPORT bool mobi_is_dictionary(const MOBIData *m)
Check if loaded document is dictionary.
Definition: util.c:2472
MOBI_EXPORT MOBI_RET mobi_meta_set_publishdate(MOBIData *m, const char *publishdate)
Set document publishdate metadata.
Definition: meta.c:369
Definition: mobi.h:56
uint32_t * unknown11
Definition: mobi.h:344
MOBI_EXPORT MOBI_RET mobi_meta_set_isbn(MOBIData *m, const char *isbn)
Set document isbn metadata.
Definition: meta.c:711
MOBI_EXPORT MOBI_RET mobi_meta_set_imprint(MOBIData *m, const char *imprint)
Set document imprint metadata.
Definition: meta.c:483
size_t tagid
Definition: mobi.h:408
uint32_t * flis_count
Definition: mobi.h:342
MOBI_EXPORT MOBI_RET mobi_meta_delete_language(MOBIData *m)
Delete all language code metadata.
Definition: meta.c:828
Definition: mobi.h:190
MOBI_EXPORT MOBIPart * mobi_get_part_by_uid(const MOBIRawml *rawml, const size_t uid)
Get rawml->markup MOBIPart part by uid.
Definition: util.c:874
MOBIPdbRecord * cncx_record
Definition: mobi.h:434
uint32_t * fragment_index
Definition: mobi.h:353
Definition: mobi.h:180
MOBI_EXPORT char * mobi_meta_get_publishdate(const MOBIData *m)
Get document publishing date metadata.
Definition: meta.c:331
uint32_t sortinfo_offset
Definition: mobi.h:232
MOBI_EXPORT MOBI_RET mobi_meta_delete_description(MOBIData *m)
Delete all description metadata.
Definition: meta.c:413
MOBI_EXPORT char * mobi_meta_get_author(const MOBIData *m)
Get document author metadata.
Definition: meta.c:160
uint32_t * ncx_index
Definition: mobi.h:351
MOBI_EXPORT MOBI_RET mobi_write_file(FILE *file, MOBIData *m)
Write mobi document to file.
Definition: write.c:445
MOBIPart * resources
Definition: mobi.h:466
MOBI_EXPORT char * mobi_meta_get_subject(const MOBIData *m)
Get document subject metadata.
Definition: meta.c:217
Main structure holding all metadata and unparsed records data.
Definition: mobi.h:373
MOBI_EXPORT MOBIExthHeader * mobi_get_exthrecord_by_tag(const MOBIData *m, const MOBIExthTag tag)
Get EXTH record with given MOBIExthTag tag.
Definition: util.c:1076
Parsed tag for an index entry.
Definition: mobi.h:407
MOBI_EXPORT size_t mobi_get_record_mb_extrasize(const MOBIPdbRecord *record, const uint16_t flags)
Calculate the size of extra multibyte section at the end of text record.
Definition: read.c:518
MOBI_EXPORT MOBI_RET mobi_meta_add_title(MOBIData *m, const char *title)
Add document title metadata.
Definition: meta.c:97
MOBIPdbRecord * rec
Definition: mobi.h:381
uint32_t * dict_input_lang
Definition: mobi.h:312
Definition: mobi.h:99
MOBIExthType
EXTH record types.
Definition: mobi.h:72
MOBI_EXPORT MOBI_RET mobi_meta_delete_isbn(MOBIData *m)
Delete all isbn metadata.
Definition: meta.c:698
struct MOBIData MOBIData
Main structure holding all metadata and unparsed records data.
Definition: mobi.h:176
Definition: mobi.h:155
MOBI_EXPORT MOBI_RET mobi_meta_add_copyright(MOBIData *m, const char *copyright)
Add document copyright metadata.
Definition: meta.c:627
MOBI_EXPORT MOBI_RET mobi_get_embedded_source(unsigned char **data, size_t *size, const MOBIData *m)
Get embedded source archive.
Definition: util.c:2165
size_t size
Definition: mobi.h:245
Definition: mobi.h:175
Definition: mobi.h:108
MOBI_EXPORT char * mobi_meta_get_copyright(const MOBIData *m)
Get document copyright metadata.
Definition: meta.c:616
Definition: mobi.h:61
Definition: mobi.h:209
uint32_t * full_name_length
Definition: mobi.h:310
Definition: mobi.h:188
MOBI_EXPORT bool mobi_exists_infl(const MOBIData *m)
Check if infl INDX is present in the loaded file.
Definition: util.c:1982
MOBI_EXPORT char * mobi_meta_get_description(const MOBIData *m)
Get document description metadata.
Definition: meta.c:388
MOBIRecord0Header * rh
Definition: mobi.h:378
Definition: mobi.h:114
char * name
Definition: mobi.h:268
uint32_t * drm_flags
Definition: mobi.h:330
Definition: mobi.h:60
MOBI_EXPORT void mobi_free(MOBIData *m)
Free MOBIData structure and all its children.
Definition: memory.c:161
MOBI_EXPORT MOBI_RET mobi_parse_kf8(MOBIData *m)
Loader will parse KF8 part of hybrid file.
Definition: util.c:2842
Header of palmdoc database file.
Definition: mobi.h:223
uint32_t * unknown15
Definition: mobi.h:354
uint32_t * dict_output_lang
Definition: mobi.h:313
char * label
Definition: mobi.h:417
struct MOBIData * next
Definition: mobi.h:382
MOBI_EXPORT MOBI_RET mobi_drm_delkey(MOBIData *m)
Remove PID stored for encryption from MOBIData structure.
Definition: util.c:2923
uint32_t * tagvalues
Definition: mobi.h:410
MOBI_EXPORT MOBIPart * mobi_get_flow_by_fid(const MOBIRawml *rawml, const char *fid)
Find flow part by flow id (fid) from kindle:flow:fid link. Flow fid is base32 encoded part uid...
Definition: util.c:925
size_t ligt_offset
Definition: mobi.h:431
uint32_t ctime
Definition: mobi.h:227
uint32_t * unknown14
Definition: mobi.h:352
uint16_t * extra_flags
Definition: mobi.h:350
Definition: mobi.h:55
MOBI_EXPORT char * mobi_meta_get_imprint(const MOBIData *m)
Get document imprint metadata.
Definition: meta.c:445
uint32_t * locale
Definition: mobi.h:311
MOBI_EXPORT char * mobi_meta_get_isbn(const MOBIData *m)
Get document ISBN metadata.
Definition: meta.c:673
MOBI_EXPORT MOBI_RET mobi_meta_add_review(MOBIData *m, const char *review)
Add document review metadata.
Definition: meta.c:570
uint32_t * unknown17
Definition: mobi.h:359
uint32_t * fdst_section_count
Definition: mobi.h:338
MOBIExthTag tag
Definition: mobi.h:266
uint32_t * drm_size
Definition: mobi.h:329
Definition: mobi.h:87
Definition: mobi.h:119
MOBI_EXPORT MOBI_RET mobi_meta_delete_imprint(MOBIData *m)
Delete all imprint metadata.
Definition: meta.c:470
Definition: mobi.h:110
MOBI_EXPORT MOBI_RET mobi_meta_set_review(MOBIData *m, const char *review)
Set document review metadata.
Definition: meta.c:597
MOBI_EXPORT char * mobi_meta_get_asin(const MOBIData *m)
Get document ASIN metadata.
Definition: meta.c:730
MOBI_EXPORT uint16_t mobi_get_textrecord_maxsize(const MOBIData *m)
Get maximal size of uncompressed text record.
Definition: util.c:2567
Definition: mobi.h:92
MOBI_EXPORT MOBIPart * mobi_get_flow_by_uid(const MOBIRawml *rawml, const size_t uid)
Get rawml->flow MOBIPart part by uid.
Definition: util.c:899
MOBI_EXPORT MOBI_RET mobi_meta_set_language(MOBIData *m, const char *language)
Set document language code metadata.
Definition: meta.c:849
uint16_t attributes
Definition: mobi.h:225
Definition: mobi.h:167
uint32_t * drm_offset
Definition: mobi.h:327
MOBIFiletype
Types of files stored in database records.
Definition: mobi.h:166
MOBIIndx * guide
Definition: mobi.h:460
uint32_t * huff_rec_count
Definition: mobi.h:317
uint32_t * unknown6
Definition: mobi.h:326
MOBIIndx * infl
Definition: mobi.h:463
size_t uid
Definition: mobi.h:445
void * data
Definition: mobi.h:258
size_t version
Definition: mobi.h:456
Definition: mobi.h:211
MOBI_EXPORT MOBI_RET mobi_meta_set_contributor(MOBIData *m, const char *contributor)
Set document contributor metadata.
Definition: meta.c:540
Definition: mobi.h:65
uint32_t * extra0_index
Definition: mobi.h:302
MOBI_EXPORT char * mobi_meta_get_publisher(const MOBIData *m)
Get document publisher metadata.
Definition: meta.c:274
uint32_t * drm_count
Definition: mobi.h:328
uint32_t appinfo_offset
Definition: mobi.h:231
MOBI_EXPORT MOBI_RET mobi_decode_font_resource(unsigned char **decoded_font, size_t *decoded_size, MOBIPart *part)
Deobfuscator and decompressor for font resources.
Definition: util.c:2298
uint8_t attributes
Definition: mobi.h:246
uint32_t * full_name_offset
Definition: mobi.h:309
MOBI_EXPORT MOBIPdbRecord * mobi_get_record_by_uid(const MOBIData *m, const size_t uid)
Get palm database record with given unique id.
Definition: util.c:849
MOBI_EXPORT char * mobi_decode_exthstring(const MOBIData *m, const unsigned char *data, const size_t size)
Decode string stored in EXTH record.
Definition: util.c:1536
bool use_kf8
Definition: mobi.h:374
size_t tags_count
Definition: mobi.h:418
MOBI_EXPORT bool mobi_is_mobipocket(const MOBIData *m)
Check if loaded document is MOBI/BOOK Mobipocket format.
Definition: util.c:2454
MOBI_EXPORT MOBI_RET mobi_meta_add_asin(MOBIData *m, const char *asin)
Add document asin metadata.
Definition: meta.c:741
Definition: mobi.h:171
Parsed INDX index entry.
Definition: mobi.h:416
size_t entries_count
Definition: mobi.h:427
size_t type
Definition: mobi.h:426
size_t tagvalues_count
Definition: mobi.h:409
Definition: mobi.h:93
Definition: mobi.h:57
uint32_t tag
Definition: mobi.h:256
Definition: mobi.h:169
Definition: mobi.h:52
unsigned char * data
Definition: mobi.h:248
MOBIExthTag
EXTH record tags.
Definition: mobi.h:81
uint32_t * skeleton_index
Definition: mobi.h:355
Definition: mobi.h:187
size_t cncx_records_count
Definition: mobi.h:433
uint16_t * first_text_index
Definition: mobi.h:334
MOBIEncoding * text_encoding
Definition: mobi.h:295
EXTH tag metadata.
Definition: mobi.h:265
unsigned char * data
Definition: mobi.h:448
Definition: mobi.h:152
MOBI_EXPORT bool mobi_exists_ncx(const MOBIData *m)
Check if ncx INDX is present in the loaded file.
Definition: util.c:1948
Definition: mobi.h:210
Definition: mobi.h:86
MOBI_EXPORT size_t mobi_get_locale_number(const char *locale_string)
Get Mobipocket locale number for a given string tag.
Definition: util.c:666
Metadata and data of a record. All records form a linked list.
Definition: mobi.h:243
MOBIIndx * frag
Definition: mobi.h:459
MOBI_EXPORT MOBI_RET mobi_parse_kf7(MOBIData *m)
Loader will parse KF7 part of hybrid file.
Definition: util.c:2826
Metadata and data of a EXTH record. All records form a linked list.
Definition: mobi.h:255
Definition: mobi.h:64
Definition: mobi.h:104
size_t ligt_entries_count
Definition: mobi.h:432
MOBI_EXPORT MOBI_RET mobi_meta_delete_title(MOBIData *m)
Delete all title metadata.
Definition: meta.c:111
MOBI_EXPORT bool mobi_exists_mobiheader(const MOBIData *m)
Check if MOBI header is loaded / present in the loaded file.
Definition: util.c:1835
struct MOBIPdbRecord * next
Definition: mobi.h:249
uint32_t * extra2_index
Definition: mobi.h:304
Definition: mobi.h:63
MOBIPart * flow
Definition: mobi.h:464
MOBI_EXPORT MOBI_RET mobi_delete_exthrecord_by_tag(MOBIData *m, const MOBIExthTag tag)
Delete all EXTH records with given MOBIExthTag tag.
Definition: util.c:1273
MOBI_EXPORT MOBI_RET mobi_meta_delete_author(MOBIData *m)
Delete all author metadata.
Definition: meta.c:185
char * full_name
Definition: mobi.h:363
Definition: mobi.h:58
MOBI_EXPORT MOBI_RET mobi_meta_add_publisher(MOBIData *m, const char *publisher)
Add document publisher metadata.
Definition: meta.c:285
uint32_t text_length
Definition: mobi.h:278
Definition: mobi.h:59
MOBI_EXPORT size_t mobi_get_kf8offset(const MOBIData *m)
Get offset of KF8 Boundary for KF7/KF8 hybrid file cached in MOBIData structure.
Definition: util.c:2708
MOBI_EXPORT MOBIExthHeader * mobi_next_exthrecord_by_tag(const MOBIData *m, const MOBIExthTag tag, MOBIExthHeader **start)
Get EXTH record with given MOBIExthTag tag. Start list search at given record.
Definition: util.c:1105
uint32_t * extra1_index
Definition: mobi.h:303