libmobi
C library for handling MOBI format ebook documents
Data Structures | Macros | Functions | Variables
util.c File Reference

Various helper functions. More...

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "util.h"
#include "parse_rawml.h"
#include "index.h"
#include "debug.h"

Data Structures

struct  HTMLEntity
 Html entity mapping to utf-8 sequence. More...
 

Macros

#define _GNU_SOURCE   1
 
#define __USE_BSD   /* for strdup on linux/glibc */
 
#define MOBI_FONT_OBFUSCATED_BUFFER_COUNT   52
 
#define PACKAGE_VERSION   "unknown"
 
#define MOBI_LANG_MAX   99
 
#define MOBI_REGION_MAX   21
 Table of Mobipocket language-region codes. More...
 
#define MOBI_UTF8_MAXBYTES   4
 

Functions

const char * mobi_version (void)
 Get libmobi version. More...
 
uint8_t mobi_unicode_to_utf8 (char *output, const size_t codepoint)
 Convert unicode codepoint to utf-8 sequence. More...
 
MOBI_RET mobi_cp1252_to_utf8 (char *output, const char *input, size_t *outsize, const size_t insize)
 Convert cp1252 encoded string to utf-8. More...
 
MOBI_RET mobi_utf8_to_cp1252 (char *output, const char *input, size_t *outsize, const size_t insize)
 Convert utf-8 encoded string to cp1252. More...
 
uint8_t mobi_ligature_to_cp1252 (const uint8_t byte1, const uint8_t byte2)
 Decode ligature to cp1252. More...
 
uint16_t mobi_ligature_to_utf16 (const uint32_t byte1, const uint32_t byte2)
 Decode ligature to utf-16. More...
 
MOBIEncoding mobi_get_encoding (const MOBIData *m)
 Get text encoding of mobi document. More...
 
bool mobi_is_cp1252 (const MOBIData *m)
 Check if document's text is cp1252 encoded. More...
 
char * mobi_strdup (const char *s)
 strdup replacement More...
 
const char * mobi_get_locale_string (const uint32_t locale_number)
 Get pointer to locale tag for a given Mobipocket locale number. More...
 
size_t mobi_get_locale_number (const char *locale_string)
 Get Mobipocket locale number for a given string tag. More...
 
MOBIFileMeta mobi_get_filemeta_by_type (const MOBIFiletype type)
 Get MOBIFileMeta tag structure by MOBIFiletype type. More...
 
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. More...
 
MOBI_RET mobi_set_fullname (MOBIData *m, const char *fullname)
 Set ebook full name stored in Record 0 at offset given in MOBI header. More...
 
MOBI_RET mobi_set_pdbname (MOBIData *m, const char *name)
 Set palm database name. More...
 
MOBIPdbRecordmobi_get_record_by_uid (const MOBIData *m, const size_t uid)
 Get palm database record with given unique id. More...
 
MOBIPartmobi_get_part_by_uid (const MOBIRawml *rawml, const size_t uid)
 Get rawml->markup MOBIPart part by uid. More...
 
MOBIPartmobi_get_flow_by_uid (const MOBIRawml *rawml, const size_t uid)
 Get rawml->flow MOBIPart part by uid. More...
 
MOBIPartmobi_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. More...
 
MOBIPartmobi_get_resource_by_uid (const MOBIRawml *rawml, const size_t uid)
 Get MOBIPart resource record with given unique id. More...
 
MOBIPartmobi_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. More...
 
MOBIFiletype mobi_get_resourcetype_by_uid (const MOBIRawml *rawml, const size_t uid)
 Get MOBIFiletype type of MOBIPart resource record with given unique id. More...
 
MOBIPdbRecordmobi_get_record_by_seqnumber (const MOBIData *m, const size_t num)
 Get palm database record with given sequential number (first record has number 0) More...
 
MOBIPdbRecordmobi_get_record_by_magic (const MOBIData *m, const unsigned char magic[4])
 Get palm database record with data header starting with given 4-byte magic string. More...
 
MOBIPdbRecordmobi_extract_records_by_seqnumber (MOBIData *m, const size_t num, size_t *count)
 Extract palm count database records starting with given sequential number from MOBIData structure. More...
 
MOBI_RET mobi_insert_records_by_seqnumber (MOBIData *m, MOBIPdbRecord *record, const size_t num)
 Insert palm database records at given sequential number. More...
 
MOBI_RET mobi_delete_records_by_seqnumber (MOBIData *m, const size_t num, size_t *count)
 Delete palm count database records starting with given sequential number from MOBIData structure. More...
 
MOBI_RET mobi_delete_record_by_seqnumber (MOBIData *m, const size_t num)
 Delete palm database record with given sequential number from MOBIData structure. More...
 
MOBIExthHeadermobi_get_exthrecord_by_tag (const MOBIData *m, const MOBIExthTag tag)
 Get EXTH record with given MOBIExthTag tag. More...
 
MOBIExthHeadermobi_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. More...
 
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. More...
 
MOBIExthHeadermobi_delete_exthrecord (MOBIData *m, MOBIExthHeader *record)
 Delete EXTH record. More...
 
MOBI_RET mobi_delete_exthrecord_by_tag (MOBIData *m, const MOBIExthTag tag)
 Delete all EXTH records with given MOBIExthTag tag. More...
 
MOBIExthMeta mobi_get_exthtagmeta_by_tag (const MOBIExthTag tag)
 Get MOBIExthMeta tag structure by MOBIExthTag tag id. More...
 
uint32_t mobi_decode_exthvalue (const unsigned char *data, const size_t size)
 Decode big-endian value stored in EXTH record. More...
 
char * mobi_decode_htmlentities (const char *input)
 Convert html entities in string to utf-8 characters. More...
 
char * mobi_decode_exthstring (const MOBIData *m, const unsigned char *data, const size_t size)
 Decode string stored in EXTH record. More...
 
uint32_t mobi_swap32 (const uint32_t val)
 Swap endianness of 32-bit value. More...
 
struct tm * mobi_pdbtime_to_time (const long pdb_time)
 Convert time values from palmdoc header to time tm struct. More...
 
int mobi_bitcount (const uint8_t byte)
 Get number of bits set in a given byte. More...
 
MOBI_RET mobi_get_rawml (const MOBIData *m, char *text, size_t *len)
 Decompress text to a text buffer. More...
 
MOBI_RET mobi_dump_rawml (const MOBIData *m, FILE *file)
 Decompress text record to an open file descriptor. More...
 
bool mobi_exists_mobiheader (const MOBIData *m)
 Check if MOBI header is loaded / present in the loaded file. More...
 
bool mobi_exists_skel_indx (const MOBIData *m)
 Check if skeleton INDX is present in the loaded file. More...
 
bool mobi_exists_fdst (const MOBIData *m)
 Check if FDST record is present in the loaded file. More...
 
size_t mobi_get_fdst_record_number (const MOBIData *m)
 Get sequential number of FDST record. More...
 
bool mobi_exists_frag_indx (const MOBIData *m)
 Check if fragments INDX is present in the loaded file. More...
 
bool mobi_exists_guide_indx (const MOBIData *m)
 Check if guide INDX is present in the loaded file. More...
 
bool mobi_exists_ncx (const MOBIData *m)
 Check if ncx INDX is present in the loaded file. More...
 
bool mobi_exists_orth (const MOBIData *m)
 Check if orth INDX is present in the loaded file. More...
 
bool mobi_exists_infl (const MOBIData *m)
 Check if infl INDX is present in the loaded file. More...
 
MOBIFiletype mobi_determine_flowpart_type (const MOBIRawml *rawml, const size_t part_number)
 Get file type of given part with number [part_number]. More...
 
MOBIFiletype mobi_determine_font_type (const unsigned char *font_data, const size_t font_size)
 Get font type of given font resource. More...
 
MOBI_RET mobi_add_audio_resource (MOBIPart *part)
 Replace part data with decoded audio data. More...
 
MOBI_RET mobi_decode_audio_resource (unsigned char **decoded_resource, size_t *decoded_size, MOBIPart *part)
 Decode audio resource. More...
 
MOBI_RET mobi_add_video_resource (MOBIPart *part)
 Replace part data with decoded video data. More...
 
MOBI_RET mobi_decode_video_resource (unsigned char **decoded_resource, size_t *decoded_size, MOBIPart *part)
 Decode video resource. More...
 
MOBI_RET mobi_get_embedded_source (unsigned char **data, size_t *size, const MOBIData *m)
 Get embedded source archive. More...
 
MOBI_RET mobi_get_embedded_log (unsigned char **data, size_t *size, const MOBIData *m)
 Get embedded conversion log. More...
 
MOBI_RET mobi_add_font_resource (MOBIPart *part)
 Replace part data with decoded font data. More...
 
MOBI_RET mobi_decode_font_resource (unsigned char **decoded_font, size_t *decoded_size, MOBIPart *part)
 Deobfuscator and decompressor for font resources. More...
 
MOBIFiletype mobi_determine_resource_type (const MOBIPdbRecord *record)
 Get resource type (image, font) by checking its magic header. More...
 
bool mobi_is_hybrid (const MOBIData *m)
 Check if loaded MOBI data is KF7/KF8 hybrid file. More...
 
bool mobi_is_mobipocket (const MOBIData *m)
 Check if loaded document is MOBI/BOOK Mobipocket format. More...
 
bool mobi_is_textread (const MOBIData *m)
 Check if loaded document is TEXt/REAd format. More...
 
bool mobi_is_dictionary (const MOBIData *m)
 Check if loaded document is dictionary. More...
 
bool mobi_is_encrypted (const MOBIData *m)
 Check if loaded document is encrypted. More...
 
bool mobi_has_drmkey (const MOBIData *m)
 Check if DRM key is set for the document. More...
 
bool mobi_has_drmcookies (const MOBIData *m)
 Check if DRM cookies are set for the document. More...
 
bool mobi_is_replica (const MOBIData *m)
 Check if loaded document is Print Replica type. More...
 
size_t mobi_get_fileversion (const MOBIData *m)
 Get mobi file version. More...
 
bool mobi_is_kf8 (const MOBIData *m)
 Is file version 8 or above. More...
 
bool mobi_is_rawml_kf8 (const MOBIRawml *rawml)
 Is file version 8 or above. More...
 
uint16_t mobi_get_textrecord_maxsize (const MOBIData *m)
 Get maximal size of uncompressed text record. More...
 
size_t mobi_get_text_maxsize (const MOBIData *m)
 Get maximal size of all uncompressed text records. More...
 
size_t mobi_get_first_resource_record (const MOBIData *m)
 Get sequential number of first resource record (image/font etc) More...
 
size_t mobi_pow (unsigned base, unsigned exp)
 Calculate exponentiation for unsigned base and exponent. More...
 
MOBI_RET mobi_base32_decode (uint32_t *decoded, const char *encoded)
 Decode positive number from base 32 to base 10. More...
 
size_t mobi_get_kf8offset (const MOBIData *m)
 Get offset of KF8 Boundary for KF7/KF8 hybrid file cached in MOBIData structure. More...
 
size_t mobi_get_kf8boundary_seqnumber (const MOBIData *m)
 Get sequential number of KF8 Boundary record for KF7/KF8 hybrid file. More...
 
uint32_t mobi_get_exthsize (const MOBIData *m)
 Get size of serialized exth record including padding. More...
 
uint32_t mobi_get_drmsize (const MOBIData *m)
 Get size of serialized DRM data. More...
 
uint16_t mobi_get_records_count (const MOBIData *m)
 Get count of palm database records. More...
 
void mobi_remove_zeros (unsigned char *buffer, size_t *len)
 Remove null characters from char buffer. More...
 
MOBI_RET mobi_parse_kf7 (MOBIData *m)
 Loader will parse KF7 part of hybrid file. More...
 
MOBI_RET mobi_parse_kf8 (MOBIData *m)
 Loader will parse KF8 part of hybrid file. More...
 
MOBI_RET mobi_remove_part_kf7 (MOBIData *m)
 Remove KF7 version from hybrid file. More...
 
MOBI_RET mobi_remove_part_kf8 (MOBIData *m)
 Remove KF8 version from hybrid file. More...
 
MOBI_RET mobi_remove_hybrid_part (MOBIData *m, const bool remove_kf8)
 Remove one version from hybrid file. More...
 
MOBI_RET mobi_swap_mobidata (MOBIData *m)
 Swap KF7 and KF8 MOBIData structures in a hybrid file. More...
 
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. More...
 
MOBI_RET mobi_drm_addvoucher (MOBIData *m, const char *serial, const time_t valid_from, const time_t valid_to, const MOBIExthTag *tamperkeys, const size_t tamperkeys_count)
 Add DRM voucher. More...
 
MOBI_RET mobi_drm_setkey (MOBIData *m, const char *pid)
 Store PID for encryption in MOBIData stucture. More...
 
MOBI_RET mobi_drm_delkey (MOBIData *m)
 Remove PID stored for encryption from MOBIData structure. More...
 
void mobi_free_internals (MOBIData *m)
 Free internals. More...
 
uint32_t mobi_get32be (const unsigned char buf[4])
 Convert char buffer to 32-bit unsigned integer big endian. More...
 
uint32_t mobi_get32le (const unsigned char buf[4])
 Convert char buffer to 32-bit unsigned integer little endian. More...
 

Variables

const MOBIFileMeta mobi_file_meta []
 Array of known file types, their extensions and mime-types. More...
 
const MOBIExthMeta mobi_exth_tags []
 Array of known EXTH tags. Name strings shamelessly copied from KindleUnpack.
 
const HTMLEntity entities []
 Basic named html entities mapping to utf-8 sequences.
 

Detailed Description

Various helper functions.

Copyright (c) 2014 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/

Macro Definition Documentation

◆ MOBI_LANG_MAX

#define MOBI_LANG_MAX   99

number of entries in mobi_locale array

◆ MOBI_REGION_MAX

#define MOBI_REGION_MAX   21

Table of Mobipocket language-region codes.

maximum number of entries in each language array

Based on IANA language-subtag registry with some custom Mobipocket modifications. http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

Function Documentation

◆ mobi_add_audio_resource()

MOBI_RET mobi_add_audio_resource ( MOBIPart part)

Replace part data with decoded audio data.

Parameters
[in,out]partMOBIPart structure containing font resource, decoded part type will be set in the structure
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_add_font_resource()

MOBI_RET mobi_add_font_resource ( MOBIPart part)

Replace part data with decoded font data.

Parameters
[in,out]partMOBIPart structure containing font resource, decoded part type will be set in the structure
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_add_video_resource()

MOBI_RET mobi_add_video_resource ( MOBIPart part)

Replace part data with decoded video data.

Parameters
[in,out]partMOBIPart structure containing font resource, decoded part type will be set in the structure
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_base32_decode()

MOBI_RET mobi_base32_decode ( uint32_t *  decoded,
const char *  encoded 
)

Decode positive number from base 32 to base 10.

Base 32 characters must be upper case. Maximal supported value is VVVVVV.

Parameters
[in,out]decodedBase 10 output number
[in]encodedBase 32 input number
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_bitcount()

int mobi_bitcount ( const uint8_t  byte)

Get number of bits set in a given byte.

Parameters
[in]byteA byte
Returns
Number of bits set

◆ mobi_cp1252_to_utf8()

MOBI_RET mobi_cp1252_to_utf8 ( char *  output,
const char *  input,
size_t *  outsize,
const size_t  insize 
)

Convert cp1252 encoded string to utf-8.

Maximum length of output string is 3 * (input string length) + 1 Output string will be null terminated (even if truncated)

Parameters
[in,out]outputOutput string
[in,out]inputInput string
[in,out]outsizeSize of the allocated output buffer, will be set to output string length (without null terminator) on return
[in]insizeLength of the input string.
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_decode_htmlentities()

char* mobi_decode_htmlentities ( const char *  input)

Convert html entities in string to utf-8 characters.

Parameters
[in]inputInput string
Returns
Converted string

◆ mobi_delete_exthrecord()

MOBIExthHeader* mobi_delete_exthrecord ( MOBIData m,
MOBIExthHeader record 
)

Delete EXTH record.

Parameters
[in,out]mMOBIData structure with loaded data
[in]recordRecord to be deleted
Returns
Pointer to next record in the linked list (NULL if none)

◆ mobi_delete_record_by_seqnumber()

MOBI_RET mobi_delete_record_by_seqnumber ( MOBIData m,
const size_t  num 
)

Delete palm database record with given sequential number from MOBIData structure.

Parameters
[in,out]mMOBIData structure with loaded data
[in]numSequential number
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_delete_records_by_seqnumber()

MOBI_RET mobi_delete_records_by_seqnumber ( MOBIData m,
const size_t  num,
size_t *  count 
)

Delete palm count database records starting with given sequential number from MOBIData structure.

Number of deleted records may be less then given count, if there are not enough records in database.

Parameters
[in,out]mMOBIData structure with loaded data
[in]numSequential number
[in,out]countRecords count, updated wth number of records effectively extracted
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_determine_flowpart_type()

MOBIFiletype mobi_determine_flowpart_type ( const MOBIRawml rawml,
const size_t  part_number 
)

Get file type of given part with number [part_number].

Parameters
[in]rawmlMOBIRawml parsed records structure
[in]part_numberSequential number of the part within rawml structure
Returns
MOBIFiletype file type

◆ mobi_determine_font_type()

MOBIFiletype mobi_determine_font_type ( const unsigned char *  font_data,
const size_t  font_size 
)

Get font type of given font resource.

Parameters
[in]font_dataFont resource data
[in]font_sizeFont resource size
Returns
MOBIFiletype file type

◆ mobi_determine_resource_type()

MOBIFiletype mobi_determine_resource_type ( const MOBIPdbRecord record)

Get resource type (image, font) by checking its magic header.

Parameters
[in]recordMOBIPdbRecord structure containing unknown record type
Returns
MOBIFiletype file type, T_UNKNOWN if not determined, T_BREAK if end of records mark found

◆ mobi_extract_records_by_seqnumber()

MOBIPdbRecord* mobi_extract_records_by_seqnumber ( MOBIData m,
const size_t  num,
size_t *  count 
)

Extract palm count database records starting with given sequential number from MOBIData structure.

Extracted records are removed from palm database. Number of extracted records may be less then given count, if there are not enough records in database.

Parameters
[in,out]mMOBIData structure with loaded data
[in]numSequential number
[in,out]countRecords count, updated with number of records effectively extracted
Returns
Pointer to MOBIPdbRecord record structure, NULL if not found or on failure

◆ mobi_free_internals()

void mobi_free_internals ( MOBIData m)

Free internals.

Parameters
[in,out]mMOBIData structure with raw data and metadata

◆ mobi_get32be()

uint32_t mobi_get32be ( const unsigned char  buf[4])

Convert char buffer to 32-bit unsigned integer big endian.

Parameters
[in]bufInput buffer
Returns
Converted value

◆ mobi_get32le()

uint32_t mobi_get32le ( const unsigned char  buf[4])

Convert char buffer to 32-bit unsigned integer little endian.

Parameters
[in]bufInput buffer
Returns
Converted value

◆ mobi_get_drmsize()

uint32_t mobi_get_drmsize ( const MOBIData m)

Get size of serialized DRM data.

Parameters
[in]mMOBIData structure
Returns
Size of DRM data, zero on failure

◆ mobi_get_encoding()

MOBIEncoding mobi_get_encoding ( const MOBIData m)

Get text encoding of mobi document.

Parameters
[in]mMOBIData structure holding document data and metadata
Returns
MOBIEncoding text encoding (MOBI_UTF8 or MOBI_CP1252)

◆ mobi_get_exthsize()

uint32_t mobi_get_exthsize ( const MOBIData m)

Get size of serialized exth record including padding.

Parameters
[in]mMOBIData structure
Returns
Size of exth record, zero on failure

◆ mobi_get_record_by_magic()

MOBIPdbRecord* mobi_get_record_by_magic ( const MOBIData m,
const unsigned char  magic[4] 
)

Get palm database record with data header starting with given 4-byte magic string.

Parameters
[in]mMOBIData structure with loaded data
[in]magicMagic header
Returns
Pointer to MOBIPdbRecord record structure, NULL if not found or on failure

◆ mobi_get_records_count()

uint16_t mobi_get_records_count ( const MOBIData m)

Get count of palm database records.

Parameters
[in]mMOBIData structure
Returns
Count of records, zero on failure

◆ mobi_get_resourcetype_by_uid()

MOBIFiletype mobi_get_resourcetype_by_uid ( const MOBIRawml rawml,
const size_t  uid 
)

Get MOBIFiletype type of MOBIPart resource record with given unique id.

Parameters
[in]rawmlMOBIRawml structure with loaded data
[in]uidUnique id
Returns
Pointer to MOBIPart resource structure, NULL on failure

◆ mobi_has_drmcookies()

bool mobi_has_drmcookies ( const MOBIData m)

Check if DRM cookies are set for the document.

Parameters
[in]mMOBIData structure with loaded Record(s) 0 headers
Returns
true or false

◆ mobi_has_drmkey()

bool mobi_has_drmkey ( const MOBIData m)

Check if DRM key is set for the document.

Parameters
[in]mMOBIData structure with loaded Record(s) 0 headers
Returns
true or false

◆ mobi_insert_records_by_seqnumber()

MOBI_RET mobi_insert_records_by_seqnumber ( MOBIData m,
MOBIPdbRecord record,
const size_t  num 
)

Insert palm database records at given sequential number.

Parameters
[in,out]mMOBIData structure with loaded data
[in,out]recordLinked list of records
[in]numSequential number
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_is_cp1252()

bool mobi_is_cp1252 ( const MOBIData m)

Check if document's text is cp1252 encoded.

Parameters
[in]mMOBIData structure holding document data and metadata
Returns
True or false

◆ mobi_is_textread()

bool mobi_is_textread ( const MOBIData m)

Check if loaded document is TEXt/REAd format.

Parameters
[in]mMOBIData structure with loaded Record(s) 0 headers
Returns
true or false

◆ mobi_ligature_to_cp1252()

uint8_t mobi_ligature_to_cp1252 ( const uint8_t  byte1,
const uint8_t  byte2 
)

Decode ligature to cp1252.

Some latin ligatures are encoded in indices to facilitate search They are listed in LIGT header, but it seems every LIGT header contains same 5 ligatures (even if not all of them are used). So, instead of parsing header, we use static replacements. Invalid control characters are skipped

Parameters
[in]byte1First byte - control character
[in]byte2Second byte of the ligature
Returns
Ligature in cp1252 encoding, zero if not found

◆ mobi_ligature_to_utf16()

uint16_t mobi_ligature_to_utf16 ( const uint32_t  byte1,
const uint32_t  byte2 
)

Decode ligature to utf-16.

Parameters
[in]byte1First byte - control character, should be <= 5
[in]byte2Second byte of the ligature
Returns
Ligature in utf-16 encoding, uni_replacement if not found

◆ mobi_pow()

size_t mobi_pow ( unsigned  base,
unsigned  exp 
)

Calculate exponentiation for unsigned base and exponent.

Parameters
[in]baseBase
[in]expExponent
Returns
Result of base raised by the exponent exp

◆ mobi_remove_part_kf7()

MOBI_RET mobi_remove_part_kf7 ( MOBIData m)

Remove KF7 version from hybrid file.

Parameters
[in,out]mMOBIData structure
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_remove_part_kf8()

MOBI_RET mobi_remove_part_kf8 ( MOBIData m)

Remove KF8 version from hybrid file.

Parameters
[in,out]mMOBIData structure
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_remove_zeros()

void mobi_remove_zeros ( unsigned char *  buffer,
size_t *  len 
)

Remove null characters from char buffer.

Parameters
[in,out]bufferCharacter buffer
[in,out]lenSize of buffer, will be updated with new length

◆ mobi_set_fullname()

MOBI_RET mobi_set_fullname ( MOBIData m,
const char *  fullname 
)

Set ebook full name stored in Record 0 at offset given in MOBI header.

Parameters
[in,out]mMOBIData structure with loaded data
[in]fullnameMemory area to be filled with zero terminated full name string
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_set_pdbname()

MOBI_RET mobi_set_pdbname ( MOBIData m,
const char *  name 
)

Set palm database name.

Parameters
[in,out]mMOBIData structure with loaded data
[in]nameName
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_strdup()

char* mobi_strdup ( const char *  s)

strdup replacement

Returned pointer must be freed by caller

Parameters
[in]sInput string
Returns
Duplicated string

◆ mobi_swap32()

uint32_t mobi_swap32 ( const uint32_t  val)

Swap endianness of 32-bit value.

Parameters
[in]val4-byte unsigned integer
Returns
Integer with swapped endianness

◆ mobi_swap_mobidata()

MOBI_RET mobi_swap_mobidata ( MOBIData m)

Swap KF7 and KF8 MOBIData structures in a hybrid file.

MOBIData structures form a circular linked list in case of hybrid files. By default KF8 structure is first one in the list. This function puts KF7 structure on the first place, so that it starts to be used by default.

Parameters
[in,out]mMOBIData structure
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_unicode_to_utf8()

uint8_t mobi_unicode_to_utf8 ( char *  output,
const size_t  codepoint 
)

Convert unicode codepoint to utf-8 sequence.

Parameters
[in,out]outputOutput string
[in]codepointUnicode codepoint
Returns
Length of utf-8 sequence (maximum 4 bytes), zero on failure

◆ mobi_utf8_to_cp1252()

MOBI_RET mobi_utf8_to_cp1252 ( char *  output,
const char *  input,
size_t *  outsize,
const size_t  insize 
)

Convert utf-8 encoded string to cp1252.

Characters out of range will be replaced with substitute character

Parameters
[in,out]outputOutput string
[in,out]inputInput string
[in,out]outsizeSize of the allocated output buffer, will be set to output string length (without null terminator) on return
[in]insizeLength of the input string.
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

Variable Documentation

◆ mobi_file_meta

const MOBIFileMeta mobi_file_meta[]
Initial value:
= {
{T_HTML, "html", "application/xhtml+xml"},
{T_CSS, "css", "text/css"},
{T_SVG, "svg", "image/svg+xml"},
{T_JPG, "jpg", "image/jpeg"},
{T_GIF, "gif", "image/gif"},
{T_PNG, "png", "image/png"},
{T_BMP, "bmp", "image/bmp"},
{T_OTF, "otf", "application/vnd.ms-opentype"},
{T_TTF, "ttf", "application/x-font-truetype"},
{T_MP3, "mp3", "audio/mpeg"},
{T_MPG, "mpg", "video/mpeg"},
{T_PDF, "pdf", "application/pdf"},
{T_OPF, "opf", "application/oebps-package+xml"},
{T_NCX, "ncx", "application/x-dtbncx+xml"},
{T_UNKNOWN, "dat", "application/unknown"}
}
@ T_GIF
Definition: mobi.h:186
@ T_JPG
Definition: mobi.h:185
@ T_TTF
Definition: mobi.h:191
@ T_BMP
Definition: mobi.h:188
@ T_MP3
Definition: mobi.h:193
@ T_MPG
Definition: mobi.h:194
@ T_NCX
Definition: mobi.h:183
@ T_UNKNOWN
Definition: mobi.h:177
@ T_PNG
Definition: mobi.h:187
@ T_OPF
Definition: mobi.h:182
@ T_PDF
Definition: mobi.h:195
@ T_HTML
Definition: mobi.h:179
@ T_CSS
Definition: mobi.h:180
@ T_SVG
Definition: mobi.h:181
@ T_OTF
Definition: mobi.h:190

Array of known file types, their extensions and mime-types.