2 @brief Eet Data Handling Library Public API Calls
4 These routines are used for Eet Library interaction
6 @mainpage Eet Library Documentation
11 @author Carsten Haitzler <raster@@rasterman.com>
12 @author David Goodlad <dgoodlad@@gmail.com>
13 @author Cedric Bail <cedric.bail@@free.fr>
14 @author Arnaud de Turckheim <quarium@@gmail.com>
15 @author Luis Felipe Strano Moraes <lfelipe@@profusion.mobi>
16 @author Chidambar Zinnoury <illogict@@online.fr>
17 @author Vincent Torri <vtorri@@univ-evry.fr>
18 @author Gustavo Sverzut Barbieri <barbieri@@profusion.mobi>
19 @author Raphael Kubo da Costa <kubo@@profusion.mobi>
20 @author Mathieu Taillefumier <mathieu.taillefumier@@free.fr>
21 @author Albin "Lutin" Tonnerre <albin.tonnerre@@gmail.com>
22 @author Adam Simpkins <adam@@adamsimpkins.net>
25 @section toc Table of Contents
33 @li @ref intro_example
35 @section intro What is Eet?
37 It is a tiny library designed to write an arbitrary set of chunks of data
38 to a file and optionally compress each chunk (very much like a zip file)
39 and allow fast random-access reading of the file later on. It does not
40 do zip as a zip itself has more complexity than is needed, and it was much
41 simpler to implement this once here.
43 Eet is extremely fast, small and simple. Eet files can be very small and
44 highly compressed, making them very optimal for just sending across the
45 internet without having to archive, compress or decompress and install them.
46 They allow for lightning-fast random-acess reads once created, making them
47 perfect for storing data that is written once (or rarely) and read many
48 times, but the program does not want to have to read it all in at once.
50 It also can encode and decode data structures in memory, as well as image
51 data for saving to Eet files or sending across the network to other
52 machines, or just writing to arbitrary files on the system. All data is
53 encoded in a platform independent way and can be written and read by any
56 @section example A simple example on using Eet
58 Here is a simple example on how to use Eet to save a series of strings to a
59 file and load them again. The advantage of using Eet over just fprintf() and
60 fscanf() is that not only can these entries be strings, they need no special
61 parsing to handle delimiter characters or escaping, they can be binary data,
62 image data, data structures containing integers, strings, other data
63 structures, linked lists and much more, without the programmer having to
64 worry about parsing, and best of all, Eet is very fast.
70 main(int argc, char **argv)
80 "Big text string here compared to others",
86 // blindly open an file for output and write strings with their NUL char
87 ef = eet_open("test.eet", EET_FILE_MODE_WRITE);
88 eet_write(ef, "Entry 1", entries[0], strlen(entries[0]) + 1, 0);
89 eet_write(ef, "Entry 2", entries[1], strlen(entries[1]) + 1, 1);
90 eet_write(ef, "Entry 3", entries[2], strlen(entries[2]) + 1, 0);
93 // open the file again and blindly get the entries we wrote
94 ef = eet_open("test.eet", EET_FILE_MODE_READ);
95 ret = eet_read(ef, "Entry 1", &size);
97 ret = eet_read(ef, "Entry 2", &size);
99 ret = eet_read(ef, "Entry 3", &size);
107 @section format What does an Eet file look like?
109 The file format is very simple. There is a directory block at the start of
110 the file listing entries and offsets into the file where they are stored,
111 their sizes, compression flags etc. followed by all the entry data strung one
112 element after the other.
114 All Eet files start with t a 4 byte magic number. It is written using network
115 byte-order (big endian, or from most significant byte first to least
116 significant byte last) and is 0x1ee7ff00 (or byte by byte 0:1e 1:e7 2:ff
117 3:00). The next 4 bytes are an integer (in big endian notation) indicating
118 how many entries are stored in the Eet file. 0 indicates it is empty. This is
119 a signed integer and thus values less than 0 are invalid, limiting the number
120 of entries in an Eet file to 0x7fffffff entries at most. The next 4 bytes is
121 the size of the directory table, in bytes, encoded in big-endian format. This
122 is a signed integer and cannot be less than 0.
124 The directory table for the file follows immediately, with a continuous list
125 of all entries in the Eet file, their offset in the file etc. The order of
126 these entries is not important, but convention would have them be from first
127 to last entry in the file. Each directory entry consiste of 5 integers, one
128 after the other, each stored as a signed, big endian integer. The first is
129 the offset in the file that the data for this entry is stored at (based from
130 the very start of the file, not relative to the end of the directory block).
131 The second integer holds flags for the entry. currently only the least
132 significant bit (bit 0) holds any useful information, and it is set to 1 if
133 the entry is compressed using zlib compression calls, or 0 if it is not
134 compressed. The next integer is the size of the entry in bytes stored in the
135 file. The next integer is the size of the data when decompressed (if it was
136 compressed) in bytes. This may be the same as the previous integer if the
137 entry was not compressed. The final integer is the number of bytes used by
138 the string identifier for the entry, without the NUL byte terminator, which
139 is not stored. The next series of bytes is the string name of the entry, with
140 the number of bytes being the same as specified in the last integer above.
141 This list of entries continues until there are no more entries left to list.
142 To read an entry from an Eet file, simply find the appropriate entry in the
143 directory table, find it's offset and size, and read it into memory. If it is
144 compressed, decompress it using zlib and then use that data.
146 Here is a data map of an Eet file. All integers are encoded using big-endian
147 notation (most significant byte first) and are signed. There is no alignment
148 of data, so all data types follow immediately on, one after the other. All
149 compressed data is compressed using the zlib compress2() function, and
150 decompressed using the zlib uncompress() function. Please see zlib
151 documentation for more information as to the encoding of compressed data.
155 [INT] Magic number (0x1ee7ff00)
156 [INT] Number of entries in the directory table
157 [INT] The size of the directory table, in bytes
159 DIRECTORY TABLE ENTRIES (as many as specified in the header):
160 [INT] Offest from file start at which entry is stored (in bytes)
161 [INT] Entry flags (1 = compressed, 0 = not compressed)
162 [INT] Size of data chunk in file (in bytes)
163 [INT] Size of the data chunk once decompressed (or the same as above, if not)
164 [INT] The length of the string itendifier, in bytes, without NUL terminator
165 [STR] Series of bytes for the string identifier, no NUL terminator
166 ... more directory entries
168 DATA STORED, ONE AFTER ANOTHER:
169 [DAT] DATA ENTRY 1...
170 [DAT] DATA ENTRY 2...
171 [DAT] DATA ENTRY 3...
175 The contents of each entry in an Eet file has no defined format as such. It
176 is an opaque chunk of data, that is up to the application to deocde, unless
177 it is an image, ecoded by Eet, or a data structure encoded by Eet. The data
178 itself for these entries can be encoded and decoded by Eet with extra helper
179 functions in Eet. eet_data_image_read() and eet_data_image_write() are used
180 to handle reading and writing image data from a known Eet file entry name.
181 eet_data_read() and eet_data_write() are used to decode and encode program
182 data structures from an Eet file, making the loading and saving of program
183 information stored in data structures a simple 1 function call process.
185 Please see src/lib/eet_data.c for information on the format of these
186 specially encoded data entries in an Eet file (for now).
189 @section compiling How to compile using Eet ?
191 Eet is a library your application links to. The procedure for this is very
192 simple. You simply have to compile your application with the appropriate
193 compiler flags that the @p pkg-config script outputs. For example:
195 Compiling C or C++ files into object files:
198 gcc -c -o main.o main.c `pkg-config --cflags eet`
201 Linking object files into a binary executable:
204 gcc -o my_application main.o `pkg-config --libs eet`
207 You simply have to make sure that pkg-config is in your shell's PATH (see
208 the manual page for your appropriate shell) and eet.pc in /usr/lib/pkgconfig
209 or its path is in the PKG_CONFIG_PATH environment variable. It's that simple
210 to link and use Eet once you have written your code to use it.
212 Since the program is linked to Eet, it is now able to use any advertised
213 API calls to serialize your data.
215 You should make sure you add any extra compile and link flags to your
216 compile commands that your application may need as well. The above example
217 is only guaranteed to make Eet add it's own requirements.
220 @section install How is it installed?
232 @section next_steps Next Steps
234 After you understood what Eet is and installed it in your system you
235 should proceed understanding the programming interface. We'd recommend
236 you to take a while to learn Eina
237 (http://docs.enlightenment.org/auto/eina/) as it is very convenient
238 and optimized, and Eet provides integration with it.
242 @li @ref Eet_File_Group to know the basics to open and save files.
243 @li @ref Eet_Data_Group to know the convenient way to serialize and
244 parse your data structures automatically. Just create your
245 descriptors and let Eet do the work for you.
247 @section intro_example Introductory Examples
251 @todo Document data format for images and data structures.
264 #endif /* ifdef EAPI */
267 # ifdef EFL_EET_BUILD
269 # define EAPI __declspec(dllexport)
270 # else /* ifdef DLL_EXPORT */
272 # endif /* ! DLL_EXPORT */
273 # else /* ifdef EFL_EET_BUILD */
274 # define EAPI __declspec(dllimport)
275 # endif /* ! EFL_EET_BUILD */
276 #else /* ifdef _WIN32 */
279 # define EAPI __attribute__ ((visibility("default")))
280 # else /* if __GNUC__ >= 4 */
282 # endif /* if __GNUC__ >= 4 */
283 # else /* ifdef __GNUC__ */
285 # endif /* ifdef __GNUC__ */
286 #endif /* ! _WIN32 */
290 #endif /* ifdef __cplusplus */
294 * @brief The file that provides the eet functions.
296 * This header provides the Eet management functions.
300 #define EET_VERSION_MAJOR 1
301 #define EET_VERSION_MINOR 4
303 * @typedef Eet_Version
305 * This is the Eet version information structure that can be used at
306 * runtiime to detect which version of eet is being used and adapt
307 * appropriately as follows for example:
310 * #if defined(EET_VERSION_MAJOR) && (EET_VERSION_MAJOR >= 1) && defined(EET_VERSION_MINOR) && (EET_VERSION_MINOR > 2)
311 * printf("Eet version: %i.%i.%i\n",
312 * eet_version->major,
313 * eet_version->minor,
314 * eet_version->micro);
315 * if (eet_version->revision > 0)
317 * printf(" Built from SVN revision # %i\n", eet_version->revision);
322 * Note the #if check can be dropped if your program refuses to compile or
323 * work with an Eet version less than 1.3.0.
325 typedef struct _Eet_Version
327 int major; /** < major (binary or source incompatible changes) */
328 int minor; /** < minor (new features, bugfixes, major improvements version) */
329 int micro; /** < micro (bugfix, internal improvements, no new features version) */
330 int revision; /** < svn revision (0 if a proper rlease or the svn revsion number Eet is built from) */
333 EAPI extern Eet_Version *eet_version;
336 * @defgroup Eet_Group Top level functions
337 * Functions that affect Eet as a whole.
344 * All the error identifiers known by Eet.
346 typedef enum _Eet_Error
348 EET_ERROR_NONE, /**< No error, it's all fine! */
349 EET_ERROR_BAD_OBJECT, /**< Given object or handle is NULL or invalid */
350 EET_ERROR_EMPTY, /**< There was nothing to do */
351 EET_ERROR_NOT_WRITABLE, /**< Could not write to file or fine is #EET_FILE_MODE_READ */
352 EET_ERROR_OUT_OF_MEMORY, /**< Could not allocate memory */
353 EET_ERROR_WRITE_ERROR, /**< Failed to write data to destination */
354 EET_ERROR_WRITE_ERROR_FILE_TOO_BIG, /**< Failed to write file since it is too big */
355 EET_ERROR_WRITE_ERROR_IO_ERROR, /**< Failed to write since generic Input/Output error */
356 EET_ERROR_WRITE_ERROR_OUT_OF_SPACE, /**< Failed to write due out of space */
357 EET_ERROR_WRITE_ERROR_FILE_CLOSED, /**< Failed to write because file was closed */
358 EET_ERROR_MMAP_FAILED, /**< Could not mmap file */
359 EET_ERROR_X509_ENCODING_FAILED, /**< Could not encode using X509 */
360 EET_ERROR_SIGNATURE_FAILED, /**< Could not validate signature */
361 EET_ERROR_INVALID_SIGNATURE, /**< Signature is invalid */
362 EET_ERROR_NOT_SIGNED, /**< File or contents are not signed */
363 EET_ERROR_NOT_IMPLEMENTED, /**< Function is not implemented */
364 EET_ERROR_PRNG_NOT_SEEDED, /**< Could not introduce random seed */
365 EET_ERROR_ENCRYPT_FAILED, /**< Could not encrypt contents */
366 EET_ERROR_DECRYPT_FAILED /**< Could not decrypt contents */
367 } Eet_Error; /**< Eet error identifiers */
374 * Initialize the EET library.
376 * @return The new init count.
385 * Shut down the EET library.
387 * @return The new init count.
398 * Eet didn't free items by default. If you are under memory
399 * presure, just call this function to recall all memory that are
400 * not yet referenced anymore. The cache take care of modification
407 eet_clearcache(void);
410 * @defgroup Eet_File_Group Eet File Main Functions
412 * Functions to create, destroy and do basic manipulation of
419 * @enum _Eet_File_Mode
420 * Modes that a file can be opened.
422 typedef enum _Eet_File_Mode
424 EET_FILE_MODE_INVALID = -1,
425 EET_FILE_MODE_READ, /**< File is read-only. */
426 EET_FILE_MODE_WRITE, /**< File is write-only. */
427 EET_FILE_MODE_READ_WRITE /**< File is for both read and write */
428 } Eet_File_Mode; /**< Modes that a file can be opened. */
432 * Opaque handle that defines an Eet file (or memory).
435 * @see eet_memopen_read()
438 typedef struct _Eet_File Eet_File;
441 * @typedef Eet_Dictionary
442 * Opaque handle that defines a file-backed (mmaped) dictionary of strings.
444 typedef struct _Eet_Dictionary Eet_Dictionary;
451 * Open an eet file on disk, and returns a handle to it.
452 * @param file The file path to the eet file. eg: @c "/tmp/file.eet".
453 * @param mode The mode for opening. Either #EET_FILE_MODE_READ,
454 * #EET_FILE_MODE_WRITE or #EET_FILE_MODE_READ_WRITE.
455 * @return An opened eet file handle.
456 * @ingroup Eet_File_Group
458 * This function will open an exiting eet file for reading, and build
459 * the directory table in memory and return a handle to the file, if it
460 * exists and can be read, and no memory errors occur on the way, otherwise
461 * NULL will be returned.
463 * It will also open an eet file for writing. This will, if successful,
464 * delete the original file and replace it with a new empty file, till
465 * the eet file handle is closed or flushed. If it cannot be opened for
466 * writing or a memory error occurs, NULL is returned.
468 * You can also open the file for read/write. If you then write a key that
469 * does not exist it will be created, if the key exists it will be replaced
472 * If the same file is opened multiple times, then the same file handle will
473 * be returned as eet maintains an internal list of all currently open
474 * files. Note that it considers files opened for read only and those opened
475 * for read/write and write only as 2 separate sets. Those that do not write
476 * to the file and those that do. Eet will allow 2 handles to the same file
477 * if they are in the 2 separate lists/groups. That means opening a file for
478 * read only looks in the read only set, and returns a handle to that file
479 * handle and increments its reference count. If you open a file for read/write
480 * or write only it looks in the write set and returns a handle after
481 * incrementing the reference count. You need to close an eet file handle
482 * as many times as it has been opened to maintain correct reference counts.
483 * Files whose modified timestamp or size do not match those of the existing
484 * referenced file handles will not be returned and a new handle will be
491 * #include <string.h>
494 * main(int argc, char **argv)
497 * char buf[1024], *ret, **list;
502 * strcpy(buf, "Here is a string of data to save!");
504 * ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_WRITE);
505 * if (!ef) return -1;
506 * if (!eet_write(ef, "/key/to_store/at", buf, 1024, 1))
507 * fprintf(stderr, "Error writing data!\n");
510 * ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ);
511 * if (!ef) return -1;
512 * list = eet_list(ef, "*", &num);
515 * for (i = 0; i < num; i++)
516 * printf("Key stored: %s\n", list[i]);
519 * ret = eet_read(ef, "/key/to_store/at", &size);
522 * printf("Data read (%i bytes):\n%s\n", size, ret);
536 eet_open(const char *file,
540 * Open an eet file directly from a memory location. The data is not copied,
541 * so you must keep it around as long as the eet file is open. There is
542 * currently no cache for this kind of Eet_File, so it's reopened every time
543 * you use eet_memopen_read.
546 * @ingroup Eet_File_Group
549 eet_memopen_read(const void *data,
553 * Get the mode an Eet_File was opened with.
554 * @param ef A valid eet file handle.
555 * @return The mode ef was opened with.
558 * @ingroup Eet_File_Group
561 eet_mode_get(Eet_File *ef);
564 * Close an eet file handle and flush and writes pending.
565 * @param ef A valid eet file handle.
567 * This function will flush any pending writes to disk if the eet file
568 * was opened for write, and free all data associated with the file handle
569 * and file, and close the file.
571 * If the eet file handle is not valid nothing will be done.
574 * @ingroup Eet_File_Group
577 eet_close(Eet_File *ef);
580 * Sync content of an eet file handle, flushing pending writes.
581 * @param ef A valid eet file handle.
583 * This function will flush any pending writes to disk. The eet file must
584 * be opened for write.
586 * If the eet file handle is not valid nothing will be done.
589 * @ingroup Eet_File_Group
592 eet_sync(Eet_File *ef);
595 * Return a handle to the shared string dictionary of the Eet file
596 * @param ef A valid eet file handle.
597 * @return A handle to the dictionary of the file
599 * This function returns a handle to the dictionary of an Eet file whose
600 * handle is @p ef, if a dictionary exists. NULL is returned otherwise or
601 * if the file handle is known to be invalid.
603 * @see eet_dictionary_string_check() to know if given string came
604 * from the dictionary or it was dynamically allocated using
605 * the #Eet_Data_Descriptor_Class instructrions.
608 * @ingroup Eet_File_Group
610 EAPI Eet_Dictionary *
611 eet_dictionary_get(Eet_File *ef);
614 * Check if a given string comes from a given dictionary
615 * @param ed A valid dictionary handle
616 * @param string A valid 0 byte terminated C string
617 * @return 1 if it is in the dictionary, 0 otherwise
619 * This checks the given dictionary to see if the given string is actually
620 * inside that dictionary (i.e. comes from it) and returns 1 if it does.
621 * If the dictionary handle is invlide, the string is NULL or the string is
622 * not in the dictionary, 0 is returned.
625 * @ingroup Eet_File_Group
628 eet_dictionary_string_check(Eet_Dictionary *ed,
632 * Read a specified entry from an eet file and return data
633 * @param ef A valid eet file handle opened for reading.
634 * @param name Name of the entry. eg: "/base/file_i_want".
635 * @param size_ret Number of bytes read from entry and returned.
636 * @return The data stored in that entry in the eet file.
638 * This function finds an entry in the eet file that is stored under the
639 * name specified, and returns that data, decompressed, if successful.
640 * NULL is returned if the lookup fails or if memory errors are
641 * encountered. It is the job of the calling program to call free() on
642 * the returned data. The number of bytes in the returned data chunk are
643 * placed in size_ret.
645 * If the eet file handle is not valid NULL is returned and size_ret is
648 * @see eet_read_cipher()
651 * @ingroup Eet_File_Group
654 eet_read(Eet_File *ef,
659 * Read a specified entry from an eet file and return data
660 * @param ef A valid eet file handle opened for reading.
661 * @param name Name of the entry. eg: "/base/file_i_want".
662 * @param size_ret Number of bytes read from entry and returned.
663 * @return The data stored in that entry in the eet file.
665 * This function finds an entry in the eet file that is stored under the
666 * name specified, and returns that data if not compressed and successful.
667 * NULL is returned if the lookup fails or if memory errors are
668 * encountered or if the data is comrpessed. The calling program must never
669 * call free() on the returned data. The number of bytes in the returned
670 * data chunk are placed in size_ret.
672 * If the eet file handle is not valid NULL is returned and size_ret is
676 * @ingroup Eet_File_Group
679 eet_read_direct(Eet_File *ef,
684 * Write a specified entry to an eet file handle
685 * @param ef A valid eet file handle opened for writing.
686 * @param name Name of the entry. eg: "/base/file_i_want".
687 * @param data Pointer to the data to be stored.
688 * @param size Length in bytes in the data to be stored.
689 * @param compress Compression flags (1 == compress, 0 = don't compress).
690 * @return bytes written on successful write, 0 on failure.
692 * This function will write the specified chunk of data to the eet file
693 * and return greater than 0 on success. 0 will be returned on failure.
695 * The eet file handle must be a valid file handle for an eet file opened
696 * for writing. If it is not, 0 will be returned and no action will be
699 * Name, and data must not be NULL, and size must be > 0. If these
700 * conditions are not met, 0 will be returned.
702 * The data will be copied (and optionally compressed) in ram, pending
703 * a flush to disk (it will stay in ram till the eet file handle is
706 * @see eet_write_cipher()
709 * @ingroup Eet_File_Group
712 eet_write(Eet_File *ef,
719 * Delete a specified entry from an Eet file being written or re-written
720 * @param ef A valid eet file handle opened for writing.
721 * @param name Name of the entry. eg: "/base/file_i_want".
722 * @return Success or failure of the delete.
724 * This function will delete the specified chunk of data from the eet file
725 * and return greater than 0 on success. 0 will be returned on failure.
727 * The eet file handle must be a valid file handle for an eet file opened
728 * for writing. If it is not, 0 will be returned and no action will be
731 * Name, must not be NULL, otherwise 0 will be returned.
734 * @ingroup Eet_File_Group
737 eet_delete(Eet_File *ef,
741 * Alias a specific section to another one. Destination may exist or not,
743 * @param ef A valid eet file handle opened for writing.
744 * @param name Name of the entry. eg: "/base/file_i_want".
745 * @param destination Destionation of the alias. eg: "/base/the_real_stuff_i_want".
746 * @param compress Compression flags (1 == compress, 0 = don't compress).
747 * @return EINA_TRUE on success, EINA_FALSE on failure.
749 * Name and Destination must not be NULL, otherwhise EINA_FALSE will be returned.
752 * @ingroup Eet_File_Group
755 eet_alias(Eet_File *ef,
757 const char *destination,
761 * List all entries in eet file matching shell glob.
762 * @param ef A valid eet file handle.
763 * @param glob A shell glob to match against.
764 * @param count_ret Number of entries found to match.
765 * @return Pointer to an array of strings.
767 * This function will list all entries in the eet file matching the
768 * supplied shell glob and return an allocated list of their names, if
769 * there are any, and if no memory errors occur.
771 * The eet file handle must be valid and glob must not be NULL, or NULL
772 * will be returned and count_ret will be filled with 0.
774 * The calling program must call free() on the array returned, but NOT
775 * on the string pointers in the array. They are taken as read-only
776 * internals from the eet file handle. They are only valid as long as
777 * the file handle is not closed. When it is closed those pointers in the
778 * array are now not valid and should not be used.
780 * On success the array returned will have a list of string pointers
781 * that are the names of the entries that matched, and count_ret will have
782 * the number of entries in this array placed in it.
784 * Hint: an easy way to list all entries in an eet file is to use a glob
788 * @ingroup Eet_File_Group
791 eet_list(Eet_File *ef,
796 * Return the number of entries in the specified eet file.
797 * @param ef A valid eet file handle.
798 * @return Number of entries in ef or -1 if the number of entries
799 * cannot be read due to open mode restrictions.
802 * @ingroup Eet_File_Group
805 eet_num_entries(Eet_File *ef);
808 * @defgroup Eet_File_Cipher_Group Eet File Ciphered Main Functions
810 * Most of the @ref Eet_File_Group have alternative versions that
811 * accounts for ciphers to protect their content.
813 * @see @ref Eet_Cipher_Group
815 * @ingroup Eet_File_Group
819 * Read a specified entry from an eet file and return data using a cipher.
820 * @param ef A valid eet file handle opened for reading.
821 * @param name Name of the entry. eg: "/base/file_i_want".
822 * @param size_ret Number of bytes read from entry and returned.
823 * @param cipher_key The key to use as cipher.
824 * @return The data stored in that entry in the eet file.
826 * This function finds an entry in the eet file that is stored under the
827 * name specified, and returns that data, decompressed, if successful.
828 * NULL is returned if the lookup fails or if memory errors are
829 * encountered. It is the job of the calling program to call free() on
830 * the returned data. The number of bytes in the returned data chunk are
831 * placed in size_ret.
833 * If the eet file handle is not valid NULL is returned and size_ret is
839 * @ingroup Eet_File_Cipher_Group
842 eet_read_cipher(Eet_File *ef,
845 const char *cipher_key);
848 * Write a specified entry to an eet file handle using a cipher.
849 * @param ef A valid eet file handle opened for writing.
850 * @param name Name of the entry. eg: "/base/file_i_want".
851 * @param data Pointer to the data to be stored.
852 * @param size Length in bytes in the data to be stored.
853 * @param compress Compression flags (1 == compress, 0 = don't compress).
854 * @param cipher_key The key to use as cipher.
855 * @return bytes written on successful write, 0 on failure.
857 * This function will write the specified chunk of data to the eet file
858 * and return greater than 0 on success. 0 will be returned on failure.
860 * The eet file handle must be a valid file handle for an eet file opened
861 * for writing. If it is not, 0 will be returned and no action will be
864 * Name, and data must not be NULL, and size must be > 0. If these
865 * conditions are not met, 0 will be returned.
867 * The data will be copied (and optionally compressed) in ram, pending
868 * a flush to disk (it will stay in ram till the eet file handle is
874 * @ingroup Eet_File_Cipher_Group
877 eet_write_cipher(Eet_File *ef,
882 const char *cipher_key);
885 * @defgroup Eet_File_Image_Group Image Store and Load
887 * Eet efficiently stores and loads images, including alpha
888 * channels and lossy compressions.
892 * Read just the header data for an image and dont decode the pixels.
893 * @param ef A valid eet file handle opened for reading.
894 * @param name Name of the entry. eg: "/base/file_i_want".
895 * @param w A pointer to the unsigned int to hold the width in pixels.
896 * @param h A pointer to the unsigned int to hold the height in pixels.
897 * @param alpha A pointer to the int to hold the alpha flag.
898 * @param compress A pointer to the int to hold the compression amount.
899 * @param quality A pointer to the int to hold the quality amount.
900 * @param lossy A pointer to the int to hold the lossiness flag.
901 * @return 1 on successful decode, 0 otherwise
903 * This function reads an image from an eet file stored under the named
904 * key in the eet file and return a pointer to the decompressed pixel data.
906 * The other parameters of the image (width, height etc.) are placed into
907 * the values pointed to (they must be supplied). The pixel data is a linear
908 * array of pixels starting from the top-left of the image scanning row by
909 * row from left to right. Each pile is a 32bit value, with the high byte
910 * being the alpha channel, the next being red, then green, and the low byte
911 * being blue. The width and height are measured in pixels and will be
912 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
913 * that the alpha channel is not used. 1 denotes that it is significant.
914 * Compress is filled with the compression value/amount the image was
915 * stored with. The quality value is filled with the quality encoding of
916 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
917 * the image was encoded lossily or not.
919 * On success the function returns 1 indicating the header was read and
920 * decoded properly, or 0 on failure.
922 * @see eet_data_image_header_read_cipher()
925 * @ingroup Eet_File_Image_Group
928 eet_data_image_header_read(Eet_File *ef,
938 * Read image data from the named key in the eet file.
939 * @param ef A valid eet file handle opened for reading.
940 * @param name Name of the entry. eg: "/base/file_i_want".
941 * @param w A pointer to the unsigned int to hold the width in pixels.
942 * @param h A pointer to the unsigned int to hold the height in pixels.
943 * @param alpha A pointer to the int to hold the alpha flag.
944 * @param compress A pointer to the int to hold the compression amount.
945 * @param quality A pointer to the int to hold the quality amount.
946 * @param lossy A pointer to the int to hold the lossiness flag.
947 * @return The image pixel data decoded
949 * This function reads an image from an eet file stored under the named
950 * key in the eet file and return a pointer to the decompressed pixel data.
952 * The other parameters of the image (width, height etc.) are placed into
953 * the values pointed to (they must be supplied). The pixel data is a linear
954 * array of pixels starting from the top-left of the image scanning row by
955 * row from left to right. Each pile is a 32bit value, with the high byte
956 * being the alpha channel, the next being red, then green, and the low byte
957 * being blue. The width and height are measured in pixels and will be
958 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
959 * that the alpha channel is not used. 1 denotes that it is significant.
960 * Compress is filled with the compression value/amount the image was
961 * stored with. The quality value is filled with the quality encoding of
962 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
963 * the image was encoded lossily or not.
965 * On success the function returns a pointer to the image data decoded. The
966 * calling application is responsible for calling free() on the image data
967 * when it is done with it. On failure NULL is returned and the parameter
968 * values may not contain any sensible data.
970 * @see eet_data_image_read_cipher()
973 * @ingroup Eet_File_Image_Group
976 eet_data_image_read(Eet_File *ef,
986 * Read image data from the named key in the eet file.
987 * @param ef A valid eet file handle opened for reading.
988 * @param name Name of the entry. eg: "/base/file_i_want".
989 * @param src_x The starting x coordinate from where to dump the stream.
990 * @param src_y The starting y coordinate from where to dump the stream.
991 * @param d A pointer to the pixel surface.
992 * @param w The expected width in pixels of the pixel surface to decode.
993 * @param h The expected height in pixels of the pixel surface to decode.
994 * @param row_stride The length of a pixels line in the destination surface.
995 * @param alpha A pointer to the int to hold the alpha flag.
996 * @param compress A pointer to the int to hold the compression amount.
997 * @param quality A pointer to the int to hold the quality amount.
998 * @param lossy A pointer to the int to hold the lossiness flag.
999 * @return 1 on success, 0 otherwise.
1001 * This function reads an image from an eet file stored under the named
1002 * key in the eet file and return a pointer to the decompressed pixel data.
1004 * The other parameters of the image (width, height etc.) are placed into
1005 * the values pointed to (they must be supplied). The pixel data is a linear
1006 * array of pixels starting from the top-left of the image scanning row by
1007 * row from left to right. Each pile is a 32bit value, with the high byte
1008 * being the alpha channel, the next being red, then green, and the low byte
1009 * being blue. The width and height are measured in pixels and will be
1010 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1011 * that the alpha channel is not used. 1 denotes that it is significant.
1012 * Compress is filled with the compression value/amount the image was
1013 * stored with. The quality value is filled with the quality encoding of
1014 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1015 * the image was encoded lossily or not.
1017 * On success the function returns 1, and 0 on failure. On failure the
1018 * parameter values may not contain any sensible data.
1020 * @see eet_data_image_read_to_surface_cipher()
1023 * @ingroup Eet_File_Image_Group
1026 eet_data_image_read_to_surface(Eet_File *ef,
1033 unsigned int row_stride,
1040 * Write image data to the named key in an eet file.
1041 * @param ef A valid eet file handle opened for writing.
1042 * @param name Name of the entry. eg: "/base/file_i_want".
1043 * @param data A pointer to the image pixel data.
1044 * @param w The width of the image in pixels.
1045 * @param h The height of the image in pixels.
1046 * @param alpha The alpha channel flag.
1047 * @param compress The compression amount.
1048 * @param quality The quality encoding amount.
1049 * @param lossy The lossiness flag.
1050 * @return Success if the data was encoded and written or not.
1052 * This function takes image pixel data and encodes it in an eet file
1053 * stored under the supplied name key, and returns how many bytes were
1054 * actually written to encode the image data.
1056 * The data expected is the same format as returned by eet_data_image_read.
1057 * If this is not the case weird things may happen. Width and height must
1058 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1059 * the alpha values are not useful and 1 meaning they are). Compress can
1060 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1061 * This is only used if the image is not lossily encoded. Quality is used on
1062 * lossy compression and should be a value from 0 to 100. The lossy flag
1063 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1064 * image quality loss (but then have a much smaller encoding).
1066 * On success this function returns the number of bytes that were required
1067 * to encode the image data, or on failure it returns 0.
1069 * @see eet_data_image_write_cipher()
1072 * @ingroup Eet_File_Image_Group
1075 eet_data_image_write(Eet_File *ef,
1086 * Decode Image data header only to get information.
1087 * @param data The encoded pixel data.
1088 * @param size The size, in bytes, of the encoded pixel data.
1089 * @param w A pointer to the unsigned int to hold the width in pixels.
1090 * @param h A pointer to the unsigned int to hold the height in pixels.
1091 * @param alpha A pointer to the int to hold the alpha flag.
1092 * @param compress A pointer to the int to hold the compression amount.
1093 * @param quality A pointer to the int to hold the quality amount.
1094 * @param lossy A pointer to the int to hold the lossiness flag.
1095 * @return 1 on success, 0 on failure.
1097 * This function takes encoded pixel data and decodes it into raw RGBA
1098 * pixels on success.
1100 * The other parameters of the image (width, height etc.) are placed into
1101 * the values pointed to (they must be supplied). The pixel data is a linear
1102 * array of pixels starting from the top-left of the image scanning row by
1103 * row from left to right. Each pixel is a 32bit value, with the high byte
1104 * being the alpha channel, the next being red, then green, and the low byte
1105 * being blue. The width and height are measured in pixels and will be
1106 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1107 * that the alpha channel is not used. 1 denotes that it is significant.
1108 * Compress is filled with the compression value/amount the image was
1109 * stored with. The quality value is filled with the quality encoding of
1110 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1111 * the image was encoded lossily or not.
1113 * On success the function returns 1 indicating the header was read and
1114 * decoded properly, or 0 on failure.
1116 * @see eet_data_image_header_decode_cipher()
1119 * @ingroup Eet_File_Image_Group
1122 eet_data_image_header_decode(const void *data,
1132 * Decode Image data into pixel data.
1133 * @param data The encoded pixel data.
1134 * @param size The size, in bytes, of the encoded pixel data.
1135 * @param w A pointer to the unsigned int to hold the width in pixels.
1136 * @param h A pointer to the unsigned int to hold the height in pixels.
1137 * @param alpha A pointer to the int to hold the alpha flag.
1138 * @param compress A pointer to the int to hold the compression amount.
1139 * @param quality A pointer to the int to hold the quality amount.
1140 * @param lossy A pointer to the int to hold the lossiness flag.
1141 * @return The image pixel data decoded
1143 * This function takes encoded pixel data and decodes it into raw RGBA
1144 * pixels on success.
1146 * The other parameters of the image (width, height etc.) are placed into
1147 * the values pointed to (they must be supplied). The pixel data is a linear
1148 * array of pixels starting from the top-left of the image scanning row by
1149 * row from left to right. Each pixel is a 32bit value, with the high byte
1150 * being the alpha channel, the next being red, then green, and the low byte
1151 * being blue. The width and height are measured in pixels and will be
1152 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1153 * that the alpha channel is not used. 1 denotes that it is significant.
1154 * Compress is filled with the compression value/amount the image was
1155 * stored with. The quality value is filled with the quality encoding of
1156 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1157 * the image was encoded lossily or not.
1159 * On success the function returns a pointer to the image data decoded. The
1160 * calling application is responsible for calling free() on the image data
1161 * when it is done with it. On failure NULL is returned and the parameter
1162 * values may not contain any sensible data.
1164 * @see eet_data_image_decode_cipher()
1167 * @ingroup Eet_File_Image_Group
1170 eet_data_image_decode(const void *data,
1180 * Decode Image data into pixel data.
1181 * @param data The encoded pixel data.
1182 * @param size The size, in bytes, of the encoded pixel data.
1183 * @param src_x The starting x coordinate from where to dump the stream.
1184 * @param src_y The starting y coordinate from where to dump the stream.
1185 * @param d A pointer to the pixel surface.
1186 * @param w The expected width in pixels of the pixel surface to decode.
1187 * @param h The expected height in pixels of the pixel surface to decode.
1188 * @param row_stride The length of a pixels line in the destination surface.
1189 * @param alpha A pointer to the int to hold the alpha flag.
1190 * @param compress A pointer to the int to hold the compression amount.
1191 * @param quality A pointer to the int to hold the quality amount.
1192 * @param lossy A pointer to the int to hold the lossiness flag.
1193 * @return 1 on success, 0 otherwise.
1195 * This function takes encoded pixel data and decodes it into raw RGBA
1196 * pixels on success.
1198 * The other parameters of the image (alpha, compress etc.) are placed into
1199 * the values pointed to (they must be supplied). The pixel data is a linear
1200 * array of pixels starting from the top-left of the image scanning row by
1201 * row from left to right. Each pixel is a 32bit value, with the high byte
1202 * being the alpha channel, the next being red, then green, and the low byte
1203 * being blue. The width and height are measured in pixels and will be
1204 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1205 * that the alpha channel is not used. 1 denotes that it is significant.
1206 * Compress is filled with the compression value/amount the image was
1207 * stored with. The quality value is filled with the quality encoding of
1208 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1209 * the image was encoded lossily or not.
1211 * On success the function returns 1, and 0 on failure. On failure the
1212 * parameter values may not contain any sensible data.
1214 * @see eet_data_image_decode_to_surface_cipher()
1217 * @ingroup Eet_File_Image_Group
1220 eet_data_image_decode_to_surface(const void *data,
1227 unsigned int row_stride,
1234 * Encode image data for storage or transmission.
1235 * @param data A pointer to the image pixel data.
1236 * @param size_ret A pointer to an int to hold the size of the returned data.
1237 * @param w The width of the image in pixels.
1238 * @param h The height of the image in pixels.
1239 * @param alpha The alpha channel flag.
1240 * @param compress The compression amount.
1241 * @param quality The quality encoding amount.
1242 * @param lossy The lossiness flag.
1243 * @return The encoded image data.
1245 * This function stakes image pixel data and encodes it with compression and
1246 * possible loss of quality (as a trade off for size) for storage or
1247 * transmission to another system.
1249 * The data expected is the same format as returned by eet_data_image_read.
1250 * If this is not the case weird things may happen. Width and height must
1251 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1252 * the alpha values are not useful and 1 meaning they are). Compress can
1253 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1254 * This is only used if the image is not lossily encoded. Quality is used on
1255 * lossy compression and should be a value from 0 to 100. The lossy flag
1256 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1257 * image quality loss (but then have a much smaller encoding).
1259 * On success this function returns a pointer to the encoded data that you
1260 * can free with free() when no longer needed.
1262 * @see eet_data_image_encode_cipher()
1265 * @ingroup Eet_File_Image_Group
1268 eet_data_image_encode(const void *data,
1278 * @defgroup Eet_File_Image_Cipher_Group Image Store and Load using a Cipher
1280 * Most of the @ref Eet_File_Image_Group have alternative versions
1281 * that accounts for ciphers to protect their content.
1283 * @see @ref Eet_Cipher_Group
1285 * @ingroup Eet_File_Image_Group
1289 * Read just the header data for an image and dont decode the pixels using a cipher.
1290 * @param ef A valid eet file handle opened for reading.
1291 * @param name Name of the entry. eg: "/base/file_i_want".
1292 * @param cipher_key The key to use as cipher.
1293 * @param w A pointer to the unsigned int to hold the width in pixels.
1294 * @param h A pointer to the unsigned int to hold the height in pixels.
1295 * @param alpha A pointer to the int to hold the alpha flag.
1296 * @param compress A pointer to the int to hold the compression amount.
1297 * @param quality A pointer to the int to hold the quality amount.
1298 * @param lossy A pointer to the int to hold the lossiness flag.
1299 * @return 1 on successful decode, 0 otherwise
1301 * This function reads an image from an eet file stored under the named
1302 * key in the eet file and return a pointer to the decompressed pixel data.
1304 * The other parameters of the image (width, height etc.) are placed into
1305 * the values pointed to (they must be supplied). The pixel data is a linear
1306 * array of pixels starting from the top-left of the image scanning row by
1307 * row from left to right. Each pile is a 32bit value, with the high byte
1308 * being the alpha channel, the next being red, then green, and the low byte
1309 * being blue. The width and height are measured in pixels and will be
1310 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1311 * that the alpha channel is not used. 1 denotes that it is significant.
1312 * Compress is filled with the compression value/amount the image was
1313 * stored with. The quality value is filled with the quality encoding of
1314 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1315 * the image was encoded lossily or not.
1317 * On success the function returns 1 indicating the header was read and
1318 * decoded properly, or 0 on failure.
1320 * @see eet_data_image_header_read()
1323 * @ingroup Eet_File_Image_Cipher_Group
1326 eet_data_image_header_read_cipher(Eet_File *ef,
1328 const char *cipher_key,
1337 * Read image data from the named key in the eet file using a cipher.
1338 * @param ef A valid eet file handle opened for reading.
1339 * @param name Name of the entry. eg: "/base/file_i_want".
1340 * @param cipher_key The key to use as cipher.
1341 * @param w A pointer to the unsigned int to hold the width in pixels.
1342 * @param h A pointer to the unsigned int to hold the height in pixels.
1343 * @param alpha A pointer to the int to hold the alpha flag.
1344 * @param compress A pointer to the int to hold the compression amount.
1345 * @param quality A pointer to the int to hold the quality amount.
1346 * @param lossy A pointer to the int to hold the lossiness flag.
1347 * @return The image pixel data decoded
1349 * This function reads an image from an eet file stored under the named
1350 * key in the eet file and return a pointer to the decompressed pixel data.
1352 * The other parameters of the image (width, height etc.) are placed into
1353 * the values pointed to (they must be supplied). The pixel data is a linear
1354 * array of pixels starting from the top-left of the image scanning row by
1355 * row from left to right. Each pile is a 32bit value, with the high byte
1356 * being the alpha channel, the next being red, then green, and the low byte
1357 * being blue. The width and height are measured in pixels and will be
1358 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1359 * that the alpha channel is not used. 1 denotes that it is significant.
1360 * Compress is filled with the compression value/amount the image was
1361 * stored with. The quality value is filled with the quality encoding of
1362 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1363 * the image was encoded lossily or not.
1365 * On success the function returns a pointer to the image data decoded. The
1366 * calling application is responsible for calling free() on the image data
1367 * when it is done with it. On failure NULL is returned and the parameter
1368 * values may not contain any sensible data.
1370 * @see eet_data_image_read()
1373 * @ingroup Eet_File_Image_Cipher_Group
1376 eet_data_image_read_cipher(Eet_File *ef,
1378 const char *cipher_key,
1387 * Read image data from the named key in the eet file using a cipher.
1388 * @param ef A valid eet file handle opened for reading.
1389 * @param name Name of the entry. eg: "/base/file_i_want".
1390 * @param cipher_key The key to use as cipher.
1391 * @param src_x The starting x coordinate from where to dump the stream.
1392 * @param src_y The starting y coordinate from where to dump the stream.
1393 * @param d A pointer to the pixel surface.
1394 * @param w The expected width in pixels of the pixel surface to decode.
1395 * @param h The expected height in pixels of the pixel surface to decode.
1396 * @param row_stride The length of a pixels line in the destination surface.
1397 * @param alpha A pointer to the int to hold the alpha flag.
1398 * @param compress A pointer to the int to hold the compression amount.
1399 * @param quality A pointer to the int to hold the quality amount.
1400 * @param lossy A pointer to the int to hold the lossiness flag.
1401 * @return 1 on success, 0 otherwise.
1403 * This function reads an image from an eet file stored under the named
1404 * key in the eet file and return a pointer to the decompressed pixel data.
1406 * The other parameters of the image (width, height etc.) are placed into
1407 * the values pointed to (they must be supplied). The pixel data is a linear
1408 * array of pixels starting from the top-left of the image scanning row by
1409 * row from left to right. Each pile is a 32bit value, with the high byte
1410 * being the alpha channel, the next being red, then green, and the low byte
1411 * being blue. The width and height are measured in pixels and will be
1412 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1413 * that the alpha channel is not used. 1 denotes that it is significant.
1414 * Compress is filled with the compression value/amount the image was
1415 * stored with. The quality value is filled with the quality encoding of
1416 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1417 * the image was encoded lossily or not.
1419 * On success the function returns 1, and 0 on failure. On failure the
1420 * parameter values may not contain any sensible data.
1422 * @see eet_data_image_read_to_surface()
1425 * @ingroup Eet_File_Image_Cipher_Group
1428 eet_data_image_read_to_surface_cipher(Eet_File *ef,
1430 const char *cipher_key,
1436 unsigned int row_stride,
1443 * Write image data to the named key in an eet file using a cipher.
1444 * @param ef A valid eet file handle opened for writing.
1445 * @param name Name of the entry. eg: "/base/file_i_want".
1446 * @param cipher_key The key to use as cipher.
1447 * @param data A pointer to the image pixel data.
1448 * @param w The width of the image in pixels.
1449 * @param h The height of the image in pixels.
1450 * @param alpha The alpha channel flag.
1451 * @param compress The compression amount.
1452 * @param quality The quality encoding amount.
1453 * @param lossy The lossiness flag.
1454 * @return Success if the data was encoded and written or not.
1456 * This function takes image pixel data and encodes it in an eet file
1457 * stored under the supplied name key, and returns how many bytes were
1458 * actually written to encode the image data.
1460 * The data expected is the same format as returned by eet_data_image_read.
1461 * If this is not the case weird things may happen. Width and height must
1462 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1463 * the alpha values are not useful and 1 meaning they are). Compress can
1464 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1465 * This is only used if the image is not lossily encoded. Quality is used on
1466 * lossy compression and should be a value from 0 to 100. The lossy flag
1467 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1468 * image quality loss (but then have a much smaller encoding).
1470 * On success this function returns the number of bytes that were required
1471 * to encode the image data, or on failure it returns 0.
1473 * @see eet_data_image_write()
1476 * @ingroup Eet_File_Image_Cipher_Group
1479 eet_data_image_write_cipher(Eet_File *ef,
1481 const char *cipher_key,
1491 * Decode Image data header only to get information using a cipher.
1492 * @param data The encoded pixel data.
1493 * @param cipher_key The key to use as cipher.
1494 * @param size The size, in bytes, of the encoded pixel data.
1495 * @param w A pointer to the unsigned int to hold the width in pixels.
1496 * @param h A pointer to the unsigned int to hold the height in pixels.
1497 * @param alpha A pointer to the int to hold the alpha flag.
1498 * @param compress A pointer to the int to hold the compression amount.
1499 * @param quality A pointer to the int to hold the quality amount.
1500 * @param lossy A pointer to the int to hold the lossiness flag.
1501 * @return 1 on success, 0 on failure.
1503 * This function takes encoded pixel data and decodes it into raw RGBA
1504 * pixels on success.
1506 * The other parameters of the image (width, height etc.) are placed into
1507 * the values pointed to (they must be supplied). The pixel data is a linear
1508 * array of pixels starting from the top-left of the image scanning row by
1509 * row from left to right. Each pixel is a 32bit value, with the high byte
1510 * being the alpha channel, the next being red, then green, and the low byte
1511 * being blue. The width and height are measured in pixels and will be
1512 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1513 * that the alpha channel is not used. 1 denotes that it is significant.
1514 * Compress is filled with the compression value/amount the image was
1515 * stored with. The quality value is filled with the quality encoding of
1516 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1517 * the image was encoded lossily or not.
1519 * On success the function returns 1 indicating the header was read and
1520 * decoded properly, or 0 on failure.
1522 * @see eet_data_image_header_decode()
1525 * @ingroup Eet_File_Image_Cipher_Group
1528 eet_data_image_header_decode_cipher(const void *data,
1529 const char *cipher_key,
1539 * Decode Image data into pixel data using a cipher.
1540 * @param data The encoded pixel data.
1541 * @param cipher_key The key to use as cipher.
1542 * @param size The size, in bytes, of the encoded pixel data.
1543 * @param w A pointer to the unsigned int to hold the width in pixels.
1544 * @param h A pointer to the unsigned int to hold the height in pixels.
1545 * @param alpha A pointer to the int to hold the alpha flag.
1546 * @param compress A pointer to the int to hold the compression amount.
1547 * @param quality A pointer to the int to hold the quality amount.
1548 * @param lossy A pointer to the int to hold the lossiness flag.
1549 * @return The image pixel data decoded
1551 * This function takes encoded pixel data and decodes it into raw RGBA
1552 * pixels on success.
1554 * The other parameters of the image (width, height etc.) are placed into
1555 * the values pointed to (they must be supplied). The pixel data is a linear
1556 * array of pixels starting from the top-left of the image scanning row by
1557 * row from left to right. Each pixel is a 32bit value, with the high byte
1558 * being the alpha channel, the next being red, then green, and the low byte
1559 * being blue. The width and height are measured in pixels and will be
1560 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1561 * that the alpha channel is not used. 1 denotes that it is significant.
1562 * Compress is filled with the compression value/amount the image was
1563 * stored with. The quality value is filled with the quality encoding of
1564 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1565 * the image was encoded lossily or not.
1567 * On success the function returns a pointer to the image data decoded. The
1568 * calling application is responsible for calling free() on the image data
1569 * when it is done with it. On failure NULL is returned and the parameter
1570 * values may not contain any sensible data.
1572 * @see eet_data_image_decode()
1575 * @ingroup Eet_File_Image_Cipher_Group
1578 eet_data_image_decode_cipher(const void *data,
1579 const char *cipher_key,
1589 * Decode Image data into pixel data using a cipher.
1590 * @param data The encoded pixel data.
1591 * @param cipher_key The key to use as cipher.
1592 * @param size The size, in bytes, of the encoded pixel data.
1593 * @param src_x The starting x coordinate from where to dump the stream.
1594 * @param src_y The starting y coordinate from where to dump the stream.
1595 * @param d A pointer to the pixel surface.
1596 * @param w The expected width in pixels of the pixel surface to decode.
1597 * @param h The expected height in pixels of the pixel surface to decode.
1598 * @param row_stride The length of a pixels line in the destination surface.
1599 * @param alpha A pointer to the int to hold the alpha flag.
1600 * @param compress A pointer to the int to hold the compression amount.
1601 * @param quality A pointer to the int to hold the quality amount.
1602 * @param lossy A pointer to the int to hold the lossiness flag.
1603 * @return 1 on success, 0 otherwise.
1605 * This function takes encoded pixel data and decodes it into raw RGBA
1606 * pixels on success.
1608 * The other parameters of the image (alpha, compress etc.) are placed into
1609 * the values pointed to (they must be supplied). The pixel data is a linear
1610 * array of pixels starting from the top-left of the image scanning row by
1611 * row from left to right. Each pixel is a 32bit value, with the high byte
1612 * being the alpha channel, the next being red, then green, and the low byte
1613 * being blue. The width and height are measured in pixels and will be
1614 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1615 * that the alpha channel is not used. 1 denotes that it is significant.
1616 * Compress is filled with the compression value/amount the image was
1617 * stored with. The quality value is filled with the quality encoding of
1618 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1619 * the image was encoded lossily or not.
1621 * On success the function returns 1, and 0 on failure. On failure the
1622 * parameter values may not contain any sensible data.
1624 * @see eet_data_image_decode_to_surface()
1627 * @ingroup Eet_File_Image_Cipher_Group
1630 eet_data_image_decode_to_surface_cipher(const void *data,
1631 const char *cipher_key,
1638 unsigned int row_stride,
1645 * Encode image data for storage or transmission using a cipher.
1646 * @param data A pointer to the image pixel data.
1647 * @param cipher_key The key to use as cipher.
1648 * @param size_ret A pointer to an int to hold the size of the returned data.
1649 * @param w The width of the image in pixels.
1650 * @param h The height of the image in pixels.
1651 * @param alpha The alpha channel flag.
1652 * @param compress The compression amount.
1653 * @param quality The quality encoding amount.
1654 * @param lossy The lossiness flag.
1655 * @return The encoded image data.
1657 * This function stakes image pixel data and encodes it with compression and
1658 * possible loss of quality (as a trade off for size) for storage or
1659 * transmission to another system.
1661 * The data expected is the same format as returned by eet_data_image_read.
1662 * If this is not the case weird things may happen. Width and height must
1663 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1664 * the alpha values are not useful and 1 meaning they are). Compress can
1665 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1666 * This is only used if the image is not lossily encoded. Quality is used on
1667 * lossy compression and should be a value from 0 to 100. The lossy flag
1668 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1669 * image quality loss (but then have a much smaller encoding).
1671 * On success this function returns a pointer to the encoded data that you
1672 * can free with free() when no longer needed.
1674 * @see eet_data_image_encode()
1677 * @ingroup Eet_File_Image_Cipher_Group
1680 eet_data_image_encode_cipher(const void *data,
1681 const char *cipher_key,
1691 * @defgroup Eet_Cipher_Group Cipher, Identity and Protection Mechanisms
1693 * Eet allows one to protect entries of an #Eet_File
1694 * individually. This may be used to ensure data was not tampered or
1695 * that third party does not read your data.
1697 * @see @ref Eet_File_Cipher_Group
1698 * @see @ref Eet_File_Image_Cipher_Group
1705 * Opaque handle that defines an identity (also known as key)
1706 * in Eet's cipher system.
1708 typedef struct _Eet_Key Eet_Key;
1715 * Callback used to request if needed the password of a private key.
1717 * @param buffer the buffer where to store the password.
1718 * @param size the maximum password size (size of buffer, including '@\0').
1719 * @param rwflag if the buffer is also readable or just writable.
1720 * @param data currently unused, may contain some context in future.
1721 * @return 1 on success and password was set to @p buffer, 0 on failure.
1724 * @ingroup Eet_Cipher_Group
1726 typedef int (*Eet_Key_Password_Callback) (char *buffer, int size, int rwflag, void *data);
1729 * Create an Eet_Key needed for signing an eet file.
1731 * The certificate should provide the public that match the private key.
1732 * No verification is done to ensure that.
1734 * @param certificate_file The file where to find the certificate.
1735 * @param private_key_file The file that contains the private key.
1736 * @param cb Function to callback if password is required to unlock
1738 * @return A key handle to use, or @c NULL on failure.
1740 * @see eet_identity_close()
1743 * @ingroup Eet_Cipher_Group
1746 eet_identity_open(const char *certificate_file,
1747 const char *private_key_file,
1748 Eet_Key_Password_Callback cb);
1751 * Close and release all ressource used by an Eet_Key. An
1752 * reference counter prevent it from being freed until all file
1753 * using it are also closed.
1755 * @param key the key handle to close and free resources.
1758 * @ingroup Eet_Cipher_Group
1761 eet_identity_close(Eet_Key *key);
1764 * Set a key to sign a file
1766 * @param ef the file to set the identity.
1767 * @param key the key handle to set as identity.
1768 * @return #EET_ERROR_BAD_OBJECT if @p ef is invalid or
1769 * #EET_ERROR_NONE on success.
1772 * @ingroup Eet_Cipher_Group
1775 eet_identity_set(Eet_File *ef,
1779 * Display both private and public key of an Eet_Key.
1781 * @param key the handle to print.
1782 * @param out where to print.
1785 * @ingroup Eet_Cipher_Group
1788 eet_identity_print(Eet_Key *key,
1792 * Get the x509 der certificate associated with an Eet_File. Will return NULL
1793 * if the file is not signed.
1795 * @param ef The file handle to query.
1796 * @param der_length The length of returned data, may be @c NULL.
1797 * @return the x509 certificate or @c NULL on error.
1800 * @ingroup Eet_Cipher_Group
1803 eet_identity_x509(Eet_File *ef,
1807 * Get the raw signature associated with an Eet_File. Will return NULL
1808 * if the file is not signed.
1810 * @param ef The file handle to query.
1811 * @param signature_length The length of returned data, may be @c NULL.
1812 * @return the raw signature or @c NULL on error.
1814 * @ingroup Eet_Cipher_Group
1817 eet_identity_signature(Eet_File *ef,
1818 int *signature_length);
1821 * Get the SHA1 associated with a file. Could be the one used to
1822 * sign the data or if the data where not signed, it will be the
1825 * @param ef The file handle to query.
1826 * @param sha1_length The length of returned data, may be @c NULL.
1827 * @return the associated SHA1 or @c NULL on error.
1830 * @ingroup Eet_Cipher_Group
1833 eet_identity_sha1(Eet_File *ef,
1837 * Display the x509 der certificate to out.
1839 * @param certificate the x509 certificate to print
1840 * @param der_length The length the certificate.
1841 * @param out where to print.
1844 * @ingroup Eet_Cipher_Group
1847 eet_identity_certificate_print(const unsigned char *certificate,
1852 * @defgroup Eet_Data_Group Eet Data Serialization
1854 * Convenience functions to serialize and parse complex data
1855 * structures to binary blobs.
1857 * While Eet core just handles binary blobs, it is often required
1858 * to save some structured data of different types, such as
1859 * strings, integers, lists, hashes and so on.
1861 * Eet can serialize and then parse data types given some
1862 * construction instructions. These are defined in two levels:
1864 * - #Eet_Data_Descriptor_Class to tell generic memory handling,
1865 * such as the size of the type, how to allocate memory, strings,
1866 * lists, hashes and so on.
1868 * - #Eet_Data_Descriptor to tell inside such type, the members and
1869 * their offsets inside the memory blob, their types and
1870 * names. These members can be simple types or other
1871 * #Eet_Data_Descriptor, allowing hierarchical types to be
1874 * Given that C provides no introspection, this process can be
1875 * quite cumbersome, so we provide lots of macros and convenience
1876 * functions to aid creating the types.
1884 * typedef struct _blah2
1889 * typedef struct _blah3
1894 * typedef struct _blah
1901 * double floating_lots;
1908 * main(int argc, char **argv)
1913 * Eet_Data_Descriptor *edd, *edd2, *edd3;
1914 * Eet_Data_Descriptor_Class eddc, eddc2, eddc3;
1922 * EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc3, Blah3);
1923 * edd3 = eet_data_descriptor_stream_new(&eddc3);
1924 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING);
1926 * EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc2, Blah2);
1927 * edd2 = eet_data_descriptor_stream_new(&eddc2);
1928 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING);
1930 * EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Blah);
1931 * edd = eet_data_descriptor_stream_new(&eddc);
1932 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "character", character, EET_T_CHAR);
1933 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "sixteen", sixteen, EET_T_SHORT);
1934 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "integer", integer, EET_T_INT);
1935 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "lots", lots, EET_T_LONG_LONG);
1936 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating", floating, EET_T_FLOAT);
1937 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating_lots", floating_lots, EET_T_DOUBLE);
1938 * EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "string", string, EET_T_STRING);
1939 * EET_DATA_DESCRIPTOR_ADD_SUB(edd, Blah, "blah2", blah2, edd2);
1940 * EET_DATA_DESCRIPTOR_ADD_LIST(edd, Blah, "blah3", blah3, edd3);
1942 * blah3.string = "PANTS";
1944 * blah2.string = "subtype string here!";
1946 * blah.character = '7';
1947 * blah.sixteen = 0x7777;
1948 * blah.integer = 0xc0def00d;
1949 * blah.lots = 0xdeadbeef31337777;
1950 * blah.floating = 3.141592654;
1951 * blah.floating_lots = 0.777777777777777;
1952 * blah.string = "bite me like a turnip";
1953 * blah.blah2 = &blah2;
1954 * blah.blah3 = eina_list_append(NULL, &blah3);
1955 * blah.blah3 = eina_list_append(blah.blah3, &blah3);
1956 * blah.blah3 = eina_list_append(blah.blah3, &blah3);
1957 * blah.blah3 = eina_list_append(blah.blah3, &blah3);
1958 * blah.blah3 = eina_list_append(blah.blah3, &blah3);
1959 * blah.blah3 = eina_list_append(blah.blah3, &blah3);
1960 * blah.blah3 = eina_list_append(blah.blah3, &blah3);
1962 * data = eet_data_descriptor_encode(edd, &blah, &size);
1963 * printf("-----DECODING\n");
1964 * blah_in = eet_data_descriptor_decode(edd, data, size);
1966 * printf("-----DECODED!\n");
1967 * printf("%c\n", blah_in->character);
1968 * printf("%x\n", (int)blah_in->sixteen);
1969 * printf("%x\n", blah_in->integer);
1970 * printf("%lx\n", blah_in->lots);
1971 * printf("%f\n", (double)blah_in->floating);
1972 * printf("%f\n", (double)blah_in->floating_lots);
1973 * printf("%s\n", blah_in->string);
1974 * printf("%p\n", blah_in->blah2);
1975 * printf(" %s\n", blah_in->blah2->string);
1980 * EINA_LIST_FOREACH(blah_in->blah3, l, blah3_in)
1982 * printf("%p\n", blah3_in);
1983 * printf(" %s\n", blah3_in->string);
1986 * eet_data_descriptor_free(edd);
1987 * eet_data_descriptor_free(edd2);
1988 * eet_data_descriptor_free(edd3);
1998 #define EET_T_UNKNOW 0 /**< Unknown data encoding type */
1999 #define EET_T_CHAR 1 /**< Data type: char */
2000 #define EET_T_SHORT 2 /**< Data type: short */
2001 #define EET_T_INT 3 /**< Data type: int */
2002 #define EET_T_LONG_LONG 4 /**< Data type: long long */
2003 #define EET_T_FLOAT 5 /**< Data type: float */
2004 #define EET_T_DOUBLE 6 /**< Data type: double */
2005 #define EET_T_UCHAR 7 /**< Data type: unsigned char */
2006 #define EET_T_USHORT 8 /**< Data type: unsigned short */
2007 #define EET_T_UINT 9 /**< Data type: unsigned int */
2008 #define EET_T_ULONG_LONG 10 /**< Data type: unsigned long long */
2009 #define EET_T_STRING 11 /**< Data type: char * */
2010 #define EET_T_INLINED_STRING 12 /**< Data type: char * (but compressed inside the resulting eet) */
2011 #define EET_T_NULL 13 /**< Data type: (void *) (only use it if you know why) */
2012 #define EET_T_F32P32 14 /**< Data type: fixed point 32.32 */
2013 #define EET_T_F16P16 15 /**< Data type: fixed point 16.16 */
2014 #define EET_T_F8P24 16 /**< Data type: fixed point 8.24 */
2015 #define EET_T_LAST 18 /**< Last data type */
2017 #define EET_G_UNKNOWN 100 /**< Unknown group data encoding type */
2018 #define EET_G_ARRAY 101 /**< Fixed size array group type */
2019 #define EET_G_VAR_ARRAY 102 /**< Variable size array group type */
2020 #define EET_G_LIST 103 /**< Linked list group type */
2021 #define EET_G_HASH 104 /**< Hash table group type */
2022 #define EET_G_UNION 105 /**< Union group type */
2023 #define EET_G_VARIANT 106 /**< Selectable subtype group */
2024 #define EET_G_LAST 107 /**< Last group type */
2026 #define EET_I_LIMIT 128 /**< Other type exist but are reserved for internal purpose. */
2029 * @typedef Eet_Data_Descriptor
2031 * Opaque handle that have information on a type members.
2033 * The members are added by means of
2034 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB(),
2035 * EET_DATA_DESCRIPTOR_ADD_LIST(), EET_DATA_DESCRIPTOR_ADD_HASH()
2036 * or eet_data_descriptor_element_add().
2038 * @see eet_data_descriptor_stream_new()
2039 * @see eet_data_descriptor_file_new()
2040 * @see eet_data_descriptor_free()
2042 typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
2045 * @def EET_DATA_DESCRIPTOR_CLASS_VERSION
2046 * The version of #Eet_Data_Descriptor_Class at the time of the
2047 * distribution of the sources. One should define this to its
2048 * version member so it is compatible with abi changes, or at least
2049 * will not crash with them.
2051 #define EET_DATA_DESCRIPTOR_CLASS_VERSION 4
2054 * @typedef Eet_Data_Descriptor_Class
2056 * Instructs Eet about memory management for different needs under
2057 * serialization and parse process.
2059 typedef struct _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class;
2061 typedef int (*Eet_Descriptor_Hash_Foreach_Callback_Callback)(void *h, const char *k, void *dt, void *fdt);
2063 typedef void *(*Eet_Descriptor_Mem_Alloc_Callback)(size_t size);
2064 typedef void (*Eet_Descriptor_Mem_Free_Callback)(void *mem);
2065 typedef char *(*Eet_Descriptor_Str_Alloc_Callback)(const char *str);
2066 typedef void (*Eet_Descriptor_Str_Free_Callback)(const char *str);
2067 typedef void *(*Eet_Descriptor_List_Next_Callback)(void *l);
2068 typedef void *(*Eet_Descriptor_List_Append_Callback)(void *l, void *d);
2069 typedef void *(*Eet_Descriptor_List_Data_Callback)(void *l);
2070 typedef void *(*Eet_Descriptor_List_Free_Callback)(void *l);
2071 typedef void (*Eet_Descriptor_Hash_Foreach_Callback)(void *h, Eet_Descriptor_Hash_Foreach_Callback_Callback func, void *fdt);
2072 typedef void *(*Eet_Descriptor_Hash_Add_Callback)(void *h, const char *k, void *d);
2073 typedef void (*Eet_Descriptor_Hash_Free_Callback)(void *h);
2074 typedef char *(*Eet_Descriptor_Str_Direct_Alloc_Callback)(const char *str);
2075 typedef void (*Eet_Descriptor_Str_Direct_Free_Callback)(const char *str);
2076 typedef const char *(*Eet_Descriptor_Type_Get_Callback)(const void *data, Eina_Bool *unknow);
2077 typedef Eina_Bool (*Eet_Descriptor_Type_Set_Callback)(const char *type, void *data, Eina_Bool unknow);
2078 typedef void *(*Eet_Descriptor_Array_Alloc_Callback)(size_t size);
2079 typedef void (*Eet_Descriptor_Array_Free_Callback)(void *mem);
2081 * @struct _Eet_Data_Descriptor_Class
2083 * Instructs Eet about memory management for different needs under
2084 * serialization and parse process.
2086 * If using Eina data types, it is advised to use the helpers
2087 * EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET() and
2088 * EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET().
2090 struct _Eet_Data_Descriptor_Class
2092 int version; /**< ABI version as #EET_DATA_DESCRIPTOR_CLASS_VERSION */
2093 const char *name; /**< Name of data type to be serialized */
2094 int size; /**< Size in bytes of data type to be serialized */
2096 Eet_Descriptor_Mem_Alloc_Callback mem_alloc; /**< how to allocate memory (usually malloc()) */
2097 Eet_Descriptor_Mem_Free_Callback mem_free; /**< how to free memory (usually free()) */
2098 Eet_Descriptor_Str_Alloc_Callback str_alloc; /**< how to allocate a string */
2099 Eet_Descriptor_Str_Free_Callback str_free; /**< how to free a string */
2100 Eet_Descriptor_List_Next_Callback list_next; /**< how to iterate to the next element of a list. Receives and should return the list node. */
2101 Eet_Descriptor_List_Append_Callback list_append; /**< how to append data @p d to list which head node is @p l */
2102 Eet_Descriptor_List_Data_Callback list_data; /**< retrieves the data from node @p l */
2103 Eet_Descriptor_List_Free_Callback list_free; /**< free all the nodes from the list which head node is @p l */
2104 Eet_Descriptor_Hash_Foreach_Callback hash_foreach; /**< iterates over all elements in the hash @p h in no specific order */
2105 Eet_Descriptor_Hash_Add_Callback hash_add; /**< add a new data @p d as key @p k in hash @p h */
2106 Eet_Descriptor_Hash_Free_Callback hash_free; /**< free all entries from the hash @p h */
2107 Eet_Descriptor_Str_Direct_Alloc_Callback str_direct_alloc; /**< how to allocate a string directly from file backed/mmaped region pointed by @p str */
2108 Eet_Descriptor_Str_Direct_Free_Callback str_direct_free; /**< how to free a string returned by str_direct_alloc */
2109 Eet_Descriptor_Type_Get_Callback type_get; /**< convert any kind of data type to a name that define an Eet_Data_Element. */
2110 Eet_Descriptor_Type_Set_Callback type_set; /**< set the type at a particular address */
2111 Eet_Descriptor_Array_Alloc_Callback array_alloc; /**< how to allocate memory for array (usually malloc()) */
2112 Eet_Descriptor_Array_Free_Callback array_free; /**< how to free memory for array (usually free()) */
2122 * Create a new empty data structure descriptor.
2123 * @param name The string name of this data structure (most be a
2124 * global constant and never change).
2125 * @param size The size of the struct (in bytes).
2126 * @param func_list_next The function to get the next list node.
2127 * @param func_list_append The function to append a member to a list.
2128 * @param func_list_data The function to get the data from a list node.
2129 * @param func_list_free The function to free an entire linked list.
2130 * @param func_hash_foreach The function to iterate through all
2131 * hash table entries.
2132 * @param func_hash_add The function to add a member to a hash table.
2133 * @param func_hash_free The function to free an entire hash table.
2134 * @return A new empty data descriptor.
2136 * This function creates a new data descriptore and returns a handle to the
2137 * new data descriptor. On creation it will be empty, containing no contents
2138 * describing anything other than the shell of the data structure.
2140 * You add structure members to the data descriptor using the macros
2141 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2142 * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2143 * adding to the description.
2145 * Once you have described all the members of a struct you want loaded, or
2146 * saved eet can load and save those members for you, encode them into
2147 * endian-independent serialised data chunks for transmission across a
2148 * a network or more.
2150 * The function pointers to the list and hash table functions are only
2151 * needed if you use those data types, else you can pass NULL instead.
2154 * @ingroup Eet_Data_Group
2156 * @deprecated use eet_data_descriptor_stream_new() or
2157 * eet_data_descriptor_file_new()
2159 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2160 eet_data_descriptor_new(const char *name,
2162 Eet_Descriptor_List_Next_Callback func_list_next,
2163 Eet_Descriptor_List_Append_Callback func_list_append,
2164 Eet_Descriptor_List_Data_Callback func_list_data,
2165 Eet_Descriptor_List_Free_Callback func_list_free,
2166 Eet_Descriptor_Hash_Foreach_Callback func_hash_foreach,
2167 Eet_Descriptor_Hash_Add_Callback func_hash_add,
2168 Eet_Descriptor_Hash_Free_Callback func_hash_free);
2172 * moving to this api from the old above. this will break things when the
2173 * move happens - but be warned
2175 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2176 eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc);
2177 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2178 eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc);
2181 * This function creates a new data descriptore and returns a handle to the
2182 * new data descriptor. On creation it will be empty, containing no contents
2183 * describing anything other than the shell of the data structure.
2184 * @param eddc The data descriptor to free.
2186 * You add structure members to the data descriptor using the macros
2187 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2188 * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2189 * adding to the description.
2191 * Once you have described all the members of a struct you want loaded, or
2192 * saved eet can load and save those members for you, encode them into
2193 * endian-independent serialised data chunks for transmission across a
2194 * a network or more.
2196 * This function specially ignore str_direct_alloc and str_direct_free. It
2197 * is useful when the eet_data you are reading don't have a dictionnary
2198 * like network stream or ipc. It also mean that all string will be allocated
2199 * and duplicated in memory.
2202 * @ingroup Eet_Data_Group
2204 EAPI Eet_Data_Descriptor *
2205 eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc);
2208 * This function creates a new data descriptore and returns a handle to the
2209 * new data descriptor. On creation it will be empty, containing no contents
2210 * describing anything other than the shell of the data structure.
2211 * @param eddc The data descriptor to free.
2213 * You add structure members to the data descriptor using the macros
2214 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2215 * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2216 * adding to the description.
2218 * Once you have described all the members of a struct you want loaded, or
2219 * saved eet can load and save those members for you, encode them into
2220 * endian-independent serialised data chunks for transmission across a
2221 * a network or more.
2223 * This function use str_direct_alloc and str_direct_free. It is
2224 * useful when the eet_data you are reading come from a file and
2225 * have a dictionnary. This will reduce memory use, improve the
2226 * possibility for the OS to page this string out. But be carrefull
2227 * all EET_T_STRING are pointer to a mmapped area and it will point
2228 * to nowhere if you close the file. So as long as you use this
2229 * strings, you need to have the Eet_File open.
2232 * @ingroup Eet_Data_Group
2234 EAPI Eet_Data_Descriptor *
2235 eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc);
2238 * This function is an helper that set all the parameter of an
2239 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2241 * @param eddc The Eet_Data_Descriptor_Class you want to set.
2242 * @param name The name of the structure described by this class.
2243 * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2244 * @param size The size of the structure described by this class.
2245 * @return EINA_TRUE if the structure was correctly set (The only
2246 * reason that could make it fail is if you did give wrong
2250 * @ingroup Eet_Data_Group
2253 eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2254 unsigned int eddc_size,
2259 * This macro is an helper that set all the parameter of an
2260 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2262 * @param clas The Eet_Data_Descriptor_Class you want to set.
2263 * @param type The type of the structure described by this class.
2264 * @return EINA_TRUE if the structure was correctly set (The only
2265 * reason that could make it fail is if you did give wrong
2269 * @ingroup Eet_Data_Group
2271 #define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(clas, type)\
2272 (eet_eina_stream_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2275 * This function is an helper that set all the parameter of an
2276 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2278 * @param eddc The Eet_Data_Descriptor_Class you want to set.
2279 * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2280 * @param name The name of the structure described by this class.
2281 * @param size The size of the structure described by this class.
2282 * @return EINA_TRUE if the structure was correctly set (The only
2283 * reason that could make it fail is if you did give wrong
2287 * @ingroup Eet_Data_Group
2290 eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2291 unsigned int eddc_size,
2296 * This macro is an helper that set all the parameter of an
2297 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2299 * @param clas The Eet_Data_Descriptor_Class you want to set.
2300 * @param type The type of the structure described by this class.
2301 * @return EINA_TRUE if the structure was correctly set (The only
2302 * reason that could make it fail is if you did give wrong
2306 * @ingroup Eet_Data_Group
2308 #define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(clas, type)\
2309 (eet_eina_file_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2312 * This function frees a data descriptor when it is not needed anymore.
2313 * @param edd The data descriptor to free.
2315 * This function takes a data descriptor handle as a parameter and frees all
2316 * data allocated for the data descriptor and the handle itself. After this
2317 * call the descriptor is no longer valid.
2320 * @ingroup Eet_Data_Group
2323 eet_data_descriptor_free(Eet_Data_Descriptor *edd);
2326 * This function is an internal used by macros.
2328 * This function is used by macros EET_DATA_DESCRIPTOR_ADD_BASIC(),
2329 * EET_DATA_DESCRIPTOR_ADD_SUB() and EET_DATA_DESCRIPTOR_ADD_LIST(). It is
2330 * complex to use by hand and should be left to be used by the macros, and
2331 * thus is not documented.
2333 * @param edd The data descriptor handle to add element (member).
2334 * @param name The name of element to be serialized.
2335 * @param type The type of element to be serialized, like
2336 * #EET_T_INT. If #EET_T_UNKNOW, then it is considered to be a
2337 * group, list or hash.
2338 * @param group_type If element type is #EET_T_UNKNOW, then the @p
2339 * group_type will speficy if it is a list (#EET_G_LIST),
2340 * array (#EET_G_ARRAY) and so on. If #EET_G_UNKNOWN, then
2341 * the member is a subtype (pointer to another type defined by
2342 * another #Eet_Data_Descriptor).
2343 * @param offset byte offset inside the source memory to be serialized.
2344 * @param count number of elements (if #EET_G_ARRAY or #EET_G_VAR_ARRAY).
2345 * @param counter_name variable that defines the name of number of elements.
2346 * @param subtype If contains a subtype, then its data descriptor.
2349 * @ingroup Eet_Data_Group
2352 eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
2357 /* int count_offset, */
2359 const char *counter_name,
2360 Eet_Data_Descriptor *subtype);
2363 * Read a data structure from an eet file and decodes it.
2364 * @param ef The eet file handle to read from.
2365 * @param edd The data descriptor handle to use when decoding.
2366 * @param name The key the data is stored under in the eet file.
2367 * @return A pointer to the decoded data structure.
2369 * This function decodes a data structure stored in an eet file, returning
2370 * a pointer to it if it decoded successfully, or NULL on failure. This
2371 * can save a programmer dozens of hours of work in writing configuration
2372 * file parsing and writing code, as eet does all that work for the program
2373 * and presents a program-friendly data structure, just as the programmer
2374 * likes. Eet can handle members being added or deleted from the data in
2375 * storage and safely zero-fills unfilled members if they were not found
2376 * in the data. It checks sizes and headers whenever it reads data, allowing
2377 * the programmer to not worry about corrupt data.
2379 * Once a data structure has been described by the programmer with the
2380 * fields they wish to save or load, storing or retrieving a data structure
2381 * from an eet file, or from a chunk of memory is as simple as a single
2384 * @see eet_data_read_cipher()
2387 * @ingroup Eet_Data_Group
2390 eet_data_read(Eet_File *ef,
2391 Eet_Data_Descriptor *edd,
2395 * Write a data structure from memory and store in an eet file.
2396 * @param ef The eet file handle to write to.
2397 * @param edd The data descriptor to use when encoding.
2398 * @param name The key to store the data under in the eet file.
2399 * @param data A pointer to the data structure to ssave and encode.
2400 * @param compress Compression flags for storage.
2401 * @return bytes written on successful write, 0 on failure.
2403 * This function is the reverse of eet_data_read(), saving a data structure
2406 * @see eet_data_write_cipher()
2409 * @ingroup Eet_Data_Group
2412 eet_data_write(Eet_File *ef,
2413 Eet_Data_Descriptor *edd,
2418 typedef void (*Eet_Dump_Callback)(void *data, const char *str);
2421 * Dump an eet encoded data structure into ascii text
2422 * @param data_in The pointer to the data to decode into a struct.
2423 * @param size_in The size of the data pointed to in bytes.
2424 * @param dumpfunc The function to call passed a string when new
2425 * data is converted to text
2426 * @param dumpdata The data to pass to the @p dumpfunc callback.
2427 * @return 1 on success, 0 on failure
2429 * This function will take a chunk of data encoded by
2430 * eet_data_descriptor_encode() and convert it into human readable
2431 * ascii text. It does this by calling the @p dumpfunc callback
2432 * for all new text that is generated. This callback should append
2433 * to any existing text buffer and will be passed the pointer @p
2434 * dumpdata as a parameter as well as a string with new text to be
2440 * void output(void *data, const char *string)
2442 * printf("%s", string);
2445 * void dump(const char *file)
2451 * f = fopen(file, "r");
2452 * fseek(f, 0, SEEK_END);
2455 * data = malloc(len);
2456 * fread(data, len, 1, f);
2458 * eet_data_text_dump(data, len, output, NULL);
2462 * @see eet_data_text_dump_cipher()
2465 * @ingroup Eet_Data_Group
2468 eet_data_text_dump(const void *data_in,
2470 Eet_Dump_Callback dumpfunc,
2474 * Take an ascii encoding from eet_data_text_dump() and re-encode in binary.
2475 * @param text The pointer to the string data to parse and encode.
2476 * @param textlen The size of the string in bytes (not including 0
2478 * @param size_ret This gets filled in with the encoded data blob
2480 * @return The encoded data on success, NULL on failure.
2482 * This function will parse the string pointed to by @p text and return
2483 * an encoded data lump the same way eet_data_descriptor_encode() takes an
2484 * in-memory data struct and encodes into a binary blob. @p text is a normal
2487 * @see eet_data_text_undump_cipher()
2490 * @ingroup Eet_Data_Group
2493 eet_data_text_undump(const char *text,
2498 * Dump an eet encoded data structure from an eet file into ascii text
2499 * @param ef A valid eet file handle.
2500 * @param name Name of the entry. eg: "/base/file_i_want".
2501 * @param dumpfunc The function to call passed a string when new
2502 * data is converted to text
2503 * @param dumpdata The data to pass to the @p dumpfunc callback.
2504 * @return 1 on success, 0 on failure
2506 * This function will take an open and valid eet file from
2507 * eet_open() request the data encoded by
2508 * eet_data_descriptor_encode() corresponding to the key @p name
2509 * and convert it into human readable ascii text. It does this by
2510 * calling the @p dumpfunc callback for all new text that is
2511 * generated. This callback should append to any existing text
2512 * buffer and will be passed the pointer @p dumpdata as a parameter
2513 * as well as a string with new text to be appended.
2515 * @see eet_data_dump_cipher()
2518 * @ingroup Eet_Data_Group
2521 eet_data_dump(Eet_File *ef,
2523 Eet_Dump_Callback dumpfunc,
2527 * Take an ascii encoding from eet_data_dump() and re-encode in binary.
2528 * @param ef A valid eet file handle.
2529 * @param name Name of the entry. eg: "/base/file_i_want".
2530 * @param text The pointer to the string data to parse and encode.
2531 * @param textlen The size of the string in bytes (not including 0
2533 * @param compress Compression flags (1 == compress, 0 = don't compress).
2534 * @return 1 on success, 0 on failure
2536 * This function will parse the string pointed to by @p text,
2537 * encode it the same way eet_data_descriptor_encode() takes an
2538 * in-memory data struct and encodes into a binary blob.
2540 * The data (optionally compressed) will be in ram, pending a flush to
2541 * disk (it will stay in ram till the eet file handle is closed though).
2543 * @see eet_data_undump_cipher()
2546 * @ingroup Eet_Data_Group
2549 eet_data_undump(Eet_File *ef,
2556 * Decode a data structure from an arbitrary location in memory.
2557 * @param edd The data descriptor to use when decoding.
2558 * @param data_in The pointer to the data to decode into a struct.
2559 * @param size_in The size of the data pointed to in bytes.
2560 * @return NULL on failure, or a valid decoded struct pointer on success.
2562 * This function will decode a data structure that has been encoded using
2563 * eet_data_descriptor_encode(), and return a data structure with all its
2564 * elements filled out, if successful, or NULL on failure.
2566 * The data to be decoded is stored at the memory pointed to by @p data_in,
2567 * and is described by the descriptor pointed to by @p edd. The data size is
2568 * passed in as the value to @p size_in, ande must be greater than 0 to
2571 * This function is useful for decoding data structures delivered to the
2572 * application by means other than an eet file, such as an IPC or socket
2573 * connection, raw files, shared memory etc.
2575 * Please see eet_data_read() for more information.
2577 * @see eet_data_descriptor_decode_cipher()
2580 * @ingroup Eet_Data_Group
2583 eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
2584 const void *data_in,
2588 * Encode a dsata struct to memory and return that encoded data.
2589 * @param edd The data descriptor to use when encoding.
2590 * @param data_in The pointer to the struct to encode into data.
2591 * @param size_ret pointer to the an int to be filled with the decoded size.
2592 * @return NULL on failure, or a valid encoded data chunk on success.
2594 * This function takes a data structutre in memory and encodes it into a
2595 * serialised chunk of data that can be decoded again by
2596 * eet_data_descriptor_decode(). This is useful for being able to transmit
2597 * data structures across sockets, pipes, IPC or shared file mechanisms,
2598 * without having to worry about memory space, machine type, endianess etc.
2600 * The parameter @p edd must point to a valid data descriptor, and
2601 * @p data_in must point to the right data structure to encode. If not, the
2602 * encoding may fail.
2604 * On success a non NULL valid pointer is returned and what @p size_ret
2605 * points to is set to the size of this decoded data, in bytes. When the
2606 * encoded data is no longer needed, call free() on it. On failure NULL is
2607 * returned and what @p size_ret points to is set to 0.
2609 * Please see eet_data_write() for more information.
2611 * @see eet_data_descriptor_encode_cipher()
2614 * @ingroup Eet_Data_Group
2617 eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
2618 const void *data_in,
2622 * Add a basic data element to a data descriptor.
2623 * @param edd The data descriptor to add the type to.
2624 * @param struct_type The type of the struct.
2625 * @param name The string name to use to encode/decode this member
2626 * (must be a constant global and never change).
2627 * @param member The struct member itself to be encoded.
2628 * @param type The type of the member to encode.
2630 * This macro is a convenience macro provided to add a member to
2631 * the data descriptor @p edd. The type of the structure is
2632 * provided as the @p struct_type parameter (for example: struct
2633 * my_struct). The @p name parameter defines a string that will be
2634 * used to uniquely name that member of the struct (it is suggested
2635 * to use the struct member itself). The @p member parameter is
2636 * the actual struct member itself (for eet_dictionary_string_check
2637 * example: values), and @p type is the basic data type of the
2638 * member which must be one of: EET_T_CHAR, EET_T_SHORT, EET_T_INT,
2639 * EET_T_LONG_LONG, EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR,
2640 * EET_T_USHORT, EET_T_UINT, EET_T_ULONG_LONG or EET_T_STRING.
2643 * @ingroup Eet_Data_Group
2645 #define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type) \
2647 struct_type ___ett; \
2648 eet_data_descriptor_element_add(edd, name, type, EET_G_UNKNOWN, \
2649 (char *)(& (___ett.member)) - \
2650 (char *)(& (___ett)), \
2651 0, /* 0, */ NULL, NULL); \
2655 * Add a sub-element type to a data descriptor
2656 * @param edd The data descriptor to add the type to.
2657 * @param struct_type The type of the struct.
2658 * @param name The string name to use to encode/decode this member
2659 * (must be a constant global and never change).
2660 * @param member The struct member itself to be encoded.
2661 * @param subtype The type of sub-type struct to add.
2663 * This macro lets you easily add a sub-type (a struct that's pointed to
2664 * by this one). All the parameters are the same as for
2665 * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception.
2666 * This must be the data descriptor of the struct that is pointed to by
2670 * @ingroup Eet_Data_Group
2672 #define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype) \
2674 struct_type ___ett; \
2675 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNKNOWN, \
2676 (char *)(& (___ett.member)) - \
2677 (char *)(& (___ett)), \
2678 0, /* 0, */ NULL, subtype); \
2682 * Add a linked list type to a data descriptor
2683 * @param edd The data descriptor to add the type to.
2684 * @param struct_type The type of the struct.
2685 * @param name The string name to use to encode/decode this member
2686 * (must be a constant global and never change).
2687 * @param member The struct member itself to be encoded.
2688 * @param subtype The type of linked list member to add.
2690 * This macro lets you easily add a linked list of other data types. All the
2691 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
2692 * @p subtype being the exception. This must be the data descriptor of the
2693 * element that is in each member of the linked list to be stored.
2696 * @ingroup Eet_Data_Group
2698 #define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype) \
2700 struct_type ___ett; \
2701 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_LIST, \
2702 (char *)(& (___ett.member)) - \
2703 (char *)(& (___ett)), \
2704 0, /* 0, */ NULL, subtype); \
2708 * Add a linked list of string to a data descriptor
2709 * @param edd The data descriptor to add the type to.
2710 * @param struct_type The type of the struct.
2711 * @param name The string name to use to encode/decode this member
2712 * (must be a constant global and never change).
2713 * @param member The struct member itself to be encoded.
2715 * This macro lets you easily add a linked list of char *. All the
2716 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
2719 * @ingroup Eet_Data_Group
2721 #define EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct_type, name, member) \
2723 struct_type ___ett; \
2724 eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_LIST, \
2725 (char *)(& (___ett.member)) - \
2726 (char *)(& (___ett)), \
2727 0, /* 0, */ NULL, NULL); \
2731 * Add a hash type to a data descriptor
2732 * @param edd The data descriptor to add the type to.
2733 * @param struct_type The type of the struct.
2734 * @param name The string name to use to encode/decode this member
2735 * (must be a constant global and never change).
2736 * @param member The struct member itself to be encoded.
2737 * @param subtype The type of hash member to add.
2739 * This macro lets you easily add a hash of other data types. All the
2740 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
2741 * @p subtype being the exception. This must be the data descriptor of the
2742 * element that is in each member of the hash to be stored.
2745 * @ingroup Eet_Data_Group
2747 #define EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype) \
2749 struct_type ___ett; \
2750 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_HASH, \
2751 (char *)(& (___ett.member)) - \
2752 (char *)(& (___ett)), \
2753 0, /* 0, */ NULL, subtype); \
2757 * Add a hash of string to a data descriptor
2758 * @param edd The data descriptor to add the type to.
2759 * @param struct_type The type of the struct.
2760 * @param name The string name to use to encode/decode this member
2761 * (must be a constant global and never change).
2762 * @param member The struct member itself to be encoded.
2764 * This macro lets you easily add a hash of string. All the
2765 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
2768 * @ingroup Eet_Data_Group
2770 #define EET_DATA_DESCRIPTOR_ADD_HASH_STRING(edd, struct_type, name, member) \
2772 struct_type ___ett; \
2773 eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_HASH, \
2774 (char *)(& (___ett.member)) - \
2775 (char *)(& (___ett)), \
2776 0, /* 0, */ NULL, NULL); \
2780 * Add a fixed size array type to a data descriptor
2781 * @param edd The data descriptor to add the type to.
2782 * @param struct_type The type of the struct.
2783 * @param name The string name to use to encode/decode this member
2784 * (must be a constant global and never change).
2785 * @param member The struct member itself to be encoded.
2786 * @param subtype The type of hash member to add.
2788 * This macro lets you easily add a fixed size array of other data
2789 * types. All the parameters are the same as for
2790 * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
2791 * exception. This must be the data descriptor of the element that
2792 * is in each member of the hash to be stored.
2795 * @ingroup Eet_Data_Group
2797 #define EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, struct_type, name, member, subtype) \
2799 struct_type ___ett; \
2800 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_ARRAY, \
2801 (char *)(& (___ett.member)) - \
2802 (char *)(& (___ett)), \
2803 /* 0, */ sizeof(___ett.member) / \
2804 sizeof(___ett.member[0]), NULL, subtype); \
2808 * Add a variable size array type to a data descriptor
2809 * @param edd The data descriptor to add the type to.
2810 * @param struct_type The type of the struct.
2811 * @param name The string name to use to encode/decode this member
2812 * (must be a constant global and never change).
2813 * @param member The struct member itself to be encoded.
2814 * @param subtype The type of hash member to add.
2816 * This macro lets you easily add a fixed size array of other data
2817 * types. All the parameters are the same as for
2818 * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
2819 * exception. This must be the data descriptor of the element that
2820 * is in each member of the hash to be stored. This assumes you have
2821 * a struct member (of type EET_T_INT) called member_count (note the
2822 * _count appended to the member) that holds the number of items in
2823 * the array. This array will be allocated separately to the struct it
2827 * @ingroup Eet_Data_Group
2829 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, struct_type, name, member, subtype) \
2831 struct_type ___ett; \
2832 eet_data_descriptor_element_add(edd, \
2836 (char *)(& (___ett.member)) - \
2837 (char *)(& (___ett)), \
2838 (char *)(& (___ett.member ## _count)) - \
2839 (char *)(& (___ett)), \
2845 * Add a variable size array type to a data descriptor
2846 * @param edd The data descriptor to add the type to.
2847 * @param struct_type The type of the struct.
2848 * @param name The string name to use to encode/decode this member
2849 * (must be a constant global and never change).
2850 * @param member The struct member itself to be encoded.
2852 * This macro lets you easily add a fixed size array of string. All
2853 * the parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
2856 * @ingroup Eet_Data_Group
2858 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY_STRING(edd, struct_type, name, member) \
2860 struct_type ___ett; \
2861 eet_data_descriptor_element_add(edd, \
2865 (char *)(& (___ett.member)) - \
2866 (char *)(& (___ett)), \
2867 (char *)(& (___ett.member ## _count)) - \
2868 (char *)(& (___ett)), \
2874 * Add an union type to a data descriptor
2875 * @param edd The data descriptor to add the type to.
2876 * @param struct_type The type of the struct.
2877 * @param name The string name to use to encode/decode this member
2878 * (must be a constant global and never change).
2879 * @param member The struct member itself to be encoded.
2880 * @param type_member The member that give hints on what is in the union.
2881 * @param unified_type Describe all possible type the union could handle.
2883 * This macro lets you easily add an union with a member that specify what is inside.
2884 * The @p unified_type is an Eet_Data_Descriptor, but only the entry that match the name
2885 * returned by type_get will be used for each serialized data. The type_get and type_set
2886 * callback of unified_type should be defined.
2889 * @ingroup Eet_Data_Group
2890 * @see Eet_Data_Descriptor_Class
2892 #define EET_DATA_DESCRIPTOR_ADD_UNION(edd, struct_type, name, member, type_member, unified_type) \
2894 struct_type ___ett; \
2895 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNION, \
2896 (char *)(& (___ett.member)) - \
2897 (char *)(& (___ett)), \
2898 (char *)(& (___ett.type_member)) - \
2899 (char *)(& (___ett)), \
2900 NULL, unified_type); \
2904 * Add a automatically selectable type to a data descriptor
2905 * @param edd The data descriptor to add the type to.
2906 * @param struct_type The type of the struct.
2907 * @param name The string name to use to encode/decode this member
2908 * (must be a constant global and never change).
2909 * @param member The struct member itself to be encoded.
2910 * @param type_member The member that give hints on what is in the union.
2911 * @param unified_type Describe all possible type the union could handle.
2913 * This macro lets you easily define what the content of @p member points to depending of
2914 * the content of @p type_member. The type_get and type_set callback of unified_type should
2915 * be defined. If the the type is not know at the time of restoring it, eet will still call
2916 * type_set of @p unified_type but the pointer will be set to a serialized binary representation
2917 * of what eet know. This make it possible, to save this pointer again by just returning the string
2918 * given previously and telling it by setting unknow to EINA_TRUE.
2921 * @ingroup Eet_Data_Group
2922 * @see Eet_Data_Descriptor_Class
2924 #define EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, struct_type, name, member, type_member, unified_type) \
2926 struct_type ___ett; \
2927 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_VARIANT, \
2928 (char *)(& (___ett.member)) - \
2929 (char *)(& (___ett)), \
2930 (char *)(& (___ett.type_member)) - \
2931 (char *)(& (___ett)), \
2932 NULL, unified_type); \
2936 * Add a mapping to a data descriptor that will be used by union, variant or inherited type
2937 * @param unified_type The data descriptor to add the mapping to.
2938 * @param name The string name to get/set type.
2939 * @param subtype The matching data descriptor.
2942 * @ingroup Eet_Data_Group
2943 * @see Eet_Data_Descriptor_Class
2945 #define EET_DATA_DESCRIPTOR_ADD_MAPPING(unified_type, name, subtype) \
2946 eet_data_descriptor_element_add(unified_type, \
2956 * @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
2958 * Most of the @ref Eet_Data_Group have alternative versions that
2959 * accounts for ciphers to protect their content.
2961 * @see @ref Eet_Cipher_Group
2963 * @ingroup Eet_Data_Group
2967 * Read a data structure from an eet file and decodes it using a cipher.
2968 * @param ef The eet file handle to read from.
2969 * @param edd The data descriptor handle to use when decoding.
2970 * @param name The key the data is stored under in the eet file.
2971 * @param cipher_key The key to use as cipher.
2972 * @return A pointer to the decoded data structure.
2974 * This function decodes a data structure stored in an eet file, returning
2975 * a pointer to it if it decoded successfully, or NULL on failure. This
2976 * can save a programmer dozens of hours of work in writing configuration
2977 * file parsing and writing code, as eet does all that work for the program
2978 * and presents a program-friendly data structure, just as the programmer
2979 * likes. Eet can handle members being added or deleted from the data in
2980 * storage and safely zero-fills unfilled members if they were not found
2981 * in the data. It checks sizes and headers whenever it reads data, allowing
2982 * the programmer to not worry about corrupt data.
2984 * Once a data structure has been described by the programmer with the
2985 * fields they wish to save or load, storing or retrieving a data structure
2986 * from an eet file, or from a chunk of memory is as simple as a single
2989 * @see eet_data_read()
2992 * @ingroup Eet_Data_Cipher_Group
2995 eet_data_read_cipher(Eet_File *ef,
2996 Eet_Data_Descriptor *edd,
2998 const char *cipher_key);
3001 * Write a data structure from memory and store in an eet file
3003 * @param ef The eet file handle to write to.
3004 * @param edd The data descriptor to use when encoding.
3005 * @param name The key to store the data under in the eet file.
3006 * @param cipher_key The key to use as cipher.
3007 * @param data A pointer to the data structure to ssave and encode.
3008 * @param compress Compression flags for storage.
3009 * @return bytes written on successful write, 0 on failure.
3011 * This function is the reverse of eet_data_read(), saving a data structure
3014 * @see eet_data_write_cipher()
3017 * @ingroup Eet_Data_Cipher_Group
3020 eet_data_write_cipher(Eet_File *ef,
3021 Eet_Data_Descriptor *edd,
3023 const char *cipher_key,
3028 * Dump an eet encoded data structure into ascii text using a cipher.
3029 * @param data_in The pointer to the data to decode into a struct.
3030 * @param cipher_key The key to use as cipher.
3031 * @param size_in The size of the data pointed to in bytes.
3032 * @param dumpfunc The function to call passed a string when new
3033 * data is converted to text
3034 * @param dumpdata The data to pass to the @p dumpfunc callback.
3035 * @return 1 on success, 0 on failure
3037 * This function will take a chunk of data encoded by
3038 * eet_data_descriptor_encode() and convert it into human readable
3039 * ascii text. It does this by calling the @p dumpfunc callback
3040 * for all new text that is generated. This callback should append
3041 * to any existing text buffer and will be passed the pointer @p
3042 * dumpdata as a parameter as well as a string with new text to be
3048 * void output(void *data, const char *string)
3050 * printf("%s", string);
3053 * void dump(const char *file)
3059 * f = fopen(file, "r");
3060 * fseek(f, 0, SEEK_END);
3063 * data = malloc(len);
3064 * fread(data, len, 1, f);
3066 * eet_data_text_dump_cipher(data, cipher_key, len, output, NULL);
3070 * @see eet_data_text_dump()
3073 * @ingroup Eet_Data_Cipher_Group
3076 eet_data_text_dump_cipher(const void *data_in,
3077 const char *cipher_key,
3079 Eet_Dump_Callback dumpfunc,
3083 * Take an ascii encoding from eet_data_text_dump() and re-encode
3084 * in binary using a cipher.
3085 * @param text The pointer to the string data to parse and encode.
3086 * @param cipher_key The key to use as cipher.
3087 * @param textlen The size of the string in bytes (not including 0
3089 * @param size_ret This gets filled in with the encoded data blob
3091 * @return The encoded data on success, NULL on failure.
3093 * This function will parse the string pointed to by @p text and return
3094 * an encoded data lump the same way eet_data_descriptor_encode() takes an
3095 * in-memory data struct and encodes into a binary blob. @p text is a normal
3098 * @see eet_data_text_undump()
3101 * @ingroup Eet_Data_Cipher_Group
3104 eet_data_text_undump_cipher(const char *text,
3105 const char *cipher_key,
3110 * Dump an eet encoded data structure from an eet file into ascii
3111 * text using a cipher.
3112 * @param ef A valid eet file handle.
3113 * @param name Name of the entry. eg: "/base/file_i_want".
3114 * @param cipher_key The key to use as cipher.
3115 * @param dumpfunc The function to call passed a string when new
3116 * data is converted to text
3117 * @param dumpdata The data to pass to the @p dumpfunc callback.
3118 * @return 1 on success, 0 on failure
3120 * This function will take an open and valid eet file from
3121 * eet_open() request the data encoded by
3122 * eet_data_descriptor_encode() corresponding to the key @p name
3123 * and convert it into human readable ascii text. It does this by
3124 * calling the @p dumpfunc callback for all new text that is
3125 * generated. This callback should append to any existing text
3126 * buffer and will be passed the pointer @p dumpdata as a parameter
3127 * as well as a string with new text to be appended.
3129 * @see eet_data_dump()
3132 * @ingroup Eet_Data_Cipher_Group
3135 eet_data_dump_cipher(Eet_File *ef,
3137 const char *cipher_key,
3138 Eet_Dump_Callback dumpfunc,
3142 * Take an ascii encoding from eet_data_dump() and re-encode in
3143 * binary using a cipher.
3144 * @param ef A valid eet file handle.
3145 * @param name Name of the entry. eg: "/base/file_i_want".
3146 * @param cipher_key The key to use as cipher.
3147 * @param text The pointer to the string data to parse and encode.
3148 * @param textlen The size of the string in bytes (not including 0
3150 * @param compress Compression flags (1 == compress, 0 = don't compress).
3151 * @return 1 on success, 0 on failure
3153 * This function will parse the string pointed to by @p text,
3154 * encode it the same way eet_data_descriptor_encode() takes an
3155 * in-memory data struct and encodes into a binary blob.
3157 * The data (optionally compressed) will be in ram, pending a flush to
3158 * disk (it will stay in ram till the eet file handle is closed though).
3160 * @see eet_data_undump()
3163 * @ingroup Eet_Data_Cipher_Group
3166 eet_data_undump_cipher(Eet_File *ef,
3168 const char *cipher_key,
3174 * Decode a data structure from an arbitrary location in memory
3176 * @param edd The data descriptor to use when decoding.
3177 * @param data_in The pointer to the data to decode into a struct.
3178 * @param cipher_key The key to use as cipher.
3179 * @param size_in The size of the data pointed to in bytes.
3180 * @return NULL on failure, or a valid decoded struct pointer on success.
3182 * This function will decode a data structure that has been encoded using
3183 * eet_data_descriptor_encode(), and return a data structure with all its
3184 * elements filled out, if successful, or NULL on failure.
3186 * The data to be decoded is stored at the memory pointed to by @p data_in,
3187 * and is described by the descriptor pointed to by @p edd. The data size is
3188 * passed in as the value to @p size_in, ande must be greater than 0 to
3191 * This function is useful for decoding data structures delivered to the
3192 * application by means other than an eet file, such as an IPC or socket
3193 * connection, raw files, shared memory etc.
3195 * Please see eet_data_read() for more information.
3197 * @see eet_data_descriptor_decode()
3200 * @ingroup Eet_Data_Cipher_Group
3203 eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
3204 const void *data_in,
3205 const char *cipher_key,
3209 * Encode a data struct to memory and return that encoded data
3211 * @param edd The data descriptor to use when encoding.
3212 * @param data_in The pointer to the struct to encode into data.
3213 * @param cipher_key The key to use as cipher.
3214 * @param size_ret pointer to the an int to be filled with the decoded size.
3215 * @return NULL on failure, or a valid encoded data chunk on success.
3217 * This function takes a data structutre in memory and encodes it into a
3218 * serialised chunk of data that can be decoded again by
3219 * eet_data_descriptor_decode(). This is useful for being able to transmit
3220 * data structures across sockets, pipes, IPC or shared file mechanisms,
3221 * without having to worry about memory space, machine type, endianess etc.
3223 * The parameter @p edd must point to a valid data descriptor, and
3224 * @p data_in must point to the right data structure to encode. If not, the
3225 * encoding may fail.
3227 * On success a non NULL valid pointer is returned and what @p size_ret
3228 * points to is set to the size of this decoded data, in bytes. When the
3229 * encoded data is no longer needed, call free() on it. On failure NULL is
3230 * returned and what @p size_ret points to is set to 0.
3232 * Please see eet_data_write() for more information.
3234 * @see eet_data_descriptor_encode()
3237 * @ingroup Eet_Data_Cipher_Group
3240 eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
3241 const void *data_in,
3242 const char *cipher_key,
3246 * @defgroup Eet_Node_Group Low-level Serialization Structures.
3248 * Functions that create, destroy and manipulate serialization nodes
3249 * used by @ref Eet_Data_Group.
3256 * Opaque handle to manage serialization node.
3258 typedef struct _Eet_Node Eet_Node;
3261 * @typedef Eet_Node_Data
3262 * Contains an union that can fit any kind of node.
3264 typedef struct _Eet_Node_Data Eet_Node_Data;
3267 * @struct _Eet_Node_Data
3268 * Contains an union that can fit any kind of node.
3270 struct _Eet_Node_Data
3282 unsigned long long ul;
3293 * @ingroup Eet_Node_Group
3296 eet_node_char_new(const char *name,
3301 * @ingroup Eet_Node_Group
3304 eet_node_short_new(const char *name,
3309 * @ingroup Eet_Node_Group
3312 eet_node_int_new(const char *name,
3317 * @ingroup Eet_Node_Group
3320 eet_node_long_long_new(const char *name,
3325 * @ingroup Eet_Node_Group
3328 eet_node_float_new(const char *name,
3333 * @ingroup Eet_Node_Group
3336 eet_node_double_new(const char *name,
3341 * @ingroup Eet_Node_Group
3344 eet_node_unsigned_char_new(const char *name,
3349 * @ingroup Eet_Node_Group
3352 eet_node_unsigned_short_new(const char *name,
3357 * @ingroup Eet_Node_Group
3360 eet_node_unsigned_int_new(const char *name,
3365 * @ingroup Eet_Node_Group
3368 eet_node_unsigned_long_long_new(const char *name,
3369 unsigned long long l);
3373 * @ingroup Eet_Node_Group
3376 eet_node_string_new(const char *name,
3381 * @ingroup Eet_Node_Group
3384 eet_node_inlined_string_new(const char *name,
3389 * @ingroup Eet_Node_Group
3392 eet_node_null_new(const char *name);
3396 * @ingroup Eet_Node_Group
3399 eet_node_list_new(const char *name,
3404 * @ingroup Eet_Node_Group
3407 eet_node_array_new(const char *name,
3413 * @ingroup Eet_Node_Group
3416 eet_node_var_array_new(const char *name,
3421 * @ingroup Eet_Node_Group
3424 eet_node_hash_new(const char *name,
3430 * @ingroup Eet_Node_Group
3433 eet_node_struct_new(const char *name,
3438 * @ingroup Eet_Node_Group
3441 eet_node_struct_child_new(const char *parent,
3446 * @ingroup Eet_Node_Group
3449 eet_node_list_append(Eet_Node *parent,
3455 * @ingroup Eet_Node_Group
3458 eet_node_struct_append(Eet_Node *parent,
3464 * @ingroup Eet_Node_Group
3467 eet_node_hash_add(Eet_Node *parent,
3474 * @ingroup Eet_Node_Group
3477 eet_node_dump(Eet_Node *n,
3479 Eet_Dump_Callback dumpfunc,
3484 * @ingroup Eet_Node_Group
3487 eet_node_del(Eet_Node *n);
3491 * @ingroup Eet_Node_Group
3494 eet_data_node_encode_cipher(Eet_Node *node,
3495 const char *cipher_key,
3500 * @ingroup Eet_Node_Group
3503 eet_data_node_decode_cipher(const void *data_in,
3504 const char *cipher_key,
3509 * @ingroup Eet_Node_Group
3512 eet_data_node_read_cipher(Eet_File *ef,
3514 const char *cipher_key);
3518 * @ingroup Eet_Node_Group
3521 eet_data_node_write_cipher(Eet_File *ef,
3523 const char *cipher_key,
3527 /* EXPERIMENTAL: THIS API MAY CHANGE IN THE FUTURE, USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING. */
3530 * @typedef Eet_Node_Walk
3531 * Describes how to walk trees of #Eet_Node.
3533 typedef struct _Eet_Node_Walk Eet_Node_Walk;
3535 typedef void *(*Eet_Node_Walk_Struct_Alloc_Callback)(const char *type, void *user_data);
3536 typedef void (*Eet_Node_Walk_Struct_Add_Callback)(void *parent, const char *name, void *child, void *user_data);
3537 typedef void *(*Eet_Node_Walk_Array_Callback)(Eina_Bool variable, const char *name, int count, void *user_data);
3538 typedef void (*Eet_Node_Walk_Insert_Callback)(void *array, int index, void *child, void *user_data);
3539 typedef void *(*Eet_Node_Walk_List_Callback)(const char *name, void *user_data);
3540 typedef void (*Eet_Node_Walk_Append_Callback)(void *list, void *child, void *user_data);
3541 typedef void *(*Eet_Node_Walk_Hash_Callback)(void *parent, const char *name, const char *key, void *value, void *user_data);
3542 typedef void *(*Eet_Node_Walk_Simple_Callback)(int type, Eet_Node_Data *data, void *user_data);
3545 * @struct _Eet_Node_Walk
3546 * Describes how to walk trees of #Eet_Node.
3548 struct _Eet_Node_Walk
3550 Eet_Node_Walk_Struct_Alloc_Callback struct_alloc;
3551 Eet_Node_Walk_Struct_Add_Callback struct_add;
3552 Eet_Node_Walk_Array_Callback array;
3553 Eet_Node_Walk_Insert_Callback insert;
3554 Eet_Node_Walk_List_Callback list;
3555 Eet_Node_Walk_Append_Callback append;
3556 Eet_Node_Walk_Hash_Callback hash;
3557 Eet_Node_Walk_Simple_Callback simple;
3561 eet_node_walk(void *parent,
3570 * @defgroup Eet_Connection_Group Helper function to use eet over a network link
3572 * Function that reconstruct and prepare packet of @ref Eet_Data_Group to be send.
3577 * @typedef Eet_Connection
3578 * Opaque handle to track paquet for a specific connection.
3580 * @ingroup Eet_Connection_Group
3582 typedef struct _Eet_Connection Eet_Connection;
3585 * @typedef Eet_Read_Cb
3586 * Called back when an @ref Eet_Data_Group has been received completly and could be used.
3588 * @ingroup Eet_Connection_Group
3590 typedef Eina_Bool Eet_Read_Cb (const void *eet_data, size_t size, void *user_data);
3593 * @typedef Eet_Write_Cb
3594 * Called back when a packet containing @ref Eet_Data_Group data is ready to be send.
3596 * @ingroup Eet_Connection_Group
3598 typedef Eina_Bool Eet_Write_Cb (const void *data, size_t size, void *user_data);
3601 * Instanciate a new connection to track.
3602 * @param eet_read_cb Function to call when one Eet_Data packet has been fully assemble.
3603 * @param eet_write_cb Function to call when one Eet_Data packet is ready to be send over the wire.
3604 * @param user_data Pointer provided to both functions to be used as a context handler.
3605 * @return NULL on failure, or a valid Eet_Connection handler.
3607 * For every connection to track you will need a separate Eet_Connection provider.
3610 * @ingroup Eet_Connection_Group
3612 EAPI Eet_Connection *
3613 eet_connection_new(Eet_Read_Cb *eet_read_cb,
3614 Eet_Write_Cb *eet_write_cb,
3615 const void *user_data);
3618 * Process a raw packet received over the link
3619 * @param conn Connection handler to track.
3620 * @param data Raw data packet.
3621 * @param size The size of that packet.
3622 * @return 0 on complete success, any other value indicate where in the stream it got wrong (It could be before that packet).
3624 * Every time you receive a packet related to your connection, you should pass
3625 * it to that function so that it could process and assemble packet has you
3626 * receive it. It will automatically call Eet_Read_Cb when one is fully received.
3629 * @ingroup Eet_Connection_Group
3632 eet_connection_received(Eet_Connection *conn,
3637 * Convert a complex structure and prepare it to be send.
3638 * @param conn Connection handler to track.
3639 * @param edd The data descriptor to use when encoding.
3640 * @param data_in The pointer to the struct to encode into data.
3641 * @param cipher_key The key to use as cipher.
3642 * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
3644 * This function serialize data_in with edd, assemble the packet and call
3645 * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
3646 * and will vanish just after the return of the callback.
3648 * @see eet_data_descriptor_encode_cipher
3651 * @ingroup Eet_Connection_Group
3654 eet_connection_send(Eet_Connection *conn,
3655 Eet_Data_Descriptor *edd,
3656 const void *data_in,
3657 const char *cipher_key);
3660 * Convert a Eet_Node tree and prepare it to be send.
3661 * @param conn Connection handler to track.
3662 * @param node The data tree to use when encoding.
3663 * @param cipher_key The key to use as cipher.
3664 * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
3666 * This function serialize node, assemble the packet and call
3667 * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
3668 * and will vanish just after the return of the callback.
3670 * @see eet_data_node_encode_cipher
3673 * @ingroup Eet_Connection_Group
3676 eet_connection_node_send(Eet_Connection *conn,
3678 const char *cipher_key);
3681 * Close a connection and lost its track.
3682 * @param conn Connection handler to close.
3683 * @param on_going Signal if a partial packet wasn't completed.
3684 * @return the user_data passed to both callback.
3687 * @ingroup Eet_Connection_Group
3690 eet_connection_close(Eet_Connection *conn,
3691 Eina_Bool *on_going);
3693 /***************************************************************************/
3697 #endif /* ifdef __cplusplus */
3699 #endif /* ifndef _EET_H */