libmobi
C library for handling MOBI format ebook documents
index.h
Go to the documentation of this file.
1 
11 #ifndef mobi_index_h
12 #define mobi_index_h
13 
14 #include "config.h"
15 #include "structure.h"
16 #include "mobi.h"
17 
22 #define INDX_TAG_GUIDE_TITLE_CNCX (unsigned[]) {1, 0}
24 #define INDX_TAG_NCX_FILEPOS (unsigned[]) {1, 0}
25 #define INDX_TAG_NCX_TEXT_CNCX (unsigned[]) {3, 0}
26 #define INDX_TAG_NCX_LEVEL (unsigned[]) {4, 0}
27 #define INDX_TAG_NCX_KIND_CNCX (unsigned[]) {5, 0}
28 #define INDX_TAG_NCX_POSFID (unsigned[]) {6, 0}
29 #define INDX_TAG_NCX_POSOFF (unsigned[]) {6, 1}
30 #define INDX_TAG_NCX_PARENT (unsigned[]) {21, 0}
31 #define INDX_TAG_NCX_CHILD_START (unsigned[]) {22, 0}
32 #define INDX_TAG_NCX_CHILD_END (unsigned[]) {23, 0}
34 #define INDX_TAG_SKEL_COUNT (unsigned[]) {1, 0}
35 #define INDX_TAG_SKEL_POSITION (unsigned[]) {6, 0}
36 #define INDX_TAG_SKEL_LENGTH (unsigned[]) {6, 1}
38 #define INDX_TAG_FRAG_AID_CNCX (unsigned[]) {2, 0}
39 #define INDX_TAG_FRAG_FILE_NR (unsigned[]) {3, 0}
40 #define INDX_TAG_FRAG_SEQUENCE_NR (unsigned[]) {4, 0}
41 #define INDX_TAG_FRAG_POSITION (unsigned[]) {6, 0}
42 #define INDX_TAG_FRAG_LENGTH (unsigned[]) {6, 1}
44 #define INDX_TAG_ORTH_POSITION (unsigned[]) {1, 0}
45 #define INDX_TAG_ORTH_LENGTH (unsigned[]) {2, 0}
47 #define INDX_TAGARR_ORTH_INFL 42
48 #define INDX_TAGARR_INFL_GROUPS 5
49 #define INDX_TAGARR_INFL_PARTS_V2 26
51 #define INDX_TAGARR_INFL_PARTS_V1 7
54 #define INDX_LABEL_SIZEMAX 1000
55 #define INDX_INFLTAG_SIZEMAX 25000
56 #define INDX_INFLBUF_SIZEMAX 500
57 #define INDX_INFLSTRINGS_MAX 500
58 #define ORDT_RECORD_MAXCNT 256 /* max entries count in old ordt */
59 #define CNCX_RECORD_MAXCNT 0xf /* max entries count */
60 #define INDX_RECORD_MAXCNT 6000 /* max index entries per record */
61 #define INDX_TOTAL_MAXCNT ((size_t) INDX_RECORD_MAXCNT * 0xffff) /* max total index entries */
62 #define INDX_NAME_SIZEMAX 0xff
63 
67 #define INDX_TAGVALUES_MAX 100
68 
72 typedef struct {
73  uint8_t tag;
74  uint8_t values_count;
75  uint8_t bitmask;
76  uint8_t control_byte;
77 } TAGXTags;
78 
85 typedef struct {
87  size_t tags_count;
89 } MOBITagx;
90 
96 typedef struct {
97  uint32_t *offsets;
98  size_t offsets_count;
99 } MOBIIdxt;
100 
107 typedef struct {
108  uint8_t *ordt1;
109  uint16_t *ordt2;
110  size_t type;
111  size_t ordt1_pos;
112  size_t ordt2_pos;
113  size_t offsets_count;
114 } MOBIOrdt;
115 
116 MOBI_RET mobi_parse_index(const MOBIData *m, MOBIIndx *indx, const size_t indx_record_number);
117 MOBI_RET mobi_parse_indx(const MOBIPdbRecord *indx_record, MOBIIndx *indx, MOBITagx *tagx, MOBIOrdt *ordt);
118 MOBI_RET mobi_get_indxentry_tagvalue(uint32_t *tagvalue, const MOBIIndexEntry *entry, const unsigned tag_arr[]);
119 size_t mobi_get_indxentry_tagarray(uint32_t **tagarr, const MOBIIndexEntry *entry, const size_t tagid);
120 bool mobi_indx_has_tag(const MOBIIndx *indx, const size_t tagid);
121 char * mobi_get_cncx_string(const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset);
122 char * mobi_get_cncx_string_utf8(const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset, MOBIEncoding cncx_encoding);
123 char * mobi_get_cncx_string_flat(const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset, const size_t length);
124 MOBI_RET mobi_decode_infl(unsigned char *decoded, int *decoded_size, const unsigned char *rule);
125 MOBI_RET mobi_trie_insert_infl(MOBITrie **root, const MOBIIndx *indx, size_t i);
126 size_t mobi_trie_get_inflgroups(char **infl_strings, MOBITrie * const root, const char *string);
127 
128 #endif
MOBI_RET
Error codes returned by functions.
Definition: mobi.h:59
MOBIEncoding
Encoding types in MOBI header (offset 28)
Definition: mobi.h:215
char * mobi_get_cncx_string_flat(const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset, const size_t length)
Get flat index entry string.
Definition: index.c:931
MOBI_RET mobi_get_indxentry_tagvalue(uint32_t *tagvalue, const MOBIIndexEntry *entry, const unsigned tag_arr[])
Get a value of tag[tagid][tagindex] for given index entry.
Definition: index.c:770
bool mobi_indx_has_tag(const MOBIIndx *indx, const size_t tagid)
Check if given tagid is present in the index.
Definition: index.c:854
MOBI_RET mobi_trie_insert_infl(MOBITrie **root, const MOBIIndx *indx, size_t i)
Insert inversed inlection string for given entry into trie structure.
Definition: index.c:1067
char * mobi_get_cncx_string(const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset)
Get compiled index entry string.
Definition: index.c:877
MOBI_RET mobi_parse_indx(const MOBIPdbRecord *indx_record, MOBIIndx *indx, MOBITagx *tagx, MOBIOrdt *ordt)
Parser of INDX record.
Definition: index.c:512
size_t mobi_get_indxentry_tagarray(uint32_t **tagarr, const MOBIIndexEntry *entry, const size_t tagid)
Get array of tagvalues of tag[tagid] for given index entry.
Definition: index.c:798
MOBI_RET mobi_parse_index(const MOBIData *m, MOBIIndx *indx, const size_t indx_record_number)
Parser of a set of index records.
Definition: index.c:707
MOBI_RET mobi_decode_infl(unsigned char *decoded, int *decoded_size, const unsigned char *rule)
Decode compiled infl index entry.
Definition: index.c:960
size_t mobi_trie_get_inflgroups(char **infl_strings, MOBITrie *const root, const char *string)
Get all matches for given string from trie structure.
Definition: index.c:1026
char * mobi_get_cncx_string_utf8(const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset, MOBIEncoding cncx_encoding)
Get compiled index entry string, converted to utf8 encoding.
Definition: index.c:905
Libmobi main header file.
Main structure holding all metadata and unparsed records data.
Definition: mobi.h:381
Parsed IDXT section (for internal INDX parsing)
Definition: index.h:96
uint32_t * offsets
Definition: index.h:97
size_t offsets_count
Definition: index.h:98
Parsed INDX index entry.
Definition: mobi.h:425
Parsed INDX record.
Definition: mobi.h:434
Parsed ORDT sections (for internal INDX parsing)
Definition: index.h:107
size_t type
Definition: index.h:110
uint8_t * ordt1
Definition: index.h:108
size_t ordt1_pos
Definition: index.h:111
size_t offsets_count
Definition: index.h:113
size_t ordt2_pos
Definition: index.h:112
uint16_t * ordt2
Definition: index.h:109
Metadata and data of a record. All records form a linked list.
Definition: mobi.h:251
Parsed TAGX section (for internal INDX parsing)
Definition: index.h:85
size_t tags_count
Definition: index.h:87
TAGXTags * tags
Definition: index.h:86
size_t control_byte_count
Definition: index.h:88
Trie storing arrays of values for character keys.
Definition: structure.h:36
Tag entries in TAGX section (for internal INDX parsing)
Definition: index.h:72
uint8_t bitmask
Definition: index.h:75
uint8_t values_count
Definition: index.h:74
uint8_t control_byte
Definition: index.h:76
uint8_t tag
Definition: index.h:73