2 @brief Eet Data Handling Library Public API Calls
4 These routines are used for Eet Library interaction
6 @mainpage Eet Library Documentation
11 Please see the @ref authors page for contact details.
13 @section toc Table of Contents
20 @li @ref intro_example
22 @section intro What is Eet?
24 It is a tiny library designed to write an arbitrary set of chunks of data
25 to a file and optionally compress each chunk (very much like a zip file)
26 and allow fast random-access reading of the file later on. It does not
27 do zip as a zip itself has more complexity than is needed, and it was much
28 simpler to implement this once here.
30 Eet is extremely fast, small and simple. Eet files can be very small and
31 highly compressed, making them very optimal for just sending across the
32 internet without having to archive, compress or decompress and install them.
33 They allow for lightning-fast random-acess reads once created, making them
34 perfect for storing data that is written once (or rarely) and read many
35 times, but the program does not want to have to read it all in at once.
37 It also can encode and decode data structures in memory, as well as image
38 data for saving to Eet files or sending across the network to other
39 machines, or just writing to arbitrary files on the system. All data is
40 encoded in a platform independent way and can be written and read by any
43 @section example A simple example on using Eet
45 Here is a simple example on how to use Eet to save a series of strings to a
46 file and load them again. The advantage of using Eet over just
48 fscanf() is that not only can these entries be strings, they need no special
49 parsing to handle delimiter characters or escaping, they can be binary data,
50 image data, data structures containing integers, strings, other data
51 structures, linked lists and much more, without the programmer having to
52 worry about parsing, and best of all, Eet is very fast.
54 This is just a very simple example that doesn't show all of the capabilities
55 of Eet, but it serves to illustrate its simplicity.
59 @section compiling How to compile using Eet ?
61 Eet is a library your application links to. The procedure for this is very
62 simple. You simply have to compile your application with the appropriate
63 compiler flags that the @p pkg-config script outputs. For example:
65 Compiling C or C++ files into object files:
68 gcc -c -o main.o main.c `pkg-config --cflags eet`
71 Linking object files into a binary executable:
74 gcc -o my_application main.o `pkg-config --libs eet`
77 You simply have to make sure that pkg-config is in your shell's PATH (see
78 the manual page for your appropriate shell) and eet.pc in /usr/lib/pkgconfig
79 or its path is in the PKG_CONFIG_PATH environment variable. It's that simple
80 to link and use Eet once you have written your code to use it.
82 Since the program is linked to Eet, it is now able to use any advertised
83 API calls to serialize your data.
85 You should make sure you add any extra compile and link flags to your
86 compile commands that your application may need as well. The above example
87 is only guaranteed to make Eet add it's own requirements.
90 @section install How is it installed?
102 @section next_steps Next Steps
104 After you understood what Eet is and installed it in your system you
105 should proceed understanding the programming interface. We'd recommend
106 you to take a while to learn Eina
107 (http://docs.enlightenment.org/auto/eina/) as it is very convenient
108 and optimized, and Eet provides integration with it.
112 @li @ref Eet_File_Group to know the basics to open and save files.
113 @li @ref Eet_Data_Group to know the convenient way to serialize and
114 parse your data structures automatically. Just create your
115 descriptors and let Eet do the work for you.
117 @section intro_example Introductory Examples
121 @todo Document data format for images and data structures.
126 @page authors Authors
127 @author Carsten Haitzler <raster@@rasterman.com>
128 @author David Goodlad <dgoodlad@@gmail.com>
129 @author Cedric Bail <cedric.bail@@free.fr>
130 @author Arnaud de Turckheim <quarium@@gmail.com>
131 @author Luis Felipe Strano Moraes <lfelipe@@profusion.mobi>
132 @author Chidambar Zinnoury <illogict@@online.fr>
133 @author Vincent Torri <vtorri@@univ-evry.fr>
134 @author Gustavo Sverzut Barbieri <barbieri@@profusion.mobi>
135 @author Raphael Kubo da Costa <kubo@@profusion.mobi>
136 @author Mathieu Taillefumier <mathieu.taillefumier@@free.fr>
137 @author Albin "Lutin" Tonnerre <albin.tonnerre@@gmail.com>
138 @author Adam Simpkins <adam@@adamsimpkins.net>
139 @author Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
141 Please contact <enlightenment-devel@lists.sourceforge.net> to get in
142 contact with the developers and maintainers.
154 #endif /* ifdef EAPI */
157 # ifdef EFL_EET_BUILD
159 # define EAPI __declspec(dllexport)
160 # else /* ifdef DLL_EXPORT */
162 # endif /* ! DLL_EXPORT */
163 # else /* ifdef EFL_EET_BUILD */
164 # define EAPI __declspec(dllimport)
165 # endif /* ! EFL_EET_BUILD */
166 #else /* ifdef _WIN32 */
169 # define EAPI __attribute__ ((visibility("default")))
170 # else /* if __GNUC__ >= 4 */
172 # endif /* if __GNUC__ >= 4 */
173 # else /* ifdef __GNUC__ */
175 # endif /* ifdef __GNUC__ */
176 #endif /* ! _WIN32 */
180 #endif /* ifdef __cplusplus */
184 * @brief The file that provides the eet functions.
186 * This header provides the Eet management functions.
190 #define EET_VERSION_MAJOR 1
191 #define EET_VERSION_MINOR 4
193 * @typedef Eet_Version
195 * This is the Eet version information structure that can be used at
196 * runtime to detect which version of eet is being used and adapt
197 * appropriately as follows for example:
200 * #if defined(EET_VERSION_MAJOR) && (EET_VERSION_MAJOR >= 1) && defined(EET_VERSION_MINOR) && (EET_VERSION_MINOR > 2)
201 * printf("Eet version: %i.%i.%i\n",
202 * eet_version->major,
203 * eet_version->minor,
204 * eet_version->micro);
205 * if (eet_version->revision > 0)
207 * printf(" Built from SVN revision # %i\n", eet_version->revision);
212 * Note the #if check can be dropped if your program refuses to compile or
213 * work with an Eet version less than 1.3.0.
215 typedef struct _Eet_Version
217 int major; /** < major (binary or source incompatible changes) */
218 int minor; /** < minor (new features, bugfixes, major improvements version) */
219 int micro; /** < micro (bugfix, internal improvements, no new features version) */
220 int revision; /** < svn revision (0 if a proper rlease or the svn revsion number Eet is built from) */
223 EAPI extern Eet_Version *eet_version;
226 * @defgroup Eet_Group Top level functions
227 * Functions that affect Eet as a whole.
234 * All the error identifiers known by Eet.
236 typedef enum _Eet_Error
238 EET_ERROR_NONE, /**< No error, it's all fine! */
239 EET_ERROR_BAD_OBJECT, /**< Given object or handle is NULL or invalid */
240 EET_ERROR_EMPTY, /**< There was nothing to do */
241 EET_ERROR_NOT_WRITABLE, /**< Could not write to file or file is #EET_FILE_MODE_READ */
242 EET_ERROR_OUT_OF_MEMORY, /**< Could not allocate memory */
243 EET_ERROR_WRITE_ERROR, /**< Failed to write data to destination */
244 EET_ERROR_WRITE_ERROR_FILE_TOO_BIG, /**< Failed to write file since it is too big */
245 EET_ERROR_WRITE_ERROR_IO_ERROR, /**< Failed to write due a generic Input/Output error */
246 EET_ERROR_WRITE_ERROR_OUT_OF_SPACE, /**< Failed to write due out of space */
247 EET_ERROR_WRITE_ERROR_FILE_CLOSED, /**< Failed to write because file was closed */
248 EET_ERROR_MMAP_FAILED, /**< Could not mmap file */
249 EET_ERROR_X509_ENCODING_FAILED, /**< Could not encode using X509 */
250 EET_ERROR_SIGNATURE_FAILED, /**< Could not validate signature */
251 EET_ERROR_INVALID_SIGNATURE, /**< Signature is invalid */
252 EET_ERROR_NOT_SIGNED, /**< File or contents are not signed */
253 EET_ERROR_NOT_IMPLEMENTED, /**< Function is not implemented */
254 EET_ERROR_PRNG_NOT_SEEDED, /**< Could not introduce random seed */
255 EET_ERROR_ENCRYPT_FAILED, /**< Could not encrypt contents */
256 EET_ERROR_DECRYPT_FAILED /**< Could not decrypt contents */
257 } Eet_Error; /**< Eet error identifiers */
264 * Initialize the EET library.
266 * The first time this function is called, it will perform all the internal
267 * initialization required for the library to function properly and incrememnt
268 * the initializiation counter. Any subsequent call only increment this counter
269 * and return its new value, so it's safe to call this function more than once.
271 * @return The new init count. Will be 0 if initialization failed.
280 * Shut down the EET library.
282 * If eet_init() was called more than once for the running application,
283 * eet_shutdown() will decrement the initialization counter and return its
284 * new value, without doing anything else. When the counter reaches 0, all
285 * of the internal elements will be shutdown and any memory used freed.
287 * @return The new init count.
298 * For a faster access to previously accessed data, Eet keeps an internal
299 * cache of files. These files will be freed automatically only when
300 * they are unused and the cache gets full, in order based on the last time
302 * On systems with little memory this may present an unnecessary constraint,
303 * so eet_clearcache() is available for users to reclaim the memory used by
304 * files that are no longer needed. Those that were open using
305 * ::EET_FILE_MODE_WRITE or ::EET_FILE_MODE_READ_WRITE and have modifications,
306 * will be written down to disk before flushing them from memory.
312 eet_clearcache(void);
315 * @defgroup Eet_File_Group Eet File Main Functions
317 * Functions to create, destroy and do basic manipulation of
320 * This sections explains how to use the most basic Eet functions, which
321 * are used to work with eet files, read data from them, store it back in or
322 * take a look at what entries it contains, without making use of the
323 * serialization capabilities explained in @ref Eet_Data_Group.
325 * The following example will serve as an introduction to most, if not all,
326 * of these functions.
328 * If you are only using Eet, this is the only header you need to include.
329 * @dontinclude eet-file.c
332 * Now let's create ourselves an eet file to play with. The following function
333 * shows step by step how to open a file and write some data in it.
334 * First, we define our file handler and some other things we'll put in it.
340 * We open a new file in write mode, and if it fails, we just return, since
341 * there's not much more we can do about it..
344 * Now, we need to write some data in our file. For now, strings will suffice,
345 * so let's just dump a bunch of them in there.
348 * As you can see, we copied a string into our static buffer, which is a bit
349 * bigger than the full length of the string, and then told Eet to write it
350 * into the file, compressed, returning the size of the data written into the
352 * This is all to show that Eet treats data as just data. It doesn't matter
353 * what that data represents (for now), it's all just bytes for it. As running
354 * the following code will show, we took a string of around 30 bytes and put it
355 * in a buffer of 1024 bytes, but the returned size won't be any of those.
358 * Next, we copy into our buffer our set of strings, including their null
359 * terminators and write them into the file. No error checking for the sake
360 * of brevitiy. And a call to eet_sync() to make sure all out data is
361 * properly written down to disk, even though we haven't yet closed the file.
364 * One more write, this time our large array of binary data and... well, I
365 * couldn't come up with a valid use of the last set of strings we stored,
366 * so let's take it out from the file with eet_delete().
369 * Finally, we close the file, saving any changes back to disk and return.
370 * Notice how, if there's any error closing the file or saving its contents,
371 * the return value from the function will be a false one, which later on
372 * will make the program exit with an error code.
375 * Moving onto our main function, we will open the same file and read it back.
376 * Trivial, but it'll show how we can do so in more than one way. We'll skip
377 * the variable declarations, as they aren't very different from what we've
380 * We start from the beginning by initializing Eet so things in general work.
381 * Forgetting to do so will result in weird results or crashes when calling
382 * any eet function, so if you experience something like that, the first thing
383 * to look at is whether eet_init() is missing.
384 * Then we call our @p create_eet_file function, described above, to make
385 * sure we have something to work with. If the function fails it will return
386 * 0 and we just exit, since nothing from here onwards will work anyway.
390 * Let's take a look now at what entries our file has. For this, we use
391 * eet_list(), which will return a list of strings, each being the name of
392 * one entry. Since we skipped before, it may be worth noting that @p list
393 * is declared as a @p char **.
394 * The @p num parameter will, of course, have the number of entries contained
396 * If everything's fine, we'll get our list and print it to the screen, and
397 * once done with it, we free the list. That's just the list, not its contents,
398 * as they are internal strings used by Eet and trying to free them will surely
402 * Reading back plain data is simple. Just a call to eet_read() with the file
403 * to read from, and the name of the entry we are interested in. We get back
404 * our data and the passed @p size parameter will contain the size of it. If
405 * the data was stored compressed, it will decompressed first.
408 * Another simple read for the set of strings from before, except those were
409 * deleted, so we should get a NULL return and continue normally.
412 * Finally, we'll get our binary data in the same way we got the strings. Once
413 * again, it makes no difference for Eet what the data is, it's up to us to
414 * know how to handle it.
417 * Now some cheating, we know that this data is an Eet file because, well...
418 * we just know it. So we are going to open it and take a look at its insides.
419 * For this, eet_open() won't work, as it needs to have a file on disk to read
420 * from and all we have is some data in RAM.
422 * So how do we do? One way would be to create a normal file and write down
423 * our data, then open it with eet_open(). Another, faster and more efficient
424 * if all we want to do is read the file, is to use eet_memopen_read().
427 * As you can see, the size we got from our previous read was put to good use
428 * this time. Unlike the first one where all we had were strings, the size
429 * of the data read only serves to demonstrate that we are reading back the
430 * entire size of our original @p buf variable.
432 * A little peeking to see how many entries the file has and to make an
433 * example of eet_num_entries() to get that number when we don't care about
437 * More cheating follows. Just like we knew this was an Eet file, we also know
438 * what key to read from, and ontop of that we know that the data in it is not
440 * Knowing all this allows us to take some shortcuts.
443 * That's a direct print of our data, whatever that data is. We don't want
444 * to worry about having to free it later, so we just used eet_direct_read()
445 * to tell Eet to gives a pointer to the internal data in the file, without
446 * duplicating it. Since we said that data was not compressed, we shouldn't
447 * worry about printing garbage to the screen (and yes, we also know the data
448 * is yet another string).
449 * We also don't care about the size of the data as it was stored in the file,
450 * so we passed NULL as the size parameter.
451 * One very important note about this, however, is that we don't care about
452 * the size parameter because the data in the file contains the null
453 * terminator for the string. So when using Eet to store strings this way,
454 * it's very important to consider whether you will keep that final null
455 * byte, or to always get the size read and do the necessary checks and copies.
456 * It's up to the user and the particular use cases to decide how this will
459 * With everything done, close this second file and free the data used to open
460 * it. And this is important, we can't free that data until we are done with
461 * the file, as Eet is using it. When opening with eet_memopen_read(), the data
462 * passed to it must be available for as long as the the file is open.
465 * Finally, we close the first file, shutdown all internal resources used by
466 * Eet and leave our main function, thus terminating our program.
469 * You can look at the full code of the example @ref eet-file.c "here".
474 * @enum _Eet_File_Mode
475 * Modes that a file can be opened.
477 typedef enum _Eet_File_Mode
479 EET_FILE_MODE_INVALID = -1,
480 EET_FILE_MODE_READ, /**< File is read-only. */
481 EET_FILE_MODE_WRITE, /**< File is write-only. */
482 EET_FILE_MODE_READ_WRITE /**< File is for both read and write */
483 } Eet_File_Mode; /**< Modes that a file can be opened. */
487 * Opaque handle that defines an Eet file (or memory).
489 * This handle will be returned by the functions eet_open() and
490 * eet_memopen_read() and is used by every other function that affects the
491 * file in any way. When you are done with it, call eet_close() to clsoe it
492 * and, if the file was open for writing, write down to disk any changes made
496 * @see eet_memopen_read()
499 typedef struct _Eet_File Eet_File;
502 * @typedef Eet_Dictionary
503 * Opaque handle that defines a file-backed (mmaped) dictionary of strings.
505 typedef struct _Eet_Dictionary Eet_Dictionary;
512 * Open an eet file on disk, and returns a handle to it.
513 * @param file The file path to the eet file. eg: @c "/tmp/file.eet".
514 * @param mode The mode for opening. Either #EET_FILE_MODE_READ,
515 * #EET_FILE_MODE_WRITE or #EET_FILE_MODE_READ_WRITE.
516 * @return An opened eet file handle.
517 * @ingroup Eet_File_Group
519 * This function will open an exiting eet file for reading, and build
520 * the directory table in memory and return a handle to the file, if it
521 * exists and can be read, and no memory errors occur on the way, otherwise
522 * NULL will be returned.
524 * It will also open an eet file for writing. This will, if successful,
525 * delete the original file and replace it with a new empty file, till
526 * the eet file handle is closed or flushed. If it cannot be opened for
527 * writing or a memory error occurs, NULL is returned.
529 * You can also open the file for read/write. If you then write a key that
530 * does not exist it will be created, if the key exists it will be replaced
533 * If the same file is opened multiple times, then the same file handle will
534 * be returned as eet maintains an internal list of all currently open
535 * files. Note that it considers files opened for read only and those opened
536 * for read/write and write only as 2 separate sets. Those that do not write
537 * to the file and those that do. Eet will allow 2 handles to the same file
538 * if they are in the 2 separate lists/groups. That means opening a file for
539 * read only looks in the read only set, and returns a handle to that file
540 * handle and increments its reference count. If you open a file for read/write
541 * or write only it looks in the write set and returns a handle after
542 * incrementing the reference count. You need to close an eet file handle
543 * as many times as it has been opened to maintain correct reference counts.
544 * Files whose modified timestamp or size do not match those of the existing
545 * referenced file handles will not be returned and a new handle will be
551 eet_open(const char *file,
555 * Open an eet file directly from a memory location. The data is not copied,
556 * so you must keep it around as long as the eet file is open. There is
557 * currently no cache for this kind of Eet_File, so it's reopened every time
558 * you use eet_memopen_read.
559 * Files opened this way will always be in read-only mode.
562 * @ingroup Eet_File_Group
565 eet_memopen_read(const void *data,
569 * Get the mode an Eet_File was opened with.
570 * @param ef A valid eet file handle.
571 * @return The mode ef was opened with.
574 * @ingroup Eet_File_Group
577 eet_mode_get(Eet_File *ef);
580 * Close an eet file handle and flush and writes pending.
581 * @param ef A valid eet file handle.
583 * This function will flush any pending writes to disk if the eet file
584 * was opened for write, and free all data associated with the file handle
585 * and file, and close the file.
587 * If the eet file handle is not valid nothing will be done.
590 * @ingroup Eet_File_Group
593 eet_close(Eet_File *ef);
596 * Sync content of an eet file handle, flushing pending writes.
597 * @param ef A valid eet file handle.
599 * This function will flush any pending writes to disk. The eet file must
600 * be opened for write.
602 * If the eet file handle is not valid nothing will be done.
605 * @ingroup Eet_File_Group
608 eet_sync(Eet_File *ef);
611 * Return a handle to the shared string dictionary of the Eet file
612 * @param ef A valid eet file handle.
613 * @return A handle to the dictionary of the file
615 * This function returns a handle to the dictionary of an Eet file whose
616 * handle is @p ef, if a dictionary exists. NULL is returned otherwise or
617 * if the file handle is known to be invalid.
619 * @see eet_dictionary_string_check() to know if given string came
620 * from the dictionary or it was dynamically allocated using
621 * the #Eet_Data_Descriptor_Class instructrions.
624 * @ingroup Eet_File_Group
626 EAPI Eet_Dictionary *
627 eet_dictionary_get(Eet_File *ef);
630 * Check if a given string comes from a given dictionary
631 * @param ed A valid dictionary handle
632 * @param string A valid 0 byte terminated C string
633 * @return 1 if it is in the dictionary, 0 otherwise
635 * This checks the given dictionary to see if the given string is actually
636 * inside that dictionary (i.e. comes from it) and returns 1 if it does.
637 * If the dictionary handle is invalid, the string is NULL or the string is
638 * not in the dictionary, 0 is returned.
641 * @ingroup Eet_File_Group
644 eet_dictionary_string_check(Eet_Dictionary *ed,
648 * Read a specified entry from an eet file and return data
649 * @param ef A valid eet file handle opened for reading.
650 * @param name Name of the entry. eg: "/base/file_i_want".
651 * @param size_ret Number of bytes read from entry and returned.
652 * @return The data stored in that entry in the eet file.
654 * This function finds an entry in the eet file that is stored under the
655 * name specified, and returns that data, decompressed, if successful.
656 * NULL is returned if the lookup fails or if memory errors are
657 * encountered. It is the job of the calling program to call free() on
658 * the returned data. The number of bytes in the returned data chunk are
659 * placed in size_ret.
661 * If the eet file handle is not valid NULL is returned and size_ret is
664 * @see eet_read_cipher()
667 * @ingroup Eet_File_Group
670 eet_read(Eet_File *ef,
675 * Read a specified entry from an eet file and return data
676 * @param ef A valid eet file handle opened for reading.
677 * @param name Name of the entry. eg: "/base/file_i_want".
678 * @param size_ret Number of bytes read from entry and returned.
679 * @return The data stored in that entry in the eet file.
681 * This function finds an entry in the eet file that is stored under the
682 * name specified, and returns that data if not compressed and successful.
683 * NULL is returned if the lookup fails or if memory errors are
684 * encountered or if the data is comrpessed. The calling program must never
685 * call free() on the returned data. The number of bytes in the returned
686 * data chunk are placed in size_ret.
688 * If the eet file handle is not valid NULL is returned and size_ret is
692 * @ingroup Eet_File_Group
695 eet_read_direct(Eet_File *ef,
700 * Write a specified entry to an eet file handle
701 * @param ef A valid eet file handle opened for writing.
702 * @param name Name of the entry. eg: "/base/file_i_want".
703 * @param data Pointer to the data to be stored.
704 * @param size Length in bytes in the data to be stored.
705 * @param compress Compression flags (1 == compress, 0 = don't compress).
706 * @return bytes written on successful write, 0 on failure.
708 * This function will write the specified chunk of data to the eet file
709 * and return greater than 0 on success. 0 will be returned on failure.
711 * The eet file handle must be a valid file handle for an eet file opened
712 * for writing. If it is not, 0 will be returned and no action will be
715 * Name, and data must not be NULL, and size must be > 0. If these
716 * conditions are not met, 0 will be returned.
718 * The data will be copied (and optionally compressed) in ram, pending
719 * a flush to disk (it will stay in ram till the eet file handle is
722 * @see eet_write_cipher()
725 * @ingroup Eet_File_Group
728 eet_write(Eet_File *ef,
735 * Delete a specified entry from an Eet file being written or re-written
736 * @param ef A valid eet file handle opened for writing.
737 * @param name Name of the entry. eg: "/base/file_i_want".
738 * @return Success or failure of the delete.
740 * This function will delete the specified chunk of data from the eet file
741 * and return greater than 0 on success. 0 will be returned on failure.
743 * The eet file handle must be a valid file handle for an eet file opened
744 * for writing. If it is not, 0 will be returned and no action will be
747 * Name, must not be NULL, otherwise 0 will be returned.
750 * @ingroup Eet_File_Group
753 eet_delete(Eet_File *ef,
757 * Alias a specific section to another one. Destination may exist or not,
758 * no checks are done.
759 * @param ef A valid eet file handle opened for writing.
760 * @param name Name of the new entry. eg: "/base/file_i_want".
761 * @param destination Actual source of the aliased entry eg: "/base/the_real_stuff_i_want".
762 * @param compress Compression flags (1 == compress, 0 = don't compress).
763 * @return EINA_TRUE on success, EINA_FALSE on failure.
765 * Name and Destination must not be NULL, otherwise EINA_FALSE will be returned.
766 * The equivalent of this would be calling 'ln -s destination name'
769 * @ingroup Eet_File_Group
772 eet_alias(Eet_File *ef,
774 const char *destination,
778 * Retrieve the filename of an Eet_File
779 * @param ef A valid eet file handle opened for writing.
780 * @return The stringshared file string opened with eet_open(), or NULL on error
782 * @note This function will return NULL for files opened with eet_memopen_read()
785 * @ingroup Eet_File_Group
788 eet_file_get(Eet_File *ef);
791 * Retrieve the destination name of an alias
792 * @param ef A valid eet file handle opened for writing
793 * @param name Name of the entry. eg: "/base/file_i_want"
794 * @return Destination of the alias. eg: "/base/the_real_stuff_i_want", NULL on failure
796 * Name must not be NULL, otherwise NULL will be returned.
799 * @ingroup Eet_File_Group
802 eet_alias_get(Eet_File *ef,
806 * List all entries in eet file matching shell glob.
807 * @param ef A valid eet file handle.
808 * @param glob A shell glob to match against.
809 * @param count_ret Number of entries found to match.
810 * @return Pointer to an array of strings.
812 * This function will list all entries in the eet file matching the
813 * supplied shell glob and return an allocated list of their names, if
814 * there are any, and if no memory errors occur.
816 * The eet file handle must be valid and glob must not be NULL, or NULL
817 * will be returned and count_ret will be filled with 0.
819 * The calling program must call free() on the array returned, but NOT
820 * on the string pointers in the array. They are taken as read-only
821 * internals from the eet file handle. They are only valid as long as
822 * the file handle is not closed. When it is closed those pointers in the
823 * array are now not valid and should not be used.
825 * On success the array returned will have a list of string pointers
826 * that are the names of the entries that matched, and count_ret will have
827 * the number of entries in this array placed in it.
829 * Hint: an easy way to list all entries in an eet file is to use a glob
833 * @ingroup Eet_File_Group
836 eet_list(Eet_File *ef,
841 * Return the number of entries in the specified eet file.
842 * @param ef A valid eet file handle.
843 * @return Number of entries in ef or -1 if the number of entries
844 * cannot be read due to open mode restrictions.
847 * @ingroup Eet_File_Group
850 eet_num_entries(Eet_File *ef);
853 * @defgroup Eet_File_Cipher_Group Eet File Ciphered Main Functions
855 * Most of the @ref Eet_File_Group have alternative versions that
856 * accounts for ciphers to protect their content.
858 * @see @ref Eet_Cipher_Group
860 * @ingroup Eet_File_Group
864 * Read a specified entry from an eet file and return data using a cipher.
865 * @param ef A valid eet file handle opened for reading.
866 * @param name Name of the entry. eg: "/base/file_i_want".
867 * @param size_ret Number of bytes read from entry and returned.
868 * @param cipher_key The key to use as cipher.
869 * @return The data stored in that entry in the eet file.
871 * This function finds an entry in the eet file that is stored under the
872 * name specified, and returns that data, decompressed, if successful.
873 * NULL is returned if the lookup fails or if memory errors are
874 * encountered. It is the job of the calling program to call free() on
875 * the returned data. The number of bytes in the returned data chunk are
876 * placed in size_ret.
878 * If the eet file handle is not valid NULL is returned and size_ret is
884 * @ingroup Eet_File_Cipher_Group
887 eet_read_cipher(Eet_File *ef,
890 const char *cipher_key);
893 * Write a specified entry to an eet file handle using a cipher.
894 * @param ef A valid eet file handle opened for writing.
895 * @param name Name of the entry. eg: "/base/file_i_want".
896 * @param data Pointer to the data to be stored.
897 * @param size Length in bytes in the data to be stored.
898 * @param compress Compression flags (1 == compress, 0 = don't compress).
899 * @param cipher_key The key to use as cipher.
900 * @return bytes written on successful write, 0 on failure.
902 * This function will write the specified chunk of data to the eet file
903 * and return greater than 0 on success. 0 will be returned on failure.
905 * The eet file handle must be a valid file handle for an eet file opened
906 * for writing. If it is not, 0 will be returned and no action will be
909 * Name, and data must not be NULL, and size must be > 0. If these
910 * conditions are not met, 0 will be returned.
912 * The data will be copied (and optionally compressed) in ram, pending
913 * a flush to disk (it will stay in ram till the eet file handle is
919 * @ingroup Eet_File_Cipher_Group
922 eet_write_cipher(Eet_File *ef,
927 const char *cipher_key);
930 * @defgroup Eet_File_Image_Group Image Store and Load
932 * Eet efficiently stores and loads images, including alpha
933 * channels and lossy compressions.
935 * Eet can handle both lossy compression with different levels of quality and
936 * non-lossy compression with different compression levels. It's also possible,
937 * given an image data, to only read its header to get the image information
938 * without decoding the entire content for it.
940 * The encode family of functions will take an image raw buffer and its
941 * parameters and compress it in memory, returning the new buffer.
942 * Likewise, the decode functions will read from the given location in memory
943 * and return the uncompressed image.
945 * The read and write functions will, respectively, encode and decode to or
946 * from an Eet file, under the specified key.
948 * These functions are fairly low level and the same functionality can be
949 * achieved using Evas and Edje, making it much easier to work with images
950 * as well as not needing to worry about things like scaling them.
954 * Read just the header data for an image and dont decode the pixels.
955 * @param ef A valid eet file handle opened for reading.
956 * @param name Name of the entry. eg: "/base/file_i_want".
957 * @param w A pointer to the unsigned int to hold the width in pixels.
958 * @param h A pointer to the unsigned int to hold the height in pixels.
959 * @param alpha A pointer to the int to hold the alpha flag.
960 * @param compress A pointer to the int to hold the compression amount.
961 * @param quality A pointer to the int to hold the quality amount.
962 * @param lossy A pointer to the int to hold the lossiness flag.
963 * @return 1 on successful decode, 0 otherwise
965 * Reads and decodes the image header data stored under the given key and
968 * The information decoded is placed in each of the parameters, which must be
969 * provided. The width and height, measured in pixels, will be stored under
970 * the variables pointed by @p w and @p h, respectively. If the read or
971 * decode of the header fails, this values will be 0. The @p alpha parameter
972 * will be 1 or 0, denoting if the alpha channel of the image is used or not.
973 * If the image was losslessly compressed, the @p compress parameter will hold
974 * the compression amount used, ranging from 0 to 9 and @p lossy will be 0.
975 * In the case of lossy compression, @p lossy will be 1, and the compression
976 * quality will be placed under @p quality, with a value ranging from 0 to 100.
978 * @see eet_data_image_header_decode()
979 * @see eet_data_image_header_read_cipher()
982 * @ingroup Eet_File_Image_Group
985 eet_data_image_header_read(Eet_File *ef,
995 * Read image data from the named key in the eet file.
996 * @param ef A valid eet file handle opened for reading.
997 * @param name Name of the entry. eg: "/base/file_i_want".
998 * @param w A pointer to the unsigned int to hold the width in pixels.
999 * @param h A pointer to the unsigned int to hold the height in pixels.
1000 * @param alpha A pointer to the int to hold the alpha flag.
1001 * @param compress A pointer to the int to hold the compression amount.
1002 * @param quality A pointer to the int to hold the quality amount.
1003 * @param lossy A pointer to the int to hold the lossiness flag.
1004 * @return The image pixel data decoded
1006 * Reads and decodes the image stored in the given Eet file under the named
1009 * The returned pixel data is a linear array of pixels starting from the
1010 * top-left of the image, scanning row by row from left to right. Each pile
1011 * is a 32bit value, with the high byte being the alpha channel, the next being
1012 * red, then green, and the low byte being blue.
1014 * The rest of the parameters are the same as in eet_data_image_header_read().
1016 * On success the function returns a pointer to the image data decoded. The
1017 * calling application is responsible for calling free() on the image data
1018 * when it is done with it. On failure NULL is returned and the parameter
1019 * values may not contain any sensible data.
1021 * @see eet_data_image_header_read()
1022 * @see eet_data_image_decode()
1023 * @see eet_data_image_read_cipher()
1024 * @see eet_data_image_read_to_surface()
1027 * @ingroup Eet_File_Image_Group
1030 eet_data_image_read(Eet_File *ef,
1040 * Read image data from the named key in the eet file and store it in the given buffer.
1041 * @param ef A valid eet file handle opened for reading.
1042 * @param name Name of the entry. eg: "/base/file_i_want".
1043 * @param src_x The starting x coordinate from where to dump the stream.
1044 * @param src_y The starting y coordinate from where to dump the stream.
1045 * @param d A pointer to the pixel surface.
1046 * @param w The expected width in pixels of the pixel surface to decode.
1047 * @param h The expected height in pixels of the pixel surface to decode.
1048 * @param row_stride The length of a pixels line in the destination surface.
1049 * @param alpha A pointer to the int to hold the alpha flag.
1050 * @param compress A pointer to the int to hold the compression amount.
1051 * @param quality A pointer to the int to hold the quality amount.
1052 * @param lossy A pointer to the int to hold the lossiness flag.
1053 * @return 1 on success, 0 otherwise.
1055 * Reads and decodes the image stored in the given Eet file, placing the
1056 * resulting pixel data in the buffer pointed by the user.
1058 * Like eet_data_image_read(), it takes the image data stored under the
1059 * @p name key in the @p ef file, but instead of returning a new buffer with
1060 * the pixel data, it places the result in the buffer pointed by @p d, which
1061 * must be provided by the user and of sufficient size to hold the requested
1062 * portion of the image.
1064 * The @p src_x and @p src_y parameters indicate the top-left corner of the
1065 * section of the image to decode. These have to be higher or equal than 0 and
1066 * less than the respective total width and height of the image. The width
1067 * and height of the section of the image to decode are given in @p w and @p h
1068 * and also can't be higher than the total width and height of the image.
1070 * The @p row_stride parameter indicates the length in bytes of each line in
1071 * the destination buffer and it has to be at least @p w * 4.
1073 * All the other parameters are the same as in eet_data_image_read().
1075 * On success the function returns 1, and 0 on failure. On failure the
1076 * parameter values may not contain any sensible data.
1078 * @see eet_data_image_read()
1079 * @see eet_data_image_decode()
1080 * @see eet_data_image_decode_to_surface()
1081 * @see eet_data_image_read_to_surface_cipher()
1084 * @ingroup Eet_File_Image_Group
1087 eet_data_image_read_to_surface(Eet_File *ef,
1094 unsigned int row_stride,
1101 * Write image data to the named key in an eet file.
1102 * @param ef A valid eet file handle opened for writing.
1103 * @param name Name of the entry. eg: "/base/file_i_want".
1104 * @param data A pointer to the image pixel data.
1105 * @param w The width of the image in pixels.
1106 * @param h The height of the image in pixels.
1107 * @param alpha The alpha channel flag.
1108 * @param compress The compression amount.
1109 * @param quality The quality encoding amount.
1110 * @param lossy The lossiness flag.
1111 * @return Success if the data was encoded and written or not.
1113 * This function takes image pixel data and encodes it in an eet file
1114 * stored under the supplied name key, and returns how many bytes were
1115 * actually written to encode the image data.
1117 * The data expected is the same format as returned by eet_data_image_read.
1118 * If this is not the case weird things may happen. Width and height must
1119 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1120 * the alpha values are not useful and 1 meaning they are). Compress can
1121 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1122 * This is only used if the image is not lossily encoded. Quality is used on
1123 * lossy compression and should be a value from 0 to 100. The lossy flag
1124 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1125 * image quality loss (but then have a much smaller encoding).
1127 * On success this function returns the number of bytes that were required
1128 * to encode the image data, or on failure it returns 0.
1130 * @see eet_data_image_read()
1131 * @see eet_data_image_encode()
1132 * @see eet_data_image_write_cipher()
1135 * @ingroup Eet_File_Image_Group
1138 eet_data_image_write(Eet_File *ef,
1149 * Decode Image data header only to get information.
1150 * @param data The encoded pixel data.
1151 * @param size The size, in bytes, of the encoded pixel data.
1152 * @param w A pointer to the unsigned int to hold the width in pixels.
1153 * @param h A pointer to the unsigned int to hold the height in pixels.
1154 * @param alpha A pointer to the int to hold the alpha flag.
1155 * @param compress A pointer to the int to hold the compression amount.
1156 * @param quality A pointer to the int to hold the quality amount.
1157 * @param lossy A pointer to the int to hold the lossiness flag.
1158 * @return 1 on success, 0 on failure.
1160 * This function works exactly like eet_data_image_header_read(), but instead
1161 * of reading from an Eet file, it takes the buffer of size @p size pointed
1162 * by @p data, which must be a valid Eet encoded image.
1164 * On success the function returns 1 indicating the header was read and
1165 * decoded properly, or 0 on failure.
1167 * @see eet_data_image_header_read()
1168 * @see eet_data_image_header_decode_cipher()
1171 * @ingroup Eet_File_Image_Group
1174 eet_data_image_header_decode(const void *data,
1184 * Decode Image data into pixel data.
1185 * @param data The encoded pixel data.
1186 * @param size The size, in bytes, of the encoded pixel data.
1187 * @param w A pointer to the unsigned int to hold the width in pixels.
1188 * @param h A pointer to the unsigned int to hold the height in pixels.
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 The image pixel data decoded
1195 * This function takes encoded pixel data and decodes it into raw RGBA
1196 * pixels on success.
1198 * It works exactly like eet_data_image_read(), but it takes the encoded
1199 * data in the @p data buffer of size @p size, instead of reading from a file.
1200 * All the others parameters are also the same.
1202 * On success the function returns a pointer to the image data decoded. The
1203 * calling application is responsible for calling free() on the image data
1204 * when it is done with it. On failure NULL is returned and the parameter
1205 * values may not contain any sensible data.
1207 * @see eet_data_image_read()
1208 * @see eet_data_image_decode_cipher()
1211 * @ingroup Eet_File_Image_Group
1214 eet_data_image_decode(const void *data,
1224 * Decode Image data into pixel data and stores in the given buffer.
1225 * @param data The encoded pixel data.
1226 * @param size The size, in bytes, of the encoded pixel data.
1227 * @param src_x The starting x coordinate from where to dump the stream.
1228 * @param src_y The starting y coordinate from where to dump the stream.
1229 * @param d A pointer to the pixel surface.
1230 * @param w The expected width in pixels of the pixel surface to decode.
1231 * @param h The expected height in pixels of the pixel surface to decode.
1232 * @param row_stride The length of a pixels line in the destination surface.
1233 * @param alpha A pointer to the int to hold the alpha flag.
1234 * @param compress A pointer to the int to hold the compression amount.
1235 * @param quality A pointer to the int to hold the quality amount.
1236 * @param lossy A pointer to the int to hold the lossiness flag.
1237 * @return 1 on success, 0 otherwise.
1239 * Like eet_data_image_read_to_surface(), but reading the given @p data buffer
1240 * instead of a file.
1242 * On success the function returns 1, and 0 on failure. On failure the
1243 * parameter values may not contain any sensible data.
1245 * @see eet_data_image_read_to_surface()
1246 * @see eet_data_image_decode_to_surface_cipher()
1249 * @ingroup Eet_File_Image_Group
1252 eet_data_image_decode_to_surface(const void *data,
1259 unsigned int row_stride,
1266 * Encode image data for storage or transmission.
1267 * @param data A pointer to the image pixel data.
1268 * @param size_ret A pointer to an int to hold the size of the returned data.
1269 * @param w The width of the image in pixels.
1270 * @param h The height of the image in pixels.
1271 * @param alpha The alpha channel flag.
1272 * @param compress The compression amount.
1273 * @param quality The quality encoding amount.
1274 * @param lossy The lossiness flag.
1275 * @return The encoded image data.
1277 * This function stakes image pixel data and encodes it with compression and
1278 * possible loss of quality (as a trade off for size) for storage or
1279 * transmission to another system.
1281 * It works like eet_data_image_write(), but instead of writing the encoded
1282 * image into an Eet file, it allocates a new buffer of the size required and
1283 * returns the encoded data in it.
1285 * On success this function returns a pointer to the encoded data that you
1286 * can free with free() when no longer needed.
1288 * @see eet_data_image_write()
1289 * @see eet_data_image_read()
1290 * @see eet_data_image_encode_cipher()
1293 * @ingroup Eet_File_Image_Group
1296 eet_data_image_encode(const void *data,
1306 * @defgroup Eet_File_Image_Cipher_Group Image Store and Load using a Cipher
1308 * Most of the @ref Eet_File_Image_Group have alternative versions
1309 * that accounts for ciphers to protect their content.
1311 * @see @ref Eet_Cipher_Group
1313 * @ingroup Eet_File_Image_Group
1317 * Read just the header data for an image and dont decode the pixels using a cipher.
1318 * @param ef A valid eet file handle opened for reading.
1319 * @param name Name of the entry. eg: "/base/file_i_want".
1320 * @param cipher_key The key to use as cipher.
1321 * @param w A pointer to the unsigned int to hold the width in pixels.
1322 * @param h A pointer to the unsigned int to hold the height in pixels.
1323 * @param alpha A pointer to the int to hold the alpha flag.
1324 * @param compress A pointer to the int to hold the compression amount.
1325 * @param quality A pointer to the int to hold the quality amount.
1326 * @param lossy A pointer to the int to hold the lossiness flag.
1327 * @return 1 on successful decode, 0 otherwise
1329 * This function reads an image from an eet file stored under the named
1330 * key in the eet file and return a pointer to the decompressed pixel data.
1332 * The other parameters of the image (width, height etc.) are placed into
1333 * the values pointed to (they must be supplied). The pixel data is a linear
1334 * array of pixels starting from the top-left of the image scanning row by
1335 * row from left to right. Each pixel is a 32bit value, with the high byte
1336 * being the alpha channel, the next being red, then green, and the low byte
1337 * being blue. The width and height are measured in pixels and will be
1338 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1339 * that the alpha channel is not used. 1 denotes that it is significant.
1340 * Compress is filled with the compression value/amount the image was
1341 * stored with. The quality value is filled with the quality encoding of
1342 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1343 * the image was encoded lossily or not.
1345 * On success the function returns 1 indicating the header was read and
1346 * decoded properly, or 0 on failure.
1348 * @see eet_data_image_header_read()
1351 * @ingroup Eet_File_Image_Cipher_Group
1354 eet_data_image_header_read_cipher(Eet_File *ef,
1356 const char *cipher_key,
1365 * Read image data from the named key in the eet file using a cipher.
1366 * @param ef A valid eet file handle opened for reading.
1367 * @param name Name of the entry. eg: "/base/file_i_want".
1368 * @param cipher_key The key to use as cipher.
1369 * @param w A pointer to the unsigned int to hold the width in pixels.
1370 * @param h A pointer to the unsigned int to hold the height in pixels.
1371 * @param alpha A pointer to the int to hold the alpha flag.
1372 * @param compress A pointer to the int to hold the compression amount.
1373 * @param quality A pointer to the int to hold the quality amount.
1374 * @param lossy A pointer to the int to hold the lossiness flag.
1375 * @return The image pixel data decoded
1377 * This function reads an image from an eet file stored under the named
1378 * key in the eet file and return a pointer to the decompressed pixel data.
1380 * The other parameters of the image (width, height etc.) are placed into
1381 * the values pointed to (they must be supplied). The pixel data is a linear
1382 * array of pixels starting from the top-left of the image scanning row by
1383 * row from left to right. Each pixel is a 32bit value, with the high byte
1384 * being the alpha channel, the next being red, then green, and the low byte
1385 * being blue. The width and height are measured in pixels and will be
1386 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1387 * that the alpha channel is not used. 1 denotes that it is significant.
1388 * Compress is filled with the compression value/amount the image was
1389 * stored with. The quality value is filled with the quality encoding of
1390 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1391 * the image was encoded lossily or not.
1393 * On success the function returns a pointer to the image data decoded. The
1394 * calling application is responsible for calling free() on the image data
1395 * when it is done with it. On failure NULL is returned and the parameter
1396 * values may not contain any sensible data.
1398 * @see eet_data_image_read()
1401 * @ingroup Eet_File_Image_Cipher_Group
1404 eet_data_image_read_cipher(Eet_File *ef,
1406 const char *cipher_key,
1415 * Read image data from the named key in the eet file using a cipher.
1416 * @param ef A valid eet file handle opened for reading.
1417 * @param name Name of the entry. eg: "/base/file_i_want".
1418 * @param cipher_key The key to use as cipher.
1419 * @param src_x The starting x coordinate from where to dump the stream.
1420 * @param src_y The starting y coordinate from where to dump the stream.
1421 * @param d A pointer to the pixel surface.
1422 * @param w The expected width in pixels of the pixel surface to decode.
1423 * @param h The expected height in pixels of the pixel surface to decode.
1424 * @param row_stride The length of a pixels line in the destination surface.
1425 * @param alpha A pointer to the int to hold the alpha flag.
1426 * @param compress A pointer to the int to hold the compression amount.
1427 * @param quality A pointer to the int to hold the quality amount.
1428 * @param lossy A pointer to the int to hold the lossiness flag.
1429 * @return 1 on success, 0 otherwise.
1431 * This function reads an image from an eet file stored under the named
1432 * key in the eet file and return a pointer to the decompressed pixel data.
1434 * The other parameters of the image (width, height etc.) are placed into
1435 * the values pointed to (they must be supplied). The pixel data is a linear
1436 * array of pixels starting from the top-left of the image scanning row by
1437 * row from left to right. Each pixel is a 32bit value, with the high byte
1438 * being the alpha channel, the next being red, then green, and the low byte
1439 * being blue. The width and height are measured in pixels and will be
1440 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1441 * that the alpha channel is not used. 1 denotes that it is significant.
1442 * Compress is filled with the compression value/amount the image was
1443 * stored with. The quality value is filled with the quality encoding of
1444 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1445 * the image was encoded lossily or not.
1447 * On success the function returns 1, and 0 on failure. On failure the
1448 * parameter values may not contain any sensible data.
1450 * @see eet_data_image_read_to_surface()
1453 * @ingroup Eet_File_Image_Cipher_Group
1456 eet_data_image_read_to_surface_cipher(Eet_File *ef,
1458 const char *cipher_key,
1464 unsigned int row_stride,
1471 * Write image data to the named key in an eet file using a cipher.
1472 * @param ef A valid eet file handle opened for writing.
1473 * @param name Name of the entry. eg: "/base/file_i_want".
1474 * @param cipher_key The key to use as cipher.
1475 * @param data A pointer to the image pixel data.
1476 * @param w The width of the image in pixels.
1477 * @param h The height of the image in pixels.
1478 * @param alpha The alpha channel flag.
1479 * @param compress The compression amount.
1480 * @param quality The quality encoding amount.
1481 * @param lossy The lossiness flag.
1482 * @return Success if the data was encoded and written or not.
1484 * This function takes image pixel data and encodes it in an eet file
1485 * stored under the supplied name key, and returns how many bytes were
1486 * actually written to encode the image data.
1488 * The data expected is the same format as returned by eet_data_image_read.
1489 * If this is not the case weird things may happen. Width and height must
1490 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1491 * the alpha values are not useful and 1 meaning they are). Compress can
1492 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1493 * This is only used if the image is not lossily encoded. Quality is used on
1494 * lossy compression and should be a value from 0 to 100. The lossy flag
1495 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1496 * image quality loss (but then have a much smaller encoding).
1498 * On success this function returns the number of bytes that were required
1499 * to encode the image data, or on failure it returns 0.
1501 * @see eet_data_image_write()
1504 * @ingroup Eet_File_Image_Cipher_Group
1507 eet_data_image_write_cipher(Eet_File *ef,
1509 const char *cipher_key,
1519 * Decode Image data header only to get information using a cipher.
1520 * @param data The encoded pixel data.
1521 * @param cipher_key The key to use as cipher.
1522 * @param size The size, in bytes, of the encoded pixel data.
1523 * @param w A pointer to the unsigned int to hold the width in pixels.
1524 * @param h A pointer to the unsigned int to hold the height in pixels.
1525 * @param alpha A pointer to the int to hold the alpha flag.
1526 * @param compress A pointer to the int to hold the compression amount.
1527 * @param quality A pointer to the int to hold the quality amount.
1528 * @param lossy A pointer to the int to hold the lossiness flag.
1529 * @return 1 on success, 0 on failure.
1531 * This function takes encoded pixel data and decodes it into raw RGBA
1532 * pixels on success.
1534 * The other parameters of the image (width, height etc.) are placed into
1535 * the values pointed to (they must be supplied). The pixel data is a linear
1536 * array of pixels starting from the top-left of the image scanning row by
1537 * row from left to right. Each pixel is a 32bit value, with the high byte
1538 * being the alpha channel, the next being red, then green, and the low byte
1539 * being blue. The width and height are measured in pixels and will be
1540 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1541 * that the alpha channel is not used. 1 denotes that it is significant.
1542 * Compress is filled with the compression value/amount the image was
1543 * stored with. The quality value is filled with the quality encoding of
1544 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1545 * the image was encoded lossily or not.
1547 * On success the function returns 1 indicating the header was read and
1548 * decoded properly, or 0 on failure.
1550 * @see eet_data_image_header_decode()
1553 * @ingroup Eet_File_Image_Cipher_Group
1556 eet_data_image_header_decode_cipher(const void *data,
1557 const char *cipher_key,
1567 * Decode Image data into pixel data using a cipher.
1568 * @param data The encoded pixel data.
1569 * @param cipher_key The key to use as cipher.
1570 * @param size The size, in bytes, of the encoded pixel data.
1571 * @param w A pointer to the unsigned int to hold the width in pixels.
1572 * @param h A pointer to the unsigned int to hold the height in pixels.
1573 * @param alpha A pointer to the int to hold the alpha flag.
1574 * @param compress A pointer to the int to hold the compression amount.
1575 * @param quality A pointer to the int to hold the quality amount.
1576 * @param lossy A pointer to the int to hold the lossiness flag.
1577 * @return The image pixel data decoded
1579 * This function takes encoded pixel data and decodes it into raw RGBA
1580 * pixels on success.
1582 * The other parameters of the image (width, height etc.) are placed into
1583 * the values pointed to (they must be supplied). The pixel data is a linear
1584 * array of pixels starting from the top-left of the image scanning row by
1585 * row from left to right. Each pixel is a 32bit value, with the high byte
1586 * being the alpha channel, the next being red, then green, and the low byte
1587 * being blue. The width and height are measured in pixels and will be
1588 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1589 * that the alpha channel is not used. 1 denotes that it is significant.
1590 * Compress is filled with the compression value/amount the image was
1591 * stored with. The quality value is filled with the quality encoding of
1592 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1593 * the image was encoded lossily or not.
1595 * On success the function returns a pointer to the image data decoded. The
1596 * calling application is responsible for calling free() on the image data
1597 * when it is done with it. On failure NULL is returned and the parameter
1598 * values may not contain any sensible data.
1600 * @see eet_data_image_decode()
1603 * @ingroup Eet_File_Image_Cipher_Group
1606 eet_data_image_decode_cipher(const void *data,
1607 const char *cipher_key,
1617 * Decode Image data into pixel data using a cipher.
1618 * @param data The encoded pixel data.
1619 * @param cipher_key The key to use as cipher.
1620 * @param size The size, in bytes, of the encoded pixel data.
1621 * @param src_x The starting x coordinate from where to dump the stream.
1622 * @param src_y The starting y coordinate from where to dump the stream.
1623 * @param d A pointer to the pixel surface.
1624 * @param w The expected width in pixels of the pixel surface to decode.
1625 * @param h The expected height in pixels of the pixel surface to decode.
1626 * @param row_stride The length of a pixels line in the destination surface.
1627 * @param alpha A pointer to the int to hold the alpha flag.
1628 * @param compress A pointer to the int to hold the compression amount.
1629 * @param quality A pointer to the int to hold the quality amount.
1630 * @param lossy A pointer to the int to hold the lossiness flag.
1631 * @return 1 on success, 0 otherwise.
1633 * This function takes encoded pixel data and decodes it into raw RGBA
1634 * pixels on success.
1636 * The other parameters of the image (alpha, compress etc.) are placed into
1637 * the values pointed to (they must be supplied). The pixel data is a linear
1638 * array of pixels starting from the top-left of the image scanning row by
1639 * row from left to right. Each pixel is a 32bit value, with the high byte
1640 * being the alpha channel, the next being red, then green, and the low byte
1641 * being blue. The width and height are measured in pixels and will be
1642 * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1643 * that the alpha channel is not used. 1 denotes that it is significant.
1644 * Compress is filled with the compression value/amount the image was
1645 * stored with. The quality value is filled with the quality encoding of
1646 * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1647 * the image was encoded lossily or not.
1649 * On success the function returns 1, and 0 on failure. On failure the
1650 * parameter values may not contain any sensible data.
1652 * @see eet_data_image_decode_to_surface()
1655 * @ingroup Eet_File_Image_Cipher_Group
1658 eet_data_image_decode_to_surface_cipher(const void *data,
1659 const char *cipher_key,
1666 unsigned int row_stride,
1673 * Encode image data for storage or transmission using a cipher.
1674 * @param data A pointer to the image pixel data.
1675 * @param cipher_key The key to use as cipher.
1676 * @param size_ret A pointer to an int to hold the size of the returned data.
1677 * @param w The width of the image in pixels.
1678 * @param h The height of the image in pixels.
1679 * @param alpha The alpha channel flag.
1680 * @param compress The compression amount.
1681 * @param quality The quality encoding amount.
1682 * @param lossy The lossiness flag.
1683 * @return The encoded image data.
1685 * This function stakes image pixel data and encodes it with compression and
1686 * possible loss of quality (as a trade off for size) for storage or
1687 * transmission to another system.
1689 * The data expected is the same format as returned by eet_data_image_read.
1690 * If this is not the case weird things may happen. Width and height must
1691 * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1692 * the alpha values are not useful and 1 meaning they are). Compress can
1693 * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1694 * This is only used if the image is not lossily encoded. Quality is used on
1695 * lossy compression and should be a value from 0 to 100. The lossy flag
1696 * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1697 * image quality loss (but then have a much smaller encoding).
1699 * On success this function returns a pointer to the encoded data that you
1700 * can free with free() when no longer needed.
1702 * @see eet_data_image_encode()
1705 * @ingroup Eet_File_Image_Cipher_Group
1708 eet_data_image_encode_cipher(const void *data,
1709 const char *cipher_key,
1719 * @defgroup Eet_Cipher_Group Cipher, Identity and Protection Mechanisms
1721 * Eet allows one to protect entries of an #Eet_File
1722 * individually. This may be used to ensure data was not tampered or
1723 * that third party does not read your data.
1725 * @see @ref Eet_File_Cipher_Group
1726 * @see @ref Eet_File_Image_Cipher_Group
1733 * Opaque handle that defines an identity (also known as key)
1734 * in Eet's cipher system.
1736 typedef struct _Eet_Key Eet_Key;
1743 * Callback used to request if needed the password of a private key.
1745 * @param buffer the buffer where to store the password.
1746 * @param size the maximum password size (size of buffer, including '@\0').
1747 * @param rwflag if the buffer is also readable or just writable.
1748 * @param data currently unused, may contain some context in future.
1749 * @return 1 on success and password was set to @p buffer, 0 on failure.
1752 * @ingroup Eet_Cipher_Group
1754 typedef int (*Eet_Key_Password_Callback)(char *buffer, int size, int rwflag, void *data);
1757 * Create an Eet_Key needed for signing an eet file.
1759 * The certificate should provide the public that match the private key.
1760 * No verification is done to ensure that.
1762 * @param certificate_file The file where to find the certificate.
1763 * @param private_key_file The file that contains the private key.
1764 * @param cb Function to callback if password is required to unlock
1766 * @return A key handle to use, or @c NULL on failure.
1768 * @see eet_identity_close()
1771 * @ingroup Eet_Cipher_Group
1774 eet_identity_open(const char *certificate_file,
1775 const char *private_key_file,
1776 Eet_Key_Password_Callback cb);
1779 * Close and release all ressource used by an Eet_Key. An
1780 * reference counter prevent it from being freed until all file
1781 * using it are also closed.
1783 * @param key the key handle to close and free resources.
1786 * @ingroup Eet_Cipher_Group
1789 eet_identity_close(Eet_Key *key);
1792 * Set a key to sign a file
1794 * @param ef the file to set the identity.
1795 * @param key the key handle to set as identity.
1796 * @return #EET_ERROR_BAD_OBJECT if @p ef is invalid or
1797 * #EET_ERROR_NONE on success.
1800 * @ingroup Eet_Cipher_Group
1803 eet_identity_set(Eet_File *ef,
1807 * Display both private and public key of an Eet_Key.
1809 * @param key the handle to print.
1810 * @param out where to print.
1813 * @ingroup Eet_Cipher_Group
1816 eet_identity_print(Eet_Key *key,
1820 * Get the x509 der certificate associated with an Eet_File. Will return NULL
1821 * if the file is not signed.
1823 * @param ef The file handle to query.
1824 * @param der_length The length of returned data, may be @c NULL.
1825 * @return the x509 certificate or @c NULL on error.
1828 * @ingroup Eet_Cipher_Group
1831 eet_identity_x509(Eet_File *ef,
1835 * Get the raw signature associated with an Eet_File. Will return NULL
1836 * if the file is not signed.
1838 * @param ef The file handle to query.
1839 * @param signature_length The length of returned data, may be @c NULL.
1840 * @return the raw signature or @c NULL on error.
1842 * @ingroup Eet_Cipher_Group
1845 eet_identity_signature(Eet_File *ef,
1846 int *signature_length);
1849 * Get the SHA1 associated with a file. Could be the one used to
1850 * sign the data or if the data where not signed, it will be the
1853 * @param ef The file handle to query.
1854 * @param sha1_length The length of returned data, may be @c NULL.
1855 * @return the associated SHA1 or @c NULL on error.
1858 * @ingroup Eet_Cipher_Group
1861 eet_identity_sha1(Eet_File *ef,
1865 * Display the x509 der certificate to out.
1867 * @param certificate the x509 certificate to print
1868 * @param der_length The length the certificate.
1869 * @param out where to print.
1872 * @ingroup Eet_Cipher_Group
1875 eet_identity_certificate_print(const unsigned char *certificate,
1880 * @defgroup Eet_Data_Group Eet Data Serialization
1882 * Convenience functions to serialize and parse complex data
1883 * structures to binary blobs.
1885 * While Eet core just handles binary blobs, it is often required
1886 * to save some structured data of different types, such as
1887 * strings, integers, lists, hashes and so on.
1889 * Eet can serialize and then parse data types given some
1890 * construction instructions. These are defined in two levels:
1892 * - #Eet_Data_Descriptor_Class to tell generic memory handling,
1893 * such as the size of the type, how to allocate memory, strings,
1894 * lists, hashes and so on.
1896 * - #Eet_Data_Descriptor to tell inside such type, the members and
1897 * their offsets inside the memory blob, their types and
1898 * names. These members can be simple types or other
1899 * #Eet_Data_Descriptor, allowing hierarchical types to be
1902 * Given that C provides no introspection, this process can be
1903 * quite cumbersome, so we provide lots of macros and convenience
1904 * functions to aid creating the types.
1906 * We make now a quick overview of some of the most commonly used elements
1907 * of this part of the library. A simple example of a configuration system
1908 * will work as a somewhat real life example that is still simple enough to
1910 * Only the relevant sections will be shown here, but you can get the full
1911 * code @ref eet-data-simple.c "here".
1913 * Ignoring the included headers, we'll begin by defining our configuration
1915 * @dontinclude eet-data-simple.c
1919 * When using Eet, you don't think in matters of what data the program needs
1920 * to run and which you would like to store. It's all the same and if it makes
1921 * more sense to keep them together, it's perfectly fine to do so. At the time
1922 * of telling Eet how your data is comprised you can leave out the things
1923 * that are runtime only and let Eet take care of the rest for you.
1925 * The key used to store the config follows, as well as the variable used to
1926 * store our data descriptor.
1927 * This last one is very important. It's the one thing that Eet will use to
1928 * identify your data, both at the time of writing it to the file and when
1931 * @skipline Eet_Data_Descriptor
1933 * Now we'll see how to create this descriptor, so Eet knows how to handle
1934 * our data later on.
1935 * Begin our function by declaring an Eet_Data_Descriptor_Class, which is
1936 * used to create the actual descriptor. This class contains the name of
1937 * our data type, its size and several functions that dictate how Eet should
1938 * handle memory to allocate the necessary bits to bring our data to life.
1939 * You, as a user, will very hardly set this class' contents directly. The
1940 * most common scenario is to use one of the provided macros that set it using
1941 * the Eina data types, so that's what we'll be doing across all our examples.
1943 * @until eet_data_descriptor_stream_new
1945 * Now that we have our descriptor, we need to make it describe something.
1946 * We do so by telling it which members of our struct we want it to know about
1948 * The eet_data_descriptor_element_add() function takes care of this, but it's
1949 * too cumbersome for normal use, so several macros are provided that make
1950 * it easier to handle. Even with them, however, code can get very repetitive
1951 * and it's not uncommon to define custom macros using them to save on typing.
1955 * Now our descriptor knows about the parts of our structure that we are
1956 * interesting in saving. You can see that not all of them are there, yet Eet
1957 * will find those that need saving and do the right thing. When loading our
1958 * data, any non-described fields in the structure will be zeroed, so there's
1959 * no need to worry about garbage memory in them.
1960 * Refer to the documentation of #EET_DATA_DESCRIPTOR_ADD_BASIC to understand
1961 * what our macro does.
1963 * We are done with our descriptor init function and it's proper to have the
1964 * relevant shutdown. Proper coding guidelines indiciate that all memory
1965 * allocated should be freed when the program ends, and since you will most
1966 * likely keep your descriptor around for the life or your application, it's
1967 * only right to free it at the end.
1971 * Not listed here, but included in the full example are functions to create
1972 * a blank configuration and free it. The first one will only be used when
1973 * no file exists to load from, or nothing is found in it, but the latter is
1974 * used regardless of where our data comes from. Unless you are reading direct
1975 * data from the Eet file, you will be in charge of freeing anything loaded
1978 * Now it's time to look at how we can load our config from some file.
1979 * Begin by opening the Eet file normally.
1980 * @skip static My_Conf_Type
1983 * And now we need to read the data from the file and decode it using our
1984 * descriptor. Fortunately, that's all done in one single step.
1987 * And that's it for all Eet cares about. But since we are dealing with a
1988 * common case, as is save and load of user configurations, the next fragment
1989 * of code shows why we have a version field in our struct, and how you can
1990 * use it to load older configuration files and update them as needed.
1993 * Finally, clsoe the file and return the newly loaded config data.
1996 * Saving data is just as easy. The full version of the following function
1997 * includes code to save to a temporary file first, so you can be sure not
1998 * to lose all your data in the case of a failure mid-writing. You can look
1999 * at it @ref eet-data-simple.c "here".
2000 * @skip static Eina_Bool
2002 * @skipline Eina_Bool ret
2008 * To close, our main function, which doesn't do much. Just take some arguments
2009 * from the command line with the name of the file to load and another one
2010 * where to save again. If input file doesn't exist, a new config structure
2011 * will be created and saved to our output file.
2016 * The following is a list of more advanced and detailed examples.
2017 * @li @ref eet_data_nested_example
2018 * @li @ref eet_data_file_descriptor
2019 * @li @ref Example_Eet_Data_File_Descriptor_02
2020 * @li @ref Example_Eet_Data_Cipher_Decipher
2024 * @page eet_data_nested_example Nested structures and Eet Data Descriptors
2026 * We've seen already a simple example of how to use Eet Data Descriptors
2027 * to handle our structures, but it didn't show how this works when you
2028 * have structures inside other structures.
2030 * Now, there's a very simple case of this, for when you have inline structs
2031 * to keep your big structure more organized, you don't need anything else
2032 * besides what @ref eet-data-simple.c "this simple example does".
2033 * Just use something like @p some_struct.sub_struct.member when adding the
2034 * member to the descriptor and it will work.
2048 * void some_function()
2051 * my_desc = eet_data_descriptor_stream_new(&eddc);
2052 * EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "a_number",
2053 * a_number, EET_T_INT);
2054 * EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "a_string",
2055 * a_string, EET_T_STRING);
2056 * EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "sub.other_num",
2057 * sub.other_num, EET_T_INT);
2058 * EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "sub.one_more",
2059 * sub.one_more", EET_T_INT);
2064 * But this is not what we are here for today. When we talk about nested
2065 * structures, what we really want are things like lists and hashes to be
2066 * taken into consideration automatically, and all their contents saved and
2067 * loaded just like ordinary integers and strings are.
2069 * And of course, Eet can do that, and considering the work it saves you as a
2070 * programmer, we could say it's even easier to do than handling just integers.
2072 * Let's begin with our example then, which is not all too different from the
2073 * simple one introduced earlier.
2075 * We won't ignore the headers this time to show how easy it is to use Eina
2076 * data types with Eet, but we'll still skip most of the code that is not
2077 * pertinent to what we want to show now, but as usual, you can get it full
2078 * by follwing @ref eet-data-nested.c "this link".
2080 * @dontinclude eet-data-nested.c
2083 * @skip typedef struct
2084 * @until } My_Conf_Subtype
2086 * Extremely similar to our previous example. Just a new struct in there, and
2087 * a pointer to a list in the one we already had. Handling a list of subtypes
2088 * is easy on our program, but now we'll see what Eet needs to work with them
2089 * (Hint: it's easy too).
2090 * @skip _my_conf_descriptor
2091 * @until _my_conf_sub_descriptor
2093 * Since we have two structures now, it's only natural that we'll need two
2094 * descriptors. One for each, which will be defined exactly as before.
2097 * @skip EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET
2098 * @until _my_conf_sub_descriptor
2100 * We create our descriptors, each for one type, and as before, we are going to
2101 * use a simple macro to set their contents, to save on typing.
2103 * @until EET_T_UCHAR
2105 * So far, nothing new. We have our descriptors and we know already how to
2106 * save them separately. But what we want is to link them together, and even
2107 * more so, we want our main type to hold a list of more than one of the new
2108 * sub type. So how do we do that?
2110 * Simple enough, we tell Eet that our main descriptor will hold a list, of
2111 * which each node will point to some type described by our new descriptor.
2112 * @skip EET_DATA_DESCRIPTOR_ADD_LIST
2113 * @until _my_conf_sub_descriptor
2115 * And that's all. We are closing the function now so as to not leave dangling
2116 * curly braces, but there's nothing more to show in this example. Only other
2117 * additions are the necessary code to free our new data, but you can see it
2118 * in the full code listing.
2123 * @page eet_data_file_descriptor Advanced use of Eet Data Descriptors
2125 * A real life example is usually the best way to see how things are used,
2126 * but they also involve a lot more code than what needs to be shown, so
2127 * instead of going that way, we'll be borrowing some pieces from one in
2128 * the following example. It's been slightly modified from the original
2129 * source to show more of the varied ways in which Eet can handle our data.
2131 * @ref eet-data-file_descriptor_01.c "This example" shows a cache of user
2132 * accounts and messages received, and it's a bit more interactive than
2133 * previous examples.
2135 * Let's begin by looking at the structures we'll be using. First we have
2136 * one to define the messages the user receives and one for the one he posts.
2137 * Straight forward and nothing new here.
2138 * @dontinclude eet-data-file_descriptor_01.c
2142 * One more to declare the account itself. This one will contain a list of
2143 * all messages received, and the posts we make ourselves will be kept in an
2144 * array. No special reason other than to show how to use arrays with Eet.
2147 * Finally, the main structure to hold our cache of accounts. We'll be looking
2148 * for these accounts by their names, so let's keep them in a hash, using
2149 * that name as the key.
2152 * As explained before, we need one descriptor for each struct we want Eet
2153 * to handle, but this time we also want to keep around our Eet file and its
2154 * string dictionary. You will see why in a moment.
2155 * @skip Eet_Data_Descriptor
2156 * @until _my_post_descriptor
2158 * @until Eet_Dictionary
2160 * The differences begin now. They aren't much, but we'll be creating our
2161 * descriptors differently. Things can be added to our cache, but we won't
2162 * be modifying the current contents, so we can consider the data read from
2163 * it to be read-only, and thus allow Eet to save time and memory by not
2164 * duplicating thins unnecessary.
2166 * @until _my_post_descriptor
2168 * As the comment in the code explains, we are asking Eet to give us strings
2169 * directly from the mapped file, which avoids having to load it in memory
2170 * and data duplication.
2171 * Of course, there are things to take into account when doing things this
2172 * way, and they will be mentioned as we encounter those special cases.
2174 * Next comes the actual description of our data, just like we did in the
2175 * previous examples.
2181 * And the account struct's description doesn't add much new, but it's worth
2184 * @until _my_post_descriptor
2186 * How to add a list we've seen before, but now we are also adding an array.
2187 * There's nothing really special about it, but it's important to note that
2188 * the EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY is used to add arrays of variable
2189 * length to a descriptor. That is, arrays just like the one we defined.
2190 * Since there's no way in C to know how long they are, we need to keep
2191 * track of the count ourselves and Eet needs to know how to do so as well.
2192 * That's what the @p posts_count member of our struct is for. When adding
2193 * our array member, this macro will look for another variable in the struct
2194 * named just like the array, but with @p _count attached to the end.
2195 * When saving our data, Eet will know how many elements the array contains
2196 * by looking into this count variable. When loading back from a file, this
2197 * variable will be set to the right number of elements.
2199 * Another option for arrays is to use EET_DATA_DESCRIPTOR_ADD_ARRAY, which
2200 * takes care of fixed sized arrays.
2201 * For example, let's suppose that we want to keep track of only the last
2202 * ten posts the user sent, and we declare our account struct as follows
2208 * Eina_List *messages;
2209 * My_Post posts[10];
2212 * Then we would add the array to our descriptor with
2214 * EET_DATA_DESCRIPTOR_ADD_ARRAY(_my_account_descriptor, My_Account, "posts",
2215 * posts, _my_post_descriptor);
2218 * Notice how this time we don't have a @p posts_count variable in our struct.
2219 * We could have it for the program to keep track of how many posts the
2220 * array actually contains, but Eet no longer needs it. Being defined that
2221 * way the array is already taking up all the memory needed for the ten
2222 * elements, and it is possible in C to determine how much it is in code.
2223 * When saving our data, Eet will just dump the entire memory blob into the
2224 * file, regardless of how much of it is really used. So it's important to
2225 * take into consideration this kind of things when defining your data types.
2226 * Each has its uses, its advantages and disadvantages and it's up to you
2227 * to decide which to use.
2229 * Now, going back to our example, we have to finish adding our data to the
2230 * descriptors. We are only missing the main one for the cache, which
2231 * contains our hash of accounts.
2232 * Unless you are using your own hash functions when setting the descriptor
2233 * class, always use hashes with string type keys.
2237 * If you remember, we told Eet not to duplicate memory when possible at the
2238 * time of loading back our data. But this doesn't mean everything will be
2239 * loaded straight from disk and we don't have to worry about freeing it.
2240 * Data in the Eet file is compressed and encoded, so it still needs to be
2241 * decoded and memory will be allocated to convert it back into something we
2242 * can use. We also need to take care of anything we add in the current
2243 * instance of the program.
2244 * To summarize, any string we get from Eet is likely to be a pointer to the
2245 * internal dictionary, and trying to free it will, in the best case, crash
2246 * our application right away.
2248 * So how do we know if we have to free a string? We check if it's part of
2249 * the dictionary, and if it's not there we can be sure it's safe to get
2256 * See how this is used when adding a new message to our cache.
2257 * @skip static My_Message
2262 * Skipping all the utility functions used by our program (remember you can
2263 * look at the full example @ref eet-data-file_descriptor_01.c "here") we get to
2264 * our cache loading code. Nothing out of the ordinary at first, just the
2265 * same old open file, read data using our main descriptor to decode it
2266 * into something we can use and check version of loaded data and if it doesn't
2267 * match, do something accordingly.
2268 * @skip static My_Cache
2273 * Then comes the interesting part. Remember how we kept two more global
2274 * variables with our descriptors? One of them we already used to check if
2275 * it was right to free a string or not, but we didn't know where it came from.
2276 * Loading our data straight from the mmapped file means that we can't close
2277 * it until we are done using it, so we need to keep its handler around until
2278 * then. It also means that any changes done to the file can, and will,
2279 * invalidate all our pointers to the file backed data, so if we add something
2280 * and save the file, we need to reload our cache.
2282 * Thus our load function checks if we had an open file, if there is it gets
2283 * closed and our variable is updated to the new handler. Then we get the
2284 * string dictionary we use to check if a string is part of it or not.
2285 * Updating any references to the cache data is up you as a programmer to
2286 * handle properly, there's nothing Eet can do in this situation.
2289 * The save function doesn't have anything new, and all that's left after it
2290 * is the main program, which doesn't really have anything of interest within
2291 * the scope of what we are learning.
2295 * @addtogroup Eet_Data_Group
2298 #define EET_T_UNKNOW 0 /**< Unknown data encoding type */
2299 #define EET_T_CHAR 1 /**< Data type: char */
2300 #define EET_T_SHORT 2 /**< Data type: short */
2301 #define EET_T_INT 3 /**< Data type: int */
2302 #define EET_T_LONG_LONG 4 /**< Data type: long long */
2303 #define EET_T_FLOAT 5 /**< Data type: float */
2304 #define EET_T_DOUBLE 6 /**< Data type: double */
2305 #define EET_T_UCHAR 7 /**< Data type: unsigned char */
2306 #define EET_T_USHORT 8 /**< Data type: unsigned short */
2307 #define EET_T_UINT 9 /**< Data type: unsigned int */
2308 #define EET_T_ULONG_LONG 10 /**< Data type: unsigned long long */
2309 #define EET_T_STRING 11 /**< Data type: char * */
2310 #define EET_T_INLINED_STRING 12 /**< Data type: char * (but compressed inside the resulting eet) */
2311 #define EET_T_NULL 13 /**< Data type: (void *) (only use it if you know why) */
2312 #define EET_T_F32P32 14 /**< Data type: fixed point 32.32 */
2313 #define EET_T_F16P16 15 /**< Data type: fixed point 16.16 */
2314 #define EET_T_F8P24 16 /**< Data type: fixed point 8.24 */
2315 #define EET_T_LAST 18 /**< Last data type */
2317 #define EET_G_UNKNOWN 100 /**< Unknown group data encoding type */
2318 #define EET_G_ARRAY 101 /**< Fixed size array group type */
2319 #define EET_G_VAR_ARRAY 102 /**< Variable size array group type */
2320 #define EET_G_LIST 103 /**< Linked list group type */
2321 #define EET_G_HASH 104 /**< Hash table group type */
2322 #define EET_G_UNION 105 /**< Union group type */
2323 #define EET_G_VARIANT 106 /**< Selectable subtype group */
2324 #define EET_G_LAST 107 /**< Last group type */
2326 #define EET_I_LIMIT 128 /**< Other type exist but are reserved for internal purpose. */
2329 * @typedef Eet_Data_Descriptor
2331 * Opaque handle that have information on a type members.
2333 * Descriptors are created using an #Eet_Data_Descriptor_Class, and they
2334 * describe the contents of the structure that will be serialized by Eet.
2335 * Not all members need be described by it, just those that should be handled
2336 * by Eet. This way it's possible to have one structure with both data to be
2337 * saved to a file, like application configuration, and runtime information
2338 * that would be meaningless to store, but is appropriate to keep together
2339 * during the program execution.
2340 * The members are added by means of
2341 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB(),
2342 * EET_DATA_DESCRIPTOR_ADD_LIST(), EET_DATA_DESCRIPTOR_ADD_HASH()
2343 * or eet_data_descriptor_element_add().
2345 * @see eet_data_descriptor_stream_new()
2346 * @see eet_data_descriptor_file_new()
2347 * @see eet_data_descriptor_free()
2349 typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
2352 * @def EET_DATA_DESCRIPTOR_CLASS_VERSION
2353 * The version of #Eet_Data_Descriptor_Class at the time of the
2354 * distribution of the sources. One should define this to its
2355 * version member so it is compatible with abi changes, or at least
2356 * will not crash with them.
2358 #define EET_DATA_DESCRIPTOR_CLASS_VERSION 4
2361 * @typedef Eet_Data_Descriptor_Class
2363 * Instructs Eet about memory management for different needs under
2364 * serialization and parse process.
2366 typedef struct _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class;
2368 typedef int (*Eet_Descriptor_Hash_Foreach_Callback_Callback)(void *h, const char *k, void *dt, void *fdt);
2370 typedef void * (*Eet_Descriptor_Mem_Alloc_Callback)(size_t size);
2371 typedef void (*Eet_Descriptor_Mem_Free_Callback)(void *mem);
2372 typedef char * (*Eet_Descriptor_Str_Alloc_Callback)(const char *str);
2373 typedef void (*Eet_Descriptor_Str_Free_Callback)(const char *str);
2374 typedef void * (*Eet_Descriptor_List_Next_Callback)(void *l);
2375 typedef void * (*Eet_Descriptor_List_Append_Callback)(void *l, void *d);
2376 typedef void * (*Eet_Descriptor_List_Data_Callback)(void *l);
2377 typedef void * (*Eet_Descriptor_List_Free_Callback)(void *l);
2378 typedef void (*Eet_Descriptor_Hash_Foreach_Callback)(void *h, Eet_Descriptor_Hash_Foreach_Callback_Callback func, void *fdt);
2379 typedef void * (*Eet_Descriptor_Hash_Add_Callback)(void *h, const char *k, void *d);
2380 typedef void (*Eet_Descriptor_Hash_Free_Callback)(void *h);
2381 typedef char * (*Eet_Descriptor_Str_Direct_Alloc_Callback)(const char *str);
2382 typedef void (*Eet_Descriptor_Str_Direct_Free_Callback)(const char *str);
2383 typedef const char * (*Eet_Descriptor_Type_Get_Callback)(const void *data, Eina_Bool *unknow);
2384 typedef Eina_Bool (*Eet_Descriptor_Type_Set_Callback)(const char *type, void *data, Eina_Bool unknow);
2385 typedef void * (*Eet_Descriptor_Array_Alloc_Callback)(size_t size);
2386 typedef void (*Eet_Descriptor_Array_Free_Callback)(void *mem);
2388 * @struct _Eet_Data_Descriptor_Class
2390 * Instructs Eet about memory management for different needs under
2391 * serialization and parse process.
2393 * The list and hash methods match the Eina API, so for a more detalied
2394 * reference on them, look at the Eina_List and Eina_Hash documentation,
2396 * For the most part these will be used with the standard Eina functions,
2397 * so using EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET() and
2398 * EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET() will set up everything
2401 struct _Eet_Data_Descriptor_Class
2403 int version; /**< ABI version. Should always be set to #EET_DATA_DESCRIPTOR_CLASS_VERSION */
2404 const char *name; /**< Name of the user data type to be serialized */
2405 int size; /**< Size in bytes of the user data type to be serialized */
2408 Eet_Descriptor_Mem_Alloc_Callback mem_alloc; /**< how to allocate memory (usually malloc()) */
2409 Eet_Descriptor_Mem_Free_Callback mem_free; /**< how to free memory (usually free()) */
2410 Eet_Descriptor_Str_Alloc_Callback str_alloc; /**< how to allocate a string */
2411 Eet_Descriptor_Str_Free_Callback str_free; /**< how to free a string */
2412 Eet_Descriptor_List_Next_Callback list_next; /**< how to iterate to the next element of a list. Receives and should return the list node. */
2413 Eet_Descriptor_List_Append_Callback list_append; /**< how to append data @p d to list which head node is @p l */
2414 Eet_Descriptor_List_Data_Callback list_data; /**< retrieves the data from node @p l */
2415 Eet_Descriptor_List_Free_Callback list_free; /**< free all the nodes from the list which head node is @p l */
2416 Eet_Descriptor_Hash_Foreach_Callback hash_foreach; /**< iterates over all elements in the hash @p h in no specific order */
2417 Eet_Descriptor_Hash_Add_Callback hash_add; /**< add a new data @p d with key @p k in hash @p h */
2418 Eet_Descriptor_Hash_Free_Callback hash_free; /**< free all entries from the hash @p h */
2419 Eet_Descriptor_Str_Direct_Alloc_Callback str_direct_alloc; /**< how to allocate a string directly from file backed/mmaped region pointed by @p str */
2420 Eet_Descriptor_Str_Direct_Free_Callback str_direct_free; /**< how to free a string returned by str_direct_alloc */
2421 Eet_Descriptor_Type_Get_Callback type_get; /**< get the type, as used in the union or variant mapping, that should be used to store the given data into the eet file. */
2422 Eet_Descriptor_Type_Set_Callback type_set; /**< called when loading a mapped type with the given @p type used to describe the type in the descriptor */
2423 Eet_Descriptor_Array_Alloc_Callback array_alloc; /**< how to allocate memory for array (usually malloc()) */
2424 Eet_Descriptor_Array_Free_Callback array_free; /**< how to free memory for array (usually free()) */
2433 * Create a new empty data structure descriptor.
2434 * @param name The string name of this data structure (most be a
2435 * global constant and never change).
2436 * @param size The size of the struct (in bytes).
2437 * @param func_list_next The function to get the next list node.
2438 * @param func_list_append The function to append a member to a list.
2439 * @param func_list_data The function to get the data from a list node.
2440 * @param func_list_free The function to free an entire linked list.
2441 * @param func_hash_foreach The function to iterate through all
2442 * hash table entries.
2443 * @param func_hash_add The function to add a member to a hash table.
2444 * @param func_hash_free The function to free an entire hash table.
2445 * @return A new empty data descriptor.
2447 * This function creates a new data descriptore and returns a handle to the
2448 * new data descriptor. On creation it will be empty, containing no contents
2449 * describing anything other than the shell of the data structure.
2451 * You add structure members to the data descriptor using the macros
2452 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2453 * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2454 * adding to the description.
2456 * Once you have described all the members of a struct you want loaded, or
2457 * saved eet can load and save those members for you, encode them into
2458 * endian-independent serialised data chunks for transmission across a
2459 * a network or more.
2461 * The function pointers to the list and hash table functions are only
2462 * needed if you use those data types, else you can pass NULL instead.
2465 * @ingroup Eet_Data_Group
2467 * @deprecated use eet_data_descriptor_stream_new() or
2468 * eet_data_descriptor_file_new()
2470 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2471 eet_data_descriptor_new(const char *name,
2473 Eet_Descriptor_List_Next_Callback func_list_next,
2474 Eet_Descriptor_List_Append_Callback func_list_append,
2475 Eet_Descriptor_List_Data_Callback func_list_data,
2476 Eet_Descriptor_List_Free_Callback func_list_free,
2477 Eet_Descriptor_Hash_Foreach_Callback func_hash_foreach,
2478 Eet_Descriptor_Hash_Add_Callback func_hash_add,
2479 Eet_Descriptor_Hash_Free_Callback func_hash_free);
2483 * moving to this api from the old above. this will break things when the
2484 * move happens - but be warned
2486 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2487 eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc);
2488 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2489 eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc);
2492 * This function creates a new data descriptor and returns a handle to the
2493 * new data descriptor. On creation it will be empty, containing no contents
2494 * describing anything other than the shell of the data structure.
2495 * @param eddc The class from where to create the data descriptor.
2497 * You add structure members to the data descriptor using the macros
2498 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2499 * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2500 * adding to the description.
2502 * Once you have described all the members of a struct you want loaded or
2503 * savedi, eet can load and save those members for you, encode them into
2504 * endian-independent serialised data chunks for transmission across a
2505 * a network or more.
2507 * This function specially ignores str_direct_alloc and str_direct_free. It
2508 * is useful when the eet_data you are reading doesn't have a dictionary,
2509 * like network stream or IPC. It also mean that all string will be allocated
2510 * and duplicated in memory.
2513 * @ingroup Eet_Data_Group
2515 EAPI Eet_Data_Descriptor *
2516 eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc);
2519 * This function creates a new data descriptor and returns a handle to the
2520 * new data descriptor. On creation it will be empty, containing no contents
2521 * describing anything other than the shell of the data structure.
2522 * @param eddc The class from where to create the data descriptor.
2524 * You add structure members to the data descriptor using the macros
2525 * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2526 * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2527 * adding to the description.
2529 * Once you have described all the members of a struct you want loaded or
2530 * savedi, eet can load and save those members for you, encode them into
2531 * endian-independent serialised data chunks for transmission across a
2532 * a network or more.
2534 * This function uses str_direct_alloc and str_direct_free. It is
2535 * useful when the eet_data you are reading come from a file and
2536 * have a dictionary. This will reduce memory use and improve the
2537 * possibility for the OS to page this string out.
2538 * However, the load speed and memory saving comes with some drawbacks to keep
2539 * in mind. If you never modify the contents of the structures loaded from
2540 * the file, all you need to remember is that closing the eet file will make
2541 * the strings go away. On the other hand, should you need to free a string,
2542 * before doing so you have to verify that it's not part of the eet dictionary.
2543 * You can do this in the following way, assuming @p ef is a valid Eet_File
2544 * and @p str is a string loaded from said file.
2547 * void eet_string_free(Eet_File *ef, const char *str)
2549 * Eet_Dictionary *dict = eet_dictionary_get(ef);
2550 * if (dict && eet_dictionary_string_check(dict, str))
2552 * // The file contains a dictionary and the given string is a part of
2553 * // of it, so we can't free it, just return.
2556 * // We assume eina_stringshare was used on the descriptor
2557 * eina_stringshare_del(str);
2562 * @ingroup Eet_Data_Group
2564 EAPI Eet_Data_Descriptor *
2565 eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc);
2568 * This function is an helper that set all the parameters of an
2569 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2571 * @param eddc The Eet_Data_Descriptor_Class you want to set.
2572 * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2573 * @param name The name of the structure described by this class.
2574 * @param size The size of the structure described by this class.
2575 * @return EINA_TRUE if the structure was correctly set (The only
2576 * reason that could make it fail is if you did give wrong
2579 * @note Unless there's a very specific reason to use this function directly,
2580 * the EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET macro is recommended.
2583 * @ingroup Eet_Data_Group
2586 eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2587 unsigned int eddc_size,
2592 * This macro is an helper that set all the parameter of an
2593 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2595 * @param clas The Eet_Data_Descriptor_Class you want to set.
2596 * @param type The type of the structure described by this class.
2597 * @return EINA_TRUE if the structure was correctly set (The only
2598 * reason that could make it fail is if you did give wrong
2601 * @see eet_data_descriptor_stream_new
2603 * @ingroup Eet_Data_Group
2605 #define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(clas, type) \
2606 (eet_eina_stream_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2609 * This function is an helper that set all the parameter of an
2610 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2612 * @param eddc The Eet_Data_Descriptor_Class you want to set.
2613 * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2614 * @param name The name of the structure described by this class.
2615 * @param size The size of the structure described by this class.
2616 * @return EINA_TRUE if the structure was correctly set (The only
2617 * reason that could make it fail is if you did give wrong
2620 * @note Unless there's a very specific reason to use this function directly,
2621 * the EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET macro is recommended.
2624 * @ingroup Eet_Data_Group
2627 eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2628 unsigned int eddc_size,
2633 * This macro is an helper that set all the parameter of an
2634 * Eet_Data_Descriptor_Class correctly when you use Eina data type
2636 * @param clas The Eet_Data_Descriptor_Class you want to set.
2637 * @param type The type of the structure described by this class.
2638 * @return EINA_TRUE if the structure was correctly set (The only
2639 * reason that could make it fail is if you did give wrong
2642 * @see eet_data_descriptor_file_new
2644 * @ingroup Eet_Data_Group
2646 #define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(clas, type) \
2647 (eet_eina_file_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2650 * This function frees a data descriptor when it is not needed anymore.
2651 * @param edd The data descriptor to free.
2653 * This function takes a data descriptor handle as a parameter and frees all
2654 * data allocated for the data descriptor and the handle itself. After this
2655 * call the descriptor is no longer valid.
2658 * @ingroup Eet_Data_Group
2661 eet_data_descriptor_free(Eet_Data_Descriptor *edd);
2664 * This function is an internal used by macros.
2666 * This function is used by macros EET_DATA_DESCRIPTOR_ADD_BASIC(),
2667 * EET_DATA_DESCRIPTOR_ADD_SUB() and EET_DATA_DESCRIPTOR_ADD_LIST(). It is
2668 * complex to use by hand and should be left to be used by the macros, and
2669 * thus is not documented.
2671 * @param edd The data descriptor handle to add element (member).
2672 * @param name The name of element to be serialized.
2673 * @param type The type of element to be serialized, like
2674 * #EET_T_INT. If #EET_T_UNKNOW, then it is considered to be a
2675 * group, list or hash.
2676 * @param group_type If element type is #EET_T_UNKNOW, then the @p
2677 * group_type will speficy if it is a list (#EET_G_LIST),
2678 * array (#EET_G_ARRAY) and so on. If #EET_G_UNKNOWN, then
2679 * the member is a subtype (pointer to another type defined by
2680 * another #Eet_Data_Descriptor).
2681 * @param offset byte offset inside the source memory to be serialized.
2682 * @param count number of elements (if #EET_G_ARRAY or #EET_G_VAR_ARRAY).
2683 * @param counter_name variable that defines the name of number of elements.
2684 * @param subtype If contains a subtype, then its data descriptor.
2687 * @ingroup Eet_Data_Group
2690 eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
2695 /* int count_offset, */
2697 const char *counter_name,
2698 Eet_Data_Descriptor *subtype);
2701 * Read a data structure from an eet file and decodes it.
2702 * @param ef The eet file handle to read from.
2703 * @param edd The data descriptor handle to use when decoding.
2704 * @param name The key the data is stored under in the eet file.
2705 * @return A pointer to the decoded data structure.
2707 * This function decodes a data structure stored in an eet file, returning
2708 * a pointer to it if it decoded successfully, or NULL on failure. This
2709 * can save a programmer dozens of hours of work in writing configuration
2710 * file parsing and writing code, as eet does all that work for the program
2711 * and presents a program-friendly data structure, just as the programmer
2712 * likes. Eet can handle members being added or deleted from the data in
2713 * storage and safely zero-fills unfilled members if they were not found
2714 * in the data. It checks sizes and headers whenever it reads data, allowing
2715 * the programmer to not worry about corrupt data.
2717 * Once a data structure has been described by the programmer with the
2718 * fields they wish to save or load, storing or retrieving a data structure
2719 * from an eet file, or from a chunk of memory is as simple as a single
2722 * @see eet_data_read_cipher()
2725 * @ingroup Eet_Data_Group
2728 eet_data_read(Eet_File *ef,
2729 Eet_Data_Descriptor *edd,
2733 * Write a data structure from memory and store in an eet file.
2734 * @param ef The eet file handle to write to.
2735 * @param edd The data descriptor to use when encoding.
2736 * @param name The key to store the data under in the eet file.
2737 * @param data A pointer to the data structure to ssave and encode.
2738 * @param compress Compression flags for storage.
2739 * @return bytes written on successful write, 0 on failure.
2741 * This function is the reverse of eet_data_read(), saving a data structure
2742 * to an eet file. The file must have been opening in write mode and the data
2743 * will be kept in memory until the file is either closed or eet_sync() is
2744 * called to flush any unwritten changes.
2746 * @see eet_data_write_cipher()
2749 * @ingroup Eet_Data_Group
2752 eet_data_write(Eet_File *ef,
2753 Eet_Data_Descriptor *edd,
2758 typedef void (*Eet_Dump_Callback)(void *data, const char *str);
2761 * Dump an eet encoded data structure into ascii text
2762 * @param data_in The pointer to the data to decode into a struct.
2763 * @param size_in The size of the data pointed to in bytes.
2764 * @param dumpfunc The function to call passed a string when new
2765 * data is converted to text
2766 * @param dumpdata The data to pass to the @p dumpfunc callback.
2767 * @return 1 on success, 0 on failure
2769 * This function will take a chunk of data encoded by
2770 * eet_data_descriptor_encode() and convert it into human readable
2771 * ascii text. It does this by calling the @p dumpfunc callback
2772 * for all new text that is generated. This callback should append
2773 * to any existing text buffer and will be passed the pointer @p
2774 * dumpdata as a parameter as well as a string with new text to be
2780 * void output(void *data, const char *string)
2782 * printf("%s", string);
2785 * void dump(const char *file)
2791 * f = fopen(file, "r");
2792 * fseek(f, 0, SEEK_END);
2795 * data = malloc(len);
2796 * fread(data, len, 1, f);
2798 * eet_data_text_dump(data, len, output, NULL);
2802 * @see eet_data_text_dump_cipher()
2805 * @ingroup Eet_Data_Group
2808 eet_data_text_dump(const void *data_in,
2810 Eet_Dump_Callback dumpfunc,
2814 * Take an ascii encoding from eet_data_text_dump() and re-encode in binary.
2815 * @param text The pointer to the string data to parse and encode.
2816 * @param textlen The size of the string in bytes (not including 0
2818 * @param size_ret This gets filled in with the encoded data blob
2820 * @return The encoded data on success, NULL on failure.
2822 * This function will parse the string pointed to by @p text and return
2823 * an encoded data lump the same way eet_data_descriptor_encode() takes an
2824 * in-memory data struct and encodes into a binary blob. @p text is a normal
2827 * @see eet_data_text_undump_cipher()
2830 * @ingroup Eet_Data_Group
2833 eet_data_text_undump(const char *text,
2838 * Dump an eet encoded data structure from an eet file into ascii text
2839 * @param ef A valid eet file handle.
2840 * @param name Name of the entry. eg: "/base/file_i_want".
2841 * @param dumpfunc The function to call passed a string when new
2842 * data is converted to text
2843 * @param dumpdata The data to pass to the @p dumpfunc callback.
2844 * @return 1 on success, 0 on failure
2846 * This function will take an open and valid eet file from
2847 * eet_open() request the data encoded by
2848 * eet_data_descriptor_encode() corresponding to the key @p name
2849 * and convert it into human readable ascii text. It does this by
2850 * calling the @p dumpfunc callback for all new text that is
2851 * generated. This callback should append to any existing text
2852 * buffer and will be passed the pointer @p dumpdata as a parameter
2853 * as well as a string with new text to be appended.
2855 * @see eet_data_dump_cipher()
2858 * @ingroup Eet_Data_Group
2861 eet_data_dump(Eet_File *ef,
2863 Eet_Dump_Callback dumpfunc,
2867 * Take an ascii encoding from eet_data_dump() and re-encode in binary.
2868 * @param ef A valid eet file handle.
2869 * @param name Name of the entry. eg: "/base/file_i_want".
2870 * @param text The pointer to the string data to parse and encode.
2871 * @param textlen The size of the string in bytes (not including 0
2873 * @param compress Compression flags (1 == compress, 0 = don't compress).
2874 * @return 1 on success, 0 on failure
2876 * This function will parse the string pointed to by @p text,
2877 * encode it the same way eet_data_descriptor_encode() takes an
2878 * in-memory data struct and encodes into a binary blob.
2880 * The data (optionally compressed) will be in ram, pending a flush to
2881 * disk (it will stay in ram till the eet file handle is closed though).
2883 * @see eet_data_undump_cipher()
2886 * @ingroup Eet_Data_Group
2889 eet_data_undump(Eet_File *ef,
2896 * Decode a data structure from an arbitrary location in memory.
2897 * @param edd The data descriptor to use when decoding.
2898 * @param data_in The pointer to the data to decode into a struct.
2899 * @param size_in The size of the data pointed to in bytes.
2900 * @return NULL on failure, or a valid decoded struct pointer on success.
2902 * This function will decode a data structure that has been encoded using
2903 * eet_data_descriptor_encode(), and return a data structure with all its
2904 * elements filled out, if successful, or NULL on failure.
2906 * The data to be decoded is stored at the memory pointed to by @p data_in,
2907 * and is described by the descriptor pointed to by @p edd. The data size is
2908 * passed in as the value to @p size_in, ande must be greater than 0 to
2911 * This function is useful for decoding data structures delivered to the
2912 * application by means other than an eet file, such as an IPC or socket
2913 * connection, raw files, shared memory etc.
2915 * Please see eet_data_read() for more information.
2917 * @see eet_data_descriptor_decode_cipher()
2920 * @ingroup Eet_Data_Group
2923 eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
2924 const void *data_in,
2928 * Encode a dsata struct to memory and return that encoded data.
2929 * @param edd The data descriptor to use when encoding.
2930 * @param data_in The pointer to the struct to encode into data.
2931 * @param size_ret pointer to the an int to be filled with the decoded size.
2932 * @return NULL on failure, or a valid encoded data chunk on success.
2934 * This function takes a data structutre in memory and encodes it into a
2935 * serialised chunk of data that can be decoded again by
2936 * eet_data_descriptor_decode(). This is useful for being able to transmit
2937 * data structures across sockets, pipes, IPC or shared file mechanisms,
2938 * without having to worry about memory space, machine type, endianess etc.
2940 * The parameter @p edd must point to a valid data descriptor, and
2941 * @p data_in must point to the right data structure to encode. If not, the
2942 * encoding may fail.
2944 * On success a non NULL valid pointer is returned and what @p size_ret
2945 * points to is set to the size of this decoded data, in bytes. When the
2946 * encoded data is no longer needed, call free() on it. On failure NULL is
2947 * returned and what @p size_ret points to is set to 0.
2949 * Please see eet_data_write() for more information.
2951 * @see eet_data_descriptor_encode_cipher()
2954 * @ingroup Eet_Data_Group
2957 eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
2958 const void *data_in,
2962 * Add a basic data element to a data descriptor.
2963 * @param edd The data descriptor to add the type to.
2964 * @param struct_type The type of the struct.
2965 * @param name The string name to use to encode/decode this member
2966 * (must be a constant global and never change).
2967 * @param member The struct member itself to be encoded.
2968 * @param type The type of the member to encode.
2970 * This macro is a convenience macro provided to add a member to
2971 * the data descriptor @p edd. The type of the structure is
2972 * provided as the @p struct_type parameter (for example: struct
2973 * my_struct). The @p name parameter defines a string that will be
2974 * used to uniquely name that member of the struct (it is suggested
2975 * to use the struct member itself). The @p member parameter is
2976 * the actual struct member itself (for example: values), and @p type is the
2977 * basic data type of the member which must be one of: EET_T_CHAR, EET_T_SHORT,
2978 * EET_T_INT, EET_T_LONG_LONG, EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR,
2979 * EET_T_USHORT, EET_T_UINT, EET_T_ULONG_LONG or EET_T_STRING.
2982 * @ingroup Eet_Data_Group
2984 #define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type) \
2986 struct_type ___ett; \
2987 eet_data_descriptor_element_add(edd, name, type, EET_G_UNKNOWN, \
2988 (char *)(& (___ett.member)) - \
2989 (char *)(& (___ett)), \
2990 0, /* 0, */ NULL, NULL); \
2994 * Add a sub-element type to a data descriptor
2995 * @param edd The data descriptor to add the type to.
2996 * @param struct_type The type of the struct.
2997 * @param name The string name to use to encode/decode this member
2998 * (must be a constant global and never change).
2999 * @param member The struct member itself to be encoded.
3000 * @param subtype The type of sub-type struct to add.
3002 * This macro lets you easily add a sub-type (a struct that's pointed to
3003 * by this one). All the parameters are the same as for
3004 * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception.
3005 * This must be the data descriptor of the struct that is pointed to by
3009 * @ingroup Eet_Data_Group
3011 #define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype) \
3013 struct_type ___ett; \
3014 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNKNOWN, \
3015 (char *)(& (___ett.member)) - \
3016 (char *)(& (___ett)), \
3017 0, /* 0, */ NULL, subtype); \
3021 * Add a linked list type to a data descriptor
3022 * @param edd The data descriptor to add the type to.
3023 * @param struct_type The type of the struct.
3024 * @param name The string name to use to encode/decode this member
3025 * (must be a constant global and never change).
3026 * @param member The struct member itself to be encoded.
3027 * @param subtype The type of linked list member to add.
3029 * This macro lets you easily add a linked list of other data types. All the
3030 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
3031 * @p subtype being the exception. This must be the data descriptor of the
3032 * element that is in each member of the linked list to be stored.
3035 * @ingroup Eet_Data_Group
3037 #define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype) \
3039 struct_type ___ett; \
3040 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_LIST, \
3041 (char *)(& (___ett.member)) - \
3042 (char *)(& (___ett)), \
3043 0, /* 0, */ NULL, subtype); \
3047 * Add a linked list of string to a data descriptor
3048 * @param edd The data descriptor to add the type to.
3049 * @param struct_type The type of the struct.
3050 * @param name The string name to use to encode/decode this member
3051 * (must be a constant global and never change).
3052 * @param member The struct member itself to be encoded.
3054 * This macro lets you easily add a linked list of char *. All the
3055 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
3058 * @ingroup Eet_Data_Group
3060 #define EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct_type, name, member) \
3062 struct_type ___ett; \
3063 eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_LIST, \
3064 (char *)(& (___ett.member)) - \
3065 (char *)(& (___ett)), \
3066 0, /* 0, */ NULL, NULL); \
3070 * Add a hash type to a data descriptor
3071 * @param edd The data descriptor to add the type to.
3072 * @param struct_type The type of the struct.
3073 * @param name The string name to use to encode/decode this member
3074 * (must be a constant global and never change).
3075 * @param member The struct member itself to be encoded.
3076 * @param subtype The type of hash member to add.
3078 * This macro lets you easily add a hash of other data types. All the
3079 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
3080 * @p subtype being the exception. This must be the data descriptor of the
3081 * element that is in each member of the hash to be stored.
3082 * The hash keys must be strings.
3085 * @ingroup Eet_Data_Group
3087 #define EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype) \
3089 struct_type ___ett; \
3090 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_HASH, \
3091 (char *)(& (___ett.member)) - \
3092 (char *)(& (___ett)), \
3093 0, /* 0, */ NULL, subtype); \
3097 * Add a hash of string to a data descriptor
3098 * @param edd The data descriptor to add the type to.
3099 * @param struct_type The type of the struct.
3100 * @param name The string name to use to encode/decode this member
3101 * (must be a constant global and never change).
3102 * @param member The struct member itself to be encoded.
3104 * This macro lets you easily add a hash of string elements. All the
3105 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_HASH().
3108 * @ingroup Eet_Data_Group
3110 #define EET_DATA_DESCRIPTOR_ADD_HASH_STRING(edd, struct_type, name, member) \
3112 struct_type ___ett; \
3113 eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_HASH, \
3114 (char *)(& (___ett.member)) - \
3115 (char *)(& (___ett)), \
3116 0, /* 0, */ NULL, NULL); \
3120 * Add an array of basic data elements to a data descriptor.
3121 * @param edd The data descriptor to add the type to.
3122 * @param struct_type The type of the struct.
3123 * @param name The string name to use to encode/decode this member
3124 * (must be a constant global and never change).
3125 * @param member The struct member itself to be encoded.
3126 * @param type The type of the member to encode.
3128 * This macro lets you easily add a fixed size array of basic data
3129 * types. All the parameters are the same as for
3130 * EET_DATA_DESCRIPTOR_ADD_BASIC().
3131 * The array must be defined with a fixed size in the declaration of the
3132 * struct containing it.
3135 * @ingroup Eet_Data_Group
3137 #define EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY(edd, struct_type, name, member, type) \
3139 struct_type ___ett; \
3140 eet_data_descriptor_element_add(edd, name, type, EET_G_ARRAY, \
3141 (char *)(& (___ett.member)) - \
3142 (char *)(& (___ett)), \
3143 sizeof(___ett.member) / \
3144 sizeof(___ett.member[0]), \
3149 * Add a fixed size array type to a data descriptor
3150 * @param edd The data descriptor to add the type to.
3151 * @param struct_type The type of the struct.
3152 * @param name The string name to use to encode/decode this member
3153 * (must be a constant global and never change).
3154 * @param member The struct member itself to be encoded.
3155 * @param subtype The type of hash member to add.
3157 * This macro lets you easily add a fixed size array of other data
3158 * types. All the parameters are the same as for
3159 * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
3160 * exception. This must be the data descriptor of the element that
3161 * is in each member of the array to be stored.
3162 * The array must be defined with a fixed size in the declaration of the
3163 * struct containing it.
3166 * @ingroup Eet_Data_Group
3168 #define EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, struct_type, name, member, subtype) \
3170 struct_type ___ett; \
3171 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_ARRAY, \
3172 (char *)(& (___ett.member)) - \
3173 (char *)(& (___ett)), \
3174 /* 0, */ sizeof(___ett.member) / \
3175 sizeof(___ett.member[0]), NULL, subtype); \
3179 * Add a variable size array type to a data descriptor
3180 * @param edd The data descriptor to add the type to.
3181 * @param struct_type The type of the struct.
3182 * @param name The string name to use to encode/decode this member
3183 * (must be a constant global and never change).
3184 * @param member The struct member itself to be encoded.
3185 * @param subtype The type of hash member to add.
3187 * This macro lets you easily add a variable size array of other data
3188 * types. All the parameters are the same as for
3189 * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
3190 * exception. This must be the data descriptor of the element that
3191 * is in each member of the array to be stored. This assumes you have
3192 * a struct member (of type EET_T_INT) called member_count (note the
3193 * _count appended to the member) that holds the number of items in
3194 * the array. This array will be allocated separately to the struct it
3198 * @ingroup Eet_Data_Group
3200 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, struct_type, name, member, subtype) \
3202 struct_type ___ett; \
3203 eet_data_descriptor_element_add(edd, \
3207 (char *)(& (___ett.member)) - \
3208 (char *)(& (___ett)), \
3209 (char *)(& (___ett.member ## _count)) - \
3210 (char *)(& (___ett)), \
3216 * Add a variable size array type to a data descriptor
3217 * @param edd The data descriptor to add the type to.
3218 * @param struct_type The type of the struct.
3219 * @param name The string name to use to encode/decode this member
3220 * (must be a constant global and never change).
3221 * @param member The struct member itself to be encoded.
3223 * This macro lets you easily add a variable size array of strings. All
3224 * the parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
3227 * @ingroup Eet_Data_Group
3229 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY_STRING(edd, struct_type, name, member) \
3231 struct_type ___ett; \
3232 eet_data_descriptor_element_add(edd, \
3236 (char *)(& (___ett.member)) - \
3237 (char *)(& (___ett)), \
3238 (char *)(& (___ett.member ## _count)) - \
3239 (char *)(& (___ett)), \
3245 * Add an union type to a data descriptor
3246 * @param edd The data descriptor to add the type to.
3247 * @param struct_type The type of the struct.
3248 * @param name The string name to use to encode/decode this member
3249 * (must be a constant global and never change).
3250 * @param member The struct member itself to be encoded.
3251 * @param type_member The member that give hints on what is in the union.
3252 * @param unified_type Describe all possible type the union could handle.
3254 * This macro lets you easily add an union with a member that specify what is inside.
3255 * The @p unified_type is an Eet_Data_Descriptor, but only the entry that match the name
3256 * returned by type_get will be used for each serialized data. The type_get and type_set
3257 * callback of unified_type should be defined.
3260 * @ingroup Eet_Data_Group
3261 * @see Eet_Data_Descriptor_Class
3263 #define EET_DATA_DESCRIPTOR_ADD_UNION(edd, struct_type, name, member, type_member, unified_type) \
3265 struct_type ___ett; \
3266 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNION, \
3267 (char *)(& (___ett.member)) - \
3268 (char *)(& (___ett)), \
3269 (char *)(& (___ett.type_member)) - \
3270 (char *)(& (___ett)), \
3271 NULL, unified_type); \
3275 * Add a automatically selectable type to a data descriptor
3276 * @param edd The data descriptor to add the type to.
3277 * @param struct_type The type of the struct.
3278 * @param name The string name to use to encode/decode this member
3279 * (must be a constant global and never change).
3280 * @param member The struct member itself to be encoded.
3281 * @param type_member The member that give hints on what is in the union.
3282 * @param unified_type Describe all possible type the union could handle.
3284 * This macro lets you easily define what the content of @p member points to depending of
3285 * the content of @p type_member. The type_get and type_set callback of unified_type should
3286 * be defined. If the the type is not know at the time of restoring it, eet will still call
3287 * type_set of @p unified_type but the pointer will be set to a serialized binary representation
3288 * of what eet know. This make it possible, to save this pointer again by just returning the string
3289 * given previously and telling it by setting unknow to EINA_TRUE.
3292 * @ingroup Eet_Data_Group
3293 * @see Eet_Data_Descriptor_Class
3295 #define EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, struct_type, name, member, type_member, unified_type) \
3297 struct_type ___ett; \
3298 eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_VARIANT, \
3299 (char *)(& (___ett.member)) - \
3300 (char *)(& (___ett)), \
3301 (char *)(& (___ett.type_member)) - \
3302 (char *)(& (___ett)), \
3303 NULL, unified_type); \
3307 * Add a mapping to a data descriptor that will be used by union, variant or inherited type
3308 * @param unified_type The data descriptor to add the mapping to.
3309 * @param name The string name to get/set type.
3310 * @param subtype The matching data descriptor.
3313 * @ingroup Eet_Data_Group
3314 * @see Eet_Data_Descriptor_Class
3316 #define EET_DATA_DESCRIPTOR_ADD_MAPPING(unified_type, name, subtype) \
3317 eet_data_descriptor_element_add(unified_type, \
3327 * @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
3329 * Most of the @ref Eet_Data_Group have alternative versions that
3330 * accounts for ciphers to protect their content.
3332 * @see @ref Eet_Cipher_Group
3334 * @ingroup Eet_Data_Group
3338 * Read a data structure from an eet file and decodes it using a cipher.
3339 * @param ef The eet file handle to read from.
3340 * @param edd The data descriptor handle to use when decoding.
3341 * @param name The key the data is stored under in the eet file.
3342 * @param cipher_key The key to use as cipher.
3343 * @return A pointer to the decoded data structure.
3345 * This function decodes a data structure stored in an eet file, returning
3346 * a pointer to it if it decoded successfully, or NULL on failure. This
3347 * can save a programmer dozens of hours of work in writing configuration
3348 * file parsing and writing code, as eet does all that work for the program
3349 * and presents a program-friendly data structure, just as the programmer
3350 * likes. Eet can handle members being added or deleted from the data in
3351 * storage and safely zero-fills unfilled members if they were not found
3352 * in the data. It checks sizes and headers whenever it reads data, allowing
3353 * the programmer to not worry about corrupt data.
3355 * Once a data structure has been described by the programmer with the
3356 * fields they wish to save or load, storing or retrieving a data structure
3357 * from an eet file, or from a chunk of memory is as simple as a single
3360 * @see eet_data_read()
3363 * @ingroup Eet_Data_Cipher_Group
3366 eet_data_read_cipher(Eet_File *ef,
3367 Eet_Data_Descriptor *edd,
3369 const char *cipher_key);
3372 * Read a data structure from an eet extended attribute and decodes it using a cipher.
3373 * @param filename The file to extract the extended attribute from.
3374 * @param attribute The attribute to get the data from.
3375 * @param edd The data descriptor handle to use when decoding.
3376 * @param cipher_key The key to use as cipher.
3377 * @return A pointer to the decoded data structure.
3379 * This function decodes a data structure stored in an eet extended attribute,
3380 * returning a pointer to it if it decoded successfully, or NULL on failure.
3381 * Eet can handle members being added or deleted from the data in
3382 * storage and safely zero-fills unfilled members if they were not found
3383 * in the data. It checks sizes and headers whenever it reads data, allowing
3384 * the programmer to not worry about corrupt data.
3386 * Once a data structure has been described by the programmer with the
3387 * fields they wish to save or load, storing or retrieving a data structure
3388 * from an eet file, from a chunk of memory or from an extended attribute
3389 * is as simple as a single function call.
3392 * @ingroup Eet_Data_Cipher_Group
3395 eet_data_xattr_cipher_get(const char *filename,
3396 const char *attribute,
3397 Eet_Data_Descriptor *edd,
3398 const char *cipher_key);
3401 * Write a data structure from memory and store in an eet file
3403 * @param ef The eet file handle to write to.
3404 * @param edd The data descriptor to use when encoding.
3405 * @param name The key to store the data under in the eet file.
3406 * @param cipher_key The key to use as cipher.
3407 * @param data A pointer to the data structure to ssave and encode.
3408 * @param compress Compression flags for storage.
3409 * @return bytes written on successful write, 0 on failure.
3411 * This function is the reverse of eet_data_read_cipher(), saving a data structure
3415 * @ingroup Eet_Data_Cipher_Group
3418 eet_data_write_cipher(Eet_File *ef,
3419 Eet_Data_Descriptor *edd,
3421 const char *cipher_key,
3426 * Write a data structure from memory and store in an eet extended attribute
3428 * @param filename The file to write the extended attribute to.
3429 * @param attribute The attribute to store the data to.
3430 * @param edd The data descriptor to use when encoding.
3431 * @param cipher_key The key to use as cipher.
3432 * @param data A pointer to the data structure to ssave and encode.
3433 * @param flags The policy to use when setting the data.
3434 * @return EINA_TRUE on success, EINA_FALSE on failure.
3436 * This function is the reverse of eet_data_xattr_cipher_get(), saving a data structure
3437 * to an eet extended attribute.
3440 * @ingroup Eet_Data_Cipher_Group
3443 eet_data_xattr_cipher_set(const char *filename,
3444 const char *attribute,
3445 Eet_Data_Descriptor *edd,
3446 const char *cipher_key,
3448 Eina_Xattr_Flags flags);
3451 * Dump an eet encoded data structure into ascii text using a cipher.
3452 * @param data_in The pointer to the data to decode into a struct.
3453 * @param cipher_key The key to use as cipher.
3454 * @param size_in The size of the data pointed to in bytes.
3455 * @param dumpfunc The function to call passed a string when new
3456 * data is converted to text
3457 * @param dumpdata The data to pass to the @p dumpfunc callback.
3458 * @return 1 on success, 0 on failure
3460 * This function will take a chunk of data encoded by
3461 * eet_data_descriptor_encode() and convert it into human readable
3462 * ascii text. It does this by calling the @p dumpfunc callback
3463 * for all new text that is generated. This callback should append
3464 * to any existing text buffer and will be passed the pointer @p
3465 * dumpdata as a parameter as well as a string with new text to be
3471 * void output(void *data, const char *string)
3473 * printf("%s", string);
3476 * void dump(const char *file)
3482 * f = fopen(file, "r");
3483 * fseek(f, 0, SEEK_END);
3486 * data = malloc(len);
3487 * fread(data, len, 1, f);
3489 * eet_data_text_dump_cipher(data, cipher_key, len, output, NULL);
3493 * @see eet_data_text_dump()
3496 * @ingroup Eet_Data_Cipher_Group
3499 eet_data_text_dump_cipher(const void *data_in,
3500 const char *cipher_key,
3502 Eet_Dump_Callback dumpfunc,
3506 * Take an ascii encoding from eet_data_text_dump() and re-encode
3507 * in binary using a cipher.
3508 * @param text The pointer to the string data to parse and encode.
3509 * @param cipher_key The key to use as cipher.
3510 * @param textlen The size of the string in bytes (not including 0
3512 * @param size_ret This gets filled in with the encoded data blob
3514 * @return The encoded data on success, NULL on failure.
3516 * This function will parse the string pointed to by @p text and return
3517 * an encoded data lump the same way eet_data_descriptor_encode() takes an
3518 * in-memory data struct and encodes into a binary blob. @p text is a normal
3521 * @see eet_data_text_undump()
3524 * @ingroup Eet_Data_Cipher_Group
3527 eet_data_text_undump_cipher(const char *text,
3528 const char *cipher_key,
3533 * Dump an eet encoded data structure from an eet file into ascii
3534 * text using a cipher.
3535 * @param ef A valid eet file handle.
3536 * @param name Name of the entry. eg: "/base/file_i_want".
3537 * @param cipher_key The key to use as cipher.
3538 * @param dumpfunc The function to call passed a string when new
3539 * data is converted to text
3540 * @param dumpdata The data to pass to the @p dumpfunc callback.
3541 * @return 1 on success, 0 on failure
3543 * This function will take an open and valid eet file from
3544 * eet_open() request the data encoded by
3545 * eet_data_descriptor_encode() corresponding to the key @p name
3546 * and convert it into human readable ascii text. It does this by
3547 * calling the @p dumpfunc callback for all new text that is
3548 * generated. This callback should append to any existing text
3549 * buffer and will be passed the pointer @p dumpdata as a parameter
3550 * as well as a string with new text to be appended.
3552 * @see eet_data_dump()
3555 * @ingroup Eet_Data_Cipher_Group
3558 eet_data_dump_cipher(Eet_File *ef,
3560 const char *cipher_key,
3561 Eet_Dump_Callback dumpfunc,
3565 * Take an ascii encoding from eet_data_dump() and re-encode in
3566 * binary using a cipher.
3567 * @param ef A valid eet file handle.
3568 * @param name Name of the entry. eg: "/base/file_i_want".
3569 * @param cipher_key The key to use as cipher.
3570 * @param text The pointer to the string data to parse and encode.
3571 * @param textlen The size of the string in bytes (not including 0
3573 * @param compress Compression flags (1 == compress, 0 = don't compress).
3574 * @return 1 on success, 0 on failure
3576 * This function will parse the string pointed to by @p text,
3577 * encode it the same way eet_data_descriptor_encode() takes an
3578 * in-memory data struct and encodes into a binary blob.
3580 * The data (optionally compressed) will be in ram, pending a flush to
3581 * disk (it will stay in ram till the eet file handle is closed though).
3583 * @see eet_data_undump()
3586 * @ingroup Eet_Data_Cipher_Group
3589 eet_data_undump_cipher(Eet_File *ef,
3591 const char *cipher_key,
3597 * Decode a data structure from an arbitrary location in memory
3599 * @param edd The data descriptor to use when decoding.
3600 * @param data_in The pointer to the data to decode into a struct.
3601 * @param cipher_key The key to use as cipher.
3602 * @param size_in The size of the data pointed to in bytes.
3603 * @return NULL on failure, or a valid decoded struct pointer on success.
3605 * This function will decode a data structure that has been encoded using
3606 * eet_data_descriptor_encode(), and return a data structure with all its
3607 * elements filled out, if successful, or NULL on failure.
3609 * The data to be decoded is stored at the memory pointed to by @p data_in,
3610 * and is described by the descriptor pointed to by @p edd. The data size is
3611 * passed in as the value to @p size_in, ande must be greater than 0 to
3614 * This function is useful for decoding data structures delivered to the
3615 * application by means other than an eet file, such as an IPC or socket
3616 * connection, raw files, shared memory etc.
3618 * Please see eet_data_read() for more information.
3620 * @see eet_data_descriptor_decode()
3623 * @ingroup Eet_Data_Cipher_Group
3626 eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
3627 const void *data_in,
3628 const char *cipher_key,
3632 * Encode a data struct to memory and return that encoded data
3634 * @param edd The data descriptor to use when encoding.
3635 * @param data_in The pointer to the struct to encode into data.
3636 * @param cipher_key The key to use as cipher.
3637 * @param size_ret pointer to the an int to be filled with the decoded size.
3638 * @return NULL on failure, or a valid encoded data chunk on success.
3640 * This function takes a data structutre in memory and encodes it into a
3641 * serialised chunk of data that can be decoded again by
3642 * eet_data_descriptor_decode(). This is useful for being able to transmit
3643 * data structures across sockets, pipes, IPC or shared file mechanisms,
3644 * without having to worry about memory space, machine type, endianess etc.
3646 * The parameter @p edd must point to a valid data descriptor, and
3647 * @p data_in must point to the right data structure to encode. If not, the
3648 * encoding may fail.
3650 * On success a non NULL valid pointer is returned and what @p size_ret
3651 * points to is set to the size of this decoded data, in bytes. When the
3652 * encoded data is no longer needed, call free() on it. On failure NULL is
3653 * returned and what @p size_ret points to is set to 0.
3655 * Please see eet_data_write() for more information.
3657 * @see eet_data_descriptor_encode()
3660 * @ingroup Eet_Data_Cipher_Group
3663 eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
3664 const void *data_in,
3665 const char *cipher_key,
3669 * @defgroup Eet_Node_Group Low-level Serialization Structures.
3671 * Functions that create, destroy and manipulate serialization nodes
3672 * used by @ref Eet_Data_Group.
3679 * Opaque handle to manage serialization node.
3681 typedef struct _Eet_Node Eet_Node;
3684 * @typedef Eet_Node_Data
3685 * Contains an union that can fit any kind of node.
3687 typedef struct _Eet_Node_Data Eet_Node_Data;
3690 * @struct _Eet_Node_Data
3691 * Contains an union that can fit any kind of node.
3693 struct _Eet_Node_Data
3705 unsigned long long ul;
3716 * @ingroup Eet_Node_Group
3719 eet_node_char_new(const char *name,
3724 * @ingroup Eet_Node_Group
3727 eet_node_short_new(const char *name,
3732 * @ingroup Eet_Node_Group
3735 eet_node_int_new(const char *name,
3740 * @ingroup Eet_Node_Group
3743 eet_node_long_long_new(const char *name,
3748 * @ingroup Eet_Node_Group
3751 eet_node_float_new(const char *name,
3756 * @ingroup Eet_Node_Group
3759 eet_node_double_new(const char *name,
3764 * @ingroup Eet_Node_Group
3767 eet_node_unsigned_char_new(const char *name,
3772 * @ingroup Eet_Node_Group
3775 eet_node_unsigned_short_new(const char *name,
3780 * @ingroup Eet_Node_Group
3783 eet_node_unsigned_int_new(const char *name,
3788 * @ingroup Eet_Node_Group
3791 eet_node_unsigned_long_long_new(const char *name,
3792 unsigned long long l);
3796 * @ingroup Eet_Node_Group
3799 eet_node_string_new(const char *name,
3804 * @ingroup Eet_Node_Group
3807 eet_node_inlined_string_new(const char *name,
3812 * @ingroup Eet_Node_Group
3815 eet_node_null_new(const char *name);
3819 * @ingroup Eet_Node_Group
3822 eet_node_list_new(const char *name,
3827 * @ingroup Eet_Node_Group
3830 eet_node_array_new(const char *name,
3836 * @ingroup Eet_Node_Group
3839 eet_node_var_array_new(const char *name,
3844 * @ingroup Eet_Node_Group
3847 eet_node_hash_new(const char *name,
3853 * @ingroup Eet_Node_Group
3856 eet_node_struct_new(const char *name,
3861 * @ingroup Eet_Node_Group
3864 eet_node_struct_child_new(const char *parent,
3868 * @brief Get a node's child nodes
3869 * @param node The node
3870 * @return The first child node which contains a pointer to the
3871 * next child node and the parent.
3875 eet_node_children_get(Eet_Node *node);
3878 * @brief Get the next node in a list of nodes
3879 * @param node The node
3880 * @return A node which contains a pointer to the
3881 * next child node and the parent.
3885 eet_node_next_get(Eet_Node *node);
3888 * @brief Get the parent node of a node
3889 * @param node The node
3890 * @return The parent node of @p node
3894 eet_node_parent_get(Eet_Node *node);
3898 * @ingroup Eet_Node_Group
3901 eet_node_list_append(Eet_Node *parent,
3907 * @ingroup Eet_Node_Group
3910 eet_node_struct_append(Eet_Node *parent,
3916 * @ingroup Eet_Node_Group
3919 eet_node_hash_add(Eet_Node *parent,
3926 * @ingroup Eet_Node_Group
3929 eet_node_dump(Eet_Node *n,
3931 Eet_Dump_Callback dumpfunc,
3935 * @brief Return the type of a node
3936 * @param node The node
3937 * @return The node's type (EET_T_$TYPE)
3941 eet_node_type_get(Eet_Node *node);
3944 * @brief Return the node's data
3945 * @param node The node
3946 * @return The data contained in the node
3949 EAPI Eet_Node_Data *
3950 eet_node_value_get(Eet_Node *node);
3954 * @ingroup Eet_Node_Group
3957 eet_node_del(Eet_Node *n);
3961 * @ingroup Eet_Node_Group
3964 eet_data_node_encode_cipher(Eet_Node *node,
3965 const char *cipher_key,
3970 * @ingroup Eet_Node_Group
3973 eet_data_node_decode_cipher(const void *data_in,
3974 const char *cipher_key,
3979 * @ingroup Eet_Node_Group
3982 eet_data_node_read_cipher(Eet_File *ef,
3984 const char *cipher_key);
3988 * @ingroup Eet_Node_Group
3991 eet_data_node_write_cipher(Eet_File *ef,
3993 const char *cipher_key,
3997 /* EXPERIMENTAL: THIS API MAY CHANGE IN THE FUTURE, USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING. */
4000 * @typedef Eet_Node_Walk
4001 * Describes how to walk trees of #Eet_Node.
4003 typedef struct _Eet_Node_Walk Eet_Node_Walk;
4005 typedef void * (*Eet_Node_Walk_Struct_Alloc_Callback)(const char *type, void *user_data);
4006 typedef void (*Eet_Node_Walk_Struct_Add_Callback)(void *parent, const char *name, void *child, void *user_data);
4007 typedef void * (*Eet_Node_Walk_Array_Callback)(Eina_Bool variable, const char *name, int count, void *user_data);
4008 typedef void (*Eet_Node_Walk_Insert_Callback)(void *array, int index, void *child, void *user_data);
4009 typedef void * (*Eet_Node_Walk_List_Callback)(const char *name, void *user_data);
4010 typedef void (*Eet_Node_Walk_Append_Callback)(void *list, void *child, void *user_data);
4011 typedef void * (*Eet_Node_Walk_Hash_Callback)(void *parent, const char *name, const char *key, void *value, void *user_data);
4012 typedef void * (*Eet_Node_Walk_Simple_Callback)(int type, Eet_Node_Data *data, void *user_data);
4015 * @struct _Eet_Node_Walk
4016 * Describes how to walk trees of #Eet_Node.
4018 struct _Eet_Node_Walk
4020 Eet_Node_Walk_Struct_Alloc_Callback struct_alloc;
4021 Eet_Node_Walk_Struct_Add_Callback struct_add;
4022 Eet_Node_Walk_Array_Callback array;
4023 Eet_Node_Walk_Insert_Callback insert;
4024 Eet_Node_Walk_List_Callback list;
4025 Eet_Node_Walk_Append_Callback append;
4026 Eet_Node_Walk_Hash_Callback hash;
4027 Eet_Node_Walk_Simple_Callback simple;
4031 eet_node_walk(void *parent,
4040 * @defgroup Eet_Connection_Group Helper function to use eet over a network link
4042 * Function that reconstruct and prepare packet of @ref Eet_Data_Group to be send.
4047 * @typedef Eet_Connection
4048 * Opaque handle to track paquet for a specific connection.
4050 * @ingroup Eet_Connection_Group
4052 typedef struct _Eet_Connection Eet_Connection;
4055 * @typedef Eet_Read_Cb
4056 * Called back when an @ref Eet_Data_Group has been received completly and could be used.
4058 * @ingroup Eet_Connection_Group
4060 typedef Eina_Bool Eet_Read_Cb (const void *eet_data, size_t size, void *user_data);
4063 * @typedef Eet_Write_Cb
4064 * Called back when a packet containing @ref Eet_Data_Group data is ready to be send.
4066 * @ingroup Eet_Connection_Group
4068 typedef Eina_Bool Eet_Write_Cb (const void *data, size_t size, void *user_data);
4071 * Instanciate a new connection to track.
4072 * @param eet_read_cb Function to call when one Eet_Data packet has been fully assemble.
4073 * @param eet_write_cb Function to call when one Eet_Data packet is ready to be send over the wire.
4074 * @param user_data Pointer provided to both functions to be used as a context handler.
4075 * @return NULL on failure, or a valid Eet_Connection handler.
4077 * For every connection to track you will need a separate Eet_Connection provider.
4080 * @ingroup Eet_Connection_Group
4082 EAPI Eet_Connection *
4083 eet_connection_new(Eet_Read_Cb *eet_read_cb,
4084 Eet_Write_Cb *eet_write_cb,
4085 const void *user_data);
4088 * Process a raw packet received over the link
4089 * @param conn Connection handler to track.
4090 * @param data Raw data packet.
4091 * @param size The size of that packet.
4092 * @return 0 on complete success, any other value indicate where in the stream it got wrong (It could be before that packet).
4094 * Every time you receive a packet related to your connection, you should pass
4095 * it to that function so that it could process and assemble packet has you
4096 * receive it. It will automatically call Eet_Read_Cb when one is fully received.
4099 * @ingroup Eet_Connection_Group
4102 eet_connection_received(Eet_Connection *conn,
4107 * Convert a complex structure and prepare it to be send.
4108 * @param conn Connection handler to track.
4109 * @param edd The data descriptor to use when encoding.
4110 * @param data_in The pointer to the struct to encode into data.
4111 * @param cipher_key The key to use as cipher.
4112 * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
4114 * This function serialize data_in with edd, assemble the packet and call
4115 * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
4116 * and will vanish just after the return of the callback.
4118 * @see eet_data_descriptor_encode_cipher
4121 * @ingroup Eet_Connection_Group
4124 eet_connection_send(Eet_Connection *conn,
4125 Eet_Data_Descriptor *edd,
4126 const void *data_in,
4127 const char *cipher_key);
4130 * Convert a Eet_Node tree and prepare it to be send.
4131 * @param conn Connection handler to track.
4132 * @param node The data tree to use when encoding.
4133 * @param cipher_key The key to use as cipher.
4134 * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
4136 * This function serialize node, assemble the packet and call
4137 * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
4138 * and will vanish just after the return of the callback.
4140 * @see eet_data_node_encode_cipher
4143 * @ingroup Eet_Connection_Group
4146 eet_connection_node_send(Eet_Connection *conn,
4148 const char *cipher_key);
4151 * Close a connection and lost its track.
4152 * @param conn Connection handler to close.
4153 * @param on_going Signal if a partial packet wasn't completed.
4154 * @return the user_data passed to both callback.
4157 * @ingroup Eet_Connection_Group
4160 eet_connection_close(Eet_Connection *conn,
4161 Eina_Bool *on_going);
4163 /***************************************************************************/
4167 #endif /* ifdef __cplusplus */
4169 #endif /* ifndef _EET_H */