eet: fix missing return types in eet doc
[framework/uifw/eet.git] / src / lib / Eet.h
1 /**
2    @brief Eet Data Handling Library Public API Calls
3
4    These routines are used for Eet Library interaction
5
6    @mainpage Eet Library Documentation
7
8    @version 1.5.0
9    @date 2000-2012
10
11    Please see the @ref authors page for contact details.
12
13    @section toc Table of Contents
14
15    @li @ref intro
16    @li @ref example
17    @li @ref compiling
18    @li @ref install
19    @li @ref next_steps
20    @li @ref intro_example
21
22    @section intro What is Eet?
23
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.
29
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-access 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.
36
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
41    architecture.
42
43    @section example A simple example on using Eet
44
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
47    fprintf() and
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.
53
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.
56
57    @include eet-basic.c
58
59    @section compiling How to compile using Eet ?
60
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:
64
65    Compiling C or C++ files into object files:
66
67    @verbatim
68    gcc -c -o main.o main.c `pkg-config --cflags eet`
69    @endverbatim
70
71    Linking object files into a binary executable:
72
73    @verbatim
74    gcc -o my_application main.o `pkg-config --libs eet`
75    @endverbatim
76
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.
81
82    Since the program is linked to Eet, it is now able to use any advertised
83    API calls to serialize your data.
84
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.
88
89
90    @section install How is it installed?
91
92    Simple:
93
94    @verbatim
95    ./configure
96    make
97    su -
98    ...
99    make install
100    @endverbatim
101
102    @section next_steps Next Steps
103
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.
109
110    Recommended reading:
111
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.
116
117    @section intro_example Introductory Examples
118
119    @ref Examples
120
121    @todo Document data format for images and data structures.
122
123  */
124
125 /**
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>
140
141    Please contact <enlightenment-devel@lists.sourceforge.net> to get in
142    contact with the developers and maintainers.
143  */
144
145 #ifndef _EET_H
146 #define _EET_H
147
148 #include <stdlib.h>
149 #include <stdio.h>
150 #include <Eina.h>
151
152 #ifdef EAPI
153 # undef EAPI
154 #endif /* ifdef EAPI */
155
156 #ifdef _WIN32
157 # ifdef EFL_EET_BUILD
158 #  ifdef DLL_EXPORT
159 #   define EAPI __declspec(dllexport)
160 #  else /* ifdef DLL_EXPORT */
161 #   define EAPI
162 #  endif /* ! DLL_EXPORT */
163 # else /* ifdef EFL_EET_BUILD */
164 #  define EAPI __declspec(dllimport)
165 # endif /* ! EFL_EET_BUILD */
166 #else /* ifdef _WIN32 */
167 # ifdef __GNUC__
168 #  if __GNUC__ >= 4
169 #   define EAPI __attribute__ ((visibility("default")))
170 #  else /* if __GNUC__ >= 4 */
171 #   define EAPI
172 #  endif /* if __GNUC__ >= 4 */
173 # else /* ifdef __GNUC__ */
174 #  define EAPI
175 # endif /* ifdef __GNUC__ */
176 #endif /* ! _WIN32 */
177
178 #ifdef __cplusplus
179 extern "C" {
180 #endif /* ifdef __cplusplus */
181
182 /**
183  * @file Eet.h
184  * @brief The file that provides the eet functions.
185  *
186  * This header provides the Eet management functions.
187  *
188  */
189
190 #define EET_VERSION_MAJOR 1
191 #define EET_VERSION_MINOR 6
192 /**
193  * @typedef Eet_Version
194  *
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:
198  *
199  * @code
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)
206  *   {
207  *     printf("  Built from SVN revision # %i\n", eet_version->revision);
208  *   }
209  * #endif
210  * @endcode
211  *
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.
214  */
215 typedef struct _Eet_Version
216 {
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) */
221 } Eet_Version;
222
223 EAPI extern Eet_Version *eet_version;
224
225 /**
226  * @defgroup Eet_Group Top level functions
227  * Functions that affect Eet as a whole.
228  *
229  * @{
230  */
231
232 /**
233  * @enum _Eet_Error
234  * All the error identifiers known by Eet.
235  */
236 typedef enum _Eet_Error
237 {
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 */
258
259 /**
260  * @}
261  */
262
263 /**
264  * Initialize the EET library.
265  *
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.
270  *
271  * @return The new init count. Will be 0 if initialization failed.
272  *
273  * @since 1.0.0
274  * @ingroup Eet_Group
275  */
276 EAPI int
277 eet_init(void);
278
279 /**
280  * Shut down the EET library.
281  *
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.
286  *
287  * @return The new init count.
288  *
289  * @since 1.0.0
290  * @ingroup Eet_Group
291  */
292 EAPI int
293 eet_shutdown(void);
294
295 /**
296  * Clear eet cache
297  *
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
301  * they were used.
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.
307  *
308  * @since 1.0.0
309  * @ingroup Eet_Group
310  */
311 EAPI void
312 eet_clearcache(void);
313
314 /**
315  * @defgroup Eet_File_Group Eet File Main Functions
316  *
317  * Functions to create, destroy and do basic manipulation of
318  * #Eet_File handles.
319  *
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.
324  *
325  * The following example will serve as an introduction to most, if not all,
326  * of these functions.
327  *
328  * If you are only using Eet, this is the only header you need to include.
329  * @dontinclude eet-file.c
330  * @skipline Eet.h
331  *
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.
335  * @line static int
336  * @skip Eet_File
337  * @until ";
338  * @skip eet_open
339  *
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..
342  * @until return
343  *
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.
346  * @until }
347  *
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
351  * file.
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.
356  * @until printf
357  *
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.
362  * @until eet_sync
363  *
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().
367  * @until eet_delete
368  *
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.
373  * @until return
374  *
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
378  * seen already.
379  *
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.
387  * @skip eet_init
388  * @until return
389  *
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
395  * in our file.
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
399  * break things.
400  * @until }
401  *
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.
406  * @until }
407  *
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.
410  * @until }
411  *
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.
415  * @until {
416  *
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.
421  *
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().
425  * @until memopen
426  *
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.
431  *
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
434  * their names.
435  * @until printf
436  *
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
439  * compressed.
440  * Knowing all this allows us to take some shortcuts.
441  * @until read_direct
442  *
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
457  * be done.
458  *
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.
463  * @until }
464  *
465  * Finally, we close the first file, shutdown all internal resources used by
466  * Eet and leave our main function, thus terminating our program.
467  * @until return
468  *
469  * You can look at the full code of the example @ref eet-file.c "here".
470  * @{
471  */
472
473 /**
474  * @enum _Eet_File_Mode
475  * Modes that a file can be opened.
476  */
477 typedef enum _Eet_File_Mode
478 {
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. */
484
485 /**
486  * @typedef Eet_File
487  * Opaque handle that defines an Eet file (or memory).
488  *
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
493  * to it.
494  *
495  * @see eet_open()
496  * @see eet_memopen_read()
497  * @see eet_close()
498  */
499 typedef struct _Eet_File Eet_File;
500
501 /**
502  * @typedef Eet_Dictionary
503  * Opaque handle that defines a file-backed (mmaped) dictionary of strings.
504  */
505 typedef struct _Eet_Dictionary Eet_Dictionary;
506
507 /**
508  * @}
509  */
510
511 /**
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
518  *
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.
523  *
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.
528  *
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
531  * by the new data.
532  *
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
546  * returned instead.
547  *
548  * @since 1.0.0
549  */
550 EAPI Eet_File *
551 eet_open(const char *file,
552          Eet_File_Mode mode);
553
554 /**
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  * @return A handle to the file.
560  *
561  * Files opened this way will always be in read-only mode.
562  *
563  * @since 1.1.0
564  * @ingroup Eet_File_Group
565  */
566 EAPI Eet_File *
567 eet_memopen_read(const void *data,
568                  size_t size);
569
570 /**
571  * Get the mode an Eet_File was opened with.
572  * @param ef A valid eet file handle.
573  * @return The mode ef was opened with.
574  *
575  * @since 1.0.0
576  * @ingroup Eet_File_Group
577  */
578 EAPI Eet_File_Mode
579 eet_mode_get(Eet_File *ef);
580
581 /**
582  * Close an eet file handle and flush pending writes.
583  * @param ef A valid eet file handle.
584  * @return An eet error identifier.
585  *
586  * This function will flush any pending writes to disk if the eet file
587  * was opened for write, and free all data associated with the file handle
588  * and file, and close the file.
589  *
590  * If the eet file handle is not valid nothing will be done.
591  *
592  * @since 1.0.0
593  * @ingroup Eet_File_Group
594  */
595 EAPI Eet_Error
596 eet_close(Eet_File *ef);
597
598 /**
599  * Sync content of an eet file handle, flushing pending writes.
600  * @param ef A valid eet file handle.
601  * @return An eet error identifier.
602  *
603  * This function will flush any pending writes to disk. The eet file must
604  * be opened for write.
605  *
606  * If the eet file handle is not valid nothing will be done.
607  *
608  * @since 1.2.4
609  * @ingroup Eet_File_Group
610  */
611 EAPI Eet_Error
612 eet_sync(Eet_File *ef);
613
614 /**
615  * Return a handle to the shared string dictionary of the Eet file
616  * @param ef A valid eet file handle.
617  * @return A handle to the dictionary of the file
618  *
619  * This function returns a handle to the dictionary of an Eet file whose
620  * handle is @p ef, if a dictionary exists. NULL is returned otherwise or
621  * if the file handle is known to be invalid.
622  *
623  * @see eet_dictionary_string_check() to know if given string came
624  *      from the dictionary or it was dynamically allocated using
625  *      the #Eet_Data_Descriptor_Class instructrions.
626  *
627  * @since 1.0.0
628  * @ingroup Eet_File_Group
629  */
630 EAPI Eet_Dictionary *
631 eet_dictionary_get(Eet_File *ef);
632
633 /**
634  * Check if a given string comes from a given dictionary
635  * @param ed A valid dictionary handle
636  * @param string A valid 0 byte terminated C string
637  * @return 1 if it is in the dictionary, 0 otherwise
638  *
639  * This checks the given dictionary to see if the given string is actually
640  * inside that dictionary (i.e. comes from it) and returns 1 if it does.
641  * If the dictionary handle is invalid, the string is NULL or the string is
642  * not in the dictionary, 0 is returned.
643  *
644  * @since 1.0.0
645  * @ingroup Eet_File_Group
646  */
647 EAPI int
648 eet_dictionary_string_check(Eet_Dictionary *ed,
649                             const char *string);
650
651 /**
652  * Return the number of strings inside a dictionary
653  * @param ed A valid dictionary handle
654  * @return the number of strings inside a dictionary
655  *
656  * @since 1.6.0
657  * @ingroup Eet_File_Group
658  */
659 EAPI int
660 eet_dictionary_count(const Eet_Dictionary *ed);
661
662 /**
663  * Read a specified entry from an eet file and return data
664  * @param ef A valid eet file handle opened for reading.
665  * @param name Name of the entry. eg: "/base/file_i_want".
666  * @param size_ret Number of bytes read from entry and returned.
667  * @return The data stored in that entry in the eet file.
668  *
669  * This function finds an entry in the eet file that is stored under the
670  * name specified, and returns that data, decompressed, if successful.
671  * NULL is returned if the lookup fails or if memory errors are
672  * encountered. It is the job of the calling program to call free() on
673  * the returned data. The number of bytes in the returned data chunk are
674  * placed in size_ret.
675  *
676  * If the eet file handle is not valid NULL is returned and size_ret is
677  * filled with 0.
678  *
679  * @see eet_read_cipher()
680  *
681  * @since 1.0.0
682  * @ingroup Eet_File_Group
683  */
684 EAPI void *
685 eet_read(Eet_File *ef,
686          const char *name,
687          int *size_ret);
688
689 /**
690  * Read a specified entry from an eet file and return data
691  * @param ef A valid eet file handle opened for reading.
692  * @param name Name of the entry. eg: "/base/file_i_want".
693  * @param size_ret Number of bytes read from entry and returned.
694  * @return The data stored in that entry in the eet file.
695  *
696  * This function finds an entry in the eet file that is stored under the
697  * name specified, and returns that data if not compressed and successful.
698  * NULL is returned if the lookup fails or if memory errors are
699  * encountered or if the data is comrpessed. The calling program must never
700  * call free() on the returned data. The number of bytes in the returned
701  * data chunk are placed in size_ret.
702  *
703  * If the eet file handle is not valid NULL is returned and size_ret is
704  * filled with 0.
705  *
706  * @since 1.0.0
707  * @ingroup Eet_File_Group
708  */
709 EAPI const void *
710 eet_read_direct(Eet_File *ef,
711                 const char *name,
712                 int *size_ret);
713
714 /**
715  * Write a specified entry to an eet file handle
716  * @param ef A valid eet file handle opened for writing.
717  * @param name Name of the entry. eg: "/base/file_i_want".
718  * @param data Pointer to the data to be stored.
719  * @param size Length in bytes in the data to be stored.
720  * @param compress Compression flags (1 == compress, 0 = don't compress).
721  * @return bytes written on successful write, 0 on failure.
722  *
723  * This function will write the specified chunk of data to the eet file
724  * and return greater than 0 on success. 0 will be returned on failure.
725  *
726  * The eet file handle must be a valid file handle for an eet file opened
727  * for writing. If it is not, 0 will be returned and no action will be
728  * performed.
729  *
730  * Name, and data must not be NULL, and size must be > 0. If these
731  * conditions are not met, 0 will be returned.
732  *
733  * The data will be copied (and optionally compressed) in ram, pending
734  * a flush to disk (it will stay in ram till the eet file handle is
735  * closed though).
736  *
737  * @see eet_write_cipher()
738  *
739  * @since 1.0.0
740  * @ingroup Eet_File_Group
741  */
742 EAPI int
743 eet_write(Eet_File *ef,
744           const char *name,
745           const void *data,
746           int size,
747           int compress);
748
749 /**
750  * Delete a specified entry from an Eet file being written or re-written
751  * @param ef A valid eet file handle opened for writing.
752  * @param name Name of the entry. eg: "/base/file_i_want".
753  * @return Success or failure of the delete.
754  *
755  * This function will delete the specified chunk of data from the eet file
756  * and return greater than 0 on success. 0 will be returned on failure.
757  *
758  * The eet file handle must be a valid file handle for an eet file opened
759  * for writing. If it is not, 0 will be returned and no action will be
760  * performed.
761  *
762  * Name, must not be NULL, otherwise 0 will be returned.
763  *
764  * @since 1.0.0
765  * @ingroup Eet_File_Group
766  */
767 EAPI int
768 eet_delete(Eet_File *ef,
769            const char *name);
770
771 /**
772  * Alias a specific section to another one. Destination may exist or not,
773  * no checks are done.
774  * @param ef A valid eet file handle opened for writing.
775  * @param name Name of the new entry. eg: "/base/file_i_want".
776  * @param destination Actual source of the aliased entry eg: "/base/the_real_stuff_i_want".
777  * @param compress Compression flags (1 == compress, 0 = don't compress).
778  * @return EINA_TRUE on success, EINA_FALSE on failure.
779  *
780  * Name and Destination must not be NULL, otherwise EINA_FALSE will be returned.
781  * The equivalent of this would be calling 'ln -s destination name'
782  *
783  * @since 1.3.3
784  * @ingroup Eet_File_Group
785  */
786 EAPI Eina_Bool
787 eet_alias(Eet_File *ef,
788           const char *name,
789           const char *destination,
790           int compress);
791
792 /**
793  * Retrieve the filename of an Eet_File
794  * @param ef A valid eet file handle opened for writing.
795  * @return The stringshared file string opened with eet_open(), or NULL on error
796  *
797  * @note This function will return NULL for files opened with eet_memopen_read()
798  *
799  * @since 1.6
800  * @ingroup Eet_File_Group
801  */
802 EAPI const char *
803 eet_file_get(Eet_File *ef);
804
805 /**
806  * Retrieve the destination name of an alias
807  * @param ef A valid eet file handle opened for writing
808  * @param name Name of the entry. eg: "/base/file_i_want"
809  * @return Destination of the alias. eg: "/base/the_real_stuff_i_want", NULL on failure
810  *
811  * Name must not be NULL, otherwise NULL will be returned.
812  *
813  * @since 1.5
814  * @ingroup Eet_File_Group
815  */
816 EAPI const char *
817 eet_alias_get(Eet_File *ef,
818               const char *name);
819
820 /**
821  * List all entries in eet file matching shell glob.
822  * @param ef A valid eet file handle.
823  * @param glob A shell glob to match against.
824  * @param count_ret Number of entries found to match.
825  * @return Pointer to an array of strings.
826  *
827  * This function will list all entries in the eet file matching the
828  * supplied shell glob and return an allocated list of their names, if
829  * there are any, and if no memory errors occur.
830  *
831  * The eet file handle must be valid and glob must not be NULL, or NULL
832  * will be returned and count_ret will be filled with 0.
833  *
834  * The calling program must call free() on the array returned, but NOT
835  * on the string pointers in the array. They are taken as read-only
836  * internals from the eet file handle. They are only valid as long as
837  * the file handle is not closed. When it is closed those pointers in the
838  * array are now not valid and should not be used.
839  *
840  * On success the array returned will have a list of string pointers
841  * that are the names of the entries that matched, and count_ret will have
842  * the number of entries in this array placed in it.
843  *
844  * Hint: an easy way to list all entries in an eet file is to use a glob
845  * value of "*".
846  *
847  * @since 1.0.0
848  * @ingroup Eet_File_Group
849  */
850 EAPI char **
851 eet_list(Eet_File *ef,
852          const char *glob,
853          int *count_ret);
854
855 /**
856  * Return the number of entries in the specified eet file.
857  * @param ef A valid eet file handle.
858  * @return Number of entries in ef or -1 if the number of entries
859  *         cannot be read due to open mode restrictions.
860  *
861  * @since 1.0.0
862  * @ingroup Eet_File_Group
863  */
864 EAPI int
865 eet_num_entries(Eet_File *ef);
866
867 /**
868  * @defgroup Eet_File_Cipher_Group Eet File Ciphered Main Functions
869  *
870  * Most of the @ref Eet_File_Group have alternative versions that
871  * accounts for ciphers to protect their content.
872  *
873  * @see @ref Eet_Cipher_Group
874  *
875  * @ingroup Eet_File_Group
876  */
877
878 /**
879  * Read a specified entry from an eet file and return data using a cipher.
880  * @param ef A valid eet file handle opened for reading.
881  * @param name Name of the entry. eg: "/base/file_i_want".
882  * @param size_ret Number of bytes read from entry and returned.
883  * @param cipher_key The key to use as cipher.
884  * @return The data stored in that entry in the eet file.
885  *
886  * This function finds an entry in the eet file that is stored under the
887  * name specified, and returns that data, decompressed, if successful.
888  * NULL is returned if the lookup fails or if memory errors are
889  * encountered. It is the job of the calling program to call free() on
890  * the returned data. The number of bytes in the returned data chunk are
891  * placed in size_ret.
892  *
893  * If the eet file handle is not valid NULL is returned and size_ret is
894  * filled with 0.
895  *
896  * @see eet_read()
897  *
898  * @since 1.0.0
899  * @ingroup Eet_File_Cipher_Group
900  */
901 EAPI void *
902 eet_read_cipher(Eet_File *ef,
903                 const char *name,
904                 int *size_ret,
905                 const char *cipher_key);
906
907 /**
908  * Write a specified entry to an eet file handle using a cipher.
909  * @param ef A valid eet file handle opened for writing.
910  * @param name Name of the entry. eg: "/base/file_i_want".
911  * @param data Pointer to the data to be stored.
912  * @param size Length in bytes in the data to be stored.
913  * @param compress Compression flags (1 == compress, 0 = don't compress).
914  * @param cipher_key The key to use as cipher.
915  * @return bytes written on successful write, 0 on failure.
916  *
917  * This function will write the specified chunk of data to the eet file
918  * and return greater than 0 on success. 0 will be returned on failure.
919  *
920  * The eet file handle must be a valid file handle for an eet file opened
921  * for writing. If it is not, 0 will be returned and no action will be
922  * performed.
923  *
924  * Name, and data must not be NULL, and size must be > 0. If these
925  * conditions are not met, 0 will be returned.
926  *
927  * The data will be copied (and optionally compressed) in ram, pending
928  * a flush to disk (it will stay in ram till the eet file handle is
929  * closed though).
930  *
931  * @see eet_write()
932  *
933  * @since 1.0.0
934  * @ingroup Eet_File_Cipher_Group
935  */
936 EAPI int
937 eet_write_cipher(Eet_File *ef,
938                  const char *name,
939                  const void *data,
940                  int size,
941                  int compress,
942                  const char *cipher_key);
943
944 /**
945  * @defgroup Eet_File_Image_Group Image Store and Load
946  *
947  * Eet efficiently stores and loads images, including alpha
948  * channels and lossy compressions.
949  *
950  * Eet can handle both lossy compression with different levels of quality and
951  * non-lossy compression with different compression levels. It's also possible,
952  * given an image data, to only read its header to get the image information
953  * without decoding the entire content for it.
954  *
955  * The encode family of functions will take an image raw buffer and its
956  * parameters and compress it in memory, returning the new buffer.
957  * Likewise, the decode functions will read from the given location in memory
958  * and return the uncompressed image.
959  *
960  * The read and write functions will, respectively, encode and decode to or
961  * from an Eet file, under the specified key.
962  *
963  * These functions are fairly low level and the same functionality can be
964  * achieved using Evas and Edje, making it much easier to work with images
965  * as well as not needing to worry about things like scaling them.
966  */
967
968 /**
969  * Read just the header data for an image and dont decode the pixels.
970  * @param ef A valid eet file handle opened for reading.
971  * @param name Name of the entry. eg: "/base/file_i_want".
972  * @param w A pointer to the unsigned int to hold the width in pixels.
973  * @param h A pointer to the unsigned int to hold the height in pixels.
974  * @param alpha A pointer to the int to hold the alpha flag.
975  * @param compress A pointer to the int to hold the compression amount.
976  * @param quality A pointer to the int to hold the quality amount.
977  * @param lossy A pointer to the int to hold the lossiness flag.
978  * @return 1 on successful decode, 0 otherwise
979  *
980  * Reads and decodes the image header data stored under the given key and
981  * Eet file.
982  *
983  * The information decoded is placed in each of the parameters, which must be
984  * provided. The width and height, measured in pixels, will be stored under
985  * the variables pointed by @p w and @p h, respectively. If the read or
986  * decode of the header fails, this values will be 0. The @p alpha parameter
987  * will be 1 or 0, denoting if the alpha channel of the image is used or not.
988  * If the image was losslessly compressed, the @p compress parameter will hold
989  * the compression amount used, ranging from 0 to 9 and @p lossy will be 0.
990  * In the case of lossy compression, @p lossy will be 1, and the compression
991  * quality will be placed under @p quality, with a value ranging from 0 to 100.
992  *
993  * @see eet_data_image_header_decode()
994  * @see eet_data_image_header_read_cipher()
995  *
996  * @since 1.0.0
997  * @ingroup Eet_File_Image_Group
998  */
999 EAPI int
1000 eet_data_image_header_read(Eet_File *ef,
1001                            const char *name,
1002                            unsigned int *w,
1003                            unsigned int *h,
1004                            int *alpha,
1005                            int *compress,
1006                            int *quality,
1007                            int *lossy);
1008
1009 /**
1010  * Read image data from the named key in the eet file.
1011  * @param ef A valid eet file handle opened for reading.
1012  * @param name Name of the entry. eg: "/base/file_i_want".
1013  * @param w A pointer to the unsigned int to hold the width in pixels.
1014  * @param h A pointer to the unsigned int to hold the height in pixels.
1015  * @param alpha A pointer to the int to hold the alpha flag.
1016  * @param compress A pointer to the int to hold the compression amount.
1017  * @param quality A pointer to the int to hold the quality amount.
1018  * @param lossy A pointer to the int to hold the lossiness flag.
1019  * @return The image pixel data decoded
1020  *
1021  * Reads and decodes the image stored in the given Eet file under the named
1022  * key.
1023  *
1024  * The returned pixel data is a linear array of pixels starting from the
1025  * top-left of the image, scanning row by row from left to right. Each pile
1026  * is a 32bit value, with the high byte being the alpha channel, the next being
1027  * red, then green, and the low byte being blue.
1028  *
1029  * The rest of the parameters are the same as in eet_data_image_header_read().
1030  *
1031  * On success the function returns a pointer to the image data decoded. The
1032  * calling application is responsible for calling free() on the image data
1033  * when it is done with it. On failure NULL is returned and the parameter
1034  * values may not contain any sensible data.
1035  *
1036  * @see eet_data_image_header_read()
1037  * @see eet_data_image_decode()
1038  * @see eet_data_image_read_cipher()
1039  * @see eet_data_image_read_to_surface()
1040  *
1041  * @since 1.0.0
1042  * @ingroup Eet_File_Image_Group
1043  */
1044 EAPI void *
1045 eet_data_image_read(Eet_File *ef,
1046                     const char *name,
1047                     unsigned int *w,
1048                     unsigned int *h,
1049                     int *alpha,
1050                     int *compress,
1051                     int *quality,
1052                     int *lossy);
1053
1054 /**
1055  * Read image data from the named key in the eet file and store it in the given buffer.
1056  * @param ef A valid eet file handle opened for reading.
1057  * @param name Name of the entry. eg: "/base/file_i_want".
1058  * @param src_x The starting x coordinate from where to dump the stream.
1059  * @param src_y The starting y coordinate from where to dump the stream.
1060  * @param d A pointer to the pixel surface.
1061  * @param w The expected width in pixels of the pixel surface to decode.
1062  * @param h The expected height in pixels of the pixel surface to decode.
1063  * @param row_stride The length of a pixels line in the destination surface.
1064  * @param alpha A pointer to the int to hold the alpha flag.
1065  * @param compress A pointer to the int to hold the compression amount.
1066  * @param quality A pointer to the int to hold the quality amount.
1067  * @param lossy A pointer to the int to hold the lossiness flag.
1068  * @return 1 on success, 0 otherwise.
1069  *
1070  * Reads and decodes the image stored in the given Eet file, placing the
1071  * resulting pixel data in the buffer pointed by the user.
1072  *
1073  * Like eet_data_image_read(), it takes the image data stored under the
1074  * @p name key in the @p ef file, but instead of returning a new buffer with
1075  * the pixel data, it places the result in the buffer pointed by @p d, which
1076  * must be provided by the user and of sufficient size to hold the requested
1077  * portion of the image.
1078  *
1079  * The @p src_x and @p src_y parameters indicate the top-left corner of the
1080  * section of the image to decode. These have to be higher or equal than 0 and
1081  * less than the respective total width and height of the image. The width
1082  * and height of the section of the image to decode are given in @p w and @p h
1083  * and also can't be higher than the total width and height of the image.
1084  *
1085  * The @p row_stride parameter indicates the length in bytes of each line in
1086  * the destination buffer and it has to be at least @p w * 4.
1087  *
1088  * All the other parameters are the same as in eet_data_image_read().
1089  *
1090  * On success the function returns 1, and 0 on failure. On failure the
1091  * parameter values may not contain any sensible data.
1092  *
1093  * @see eet_data_image_read()
1094  * @see eet_data_image_decode()
1095  * @see eet_data_image_decode_to_surface()
1096  * @see eet_data_image_read_to_surface_cipher()
1097  *
1098  * @since 1.0.2
1099  * @ingroup Eet_File_Image_Group
1100  */
1101 EAPI int
1102 eet_data_image_read_to_surface(Eet_File *ef,
1103                                const char *name,
1104                                unsigned int src_x,
1105                                unsigned int src_y,
1106                                unsigned int *d,
1107                                unsigned int w,
1108                                unsigned int h,
1109                                unsigned int row_stride,
1110                                int *alpha,
1111                                int *compress,
1112                                int *quality,
1113                                int *lossy);
1114
1115 /**
1116  * Write image data to the named key in an eet file.
1117  * @param ef A valid eet file handle opened for writing.
1118  * @param name Name of the entry. eg: "/base/file_i_want".
1119  * @param data A pointer to the image pixel data.
1120  * @param w The width of the image in pixels.
1121  * @param h The height of the image in pixels.
1122  * @param alpha The alpha channel flag.
1123  * @param compress The compression amount.
1124  * @param quality The quality encoding amount.
1125  * @param lossy The lossiness flag.
1126  * @return Success if the data was encoded and written or not.
1127  *
1128  * This function takes image pixel data and encodes it in an eet file
1129  * stored under the supplied name key, and returns how many bytes were
1130  * actually written to encode the image data.
1131  *
1132  * The data expected is the same format as returned by eet_data_image_read.
1133  * If this is not the case weird things may happen. Width and height must
1134  * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1135  * the alpha values are not useful and 1 meaning they are). Compress can
1136  * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1137  * This is only used if the image is not lossily encoded. Quality is used on
1138  * lossy compression and should be a value from 0 to 100. The lossy flag
1139  * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1140  * image quality loss (but then have a much smaller encoding).
1141  *
1142  * On success this function returns the number of bytes that were required
1143  * to encode the image data, or on failure it returns 0.
1144  *
1145  * @see eet_data_image_read()
1146  * @see eet_data_image_encode()
1147  * @see eet_data_image_write_cipher()
1148  *
1149  * @since 1.0.0
1150  * @ingroup Eet_File_Image_Group
1151  */
1152 EAPI int
1153 eet_data_image_write(Eet_File *ef,
1154                      const char *name,
1155                      const void *data,
1156                      unsigned int w,
1157                      unsigned int h,
1158                      int alpha,
1159                      int compress,
1160                      int quality,
1161                      int lossy);
1162
1163 /**
1164  * Decode Image data header only to get information.
1165  * @param data The encoded pixel data.
1166  * @param size The size, in bytes, of the encoded pixel data.
1167  * @param w A pointer to the unsigned int to hold the width in pixels.
1168  * @param h A pointer to the unsigned int to hold the height in pixels.
1169  * @param alpha A pointer to the int to hold the alpha flag.
1170  * @param compress A pointer to the int to hold the compression amount.
1171  * @param quality A pointer to the int to hold the quality amount.
1172  * @param lossy A pointer to the int to hold the lossiness flag.
1173  * @return 1 on success, 0 on failure.
1174  *
1175  * This function works exactly like eet_data_image_header_read(), but instead
1176  * of reading from an Eet file, it takes the buffer of size @p size pointed
1177  * by @p data, which must be a valid Eet encoded image.
1178  *
1179  * On success the function returns 1 indicating the header was read and
1180  * decoded properly, or 0 on failure.
1181  *
1182  * @see eet_data_image_header_read()
1183  * @see eet_data_image_header_decode_cipher()
1184  *
1185  * @since 1.0.0
1186  * @ingroup Eet_File_Image_Group
1187  */
1188 EAPI int
1189 eet_data_image_header_decode(const void *data,
1190                              int size,
1191                              unsigned int *w,
1192                              unsigned int *h,
1193                              int *alpha,
1194                              int *compress,
1195                              int *quality,
1196                              int *lossy);
1197
1198 /**
1199  * Decode Image data into pixel data.
1200  * @param data The encoded pixel data.
1201  * @param size The size, in bytes, of the encoded pixel data.
1202  * @param w A pointer to the unsigned int to hold the width in pixels.
1203  * @param h A pointer to the unsigned int to hold the height in pixels.
1204  * @param alpha A pointer to the int to hold the alpha flag.
1205  * @param compress A pointer to the int to hold the compression amount.
1206  * @param quality A pointer to the int to hold the quality amount.
1207  * @param lossy A pointer to the int to hold the lossiness flag.
1208  * @return The image pixel data decoded
1209  *
1210  * This function takes encoded pixel data and decodes it into raw RGBA
1211  * pixels on success.
1212  *
1213  * It works exactly like eet_data_image_read(), but it takes the encoded
1214  * data in the @p data buffer of size @p size, instead of reading from a file.
1215  * All the others parameters are also the same.
1216  *
1217  * On success the function returns a pointer to the image data decoded. The
1218  * calling application is responsible for calling free() on the image data
1219  * when it is done with it. On failure NULL is returned and the parameter
1220  * values may not contain any sensible data.
1221  *
1222  * @see eet_data_image_read()
1223  * @see eet_data_image_decode_cipher()
1224  *
1225  * @since 1.0.0
1226  * @ingroup Eet_File_Image_Group
1227  */
1228 EAPI void *
1229 eet_data_image_decode(const void *data,
1230                       int size,
1231                       unsigned int *w,
1232                       unsigned int *h,
1233                       int *alpha,
1234                       int *compress,
1235                       int *quality,
1236                       int *lossy);
1237
1238 /**
1239  * Decode Image data into pixel data and stores in the given buffer.
1240  * @param data The encoded pixel data.
1241  * @param size The size, in bytes, of the encoded pixel data.
1242  * @param src_x The starting x coordinate from where to dump the stream.
1243  * @param src_y The starting y coordinate from where to dump the stream.
1244  * @param d A pointer to the pixel surface.
1245  * @param w The expected width in pixels of the pixel surface to decode.
1246  * @param h The expected height in pixels of the pixel surface to decode.
1247  * @param row_stride The length of a pixels line in the destination surface.
1248  * @param alpha A pointer to the int to hold the alpha flag.
1249  * @param compress A pointer to the int to hold the compression amount.
1250  * @param quality A pointer to the int to hold the quality amount.
1251  * @param lossy A pointer to the int to hold the lossiness flag.
1252  * @return 1 on success, 0 otherwise.
1253  *
1254  * Like eet_data_image_read_to_surface(), but reading the given @p data buffer
1255  * instead of a file.
1256  *
1257  * On success the function returns 1, and 0 on failure. On failure the
1258  * parameter values may not contain any sensible data.
1259  *
1260  * @see eet_data_image_read_to_surface()
1261  * @see eet_data_image_decode_to_surface_cipher()
1262  *
1263  * @since 1.0.2
1264  * @ingroup Eet_File_Image_Group
1265  */
1266 EAPI int
1267 eet_data_image_decode_to_surface(const void *data,
1268                                  int size,
1269                                  unsigned int src_x,
1270                                  unsigned int src_y,
1271                                  unsigned int *d,
1272                                  unsigned int w,
1273                                  unsigned int h,
1274                                  unsigned int row_stride,
1275                                  int *alpha,
1276                                  int *compress,
1277                                  int *quality,
1278                                  int *lossy);
1279
1280 /**
1281  * Encode image data for storage or transmission.
1282  * @param data A pointer to the image pixel data.
1283  * @param size_ret A pointer to an int to hold the size of the returned data.
1284  * @param w The width of the image in pixels.
1285  * @param h The height of the image in pixels.
1286  * @param alpha The alpha channel flag.
1287  * @param compress The compression amount.
1288  * @param quality The quality encoding amount.
1289  * @param lossy The lossiness flag.
1290  * @return The encoded image data.
1291  *
1292  * This function stakes image pixel data and encodes it with compression and
1293  * possible loss of quality (as a trade off for size) for storage or
1294  * transmission to another system.
1295  *
1296  * It works like eet_data_image_write(), but instead of writing the encoded
1297  * image into an Eet file, it allocates a new buffer of the size required and
1298  * returns the encoded data in it.
1299  *
1300  * On success this function returns a pointer to the encoded data that you
1301  * can free with free() when no longer needed.
1302  *
1303  * @see eet_data_image_write()
1304  * @see eet_data_image_read()
1305  * @see eet_data_image_encode_cipher()
1306  *
1307  * @since 1.0.0
1308  * @ingroup Eet_File_Image_Group
1309  */
1310 EAPI void *
1311 eet_data_image_encode(const void *data,
1312                       int *size_ret,
1313                       unsigned int w,
1314                       unsigned int h,
1315                       int alpha,
1316                       int compress,
1317                       int quality,
1318                       int lossy);
1319
1320 /**
1321  * @defgroup Eet_File_Image_Cipher_Group Image Store and Load using a Cipher
1322  *
1323  * Most of the @ref Eet_File_Image_Group have alternative versions
1324  * that accounts for ciphers to protect their content.
1325  *
1326  * @see @ref Eet_Cipher_Group
1327  *
1328  * @ingroup Eet_File_Image_Group
1329  */
1330
1331 /**
1332  * Read just the header data for an image and dont decode the pixels using a cipher.
1333  * @param ef A valid eet file handle opened for reading.
1334  * @param name Name of the entry. eg: "/base/file_i_want".
1335  * @param cipher_key The key to use as cipher.
1336  * @param w A pointer to the unsigned int to hold the width in pixels.
1337  * @param h A pointer to the unsigned int to hold the height in pixels.
1338  * @param alpha A pointer to the int to hold the alpha flag.
1339  * @param compress A pointer to the int to hold the compression amount.
1340  * @param quality A pointer to the int to hold the quality amount.
1341  * @param lossy A pointer to the int to hold the lossiness flag.
1342  * @return 1 on successful decode, 0 otherwise
1343  *
1344  * This function reads an image from an eet file stored under the named
1345  * key in the eet file and return a pointer to the decompressed pixel data.
1346  *
1347  * The other parameters of the image (width, height etc.) are placed into
1348  * the values pointed to (they must be supplied). The pixel data is a linear
1349  * array of pixels starting from the top-left of the image scanning row by
1350  * row from left to right. Each pixel is a 32bit value, with the high byte
1351  * being the alpha channel, the next being red, then green, and the low byte
1352  * being blue. The width and height are measured in pixels and will be
1353  * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1354  * that the alpha channel is not used. 1 denotes that it is significant.
1355  * Compress is filled with the compression value/amount the image was
1356  * stored with. The quality value is filled with the quality encoding of
1357  * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1358  * the image was encoded lossily or not.
1359  *
1360  * On success the function returns 1 indicating the header was read and
1361  * decoded properly, or 0 on failure.
1362  *
1363  * @see eet_data_image_header_read()
1364  *
1365  * @since 1.0.0
1366  * @ingroup Eet_File_Image_Cipher_Group
1367  */
1368 EAPI int
1369 eet_data_image_header_read_cipher(Eet_File *ef,
1370                                   const char *name,
1371                                   const char *cipher_key,
1372                                   unsigned int *w,
1373                                   unsigned int *h,
1374                                   int *alpha,
1375                                   int *compress,
1376                                   int *quality,
1377                                   int *lossy);
1378
1379 /**
1380  * Read image data from the named key in the eet file using a cipher.
1381  * @param ef A valid eet file handle opened for reading.
1382  * @param name Name of the entry. eg: "/base/file_i_want".
1383  * @param cipher_key The key to use as cipher.
1384  * @param w A pointer to the unsigned int to hold the width in pixels.
1385  * @param h A pointer to the unsigned int to hold the height in pixels.
1386  * @param alpha A pointer to the int to hold the alpha flag.
1387  * @param compress A pointer to the int to hold the compression amount.
1388  * @param quality A pointer to the int to hold the quality amount.
1389  * @param lossy A pointer to the int to hold the lossiness flag.
1390  * @return The image pixel data decoded
1391  *
1392  * This function reads an image from an eet file stored under the named
1393  * key in the eet file and return a pointer to the decompressed pixel data.
1394  *
1395  * The other parameters of the image (width, height etc.) are placed into
1396  * the values pointed to (they must be supplied). The pixel data is a linear
1397  * array of pixels starting from the top-left of the image scanning row by
1398  * row from left to right. Each pixel is a 32bit value, with the high byte
1399  * being the alpha channel, the next being red, then green, and the low byte
1400  * being blue. The width and height are measured in pixels and will be
1401  * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1402  * that the alpha channel is not used. 1 denotes that it is significant.
1403  * Compress is filled with the compression value/amount the image was
1404  * stored with. The quality value is filled with the quality encoding of
1405  * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1406  * the image was encoded lossily or not.
1407  *
1408  * On success the function returns a pointer to the image data decoded. The
1409  * calling application is responsible for calling free() on the image data
1410  * when it is done with it. On failure NULL is returned and the parameter
1411  * values may not contain any sensible data.
1412  *
1413  * @see eet_data_image_read()
1414  *
1415  * @since 1.0.0
1416  * @ingroup Eet_File_Image_Cipher_Group
1417  */
1418 EAPI void *
1419 eet_data_image_read_cipher(Eet_File *ef,
1420                            const char *name,
1421                            const char *cipher_key,
1422                            unsigned int *w,
1423                            unsigned int *h,
1424                            int *alpha,
1425                            int *compress,
1426                            int *quality,
1427                            int *lossy);
1428
1429 /**
1430  * Read image data from the named key in the eet file using a cipher.
1431  * @param ef A valid eet file handle opened for reading.
1432  * @param name Name of the entry. eg: "/base/file_i_want".
1433  * @param cipher_key The key to use as cipher.
1434  * @param src_x The starting x coordinate from where to dump the stream.
1435  * @param src_y The starting y coordinate from where to dump the stream.
1436  * @param d A pointer to the pixel surface.
1437  * @param w The expected width in pixels of the pixel surface to decode.
1438  * @param h The expected height in pixels of the pixel surface to decode.
1439  * @param row_stride The length of a pixels line in the destination surface.
1440  * @param alpha A pointer to the int to hold the alpha flag.
1441  * @param compress A pointer to the int to hold the compression amount.
1442  * @param quality A pointer to the int to hold the quality amount.
1443  * @param lossy A pointer to the int to hold the lossiness flag.
1444  * @return 1 on success, 0 otherwise.
1445  *
1446  * This function reads an image from an eet file stored under the named
1447  * key in the eet file and return a pointer to the decompressed pixel data.
1448  *
1449  * The other parameters of the image (width, height etc.) are placed into
1450  * the values pointed to (they must be supplied). The pixel data is a linear
1451  * array of pixels starting from the top-left of the image scanning row by
1452  * row from left to right. Each pixel is a 32bit value, with the high byte
1453  * being the alpha channel, the next being red, then green, and the low byte
1454  * being blue. The width and height are measured in pixels and will be
1455  * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1456  * that the alpha channel is not used. 1 denotes that it is significant.
1457  * Compress is filled with the compression value/amount the image was
1458  * stored with. The quality value is filled with the quality encoding of
1459  * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1460  * the image was encoded lossily or not.
1461  *
1462  * On success the function returns 1, and 0 on failure. On failure the
1463  * parameter values may not contain any sensible data.
1464  *
1465  * @see eet_data_image_read_to_surface()
1466  *
1467  * @since 1.0.2
1468  * @ingroup Eet_File_Image_Cipher_Group
1469  */
1470 EAPI int
1471 eet_data_image_read_to_surface_cipher(Eet_File *ef,
1472                                       const char *name,
1473                                       const char *cipher_key,
1474                                       unsigned int src_x,
1475                                       unsigned int src_y,
1476                                       unsigned int *d,
1477                                       unsigned int w,
1478                                       unsigned int h,
1479                                       unsigned int row_stride,
1480                                       int *alpha,
1481                                       int *compress,
1482                                       int *quality,
1483                                       int *lossy);
1484
1485 /**
1486  * Write image data to the named key in an eet file using a cipher.
1487  * @param ef A valid eet file handle opened for writing.
1488  * @param name Name of the entry. eg: "/base/file_i_want".
1489  * @param cipher_key The key to use as cipher.
1490  * @param data A pointer to the image pixel data.
1491  * @param w The width of the image in pixels.
1492  * @param h The height of the image in pixels.
1493  * @param alpha The alpha channel flag.
1494  * @param compress The compression amount.
1495  * @param quality The quality encoding amount.
1496  * @param lossy The lossiness flag.
1497  * @return Success if the data was encoded and written or not.
1498  *
1499  * This function takes image pixel data and encodes it in an eet file
1500  * stored under the supplied name key, and returns how many bytes were
1501  * actually written to encode the image data.
1502  *
1503  * The data expected is the same format as returned by eet_data_image_read.
1504  * If this is not the case weird things may happen. Width and height must
1505  * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1506  * the alpha values are not useful and 1 meaning they are). Compress can
1507  * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1508  * This is only used if the image is not lossily encoded. Quality is used on
1509  * lossy compression and should be a value from 0 to 100. The lossy flag
1510  * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1511  * image quality loss (but then have a much smaller encoding).
1512  *
1513  * On success this function returns the number of bytes that were required
1514  * to encode the image data, or on failure it returns 0.
1515  *
1516  * @see eet_data_image_write()
1517  *
1518  * @since 1.0.0
1519  * @ingroup Eet_File_Image_Cipher_Group
1520  */
1521 EAPI int
1522 eet_data_image_write_cipher(Eet_File *ef,
1523                             const char *name,
1524                             const char *cipher_key,
1525                             const void *data,
1526                             unsigned int w,
1527                             unsigned int h,
1528                             int alpha,
1529                             int compress,
1530                             int quality,
1531                             int lossy);
1532
1533 /**
1534  * Decode Image data header only to get information using a cipher.
1535  * @param data The encoded pixel data.
1536  * @param cipher_key The key to use as cipher.
1537  * @param size The size, in bytes, of the encoded pixel data.
1538  * @param w A pointer to the unsigned int to hold the width in pixels.
1539  * @param h A pointer to the unsigned int to hold the height in pixels.
1540  * @param alpha A pointer to the int to hold the alpha flag.
1541  * @param compress A pointer to the int to hold the compression amount.
1542  * @param quality A pointer to the int to hold the quality amount.
1543  * @param lossy A pointer to the int to hold the lossiness flag.
1544  * @return 1 on success, 0 on failure.
1545  *
1546  * This function takes encoded pixel data and decodes it into raw RGBA
1547  * pixels on success.
1548  *
1549  * The other parameters of the image (width, height etc.) are placed into
1550  * the values pointed to (they must be supplied). The pixel data is a linear
1551  * array of pixels starting from the top-left of the image scanning row by
1552  * row from left to right. Each pixel is a 32bit value, with the high byte
1553  * being the alpha channel, the next being red, then green, and the low byte
1554  * being blue. The width and height are measured in pixels and will be
1555  * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1556  * that the alpha channel is not used. 1 denotes that it is significant.
1557  * Compress is filled with the compression value/amount the image was
1558  * stored with. The quality value is filled with the quality encoding of
1559  * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1560  * the image was encoded lossily or not.
1561  *
1562  * On success the function returns 1 indicating the header was read and
1563  * decoded properly, or 0 on failure.
1564  *
1565  * @see eet_data_image_header_decode()
1566  *
1567  * @since 1.0.0
1568  * @ingroup Eet_File_Image_Cipher_Group
1569  */
1570 EAPI int
1571 eet_data_image_header_decode_cipher(const void *data,
1572                                     const char *cipher_key,
1573                                     int size,
1574                                     unsigned int *w,
1575                                     unsigned int *h,
1576                                     int *alpha,
1577                                     int *compress,
1578                                     int *quality,
1579                                     int *lossy);
1580
1581 /**
1582  * Decode Image data into pixel data using a cipher.
1583  * @param data The encoded pixel data.
1584  * @param cipher_key The key to use as cipher.
1585  * @param size The size, in bytes, of the encoded pixel data.
1586  * @param w A pointer to the unsigned int to hold the width in pixels.
1587  * @param h A pointer to the unsigned int to hold the height in pixels.
1588  * @param alpha A pointer to the int to hold the alpha flag.
1589  * @param compress A pointer to the int to hold the compression amount.
1590  * @param quality A pointer to the int to hold the quality amount.
1591  * @param lossy A pointer to the int to hold the lossiness flag.
1592  * @return The image pixel data decoded
1593  *
1594  * This function takes encoded pixel data and decodes it into raw RGBA
1595  * pixels on success.
1596  *
1597  * The other parameters of the image (width, height etc.) are placed into
1598  * the values pointed to (they must be supplied). The pixel data is a linear
1599  * array of pixels starting from the top-left of the image scanning row by
1600  * row from left to right. Each pixel is a 32bit value, with the high byte
1601  * being the alpha channel, the next being red, then green, and the low byte
1602  * being blue. The width and height are measured in pixels and will be
1603  * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1604  * that the alpha channel is not used. 1 denotes that it is significant.
1605  * Compress is filled with the compression value/amount the image was
1606  * stored with. The quality value is filled with the quality encoding of
1607  * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1608  * the image was encoded lossily or not.
1609  *
1610  * On success the function returns a pointer to the image data decoded. The
1611  * calling application is responsible for calling free() on the image data
1612  * when it is done with it. On failure NULL is returned and the parameter
1613  * values may not contain any sensible data.
1614  *
1615  * @see eet_data_image_decode()
1616  *
1617  * @since 1.0.0
1618  * @ingroup Eet_File_Image_Cipher_Group
1619  */
1620 EAPI void *
1621 eet_data_image_decode_cipher(const void *data,
1622                              const char *cipher_key,
1623                              int size,
1624                              unsigned int *w,
1625                              unsigned int *h,
1626                              int *alpha,
1627                              int *compress,
1628                              int *quality,
1629                              int *lossy);
1630
1631 /**
1632  * Decode Image data into pixel data using a cipher.
1633  * @param data The encoded pixel data.
1634  * @param cipher_key The key to use as cipher.
1635  * @param size The size, in bytes, of the encoded pixel data.
1636  * @param src_x The starting x coordinate from where to dump the stream.
1637  * @param src_y The starting y coordinate from where to dump the stream.
1638  * @param d A pointer to the pixel surface.
1639  * @param w The expected width in pixels of the pixel surface to decode.
1640  * @param h The expected height in pixels of the pixel surface to decode.
1641  * @param row_stride The length of a pixels line in the destination surface.
1642  * @param alpha A pointer to the int to hold the alpha flag.
1643  * @param compress A pointer to the int to hold the compression amount.
1644  * @param quality A pointer to the int to hold the quality amount.
1645  * @param lossy A pointer to the int to hold the lossiness flag.
1646  * @return 1 on success, 0 otherwise.
1647  *
1648  * This function takes encoded pixel data and decodes it into raw RGBA
1649  * pixels on success.
1650  *
1651  * The other parameters of the image (alpha, compress etc.) are placed into
1652  * the values pointed to (they must be supplied). The pixel data is a linear
1653  * array of pixels starting from the top-left of the image scanning row by
1654  * row from left to right. Each pixel is a 32bit value, with the high byte
1655  * being the alpha channel, the next being red, then green, and the low byte
1656  * being blue. The width and height are measured in pixels and will be
1657  * greater than 0 when returned. The alpha flag is either 0 or 1. 0 denotes
1658  * that the alpha channel is not used. 1 denotes that it is significant.
1659  * Compress is filled with the compression value/amount the image was
1660  * stored with. The quality value is filled with the quality encoding of
1661  * the image file (0 - 100). The lossy flags is either 0 or 1 as to if
1662  * the image was encoded lossily or not.
1663  *
1664  * On success the function returns 1, and 0 on failure. On failure the
1665  * parameter values may not contain any sensible data.
1666  *
1667  * @see eet_data_image_decode_to_surface()
1668  *
1669  * @since 1.0.2
1670  * @ingroup Eet_File_Image_Cipher_Group
1671  */
1672 EAPI int
1673 eet_data_image_decode_to_surface_cipher(const void *data,
1674                                         const char *cipher_key,
1675                                         int size,
1676                                         unsigned int src_x,
1677                                         unsigned int src_y,
1678                                         unsigned int *d,
1679                                         unsigned int w,
1680                                         unsigned int h,
1681                                         unsigned int row_stride,
1682                                         int *alpha,
1683                                         int *compress,
1684                                         int *quality,
1685                                         int *lossy);
1686
1687 /**
1688  * Encode image data for storage or transmission using a cipher.
1689  * @param data A pointer to the image pixel data.
1690  * @param cipher_key The key to use as cipher.
1691  * @param size_ret A pointer to an int to hold the size of the returned data.
1692  * @param w The width of the image in pixels.
1693  * @param h The height of the image in pixels.
1694  * @param alpha The alpha channel flag.
1695  * @param compress The compression amount.
1696  * @param quality The quality encoding amount.
1697  * @param lossy The lossiness flag.
1698  * @return The encoded image data.
1699  *
1700  * This function stakes image pixel data and encodes it with compression and
1701  * possible loss of quality (as a trade off for size) for storage or
1702  * transmission to another system.
1703  *
1704  * The data expected is the same format as returned by eet_data_image_read.
1705  * If this is not the case weird things may happen. Width and height must
1706  * be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
1707  * the alpha values are not useful and 1 meaning they are). Compress can
1708  * be from 0 to 9 (0 meaning no compression, 9 meaning full compression).
1709  * This is only used if the image is not lossily encoded. Quality is used on
1710  * lossy compression and should be a value from 0 to 100. The lossy flag
1711  * can be 0 or 1. 0 means encode losslessly and 1 means to encode with
1712  * image quality loss (but then have a much smaller encoding).
1713  *
1714  * On success this function returns a pointer to the encoded data that you
1715  * can free with free() when no longer needed.
1716  *
1717  * @see eet_data_image_encode()
1718  *
1719  * @since 1.0.0
1720  * @ingroup Eet_File_Image_Cipher_Group
1721  */
1722 EAPI void *
1723 eet_data_image_encode_cipher(const void *data,
1724                              const char *cipher_key,
1725                              unsigned int w,
1726                              unsigned int h,
1727                              int alpha,
1728                              int compress,
1729                              int quality,
1730                              int lossy,
1731                              int *size_ret);
1732
1733 /**
1734  * @defgroup Eet_Cipher_Group Cipher, Identity and Protection Mechanisms
1735  *
1736  * Eet allows one to protect entries of an #Eet_File
1737  * individually. This may be used to ensure data was not tampered or
1738  * that third party does not read your data.
1739  *
1740  * @see @ref Eet_File_Cipher_Group
1741  * @see @ref Eet_File_Image_Cipher_Group
1742  *
1743  * @{
1744  */
1745
1746 /**
1747  * @typedef Eet_Key
1748  * Opaque handle that defines an identity (also known as key)
1749  * in Eet's cipher system.
1750  */
1751 typedef struct _Eet_Key Eet_Key;
1752
1753 /**
1754  * @}
1755  */
1756
1757 /**
1758  * Callback used to request if needed the password of a private key.
1759  *
1760  * @param buffer the buffer where to store the password.
1761  * @param size the maximum password size (size of buffer, including '@\0').
1762  * @param rwflag if the buffer is also readable or just writable.
1763  * @param data currently unused, may contain some context in future.
1764  * @return 1 on success and password was set to @p buffer, 0 on failure.
1765  *
1766  * @since 1.2.0
1767  * @ingroup Eet_Cipher_Group
1768  */
1769 typedef int (*Eet_Key_Password_Callback)(char *buffer, int size, int rwflag, void *data);
1770
1771 /**
1772  * Create an Eet_Key needed for signing an eet file.
1773  *
1774  * The certificate should provide the public that match the private key.
1775  * No verification is done to ensure that.
1776  *
1777  * @param certificate_file The file where to find the certificate.
1778  * @param private_key_file The file that contains the private key.
1779  * @param cb Function to callback if password is required to unlock
1780  *        private key.
1781  * @return A key handle to use, or @c NULL on failure.
1782  *
1783  * @see eet_identity_close()
1784  *
1785  * @since 1.2.0
1786  * @ingroup Eet_Cipher_Group
1787  */
1788 EAPI Eet_Key *
1789 eet_identity_open(const char *certificate_file,
1790                   const char *private_key_file,
1791                   Eet_Key_Password_Callback cb);
1792
1793 /**
1794  * Close and release all ressource used by an Eet_Key.  An
1795  * reference counter prevent it from being freed until all file
1796  * using it are also closed.
1797  *
1798  * @param key the key handle to close and free resources.
1799  *
1800  * @since 1.2.0
1801  * @ingroup Eet_Cipher_Group
1802  */
1803 EAPI void
1804 eet_identity_close(Eet_Key *key);
1805
1806 /**
1807  * Set a key to sign a file
1808  *
1809  * @param ef the file to set the identity.
1810  * @param key the key handle to set as identity.
1811  * @return #EET_ERROR_BAD_OBJECT if @p ef is invalid or
1812  *         #EET_ERROR_NONE on success.
1813  *
1814  * @since 1.2.0
1815  * @ingroup Eet_Cipher_Group
1816  */
1817 EAPI Eet_Error
1818 eet_identity_set(Eet_File *ef,
1819                  Eet_Key *key);
1820
1821 /**
1822  * Display both private and public key of an Eet_Key.
1823  *
1824  * @param key the handle to print.
1825  * @param out where to print.
1826  *
1827  * @since 1.2.0
1828  * @ingroup Eet_Cipher_Group
1829  */
1830 EAPI void
1831 eet_identity_print(Eet_Key *key,
1832                    FILE *out);
1833
1834 /**
1835  * Get the x509 der certificate associated with an Eet_File. Will return NULL
1836  * if the file is not signed.
1837  *
1838  * @param ef The file handle to query.
1839  * @param der_length The length of returned data, may be @c NULL.
1840  * @return the x509 certificate or @c NULL on error.
1841  *
1842  * @since 1.2.0
1843  * @ingroup Eet_Cipher_Group
1844  */
1845 EAPI const void *
1846 eet_identity_x509(Eet_File *ef,
1847                   int *der_length);
1848
1849 /**
1850  * Get the raw signature associated with an Eet_File. Will return NULL
1851  * if the file is not signed.
1852  *
1853  * @param ef The file handle to query.
1854  * @param signature_length The length of returned data, may be @c NULL.
1855  * @return the raw signature or @c NULL on error.
1856  *
1857  * @ingroup Eet_Cipher_Group
1858  */
1859 EAPI const void *
1860 eet_identity_signature(Eet_File *ef,
1861                        int *signature_length);
1862
1863 /**
1864  * Get the SHA1 associated with a file. Could be the one used to
1865  * sign the data or if the data where not signed, it will be the
1866  * SHA1 of the file.
1867  *
1868  * @param ef The file handle to query.
1869  * @param sha1_length The length of returned data, may be @c NULL.
1870  * @return the associated SHA1 or @c NULL on error.
1871  *
1872  * @since 1.2.0
1873  * @ingroup Eet_Cipher_Group
1874  */
1875 EAPI const void *
1876 eet_identity_sha1(Eet_File *ef,
1877                   int *sha1_length);
1878
1879 /**
1880  * Display the x509 der certificate to out.
1881  *
1882  * @param certificate the x509 certificate to print
1883  * @param der_length The length the certificate.
1884  * @param out where to print.
1885  *
1886  * @since 1.2.0
1887  * @ingroup Eet_Cipher_Group
1888  */
1889 EAPI void
1890 eet_identity_certificate_print(const unsigned char *certificate,
1891                                int der_length,
1892                                FILE *out);
1893
1894 /**
1895  * @defgroup Eet_Data_Group Eet Data Serialization
1896  *
1897  * Convenience functions to serialize and parse complex data
1898  * structures to binary blobs.
1899  *
1900  * While Eet core just handles binary blobs, it is often required
1901  * to save some structured data of different types, such as
1902  * strings, integers, lists, hashes and so on.
1903  *
1904  * Eet can serialize and then parse data types given some
1905  * construction instructions. These are defined in two levels:
1906  *
1907  * - #Eet_Data_Descriptor_Class to tell generic memory handling,
1908  *   such as the size of the type, how to allocate memory, strings,
1909  *   lists, hashes and so on.
1910  *
1911  * - #Eet_Data_Descriptor to tell inside such type, the members and
1912  *   their offsets inside the memory blob, their types and
1913  *   names. These members can be simple types or other
1914  *   #Eet_Data_Descriptor, allowing hierarchical types to be
1915  *   defined.
1916  *
1917  * Given that C provides no introspection, this process can be
1918  * quite cumbersome, so we provide lots of macros and convenience
1919  * functions to aid creating the types.
1920  *
1921  * We make now a quick overview of some of the most commonly used elements
1922  * of this part of the library. A simple example of a configuration system
1923  * will work as a somewhat real life example that is still simple enough to
1924  * follow.
1925  * Only the relevant sections will be shown here, but you can get the full
1926  * code @ref eet-data-simple.c "here".
1927  *
1928  * Ignoring the included headers, we'll begin by defining our configuration
1929  * struct.
1930  * @dontinclude eet-data-simple.c
1931  * @skip typedef
1932  * @until }
1933  *
1934  * When using Eet, you don't think in matters of what data the program needs
1935  * to run and which you would like to store. It's all the same and if it makes
1936  * more sense to keep them together, it's perfectly fine to do so. At the time
1937  * of telling Eet how your data is comprised you can leave out the things
1938  * that are runtime only and let Eet take care of the rest for you.
1939  *
1940  * The key used to store the config follows, as well as the variable used to
1941  * store our data descriptor.
1942  * This last one is very important. It's the one thing that Eet will use to
1943  * identify your data, both at the time of writing it to the file and when
1944  * loading from it.
1945  * @skipline MY_CONF
1946  * @skipline Eet_Data_Descriptor
1947  *
1948  * Now we'll see how to create this descriptor, so Eet knows how to handle
1949  * our data later on.
1950  * Begin our function by declaring an Eet_Data_Descriptor_Class, which is
1951  * used to create the actual descriptor. This class contains the name of
1952  * our data type, its size and several functions that dictate how Eet should
1953  * handle memory to allocate the necessary bits to bring our data to life.
1954  * You, as a user, will very hardly set this class' contents directly. The
1955  * most common scenario is to use one of the provided macros that set it using
1956  * the Eina data types, so that's what we'll be doing across all our examples.
1957  * @skip static void
1958  * @until eet_data_descriptor_stream_new
1959  *
1960  * Now that we have our descriptor, we need to make it describe something.
1961  * We do so by telling it which members of our struct we want it to know about
1962  * and their types.
1963  * The eet_data_descriptor_element_add() function takes care of this, but it's
1964  * too cumbersome for normal use, so several macros are provided that make
1965  * it easier to handle. Even with them, however, code can get very repetitive
1966  * and it's not uncommon to define custom macros using them to save on typing.
1967  * @skip #define
1968  * @until }
1969  *
1970  * Now our descriptor knows about the parts of our structure that we are
1971  * interesting in saving. You can see that not all of them are there, yet Eet
1972  * will find those that need saving and do the right thing. When loading our
1973  * data, any non-described fields in the structure will be zeroed, so there's
1974  * no need to worry about garbage memory in them.
1975  * Refer to the documentation of #EET_DATA_DESCRIPTOR_ADD_BASIC to understand
1976  * what our macro does.
1977  *
1978  * We are done with our descriptor init function and it's proper to have the
1979  * relevant shutdown. Proper coding guidelines indiciate that all memory
1980  * allocated should be freed when the program ends, and since you will most
1981  * likely keep your descriptor around for the life or your application, it's
1982  * only right to free it at the end.
1983  * @skip static void
1984  * @until }
1985  *
1986  * Not listed here, but included in the full example are functions to create
1987  * a blank configuration and free it. The first one will only be used when
1988  * no file exists to load from, or nothing is found in it, but the latter is
1989  * used regardless of where our data comes from. Unless you are reading direct
1990  * data from the Eet file, you will be in charge of freeing anything loaded
1991  * from it.
1992  *
1993  * Now it's time to look at how we can load our config from some file.
1994  * Begin by opening the Eet file normally.
1995  * @skip static My_Conf_Type
1996  * @until }
1997  *
1998  * And now we need to read the data from the file and decode it using our
1999  * descriptor. Fortunately, that's all done in one single step.
2000  * @until goto
2001  *
2002  * And that's it for all Eet cares about. But since we are dealing with a
2003  * common case, as is save and load of user configurations, the next fragment
2004  * of code shows why we have a version field in our struct, and how you can
2005  * use it to load older configuration files and update them as needed.
2006  * @until }
2007  *
2008  * Finally, clsoe the file and return the newly loaded config data.
2009  * @until }
2010  *
2011  * Saving data is just as easy. The full version of the following function
2012  * includes code to save to a temporary file first, so you can be sure not
2013  * to lose all your data in the case of a failure mid-writing. You can look
2014  * at it @ref eet-data-simple.c "here".
2015  * @skip static Eina_Bool
2016  * @until {
2017  * @skipline Eina_Bool ret
2018  * @skip eet_open
2019  * @until eet_close
2020  * @skip return
2021  * @until }
2022  *
2023  * To close, our main function, which doesn't do much. Just take some arguments
2024  * from the command line with the name of the file to load and another one
2025  * where to save again. If input file doesn't exist, a new config structure
2026  * will be created and saved to our output file.
2027  * @skip int main
2028  * @until return ret
2029  * @until }
2030  *
2031  * The following is a list of more advanced and detailed examples.
2032  * @li @ref eet_data_nested_example
2033  * @li @ref eet_data_file_descriptor
2034  * @li @ref Example_Eet_Data_File_Descriptor_02
2035  * @li @ref Example_Eet_Data_Cipher_Decipher
2036  */
2037
2038 /**
2039  * @page eet_data_nested_example Nested structures and Eet Data Descriptors
2040  *
2041  * We've seen already a simple example of how to use Eet Data Descriptors
2042  * to handle our structures, but it didn't show how this works when you
2043  * have structures inside other structures.
2044  *
2045  * Now, there's a very simple case of this, for when you have inline structs
2046  * to keep your big structure more organized, you don't need anything else
2047  * besides what @ref eet-data-simple.c "this simple example does".
2048  * Just use something like @p some_struct.sub_struct.member when adding the
2049  * member to the descriptor and it will work.
2050  *
2051  * For example:
2052  * @code
2053  * typedef struct
2054  * {
2055  *    int a_number;
2056  *    char *a_string;
2057  *    struct {
2058  *       int other_num;
2059  *       int one_more;
2060  *    } sub;
2061  * } some_struct;
2062  *
2063  * void some_function()
2064  * {
2065  *    ...
2066  *    my_desc = eet_data_descriptor_stream_new(&eddc);
2067  *    EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "a_number",
2068  *                                  a_number, EET_T_INT);
2069  *    EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "a_string",
2070  *                                  a_string, EET_T_STRING);
2071  *    EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "sub.other_num",
2072  *                                  sub.other_num, EET_T_INT);
2073  *    EET_DATA_DESCRIPTOR_ADD_BASIC(my_desc, some_struct, "sub.one_more",
2074  *                                  sub.one_more", EET_T_INT);
2075  *    ...
2076  * }
2077  * @endcode
2078  *
2079  * But this is not what we are here for today. When we talk about nested
2080  * structures, what we really want are things like lists and hashes to be
2081  * taken into consideration automatically, and all their contents saved and
2082  * loaded just like ordinary integers and strings are.
2083  *
2084  * And of course, Eet can do that, and considering the work it saves you as a
2085  * programmer, we could say it's even easier to do than handling just integers.
2086  *
2087  * Let's begin with our example then, which is not all too different from the
2088  * simple one introduced earlier.
2089  *
2090  * We won't ignore the headers this time to show how easy it is to use Eina
2091  * data types with Eet, but we'll still skip most of the code that is not
2092  * pertinent to what we want to show now, but as usual, you can get it full
2093  * by follwing @ref eet-data-nested.c "this link".
2094  *
2095  * @dontinclude eet-data-nested.c
2096  * @skipline Eina.h
2097  * @skipline Eet.h
2098  * @skip typedef struct
2099  * @until } My_Conf_Subtype
2100  *
2101  * Extremely similar to our previous example. Just a new struct in there, and
2102  * a pointer to a list in the one we already had. Handling a list of subtypes
2103  * is easy on our program, but now we'll see what Eet needs to work with them
2104  * (Hint: it's easy too).
2105  * @skip _my_conf_descriptor
2106  * @until _my_conf_sub_descriptor
2107  *
2108  * Since we have two structures now, it's only natural that we'll need two
2109  * descriptors. One for each, which will be defined exactly as before.
2110  * @skip static void
2111  * @until eddc
2112  * @skip EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET
2113  * @until _my_conf_sub_descriptor
2114  *
2115  * We create our descriptors, each for one type, and as before, we are going to
2116  * use a simple macro to set their contents, to save on typing.
2117  * @skip #define
2118  * @until EET_T_UCHAR
2119  *
2120  * So far, nothing new. We have our descriptors and we know already how to
2121  * save them separately. But what we want is to link them together, and even
2122  * more so, we want our main type to hold a list of more than one of the new
2123  * sub type. So how do we do that?
2124  *
2125  * Simple enough, we tell Eet that our main descriptor will hold a list, of
2126  * which each node will point to some type described by our new descriptor.
2127  * @skip EET_DATA_DESCRIPTOR_ADD_LIST
2128  * @until _my_conf_sub_descriptor
2129  *
2130  * And that's all. We are closing the function now so as to not leave dangling
2131  * curly braces, but there's nothing more to show in this example. Only other
2132  * additions are the necessary code to free our new data, but you can see it
2133  * in the full code listing.
2134  * @until }
2135  */
2136
2137 /**
2138  * @page eet_data_file_descriptor Advanced use of Eet Data Descriptors
2139  *
2140  * A real life example is usually the best way to see how things are used,
2141  * but they also involve a lot more code than what needs to be shown, so
2142  * instead of going that way, we'll be borrowing some pieces from one in
2143  * the following example. It's been slightly modified from the original
2144  * source to show more of the varied ways in which Eet can handle our data.
2145  *
2146  * @ref eet-data-file_descriptor_01.c "This example" shows a cache of user
2147  * accounts and messages received, and it's a bit more interactive than
2148  * previous examples.
2149  *
2150  * Let's begin by looking at the structures we'll be using. First we have
2151  * one to define the messages the user receives and one for the one he posts.
2152  * Straight forward and nothing new here.
2153  * @dontinclude eet-data-file_descriptor_01.c
2154  * @skip typedef
2155  * @until My_Post
2156  *
2157  * One more to declare the account itself. This one will contain a list of
2158  * all messages received, and the posts we make ourselves will be kept in an
2159  * array. No special reason other than to show how to use arrays with Eet.
2160  * @until My_Account
2161  *
2162  * Finally, the main structure to hold our cache of accounts. We'll be looking
2163  * for these accounts by their names, so let's keep them in a hash, using
2164  * that name as the key.
2165  * @until My_Cache
2166  *
2167  * As explained before, we need one descriptor for each struct we want Eet
2168  * to handle, but this time we also want to keep around our Eet file and its
2169  * string dictionary. You will see why in a moment.
2170  * @skip Eet_Data_Descriptor
2171  * @until _my_post_descriptor
2172  * @skip Eet_File
2173  * @until Eet_Dictionary
2174  *
2175  * The differences begin now. They aren't much, but we'll be creating our
2176  * descriptors differently. Things can be added to our cache, but we won't
2177  * be modifying the current contents, so we can consider the data read from
2178  * it to be read-only, and thus allow Eet to save time and memory by not
2179  * duplicating thins unnecessary.
2180  * @skip static void
2181  * @until _my_post_descriptor
2182  *
2183  * As the comment in the code explains, we are asking Eet to give us strings
2184  * directly from the mapped file, which avoids having to load it in memory
2185  * and data duplication.
2186  * Of course, there are things to take into account when doing things this
2187  * way, and they will be mentioned as we encounter those special cases.
2188  *
2189  * Next comes the actual description of our data, just like we did in the
2190  * previous examples.
2191  * @skip #define
2192  * @until #undef
2193  * @until #define
2194  * @until #undef
2195  *
2196  * And the account struct's description doesn't add much new, but it's worth
2197  * commenting on it.
2198  * @skip #define
2199  * @until _my_post_descriptor
2200  *
2201  * How to add a list we've seen before, but now we are also adding an array.
2202  * There's nothing really special about it, but it's important to note that
2203  * the EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY is used to add arrays of variable
2204  * length to a descriptor. That is, arrays just like the one we defined.
2205  * Since there's no way in C to know how long they are, we need to keep
2206  * track of the count ourselves and Eet needs to know how to do so as well.
2207  * That's what the @p posts_count member of our struct is for. When adding
2208  * our array member, this macro will look for another variable in the struct
2209  * named just like the array, but with @p _count attached to the end.
2210  * When saving our data, Eet will know how many elements the array contains
2211  * by looking into this count variable. When loading back from a file, this
2212  * variable will be set to the right number of elements.
2213  *
2214  * Another option for arrays is to use EET_DATA_DESCRIPTOR_ADD_ARRAY, which
2215  * takes care of fixed sized arrays.
2216  * For example, let's suppose that we want to keep track of only the last
2217  * ten posts the user sent, and we declare our account struct as follows
2218  * @code
2219  * typedef struct
2220  * {
2221  *    unsigned int id;
2222  *    const char  *name;
2223  *    Eina_List   *messages;
2224  *    My_Post      posts[10];
2225  * } My_Account;
2226  * @endcode
2227  * Then we would add the array to our descriptor with
2228  * @code
2229  * EET_DATA_DESCRIPTOR_ADD_ARRAY(_my_account_descriptor, My_Account, "posts",
2230  *                               posts, _my_post_descriptor);
2231  * @endcode
2232  *
2233  * Notice how this time we don't have a @p posts_count variable in our struct.
2234  * We could have it for the program to keep track of how many posts the
2235  * array actually contains, but Eet no longer needs it. Being defined that
2236  * way the array is already taking up all the memory needed for the ten
2237  * elements, and it is possible in C to determine how much it is in code.
2238  * When saving our data, Eet will just dump the entire memory blob into the
2239  * file, regardless of how much of it is really used. So it's important to
2240  * take into consideration this kind of things when defining your data types.
2241  * Each has its uses, its advantages and disadvantages and it's up to you
2242  * to decide which to use.
2243  *
2244  * Now, going back to our example, we have to finish adding our data to the
2245  * descriptors. We are only missing the main one for the cache, which
2246  * contains our hash of accounts.
2247  * Unless you are using your own hash functions when setting the descriptor
2248  * class, always use hashes with string type keys.
2249  * @skip #define
2250  * @until }
2251  *
2252  * If you remember, we told Eet not to duplicate memory when possible at the
2253  * time of loading back our data. But this doesn't mean everything will be
2254  * loaded straight from disk and we don't have to worry about freeing it.
2255  * Data in the Eet file is compressed and encoded, so it still needs to be
2256  * decoded and memory will be allocated to convert it back into something we
2257  * can use. We also need to take care of anything we add in the current
2258  * instance of the program.
2259  * To summarize, any string we get from Eet is likely to be a pointer to the
2260  * internal dictionary, and trying to free it will, in the best case, crash
2261  * our application right away.
2262  *
2263  * So how do we know if we have to free a string? We check if it's part of
2264  * the dictionary, and if it's not there we can be sure it's safe to get
2265  * rid of it.
2266  * @skip static void
2267  * @skip }
2268  * @skip static void
2269  * @until }
2270  *
2271  * See how this is used when adding a new message to our cache.
2272  * @skip static My_Message
2273  * @until return msg
2274  * @until free(msg)
2275  * @until }
2276  *
2277  * Skipping all the utility functions used by our program (remember you can
2278  * look at the full example @ref eet-data-file_descriptor_01.c "here") we get to
2279  * our cache loading code. Nothing out of the ordinary at first, just the
2280  * same old open file, read data using our main descriptor to decode it
2281  * into something we can use and check version of loaded data and if it doesn't
2282  * match, do something accordingly.
2283  * @skip static My_Cache
2284  * @until }
2285  * @until }
2286  * @until }
2287  *
2288  * Then comes the interesting part. Remember how we kept two more global
2289  * variables with our descriptors? One of them we already used to check if
2290  * it was right to free a string or not, but we didn't know where it came from.
2291  * Loading our data straight from the mmapped file means that we can't close
2292  * it until we are done using it, so we need to keep its handler around until
2293  * then. It also means that any changes done to the file can, and will,
2294  * invalidate all our pointers to the file backed data, so if we add something
2295  * and save the file, we need to reload our cache.
2296  *
2297  * Thus our load function checks if we had an open file, if there is it gets
2298  * closed and our variable is updated to the new handler. Then we get the
2299  * string dictionary we use to check if a string is part of it or not.
2300  * Updating any references to the cache data is up you as a programmer to
2301  * handle properly, there's nothing Eet can do in this situation.
2302  * @until }
2303  *
2304  * The save function doesn't have anything new, and all that's left after it
2305  * is the main program, which doesn't really have anything of interest within
2306  * the scope of what we are learning.
2307  */
2308
2309 /**
2310  * @addtogroup Eet_Data_Group
2311  * @{
2312  */
2313 #define EET_T_UNKNOW         0 /**< Unknown data encoding type */
2314 #define EET_T_CHAR           1 /**< Data type: char */
2315 #define EET_T_SHORT          2 /**< Data type: short */
2316 #define EET_T_INT            3 /**< Data type: int */
2317 #define EET_T_LONG_LONG      4 /**< Data type: long long */
2318 #define EET_T_FLOAT          5 /**< Data type: float */
2319 #define EET_T_DOUBLE         6 /**< Data type: double */
2320 #define EET_T_UCHAR          7 /**< Data type: unsigned char */
2321 #define EET_T_USHORT         8 /**< Data type: unsigned short */
2322 #define EET_T_UINT           9 /**< Data type: unsigned int */
2323 #define EET_T_ULONG_LONG     10 /**< Data type: unsigned long long */
2324 #define EET_T_STRING         11 /**< Data type: char * */
2325 #define EET_T_INLINED_STRING 12 /**< Data type: char * (but compressed inside the resulting eet) */
2326 #define EET_T_NULL           13 /**< Data type: (void *) (only use it if you know why) */
2327 #define EET_T_F32P32         14 /**< Data type: fixed point 32.32 */
2328 #define EET_T_F16P16         15 /**< Data type: fixed point 16.16 */
2329 #define EET_T_F8P24          16 /**< Data type: fixed point 8.24 */
2330 #define EET_T_LAST           18 /**< Last data type */
2331
2332 #define EET_G_UNKNOWN        100 /**< Unknown group data encoding type */
2333 #define EET_G_ARRAY          101 /**< Fixed size array group type */
2334 #define EET_G_VAR_ARRAY      102 /**< Variable size array group type */
2335 #define EET_G_LIST           103 /**< Linked list group type */
2336 #define EET_G_HASH           104 /**< Hash table group type */
2337 #define EET_G_UNION          105 /**< Union group type */
2338 #define EET_G_VARIANT        106 /**< Selectable subtype group */
2339 #define EET_G_LAST           107 /**< Last group type */
2340
2341 #define EET_I_LIMIT          128 /**< Other type exist but are reserved for internal purpose. */
2342
2343 /**
2344  * @typedef Eet_Data_Descriptor
2345  *
2346  * Opaque handle that have information on a type members.
2347  *
2348  * Descriptors are created using an #Eet_Data_Descriptor_Class, and they
2349  * describe the contents of the structure that will be serialized by Eet.
2350  * Not all members need be described by it, just those that should be handled
2351  * by Eet. This way it's possible to have one structure with both data to be
2352  * saved to a file, like application configuration, and runtime information
2353  * that would be meaningless to store, but is appropriate to keep together
2354  * during the program execution.
2355  * The members are added by means of
2356  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB(),
2357  * EET_DATA_DESCRIPTOR_ADD_LIST(), EET_DATA_DESCRIPTOR_ADD_HASH()
2358  * or eet_data_descriptor_element_add().
2359  *
2360  * @see eet_data_descriptor_stream_new()
2361  * @see eet_data_descriptor_file_new()
2362  * @see eet_data_descriptor_free()
2363  */
2364 typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
2365
2366 /**
2367  * @def EET_DATA_DESCRIPTOR_CLASS_VERSION
2368  * The version of #Eet_Data_Descriptor_Class at the time of the
2369  * distribution of the sources. One should define this to its
2370  * version member so it is compatible with abi changes, or at least
2371  * will not crash with them.
2372  */
2373 #define EET_DATA_DESCRIPTOR_CLASS_VERSION 4
2374
2375 /**
2376  * @typedef Eet_Data_Descriptor_Class
2377  *
2378  * Instructs Eet about memory management for different needs under
2379  * serialization and parse process.
2380  */
2381 typedef struct _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class;
2382
2383 typedef int                             (*Eet_Descriptor_Hash_Foreach_Callback_Callback)(void *h, const char *k, void *dt, void *fdt);
2384
2385 typedef void *                          (*Eet_Descriptor_Mem_Alloc_Callback)(size_t size);
2386 typedef void                            (*Eet_Descriptor_Mem_Free_Callback)(void *mem);
2387 typedef char *                          (*Eet_Descriptor_Str_Alloc_Callback)(const char *str);
2388 typedef void                            (*Eet_Descriptor_Str_Free_Callback)(const char *str);
2389 typedef void *                          (*Eet_Descriptor_List_Next_Callback)(void *l);
2390 typedef void *                          (*Eet_Descriptor_List_Append_Callback)(void *l, void *d);
2391 typedef void *                          (*Eet_Descriptor_List_Data_Callback)(void *l);
2392 typedef void *                          (*Eet_Descriptor_List_Free_Callback)(void *l);
2393 typedef void                            (*Eet_Descriptor_Hash_Foreach_Callback)(void *h, Eet_Descriptor_Hash_Foreach_Callback_Callback func, void *fdt);
2394 typedef void *                          (*Eet_Descriptor_Hash_Add_Callback)(void *h, const char *k, void *d);
2395 typedef void                            (*Eet_Descriptor_Hash_Free_Callback)(void *h);
2396 typedef char *                          (*Eet_Descriptor_Str_Direct_Alloc_Callback)(const char *str);
2397 typedef void                            (*Eet_Descriptor_Str_Direct_Free_Callback)(const char *str);
2398 typedef const char *                    (*Eet_Descriptor_Type_Get_Callback)(const void *data, Eina_Bool *unknow);
2399 typedef Eina_Bool                       (*Eet_Descriptor_Type_Set_Callback)(const char *type, void *data, Eina_Bool unknow);
2400 typedef void *                          (*Eet_Descriptor_Array_Alloc_Callback)(size_t size);
2401 typedef void                            (*Eet_Descriptor_Array_Free_Callback)(void *mem);
2402 /**
2403  * @struct _Eet_Data_Descriptor_Class
2404  *
2405  * Instructs Eet about memory management for different needs under
2406  * serialization and parse process.
2407  *
2408  * The list and hash methods match the Eina API, so for a more detalied
2409  * reference on them, look at the Eina_List and Eina_Hash documentation,
2410  * respectively.
2411  * For the most part these will be used with the standard Eina functions,
2412  * so using EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET() and
2413  * EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET() will set up everything
2414  * accordingly.
2415  */
2416 struct _Eet_Data_Descriptor_Class
2417 {
2418    int         version;  /**< ABI version. Should always be set to #EET_DATA_DESCRIPTOR_CLASS_VERSION */
2419    const char *name;  /**< Name of the user data type to be serialized */
2420    int         size;  /**< Size in bytes of the user data type to be serialized */
2421    struct
2422    {
2423       Eet_Descriptor_Mem_Alloc_Callback        mem_alloc; /**< how to allocate memory (usually malloc()) */
2424       Eet_Descriptor_Mem_Free_Callback         mem_free; /**< how to free memory (usually free()) */
2425       Eet_Descriptor_Str_Alloc_Callback        str_alloc; /**< how to allocate a string */
2426       Eet_Descriptor_Str_Free_Callback         str_free; /**< how to free a string */
2427       Eet_Descriptor_List_Next_Callback        list_next; /**< how to iterate to the next element of a list. Receives and should return the list node. */
2428       Eet_Descriptor_List_Append_Callback      list_append; /**< how to append data @p d to list which head node is @p l */
2429       Eet_Descriptor_List_Data_Callback        list_data; /**< retrieves the data from node @p l */
2430       Eet_Descriptor_List_Free_Callback        list_free; /**< free all the nodes from the list which head node is @p l */
2431       Eet_Descriptor_Hash_Foreach_Callback     hash_foreach; /**< iterates over all elements in the hash @p h in no specific order */
2432       Eet_Descriptor_Hash_Add_Callback         hash_add; /**< add a new data @p d with key @p k in hash @p h */
2433       Eet_Descriptor_Hash_Free_Callback        hash_free; /**< free all entries from the hash @p h */
2434       Eet_Descriptor_Str_Direct_Alloc_Callback str_direct_alloc; /**< how to allocate a string directly from file backed/mmaped region pointed by @p str */
2435       Eet_Descriptor_Str_Direct_Free_Callback  str_direct_free; /**< how to free a string returned by str_direct_alloc */
2436       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. */
2437       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 */
2438       Eet_Descriptor_Array_Alloc_Callback      array_alloc; /**< how to allocate memory for array (usually malloc()) */
2439       Eet_Descriptor_Array_Free_Callback       array_free; /**< how to free memory for array (usually free()) */
2440    } func;
2441 };
2442
2443 /**
2444  * @}
2445  */
2446
2447 /**
2448  * Create a new empty data structure descriptor.
2449  * @param name The string name of this data structure (most be a
2450  *        global constant and never change).
2451  * @param size The size of the struct (in bytes).
2452  * @param func_list_next The function to get the next list node.
2453  * @param func_list_append The function to append a member to a list.
2454  * @param func_list_data The function to get the data from a list node.
2455  * @param func_list_free The function to free an entire linked list.
2456  * @param func_hash_foreach The function to iterate through all
2457  *        hash table entries.
2458  * @param func_hash_add The function to add a member to a hash table.
2459  * @param func_hash_free The function to free an entire hash table.
2460  * @return A new empty data descriptor.
2461  *
2462  * This function creates a new data descriptore and returns a handle to the
2463  * new data descriptor. On creation it will be empty, containing no contents
2464  * describing anything other than the shell of the data structure.
2465  *
2466  * You add structure members to the data descriptor using the macros
2467  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2468  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2469  * adding to the description.
2470  *
2471  * Once you have described all the members of a struct you want loaded, or
2472  * saved eet can load and save those members for you, encode them into
2473  * endian-independent serialised data chunks for transmission across a
2474  * a network or more.
2475  *
2476  * The function pointers to the list and hash table functions are only
2477  * needed if you use those data types, else you can pass NULL instead.
2478  *
2479  * @since 1.0.0
2480  * @ingroup Eet_Data_Group
2481  *
2482  * @deprecated use eet_data_descriptor_stream_new() or
2483  *             eet_data_descriptor_file_new()
2484  */
2485 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2486 eet_data_descriptor_new(const char *name,
2487                         int size,
2488                         Eet_Descriptor_List_Next_Callback func_list_next,
2489                         Eet_Descriptor_List_Append_Callback func_list_append,
2490                         Eet_Descriptor_List_Data_Callback func_list_data,
2491                         Eet_Descriptor_List_Free_Callback func_list_free,
2492                         Eet_Descriptor_Hash_Foreach_Callback func_hash_foreach,
2493                         Eet_Descriptor_Hash_Add_Callback func_hash_add,
2494                         Eet_Descriptor_Hash_Free_Callback func_hash_free);
2495 /*
2496  * FIXME:
2497  *
2498  * moving to this api from the old above. this will break things when the
2499  * move happens - but be warned
2500  */
2501 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2502  eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc);
2503 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2504  eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc);
2505
2506 /**
2507  * This function creates a new data descriptor and returns a handle to the
2508  * new data descriptor. On creation it will be empty, containing no contents
2509  * describing anything other than the shell of the data structure.
2510  * @param eddc The class from where to create the data descriptor.
2511  * @return A handle to the new data descriptor.
2512  *
2513  * You add structure members to the data descriptor using the macros
2514  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2515  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2516  * adding to the description.
2517  *
2518  * Once you have described all the members of a struct you want loaded or
2519  * saved, eet can load and save those members for you, encode them into
2520  * endian-independent serialised data chunks for transmission across a
2521  * network or more.
2522  *
2523  * This function specially ignores str_direct_alloc and str_direct_free. It
2524  * is useful when the eet_data you are reading doesn't have a dictionary,
2525  * like network stream or IPC. It also mean that all string will be allocated
2526  * and duplicated in memory.
2527  *
2528  * @since 1.2.3
2529  * @ingroup Eet_Data_Group
2530  */
2531 EAPI Eet_Data_Descriptor *
2532 eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc);
2533
2534 /**
2535  * This function creates a new data descriptor and returns a handle to the
2536  * new data descriptor. On creation it will be empty, containing no contents
2537  * describing anything other than the shell of the data structure.
2538  * @param eddc The class from where to create the data descriptor.
2539  * @return A handle to the new data descriptor.
2540  *
2541  * You add structure members to the data descriptor using the macros
2542  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2543  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2544  * adding to the description.
2545  *
2546  * Once you have described all the members of a struct you want loaded or
2547  * savedi, eet can load and save those members for you, encode them into
2548  * endian-independent serialised data chunks for transmission across a
2549  * a network or more.
2550  *
2551  * This function uses str_direct_alloc and str_direct_free. It is
2552  * useful when the eet_data you are reading come from a file and
2553  * have a dictionary. This will reduce memory use and improve the
2554  * possibility for the OS to page this string out.
2555  * However, the load speed and memory saving comes with some drawbacks to keep
2556  * in mind. If you never modify the contents of the structures loaded from
2557  * the file, all you need to remember is that closing the eet file will make
2558  * the strings go away. On the other hand, should you need to free a string,
2559  * before doing so you have to verify that it's not part of the eet dictionary.
2560  * You can do this in the following way, assuming @p ef is a valid Eet_File
2561  * and @p str is a string loaded from said file.
2562  *
2563  * @code
2564  * void eet_string_free(Eet_File *ef, const char *str)
2565  * {
2566  *    Eet_Dictionary *dict = eet_dictionary_get(ef);
2567  *    if (dict && eet_dictionary_string_check(dict, str))
2568  *      {
2569  *         // The file contains a dictionary and the given string is a part of
2570  *         // of it, so we can't free it, just return.
2571  *         return;
2572  *      }
2573  *    // We assume eina_stringshare was used on the descriptor
2574  *    eina_stringshare_del(str);
2575  * }
2576  * @endcode
2577  *
2578  * @since 1.2.3
2579  * @ingroup Eet_Data_Group
2580  */
2581 EAPI Eet_Data_Descriptor *
2582 eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc);
2583
2584 /**
2585  * This function is an helper that set all the parameters of an
2586  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2587  * with a stream.
2588  * @param eddc The Eet_Data_Descriptor_Class you want to set.
2589  * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2590  * @param name The name of the structure described by this class.
2591  * @param size The size of the structure described by this class.
2592  * @return EINA_TRUE if the structure was correctly set (The only
2593  *         reason that could make it fail is if you did give wrong
2594  *         parameter).
2595  *
2596  * @note Unless there's a very specific reason to use this function directly,
2597  * the EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET macro is recommended.
2598  *
2599  * @since 1.2.3
2600  * @ingroup Eet_Data_Group
2601  */
2602 EAPI Eina_Bool
2603 eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2604                                           unsigned int eddc_size,
2605                                           const char *name,
2606                                           int size);
2607
2608 /**
2609  * This macro is an helper that set all the parameter of an
2610  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2611  * with stream.
2612  * @param clas The Eet_Data_Descriptor_Class you want to set.
2613  * @param type The type of the structure described by this class.
2614  * @return EINA_TRUE if the structure was correctly set (The only
2615  *         reason that could make it fail is if you did give wrong
2616  *         parameter).
2617  *
2618  * @see eet_data_descriptor_stream_new
2619  * @since 1.2.3
2620  * @ingroup Eet_Data_Group
2621  */
2622 #define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(clas, type) \
2623   (eet_eina_stream_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2624
2625 /**
2626  * This function is an helper that set all the parameter of an
2627  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2628  * with a file.
2629  * @param eddc The Eet_Data_Descriptor_Class you want to set.
2630  * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2631  * @param name The name of the structure described by this class.
2632  * @param size The size of the structure described by this class.
2633  * @return EINA_TRUE if the structure was correctly set (The only
2634  *         reason that could make it fail is if you did give wrong
2635  *         parameter).
2636  *
2637  * @note Unless there's a very specific reason to use this function directly,
2638  * the EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET macro is recommended.
2639  *
2640  * @since 1.2.3
2641  * @ingroup Eet_Data_Group
2642  */
2643 EAPI Eina_Bool
2644 eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2645                                         unsigned int eddc_size,
2646                                         const char *name,
2647                                         int size);
2648
2649 /**
2650  * This macro is an helper that set all the parameter of an
2651  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2652  * with file.
2653  * @param clas The Eet_Data_Descriptor_Class you want to set.
2654  * @param type The type of the structure described by this class.
2655  * @return EINA_TRUE if the structure was correctly set (The only
2656  *         reason that could make it fail is if you did give wrong
2657  *         parameter).
2658  *
2659  * @see eet_data_descriptor_file_new
2660  * @since 1.2.3
2661  * @ingroup Eet_Data_Group
2662  */
2663 #define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(clas, type) \
2664   (eet_eina_file_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2665
2666 /**
2667  * This function frees a data descriptor when it is not needed anymore.
2668  * @param edd The data descriptor to free.
2669  *
2670  * This function takes a data descriptor handle as a parameter and frees all
2671  * data allocated for the data descriptor and the handle itself. After this
2672  * call the descriptor is no longer valid.
2673  *
2674  * @since 1.0.0
2675  * @ingroup Eet_Data_Group
2676  */
2677 EAPI void
2678 eet_data_descriptor_free(Eet_Data_Descriptor *edd);
2679
2680 /**
2681  * This function is an internal used by macros.
2682  *
2683  * This function is used by macros EET_DATA_DESCRIPTOR_ADD_BASIC(),
2684  * EET_DATA_DESCRIPTOR_ADD_SUB() and EET_DATA_DESCRIPTOR_ADD_LIST(). It is
2685  * complex to use by hand and should be left to be used by the macros, and
2686  * thus is not documented.
2687  *
2688  * @param edd The data descriptor handle to add element (member).
2689  * @param name The name of element to be serialized.
2690  * @param type The type of element to be serialized, like
2691  *        #EET_T_INT. If #EET_T_UNKNOW, then it is considered to be a
2692  *        group, list or hash.
2693  * @param group_type If element type is #EET_T_UNKNOW, then the @p
2694  *        group_type will speficy if it is a list (#EET_G_LIST),
2695  *        array (#EET_G_ARRAY) and so on. If #EET_G_UNKNOWN, then
2696  *        the member is a subtype (pointer to another type defined by
2697  *        another #Eet_Data_Descriptor).
2698  * @param offset byte offset inside the source memory to be serialized.
2699  * @param count number of elements (if #EET_G_ARRAY or #EET_G_VAR_ARRAY).
2700  * @param counter_name variable that defines the name of number of elements.
2701  * @param subtype If contains a subtype, then its data descriptor.
2702  *
2703  * @since 1.0.0
2704  * @ingroup Eet_Data_Group
2705  */
2706 EAPI void
2707 eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
2708                                 const char *name,
2709                                 int type,
2710                                 int group_type,
2711                                 int offset,
2712      /* int                  count_offset, */
2713                                 int count,
2714                                 const char *counter_name,
2715                                 Eet_Data_Descriptor *subtype);
2716
2717 /**
2718  * Read a data structure from an eet file and decodes it.
2719  * @param ef The eet file handle to read from.
2720  * @param edd The data descriptor handle to use when decoding.
2721  * @param name The key the data is stored under in the eet file.
2722  * @return A pointer to the decoded data structure.
2723  *
2724  * This function decodes a data structure stored in an eet file, returning
2725  * a pointer to it if it decoded successfully, or NULL on failure. This
2726  * can save a programmer dozens of hours of work in writing configuration
2727  * file parsing and writing code, as eet does all that work for the program
2728  * and presents a program-friendly data structure, just as the programmer
2729  * likes. Eet can handle members being added or deleted from the data in
2730  * storage and safely zero-fills unfilled members if they were not found
2731  * in the data. It checks sizes and headers whenever it reads data, allowing
2732  * the programmer to not worry about corrupt data.
2733  *
2734  * Once a data structure has been described by the programmer with the
2735  * fields they wish to save or load, storing or retrieving a data structure
2736  * from an eet file, or from a chunk of memory is as simple as a single
2737  * function call.
2738  *
2739  * @see eet_data_read_cipher()
2740  *
2741  * @since 1.0.0
2742  * @ingroup Eet_Data_Group
2743  */
2744 EAPI void *
2745 eet_data_read(Eet_File *ef,
2746               Eet_Data_Descriptor *edd,
2747               const char *name);
2748
2749 /**
2750  * Write a data structure from memory and store in an eet file.
2751  * @param ef The eet file handle to write to.
2752  * @param edd The data descriptor to use when encoding.
2753  * @param name The key to store the data under in the eet file.
2754  * @param data A pointer to the data structure to ssave and encode.
2755  * @param compress Compression flags for storage.
2756  * @return bytes written on successful write, 0 on failure.
2757  *
2758  * This function is the reverse of eet_data_read(), saving a data structure
2759  * to an eet file. The file must have been opening in write mode and the data
2760  * will be kept in memory until the file is either closed or eet_sync() is
2761  * called to flush any unwritten changes.
2762  *
2763  * @see eet_data_write_cipher()
2764  *
2765  * @since 1.0.0
2766  * @ingroup Eet_Data_Group
2767  */
2768 EAPI int
2769 eet_data_write(Eet_File *ef,
2770                Eet_Data_Descriptor *edd,
2771                const char *name,
2772                const void *data,
2773                int compress);
2774
2775 typedef void (*Eet_Dump_Callback)(void *data, const char *str);
2776
2777 /**
2778  * Dump an eet encoded data structure into ascii text
2779  * @param data_in The pointer to the data to decode into a struct.
2780  * @param size_in The size of the data pointed to in bytes.
2781  * @param dumpfunc The function to call passed a string when new
2782  *        data is converted to text
2783  * @param dumpdata The data to pass to the @p dumpfunc callback.
2784  * @return 1 on success, 0 on failure
2785  *
2786  * This function will take a chunk of data encoded by
2787  * eet_data_descriptor_encode() and convert it into human readable
2788  * ascii text.  It does this by calling the @p dumpfunc callback
2789  * for all new text that is generated. This callback should append
2790  * to any existing text buffer and will be passed the pointer @p
2791  * dumpdata as a parameter as well as a string with new text to be
2792  * appended.
2793  *
2794  * Example:
2795  *
2796  * @code
2797  * void output(void *data, const char *string)
2798  * {
2799  *   printf("%s", string);
2800  * }
2801  *
2802  * void dump(const char *file)
2803  * {
2804  *   FILE *f;
2805  *   int len;
2806  *   void *data;
2807  *
2808  *   f = fopen(file, "r");
2809  *   fseek(f, 0, SEEK_END);
2810  *   len = ftell(f);
2811  *   rewind(f);
2812  *   data = malloc(len);
2813  *   fread(data, len, 1, f);
2814  *   fclose(f);
2815  *   eet_data_text_dump(data, len, output, NULL);
2816  * }
2817  * @endcode
2818  *
2819  * @see eet_data_text_dump_cipher()
2820  *
2821  * @since 1.0.0
2822  * @ingroup Eet_Data_Group
2823  */
2824 EAPI int
2825 eet_data_text_dump(const void *data_in,
2826                    int size_in,
2827                    Eet_Dump_Callback dumpfunc,
2828                    void *dumpdata);
2829
2830 /**
2831  * Take an ascii encoding from eet_data_text_dump() and re-encode in binary.
2832  * @param text The pointer to the string data to parse and encode.
2833  * @param textlen The size of the string in bytes (not including 0
2834  *        byte terminator).
2835  * @param size_ret This gets filled in with the encoded data blob
2836  *        size in bytes.
2837  * @return The encoded data on success, NULL on failure.
2838  *
2839  * This function will parse the string pointed to by @p text and return
2840  * an encoded data lump the same way eet_data_descriptor_encode() takes an
2841  * in-memory data struct and encodes into a binary blob. @p text is a normal
2842  * C string.
2843  *
2844  * @see eet_data_text_undump_cipher()
2845  *
2846  * @since 1.0.0
2847  * @ingroup Eet_Data_Group
2848  */
2849 EAPI void *
2850 eet_data_text_undump(const char *text,
2851                      int textlen,
2852                      int *size_ret);
2853
2854 /**
2855  * Dump an eet encoded data structure from an eet file into ascii text
2856  * @param ef A valid eet file handle.
2857  * @param name Name of the entry. eg: "/base/file_i_want".
2858  * @param dumpfunc The function to call passed a string when new
2859  *        data is converted to text
2860  * @param dumpdata The data to pass to the @p dumpfunc callback.
2861  * @return 1 on success, 0 on failure
2862  *
2863  * This function will take an open and valid eet file from
2864  * eet_open() request the data encoded by
2865  * eet_data_descriptor_encode() corresponding to the key @p name
2866  * and convert it into human readable ascii text. It does this by
2867  * calling the @p dumpfunc callback for all new text that is
2868  * generated. This callback should append to any existing text
2869  * buffer and will be passed the pointer @p dumpdata as a parameter
2870  * as well as a string with new text to be appended.
2871  *
2872  * @see eet_data_dump_cipher()
2873  *
2874  * @since 1.0.0
2875  * @ingroup Eet_Data_Group
2876  */
2877 EAPI int
2878 eet_data_dump(Eet_File *ef,
2879               const char *name,
2880               Eet_Dump_Callback dumpfunc,
2881               void *dumpdata);
2882
2883 /**
2884  * Take an ascii encoding from eet_data_dump() and re-encode in binary.
2885  * @param ef A valid eet file handle.
2886  * @param name Name of the entry. eg: "/base/file_i_want".
2887  * @param text The pointer to the string data to parse and encode.
2888  * @param textlen The size of the string in bytes (not including 0
2889  *        byte terminator).
2890  * @param compress Compression flags (1 == compress, 0 = don't compress).
2891  * @return 1 on success, 0 on failure
2892  *
2893  * This function will parse the string pointed to by @p text,
2894  * encode it the same way eet_data_descriptor_encode() takes an
2895  * in-memory data struct and encodes into a binary blob.
2896  *
2897  * The data (optionally compressed) will be in ram, pending a flush to
2898  * disk (it will stay in ram till the eet file handle is closed though).
2899  *
2900  * @see eet_data_undump_cipher()
2901  *
2902  * @since 1.0.0
2903  * @ingroup Eet_Data_Group
2904  */
2905 EAPI int
2906 eet_data_undump(Eet_File *ef,
2907                 const char *name,
2908                 const char *text,
2909                 int textlen,
2910                 int compress);
2911
2912 /**
2913  * Decode a data structure from an arbitrary location in memory.
2914  * @param edd The data  descriptor to use when decoding.
2915  * @param data_in The pointer to the data to decode into a struct.
2916  * @param size_in The size of the data pointed to in bytes.
2917  * @return NULL on failure, or a valid decoded struct pointer on success.
2918  *
2919  * This function will decode a data structure that has been encoded using
2920  * eet_data_descriptor_encode(), and return a data structure with all its
2921  * elements filled out, if successful, or NULL on failure.
2922  *
2923  * The data to be decoded is stored at the memory pointed to by @p data_in,
2924  * and is described by the descriptor pointed to by @p edd. The data size is
2925  * passed in as the value to @p size_in, ande must be greater than 0 to
2926  * succeed.
2927  *
2928  * This function is useful for decoding data structures delivered to the
2929  * application by means other than an eet file, such as an IPC or socket
2930  * connection, raw files, shared memory etc.
2931  *
2932  * Please see eet_data_read() for more information.
2933  *
2934  * @see eet_data_descriptor_decode_cipher()
2935  *
2936  * @since 1.0.0
2937  * @ingroup Eet_Data_Group
2938  */
2939 EAPI void *
2940 eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
2941                            const void *data_in,
2942                            int size_in);
2943
2944 /**
2945  * Encode a dsata struct to memory and return that encoded data.
2946  * @param edd The data  descriptor to use when encoding.
2947  * @param data_in The pointer to the struct to encode into data.
2948  * @param size_ret pointer to the an int to be filled with the decoded size.
2949  * @return NULL on failure, or a valid encoded data chunk on success.
2950  *
2951  * This function takes a data structutre in memory and encodes it into a
2952  * serialised chunk of data that can be decoded again by
2953  * eet_data_descriptor_decode(). This is useful for being able to transmit
2954  * data structures across sockets, pipes, IPC or shared file mechanisms,
2955  * without having to worry about memory space, machine type, endianess etc.
2956  *
2957  * The parameter @p edd must point to a valid data descriptor, and
2958  * @p data_in must point to the right data structure to encode. If not, the
2959  * encoding may fail.
2960  *
2961  * On success a non NULL valid pointer is returned and what @p size_ret
2962  * points to is set to the size of this decoded data, in bytes. When the
2963  * encoded data is no longer needed, call free() on it. On failure NULL is
2964  * returned and what @p size_ret points to is set to 0.
2965  *
2966  * Please see eet_data_write() for more information.
2967  *
2968  * @see eet_data_descriptor_encode_cipher()
2969  *
2970  * @since 1.0.0
2971  * @ingroup Eet_Data_Group
2972  */
2973 EAPI void *
2974 eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
2975                            const void *data_in,
2976                            int *size_ret);
2977
2978 /**
2979  * Add a basic data element to a data descriptor.
2980  * @param edd The data descriptor to add the type to.
2981  * @param struct_type The type of the struct.
2982  * @param name The string name to use to encode/decode this member
2983  *        (must be a constant global and never change).
2984  * @param member The struct member itself to be encoded.
2985  * @param type The type of the member to encode.
2986  *
2987  * This macro is a convenience macro provided to add a member to
2988  * the data descriptor @p edd. The type of the structure is
2989  * provided as the @p struct_type parameter (for example: struct
2990  * my_struct). The @p name parameter defines a string that will be
2991  * used to uniquely name that member of the struct (it is suggested
2992  * to use the struct member itself).  The @p member parameter is
2993  * the actual struct member itself (for example: values), and @p type is the
2994  * basic data type of the member which must be one of: EET_T_CHAR, EET_T_SHORT,
2995  * EET_T_INT, EET_T_LONG_LONG, EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR,
2996  * EET_T_USHORT, EET_T_UINT, EET_T_ULONG_LONG or EET_T_STRING.
2997  *
2998  * @since 1.0.0
2999  * @ingroup Eet_Data_Group
3000  */
3001 #define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type) \
3002   do {                                                                      \
3003        struct_type ___ett;                                                  \
3004        eet_data_descriptor_element_add(edd, name, type, EET_G_UNKNOWN,      \
3005                                        (char *)(& (___ett.member)) -        \
3006                                        (char *)(& (___ett)),                \
3007                                        0, /* 0,  */ NULL, NULL);            \
3008     } while(0)
3009
3010 /**
3011  * Add a sub-element type to a data descriptor
3012  * @param edd The data descriptor to add the type to.
3013  * @param struct_type The type of the struct.
3014  * @param name The string name to use to encode/decode this member
3015  *        (must be a constant global and never change).
3016  * @param member The struct member itself to be encoded.
3017  * @param subtype The type of sub-type struct to add.
3018  *
3019  * This macro lets you easily add a sub-type (a struct that's pointed to
3020  * by this one). All the parameters are the same as for
3021  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception.
3022  * This must be the data descriptor of the struct that is pointed to by
3023  * this element.
3024  *
3025  * @since 1.0.0
3026  * @ingroup Eet_Data_Group
3027  */
3028 #define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype)   \
3029   do {                                                                         \
3030        struct_type ___ett;                                                     \
3031        eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNKNOWN, \
3032                                        (char *)(& (___ett.member)) -           \
3033                                        (char *)(& (___ett)),                   \
3034                                        0, /* 0,  */ NULL, subtype);            \
3035     } while (0)
3036
3037 /**
3038  * Add a linked list type to a data descriptor
3039  * @param edd The data descriptor to add the type to.
3040  * @param struct_type The type of the struct.
3041  * @param name The string name to use to encode/decode this member
3042  *        (must be a constant global and never change).
3043  * @param member The struct member itself to be encoded.
3044  * @param subtype The type of linked list member to add.
3045  *
3046  * This macro lets you easily add a linked list of other data types. All the
3047  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
3048  * @p subtype being the exception. This must be the data descriptor of the
3049  * element that is in each member of the linked list to be stored.
3050  *
3051  * @since 1.0.0
3052  * @ingroup Eet_Data_Group
3053  */
3054 #define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype) \
3055   do {                                                                        \
3056        struct_type ___ett;                                                    \
3057        eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_LIST,   \
3058                                        (char *)(& (___ett.member)) -          \
3059                                        (char *)(& (___ett)),                  \
3060                                        0, /* 0,  */ NULL, subtype);           \
3061     } while (0)
3062
3063 /**
3064  * Add a linked list of string to a data descriptor
3065  * @param edd The data descriptor to add the type to.
3066  * @param struct_type The type of the struct.
3067  * @param name The string name to use to encode/decode this member
3068  *        (must be a constant global and never change).
3069  * @param member The struct member itself to be encoded.
3070  *
3071  * This macro lets you easily add a linked list of char *. All the
3072  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
3073  *
3074  * @since 1.5.0
3075  * @ingroup Eet_Data_Group
3076  */
3077 #define EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct_type, name, member) \
3078   do {                                                                      \
3079        struct_type ___ett;                                                  \
3080        eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_LIST, \
3081                                        (char *)(& (___ett.member)) -        \
3082                                        (char *)(& (___ett)),                \
3083                                        0, /* 0,  */ NULL, NULL);            \
3084     } while (0)
3085
3086 /**
3087  * Add a hash type to a data descriptor
3088  * @param edd The data descriptor to add the type to.
3089  * @param struct_type The type of the struct.
3090  * @param name The string name to use to encode/decode this member
3091  *        (must be a constant global and never change).
3092  * @param member The struct member itself to be encoded.
3093  * @param subtype The type of hash member to add.
3094  *
3095  * This macro lets you easily add a hash of other data types. All the
3096  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
3097  * @p subtype being the exception. This must be the data descriptor of the
3098  * element that is in each member of the hash to be stored.
3099  * The hash keys must be strings.
3100  *
3101  * @since 1.0.0
3102  * @ingroup Eet_Data_Group
3103  */
3104 #define EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype) \
3105   do {                                                                        \
3106        struct_type ___ett;                                                    \
3107        eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_HASH,   \
3108                                        (char *)(& (___ett.member)) -          \
3109                                        (char *)(& (___ett)),                  \
3110                                        0, /* 0,  */ NULL, subtype);           \
3111     } while (0)
3112
3113 /**
3114  * Add a hash of string to a data descriptor
3115  * @param edd The data descriptor to add the type to.
3116  * @param struct_type The type of the struct.
3117  * @param name The string name to use to encode/decode this member
3118  *        (must be a constant global and never change).
3119  * @param member The struct member itself to be encoded.
3120  *
3121  * This macro lets you easily add a hash of string elements. All the
3122  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_HASH().
3123  *
3124  * @since 1.3.4
3125  * @ingroup Eet_Data_Group
3126  */
3127 #define EET_DATA_DESCRIPTOR_ADD_HASH_STRING(edd, struct_type, name, member) \
3128   do {                                                                      \
3129        struct_type ___ett;                                                  \
3130        eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_HASH, \
3131                                        (char *)(& (___ett.member)) -        \
3132                                        (char *)(& (___ett)),                \
3133                                        0, /* 0,  */ NULL, NULL);            \
3134     } while (0)
3135
3136 /**
3137  * Add an array of basic data elements to a data descriptor.
3138  * @param edd The data descriptor to add the type to.
3139  * @param struct_type The type of the struct.
3140  * @param name The string name to use to encode/decode this member
3141  *        (must be a constant global and never change).
3142  * @param member The struct member itself to be encoded.
3143  * @param type The type of the member to encode.
3144  *
3145  * This macro lets you easily add a fixed size array of basic data
3146  * types. All the parameters are the same as for
3147  * EET_DATA_DESCRIPTOR_ADD_BASIC().
3148  * The array must be defined with a fixed size in the declaration of the
3149  * struct containing it.
3150  *
3151  * @since 1.5.0
3152  * @ingroup Eet_Data_Group
3153  */
3154 #define EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY(edd, struct_type, name, member, type) \
3155   do {                                                                            \
3156        struct_type ___ett;                                                        \
3157        eet_data_descriptor_element_add(edd, name, type, EET_G_ARRAY,              \
3158                                        (char *)(& (___ett.member)) -              \
3159                                        (char *)(& (___ett)),                      \
3160                                        sizeof(___ett.member) /                    \
3161                                        sizeof(___ett.member[0]),                  \
3162                                        NULL, NULL);                               \
3163     } while(0)
3164
3165 /**
3166  * Add a variable array of basic data elements to a data descriptor.
3167  * @param edd The data descriptor to add the type to.
3168  * @param struct_type The type of the struct.
3169  * @param name The string name to use to encode/decode this member
3170  *        (must be a constant global and never change).
3171  * @param member The struct member itself to be encoded.
3172  * @param type The type of the member to encode.
3173  *
3174  * This macro lets you easily add a variable size array of basic data
3175  * types. All the parameters are the same as for
3176  * EET_DATA_DESCRIPTOR_ADD_BASIC(). This assumes you have
3177  * a struct member (of type EET_T_INT) called member_count (note the
3178  * _count appended to the member) that holds the number of items in
3179  * the array. This array will be allocated separately to the struct it
3180  * is in.
3181  *
3182  * @since 1.6.0
3183  * @ingroup Eet_Data_Group
3184  */
3185 #define EET_DATA_DESCRIPTOR_ADD_BASIC_VAR_ARRAY(edd, struct_type, name, member, type) \
3186   do {                                                                                \
3187        struct_type ___ett;                                                            \
3188        eet_data_descriptor_element_add(edd, name, type, EET_G_VAR_ARRAY,              \
3189                                        (char *)(& (___ett.member)) -                  \
3190                                        (char *)(& (___ett)),                          \
3191                                        (char *)(& (___ett.member ## _count)) -        \
3192                                        (char *)(& (___ett)),                          \
3193                                        NULL,                                          \
3194                                        NULL);                                         \
3195     } while(0)
3196
3197 /**
3198  * Add a fixed size array type to a data descriptor
3199  * @param edd The data descriptor to add the type to.
3200  * @param struct_type The type of the struct.
3201  * @param name The string name to use to encode/decode this member
3202  *        (must be a constant global and never change).
3203  * @param member The struct member itself to be encoded.
3204  * @param subtype The type of hash member to add.
3205  *
3206  * This macro lets you easily add a fixed size array of other data
3207  * types. All the parameters are the same as for
3208  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
3209  * exception. This must be the data descriptor of the element that
3210  * is in each member of the array to be stored.
3211  * The array must be defined with a fixed size in the declaration of the
3212  * struct containing it.
3213  *
3214  * @since 1.0.2
3215  * @ingroup Eet_Data_Group
3216  */
3217 #define EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, struct_type, name, member, subtype)   \
3218   do {                                                                           \
3219        struct_type ___ett;                                                       \
3220        eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_ARRAY,     \
3221                                        (char *)(& (___ett.member)) -             \
3222                                        (char *)(& (___ett)),                     \
3223                                        /* 0,  */ sizeof(___ett.member) /         \
3224                                        sizeof(___ett.member[0]), NULL, subtype); \
3225     } while (0)
3226
3227 /**
3228  * Add a variable size array type to a data descriptor
3229  * @param edd The data descriptor to add the type to.
3230  * @param struct_type The type of the struct.
3231  * @param name The string name to use to encode/decode this member
3232  *        (must be a constant global and never change).
3233  * @param member The struct member itself to be encoded.
3234  * @param subtype The type of hash member to add.
3235  *
3236  * This macro lets you easily add a variable size array of other data
3237  * types. All the parameters are the same as for
3238  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
3239  * exception. This must be the data descriptor of the element that
3240  * is in each member of the array to be stored. This assumes you have
3241  * a struct member (of type EET_T_INT) called member_count (note the
3242  * _count appended to the member) that holds the number of items in
3243  * the array. This array will be allocated separately to the struct it
3244  * is in.
3245  *
3246  * @since 1.0.2
3247  * @ingroup Eet_Data_Group
3248  */
3249 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, struct_type, name, member, subtype) \
3250   do {                                                                             \
3251        struct_type ___ett;                                                         \
3252        eet_data_descriptor_element_add(edd,                                        \
3253                                        name,                                       \
3254                                        EET_T_UNKNOW,                               \
3255                                        EET_G_VAR_ARRAY,                            \
3256                                        (char *)(& (___ett.member)) -               \
3257                                        (char *)(& (___ett)),                       \
3258                                        (char *)(& (___ett.member ## _count)) -     \
3259                                        (char *)(& (___ett)),                       \
3260                                        /* 0,  */ NULL,                             \
3261                                        subtype);                                   \
3262     } while (0)
3263
3264 /**
3265  * Add a variable size array type to a data descriptor
3266  * @param edd The data descriptor to add the type to.
3267  * @param struct_type The type of the struct.
3268  * @param name The string name to use to encode/decode this member
3269  *        (must be a constant global and never change).
3270  * @param member The struct member itself to be encoded.
3271  *
3272  * This macro lets you easily add a variable size array of strings. All
3273  * the parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
3274  *
3275  * @since 1.4.0
3276  * @ingroup Eet_Data_Group
3277  */
3278 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY_STRING(edd, struct_type, name, member) \
3279   do {                                                                           \
3280        struct_type ___ett;                                                       \
3281        eet_data_descriptor_element_add(edd,                                      \
3282                                        name,                                     \
3283                                        EET_T_STRING,                             \
3284                                        EET_G_VAR_ARRAY,                          \
3285                                        (char *)(& (___ett.member)) -             \
3286                                        (char *)(& (___ett)),                     \
3287                                        (char *)(& (___ett.member ## _count)) -   \
3288                                        (char *)(& (___ett)),                     \
3289                                        /* 0,  */ NULL,                           \
3290                                        NULL);                                    \
3291     } while (0)
3292
3293 /**
3294  * Add an union type to a data descriptor
3295  * @param edd The data descriptor to add the type to.
3296  * @param struct_type The type of the struct.
3297  * @param name The string name to use to encode/decode this member
3298  *        (must be a constant global and never change).
3299  * @param member The struct member itself to be encoded.
3300  * @param type_member The member that give hints on what is in the union.
3301  * @param unified_type Describe all possible type the union could handle.
3302  *
3303  * This macro lets you easily add an union with a member that specify what is inside.
3304  * The @p unified_type is an Eet_Data_Descriptor, but only the entry that match the name
3305  * returned by type_get will be used for each serialized data. The type_get and type_set
3306  * callback of unified_type should be defined.
3307  *
3308  * @since 1.2.4
3309  * @ingroup Eet_Data_Group
3310  * @see Eet_Data_Descriptor_Class
3311  */
3312 #define EET_DATA_DESCRIPTOR_ADD_UNION(edd, struct_type, name, member, type_member, unified_type) \
3313   do {                                                                                           \
3314        struct_type ___ett;                                                                       \
3315        eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNION,                     \
3316                                        (char *)(& (___ett.member)) -                             \
3317                                        (char *)(& (___ett)),                                     \
3318                                        (char *)(& (___ett.type_member)) -                        \
3319                                        (char *)(& (___ett)),                                     \
3320                                        NULL, unified_type);                                      \
3321     } while (0)
3322
3323 /**
3324  * Add a automatically selectable type to a data descriptor
3325  * @param edd The data descriptor to add the type to.
3326  * @param struct_type The type of the struct.
3327  * @param name The string name to use to encode/decode this member
3328  *        (must be a constant global and never change).
3329  * @param member The struct member itself to be encoded.
3330  * @param type_member The member that give hints on what is in the union.
3331  * @param unified_type Describe all possible type the union could handle.
3332  *
3333  * This macro lets you easily define what the content of @p member points to depending of
3334  * the content of @p type_member. The type_get and type_set callback of unified_type should
3335  * be defined. If the the type is not know at the time of restoring it, eet will still call
3336  * type_set of @p unified_type but the pointer will be set to a serialized binary representation
3337  * of what eet know. This make it possible, to save this pointer again by just returning the string
3338  * given previously and telling it by setting unknow to EINA_TRUE.
3339  *
3340  * @since 1.2.4
3341  * @ingroup Eet_Data_Group
3342  * @see Eet_Data_Descriptor_Class
3343  */
3344 #define EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, struct_type, name, member, type_member, unified_type) \
3345   do {                                                                                             \
3346        struct_type ___ett;                                                                         \
3347        eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_VARIANT,                     \
3348                                        (char *)(& (___ett.member)) -                               \
3349                                        (char *)(& (___ett)),                                       \
3350                                        (char *)(& (___ett.type_member)) -                          \
3351                                        (char *)(& (___ett)),                                       \
3352                                        NULL, unified_type);                                        \
3353     } while (0)
3354
3355 /**
3356  * Add a mapping to a data descriptor that will be used by union, variant or inherited type
3357  * @param unified_type The data descriptor to add the mapping to.
3358  * @param name The string name to get/set type.
3359  * @param subtype The matching data descriptor.
3360  *
3361  * @since 1.2.4
3362  * @ingroup Eet_Data_Group
3363  * @see Eet_Data_Descriptor_Class
3364  */
3365 #define EET_DATA_DESCRIPTOR_ADD_MAPPING(unified_type, name, subtype) \
3366   eet_data_descriptor_element_add(unified_type,                      \
3367                                   name,                              \
3368                                   EET_T_UNKNOW,                      \
3369                                   EET_G_UNKNOWN,                     \
3370                                   0,                                 \
3371                                   0,                                 \
3372                                   NULL,                              \
3373                                   subtype)
3374
3375 /**
3376  * @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
3377  *
3378  * Most of the @ref Eet_Data_Group have alternative versions that
3379  * accounts for ciphers to protect their content.
3380  *
3381  * @see @ref Eet_Cipher_Group
3382  *
3383  * @ingroup Eet_Data_Group
3384  */
3385
3386 /**
3387  * Read a data structure from an eet file and decodes it using a cipher.
3388  * @param ef The eet file handle to read from.
3389  * @param edd The data descriptor handle to use when decoding.
3390  * @param name The key the data is stored under in the eet file.
3391  * @param cipher_key The key to use as cipher.
3392  * @return A pointer to the decoded data structure.
3393  *
3394  * This function decodes a data structure stored in an eet file, returning
3395  * a pointer to it if it decoded successfully, or NULL on failure. This
3396  * can save a programmer dozens of hours of work in writing configuration
3397  * file parsing and writing code, as eet does all that work for the program
3398  * and presents a program-friendly data structure, just as the programmer
3399  * likes. Eet can handle members being added or deleted from the data in
3400  * storage and safely zero-fills unfilled members if they were not found
3401  * in the data. It checks sizes and headers whenever it reads data, allowing
3402  * the programmer to not worry about corrupt data.
3403  *
3404  * Once a data structure has been described by the programmer with the
3405  * fields they wish to save or load, storing or retrieving a data structure
3406  * from an eet file, or from a chunk of memory is as simple as a single
3407  * function call.
3408  *
3409  * @see eet_data_read()
3410  *
3411  * @since 1.0.0
3412  * @ingroup Eet_Data_Cipher_Group
3413  */
3414 EAPI void *
3415 eet_data_read_cipher(Eet_File *ef,
3416                      Eet_Data_Descriptor *edd,
3417                      const char *name,
3418                      const char *cipher_key);
3419
3420 /**
3421  * Read a data structure from an eet extended attribute and decodes it using a cipher.
3422  * @param filename The file to extract the extended attribute from.
3423  * @param attribute The attribute to get the data from.
3424  * @param edd The data descriptor handle to use when decoding.
3425  * @param cipher_key The key to use as cipher.
3426  * @return A pointer to the decoded data structure.
3427  *
3428  * This function decodes a data structure stored in an eet extended attribute,
3429  * returning a pointer to it if it decoded successfully, or NULL on failure.
3430  * Eet can handle members being added or deleted from the data in
3431  * storage and safely zero-fills unfilled members if they were not found
3432  * in the data. It checks sizes and headers whenever it reads data, allowing
3433  * the programmer to not worry about corrupt data.
3434  *
3435  * Once a data structure has been described by the programmer with the
3436  * fields they wish to save or load, storing or retrieving a data structure
3437  * from an eet file, from a chunk of memory or from an extended attribute
3438  * is as simple as a single function call.
3439  *
3440  * @since 1.5.0
3441  * @ingroup Eet_Data_Cipher_Group
3442  */
3443 EAPI void *
3444 eet_data_xattr_cipher_get(const char *filename,
3445                           const char *attribute,
3446                           Eet_Data_Descriptor *edd,
3447                           const char *cipher_key);
3448
3449 /**
3450  * Write a data structure from memory and store in an eet file
3451  * using a cipher.
3452  * @param ef The eet file handle to write to.
3453  * @param edd The data descriptor to use when encoding.
3454  * @param name The key to store the data under in the eet file.
3455  * @param cipher_key The key to use as cipher.
3456  * @param data A pointer to the data structure to ssave and encode.
3457  * @param compress Compression flags for storage.
3458  * @return bytes written on successful write, 0 on failure.
3459  *
3460  * This function is the reverse of eet_data_read_cipher(), saving a data structure
3461  * to an eet file.
3462  *
3463  * @since 1.0.0
3464  * @ingroup Eet_Data_Cipher_Group
3465  */
3466 EAPI int
3467 eet_data_write_cipher(Eet_File *ef,
3468                       Eet_Data_Descriptor *edd,
3469                       const char *name,
3470                       const char *cipher_key,
3471                       const void *data,
3472                       int compress);
3473
3474 /**
3475  * Write a data structure from memory and store in an eet extended attribute
3476  * using a cipher.
3477  * @param filename The file to write the extended attribute to.
3478  * @param attribute The attribute to store the data to.
3479  * @param edd The data descriptor to use when encoding.
3480  * @param cipher_key The key to use as cipher.
3481  * @param data A pointer to the data structure to ssave and encode.
3482  * @param flags The policy to use when setting the data.
3483  * @return EINA_TRUE on success, EINA_FALSE on failure.
3484  *
3485  * This function is the reverse of eet_data_xattr_cipher_get(), saving a data structure
3486  * to an eet extended attribute.
3487  *
3488  * @since 1.5.0
3489  * @ingroup Eet_Data_Cipher_Group
3490  */
3491 EAPI Eina_Bool
3492 eet_data_xattr_cipher_set(const char *filename,
3493                           const char *attribute,
3494                           Eet_Data_Descriptor *edd,
3495                           const char *cipher_key,
3496                           const void *data,
3497                           Eina_Xattr_Flags flags);
3498
3499 /**
3500  * Dump an eet encoded data structure into ascii text using a cipher.
3501  * @param data_in The pointer to the data to decode into a struct.
3502  * @param cipher_key The key to use as cipher.
3503  * @param size_in The size of the data pointed to in bytes.
3504  * @param dumpfunc The function to call passed a string when new
3505  *        data is converted to text
3506  * @param dumpdata The data to pass to the @p dumpfunc callback.
3507  * @return 1 on success, 0 on failure
3508  *
3509  * This function will take a chunk of data encoded by
3510  * eet_data_descriptor_encode() and convert it into human readable
3511  * ascii text.  It does this by calling the @p dumpfunc callback
3512  * for all new text that is generated. This callback should append
3513  * to any existing text buffer and will be passed the pointer @p
3514  * dumpdata as a parameter as well as a string with new text to be
3515  * appended.
3516  *
3517  * Example:
3518  *
3519  * @code
3520  * void output(void *data, const char *string)
3521  * {
3522  *   printf("%s", string);
3523  * }
3524  *
3525  * void dump(const char *file)
3526  * {
3527  *   FILE *f;
3528  *   int len;
3529  *   void *data;
3530  *
3531  *   f = fopen(file, "r");
3532  *   fseek(f, 0, SEEK_END);
3533  *   len = ftell(f);
3534  *   rewind(f);
3535  *   data = malloc(len);
3536  *   fread(data, len, 1, f);
3537  *   fclose(f);
3538  *   eet_data_text_dump_cipher(data, cipher_key, len, output, NULL);
3539  * }
3540  * @endcode
3541  *
3542  * @see eet_data_text_dump()
3543  *
3544  * @since 1.0.0
3545  * @ingroup Eet_Data_Cipher_Group
3546  */
3547 EAPI int
3548 eet_data_text_dump_cipher(const void *data_in,
3549                           const char *cipher_key,
3550                           int size_in,
3551                           Eet_Dump_Callback dumpfunc,
3552                           void *dumpdata);
3553
3554 /**
3555  * Take an ascii encoding from eet_data_text_dump() and re-encode
3556  * in binary using a cipher.
3557  * @param text The pointer to the string data to parse and encode.
3558  * @param cipher_key The key to use as cipher.
3559  * @param textlen The size of the string in bytes (not including 0
3560  *        byte terminator).
3561  * @param size_ret This gets filled in with the encoded data blob
3562  *        size in bytes.
3563  * @return The encoded data on success, NULL on failure.
3564  *
3565  * This function will parse the string pointed to by @p text and return
3566  * an encoded data lump the same way eet_data_descriptor_encode() takes an
3567  * in-memory data struct and encodes into a binary blob. @p text is a normal
3568  * C string.
3569  *
3570  * @see eet_data_text_undump()
3571  *
3572  * @since 1.0.0
3573  * @ingroup Eet_Data_Cipher_Group
3574  */
3575 EAPI void *
3576 eet_data_text_undump_cipher(const char *text,
3577                             const char *cipher_key,
3578                             int textlen,
3579                             int *size_ret);
3580
3581 /**
3582  * Dump an eet encoded data structure from an eet file into ascii
3583  * text using a cipher.
3584  * @param ef A valid eet file handle.
3585  * @param name Name of the entry. eg: "/base/file_i_want".
3586  * @param cipher_key The key to use as cipher.
3587  * @param dumpfunc The function to call passed a string when new
3588  *        data is converted to text
3589  * @param dumpdata The data to pass to the @p dumpfunc callback.
3590  * @return 1 on success, 0 on failure
3591  *
3592  * This function will take an open and valid eet file from
3593  * eet_open() request the data encoded by
3594  * eet_data_descriptor_encode() corresponding to the key @p name
3595  * and convert it into human readable ascii text. It does this by
3596  * calling the @p dumpfunc callback for all new text that is
3597  * generated. This callback should append to any existing text
3598  * buffer and will be passed the pointer @p dumpdata as a parameter
3599  * as well as a string with new text to be appended.
3600  *
3601  * @see eet_data_dump()
3602  *
3603  * @since 1.0.0
3604  * @ingroup Eet_Data_Cipher_Group
3605  */
3606 EAPI int
3607 eet_data_dump_cipher(Eet_File *ef,
3608                      const char *name,
3609                      const char *cipher_key,
3610                      Eet_Dump_Callback dumpfunc,
3611                      void *dumpdata);
3612
3613 /**
3614  * Take an ascii encoding from eet_data_dump() and re-encode in
3615  * binary using a cipher.
3616  * @param ef A valid eet file handle.
3617  * @param name Name of the entry. eg: "/base/file_i_want".
3618  * @param cipher_key The key to use as cipher.
3619  * @param text The pointer to the string data to parse and encode.
3620  * @param textlen The size of the string in bytes (not including 0
3621  *        byte terminator).
3622  * @param compress Compression flags (1 == compress, 0 = don't compress).
3623  * @return 1 on success, 0 on failure
3624  *
3625  * This function will parse the string pointed to by @p text,
3626  * encode it the same way eet_data_descriptor_encode() takes an
3627  * in-memory data struct and encodes into a binary blob.
3628  *
3629  * The data (optionally compressed) will be in ram, pending a flush to
3630  * disk (it will stay in ram till the eet file handle is closed though).
3631  *
3632  * @see eet_data_undump()
3633  *
3634  * @since 1.0.0
3635  * @ingroup Eet_Data_Cipher_Group
3636  */
3637 EAPI int
3638 eet_data_undump_cipher(Eet_File *ef,
3639                        const char *name,
3640                        const char *cipher_key,
3641                        const char *text,
3642                        int textlen,
3643                        int compress);
3644
3645 /**
3646  * Decode a data structure from an arbitrary location in memory
3647  * using a cipher.
3648  * @param edd The data  descriptor to use when decoding.
3649  * @param data_in The pointer to the data to decode into a struct.
3650  * @param cipher_key The key to use as cipher.
3651  * @param size_in The size of the data pointed to in bytes.
3652  * @return NULL on failure, or a valid decoded struct pointer on success.
3653  *
3654  * This function will decode a data structure that has been encoded using
3655  * eet_data_descriptor_encode(), and return a data structure with all its
3656  * elements filled out, if successful, or NULL on failure.
3657  *
3658  * The data to be decoded is stored at the memory pointed to by @p data_in,
3659  * and is described by the descriptor pointed to by @p edd. The data size is
3660  * passed in as the value to @p size_in, ande must be greater than 0 to
3661  * succeed.
3662  *
3663  * This function is useful for decoding data structures delivered to the
3664  * application by means other than an eet file, such as an IPC or socket
3665  * connection, raw files, shared memory etc.
3666  *
3667  * Please see eet_data_read() for more information.
3668  *
3669  * @see eet_data_descriptor_decode()
3670  *
3671  * @since 1.0.0
3672  * @ingroup Eet_Data_Cipher_Group
3673  */
3674 EAPI void *
3675 eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
3676                                   const void *data_in,
3677                                   const char *cipher_key,
3678                                   int size_in);
3679
3680 /**
3681  * Encode a data struct to memory and return that encoded data
3682  * using a cipher.
3683  * @param edd The data  descriptor to use when encoding.
3684  * @param data_in The pointer to the struct to encode into data.
3685  * @param cipher_key The key to use as cipher.
3686  * @param size_ret pointer to the an int to be filled with the decoded size.
3687  * @return NULL on failure, or a valid encoded data chunk on success.
3688  *
3689  * This function takes a data structutre in memory and encodes it into a
3690  * serialised chunk of data that can be decoded again by
3691  * eet_data_descriptor_decode(). This is useful for being able to transmit
3692  * data structures across sockets, pipes, IPC or shared file mechanisms,
3693  * without having to worry about memory space, machine type, endianess etc.
3694  *
3695  * The parameter @p edd must point to a valid data descriptor, and
3696  * @p data_in must point to the right data structure to encode. If not, the
3697  * encoding may fail.
3698  *
3699  * On success a non NULL valid pointer is returned and what @p size_ret
3700  * points to is set to the size of this decoded data, in bytes. When the
3701  * encoded data is no longer needed, call free() on it. On failure NULL is
3702  * returned and what @p size_ret points to is set to 0.
3703  *
3704  * Please see eet_data_write() for more information.
3705  *
3706  * @see eet_data_descriptor_encode()
3707  *
3708  * @since 1.0.0
3709  * @ingroup Eet_Data_Cipher_Group
3710  */
3711 EAPI void *
3712 eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
3713                                   const void *data_in,
3714                                   const char *cipher_key,
3715                                   int *size_ret);
3716
3717 /**
3718  * @defgroup Eet_Node_Group Low-level Serialization Structures.
3719  *
3720  * Functions that create, destroy and manipulate serialization nodes
3721  * used by @ref Eet_Data_Group.
3722  *
3723  * @{
3724  */
3725
3726 /**
3727  * @typedef Eet_Node
3728  * Opaque handle to manage serialization node.
3729  */
3730 typedef struct _Eet_Node Eet_Node;
3731
3732 /**
3733  * @typedef Eet_Node_Data
3734  * Contains an union that can fit any kind of node.
3735  */
3736 typedef struct _Eet_Node_Data Eet_Node_Data;
3737
3738 /**
3739  * @struct _Eet_Node_Data
3740  * Contains an union that can fit any kind of node.
3741  */
3742 struct _Eet_Node_Data
3743 {
3744    union {
3745       char               c;
3746       short              s;
3747       int                i;
3748       long long          l;
3749       float              f;
3750       double             d;
3751       unsigned char      uc;
3752       unsigned short     us;
3753       unsigned int       ui;
3754       unsigned long long ul;
3755       const char        *str;
3756    } value;
3757 };
3758
3759 /**
3760  * @}
3761  */
3762
3763 /**
3764  * TODO FIX ME
3765  * @ingroup Eet_Node_Group
3766  */
3767 EAPI Eet_Node *
3768 eet_node_char_new(const char *name,
3769                   char c);
3770
3771 /**
3772  * TODO FIX ME
3773  * @ingroup Eet_Node_Group
3774  */
3775 EAPI Eet_Node *
3776 eet_node_short_new(const char *name,
3777                    short s);
3778
3779 /**
3780  * TODO FIX ME
3781  * @ingroup Eet_Node_Group
3782  */
3783 EAPI Eet_Node *
3784 eet_node_int_new(const char *name,
3785                  int i);
3786
3787 /**
3788  * TODO FIX ME
3789  * @ingroup Eet_Node_Group
3790  */
3791 EAPI Eet_Node *
3792 eet_node_long_long_new(const char *name,
3793                        long long l);
3794
3795 /**
3796  * TODO FIX ME
3797  * @ingroup Eet_Node_Group
3798  */
3799 EAPI Eet_Node *
3800 eet_node_float_new(const char *name,
3801                    float f);
3802
3803 /**
3804  * TODO FIX ME
3805  * @ingroup Eet_Node_Group
3806  */
3807 EAPI Eet_Node *
3808 eet_node_double_new(const char *name,
3809                     double d);
3810
3811 /**
3812  * TODO FIX ME
3813  * @ingroup Eet_Node_Group
3814  */
3815 EAPI Eet_Node *
3816 eet_node_unsigned_char_new(const char *name,
3817                            unsigned char uc);
3818
3819 /**
3820  * TODO FIX ME
3821  * @ingroup Eet_Node_Group
3822  */
3823 EAPI Eet_Node *
3824 eet_node_unsigned_short_new(const char *name,
3825                             unsigned short us);
3826
3827 /**
3828  * TODO FIX ME
3829  * @ingroup Eet_Node_Group
3830  */
3831 EAPI Eet_Node *
3832 eet_node_unsigned_int_new(const char *name,
3833                           unsigned int ui);
3834
3835 /**
3836  * TODO FIX ME
3837  * @ingroup Eet_Node_Group
3838  */
3839 EAPI Eet_Node *
3840 eet_node_unsigned_long_long_new(const char *name,
3841                                 unsigned long long l);
3842
3843 /**
3844  * TODO FIX ME
3845  * @ingroup Eet_Node_Group
3846  */
3847 EAPI Eet_Node *
3848 eet_node_string_new(const char *name,
3849                     const char *str);
3850
3851 /**
3852  * TODO FIX ME
3853  * @ingroup Eet_Node_Group
3854  */
3855 EAPI Eet_Node *
3856 eet_node_inlined_string_new(const char *name,
3857                             const char *str);
3858
3859 /**
3860  * TODO FIX ME
3861  * @ingroup Eet_Node_Group
3862  */
3863 EAPI Eet_Node *
3864 eet_node_null_new(const char *name);
3865
3866 /**
3867  * TODO FIX ME
3868  * @ingroup Eet_Node_Group
3869  */
3870 EAPI Eet_Node *
3871 eet_node_list_new(const char *name,
3872                   Eina_List *nodes);
3873
3874 /**
3875  * TODO FIX ME
3876  * @ingroup Eet_Node_Group
3877  */
3878 EAPI Eet_Node *
3879 eet_node_array_new(const char *name,
3880                    int count,
3881                    Eina_List *nodes);
3882
3883 /**
3884  * TODO FIX ME
3885  * @ingroup Eet_Node_Group
3886  */
3887 EAPI Eet_Node *
3888 eet_node_var_array_new(const char *name,
3889                        Eina_List *nodes);
3890
3891 /**
3892  * TODO FIX ME
3893  * @ingroup Eet_Node_Group
3894  */
3895 EAPI Eet_Node *
3896 eet_node_hash_new(const char *name,
3897                   const char *key,
3898                   Eet_Node *node);
3899
3900 /**
3901  * TODO FIX ME
3902  * @ingroup Eet_Node_Group
3903  */
3904 EAPI Eet_Node *
3905 eet_node_struct_new(const char *name,
3906                     Eina_List *nodes);
3907
3908 /**
3909  * TODO FIX ME
3910  * @ingroup Eet_Node_Group
3911  */
3912 EAPI Eet_Node *
3913 eet_node_struct_child_new(const char *parent,
3914                           Eet_Node *child);
3915
3916 /**
3917  * @brief Get a node's child nodes
3918  * @param node The node
3919  * @return The first child node which contains a pointer to the
3920  * next child node and the parent.
3921  * @since 1.5
3922  */
3923 EAPI Eet_Node *
3924 eet_node_children_get(Eet_Node *node);
3925
3926 /**
3927  * @brief Get the next node in a list of nodes
3928  * @param node The node
3929  * @return A node which contains a pointer to the
3930  * next child node and the parent.
3931  * @since 1.5
3932  */
3933 EAPI Eet_Node *
3934 eet_node_next_get(Eet_Node *node);
3935
3936 /**
3937  * @brief Get the parent node of a node
3938  * @param node The node
3939  * @return The parent node of @p node
3940  * @since 1.5
3941  */
3942 EAPI Eet_Node *
3943 eet_node_parent_get(Eet_Node *node);
3944
3945 /**
3946  * TODO FIX ME
3947  * @ingroup Eet_Node_Group
3948  */
3949 EAPI void
3950 eet_node_list_append(Eet_Node *parent,
3951                      const char *name,
3952                      Eet_Node *child);
3953
3954 /**
3955  * TODO FIX ME
3956  * @ingroup Eet_Node_Group
3957  */
3958 EAPI void
3959 eet_node_struct_append(Eet_Node *parent,
3960                        const char *name,
3961                        Eet_Node *child);
3962
3963 /**
3964  * TODO FIX ME
3965  * @ingroup Eet_Node_Group
3966  */
3967 EAPI void
3968 eet_node_hash_add(Eet_Node *parent,
3969                   const char *name,
3970                   const char *key,
3971                   Eet_Node *child);
3972
3973 /**
3974  * TODO FIX ME
3975  * @ingroup Eet_Node_Group
3976  */
3977 EAPI void
3978 eet_node_dump(Eet_Node *n,
3979               int dumplevel,
3980               Eet_Dump_Callback dumpfunc,
3981               void *dumpdata);
3982
3983 /**
3984  * @brief Return the type of a node
3985  * @param node The node
3986  * @return The node's type (EET_T_$TYPE)
3987  * @since 1.5
3988  */
3989 EAPI int
3990 eet_node_type_get(Eet_Node *node);
3991
3992 /**
3993  * @brief Return the node's data
3994  * @param node The node
3995  * @return The data contained in the node
3996  * @since 1.5
3997  */
3998 EAPI Eet_Node_Data *
3999 eet_node_value_get(Eet_Node *node);
4000
4001 /**
4002  * TODO FIX ME
4003  * @ingroup Eet_Node_Group
4004  */
4005 EAPI void
4006 eet_node_del(Eet_Node *n);
4007
4008 /**
4009  * TODO FIX ME
4010  * @ingroup Eet_Node_Group
4011  */
4012 EAPI void *
4013 eet_data_node_encode_cipher(Eet_Node *node,
4014                             const char *cipher_key,
4015                             int *size_ret);
4016
4017 /**
4018  * TODO FIX ME
4019  * @ingroup Eet_Node_Group
4020  */
4021 EAPI Eet_Node *
4022 eet_data_node_decode_cipher(const void *data_in,
4023                             const char *cipher_key,
4024                             int size_in);
4025
4026 /**
4027  * TODO FIX ME
4028  * @ingroup Eet_Node_Group
4029  */
4030 EAPI Eet_Node *
4031 eet_data_node_read_cipher(Eet_File *ef,
4032                           const char *name,
4033                           const char *cipher_key);
4034
4035 /**
4036  * TODO FIX ME
4037  * @ingroup Eet_Node_Group
4038  */
4039 EAPI int
4040 eet_data_node_write_cipher(Eet_File *ef,
4041                            const char *name,
4042                            const char *cipher_key,
4043                            Eet_Node *node,
4044                            int compress);
4045
4046 /* EXPERIMENTAL: THIS API MAY CHANGE IN THE FUTURE, USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING. */
4047
4048 /**
4049  * @typedef Eet_Node_Walk
4050  * Describes how to walk trees of #Eet_Node.
4051  */
4052 typedef struct _Eet_Node_Walk Eet_Node_Walk;
4053
4054 typedef void *              (*Eet_Node_Walk_Struct_Alloc_Callback)(const char *type, void *user_data);
4055 typedef void                (*Eet_Node_Walk_Struct_Add_Callback)(void *parent, const char *name, void *child, void *user_data);
4056 typedef void *              (*Eet_Node_Walk_Array_Callback)(Eina_Bool variable, const char *name, int count, void *user_data);
4057 typedef void                (*Eet_Node_Walk_Insert_Callback)(void *array, int index, void *child, void *user_data);
4058 typedef void *              (*Eet_Node_Walk_List_Callback)(const char *name, void *user_data);
4059 typedef void                (*Eet_Node_Walk_Append_Callback)(void *list, void *child, void *user_data);
4060 typedef void *              (*Eet_Node_Walk_Hash_Callback)(void *parent, const char *name, const char *key, void *value, void *user_data);
4061 typedef void *              (*Eet_Node_Walk_Simple_Callback)(int type, Eet_Node_Data *data, void *user_data);
4062
4063 /**
4064  * @struct _Eet_Node_Walk
4065  * Describes how to walk trees of #Eet_Node.
4066  */
4067 struct _Eet_Node_Walk
4068 {
4069    Eet_Node_Walk_Struct_Alloc_Callback struct_alloc;
4070    Eet_Node_Walk_Struct_Add_Callback   struct_add;
4071    Eet_Node_Walk_Array_Callback        array;
4072    Eet_Node_Walk_Insert_Callback       insert;
4073    Eet_Node_Walk_List_Callback         list;
4074    Eet_Node_Walk_Append_Callback       append;
4075    Eet_Node_Walk_Hash_Callback         hash;
4076    Eet_Node_Walk_Simple_Callback       simple;
4077 };
4078
4079 EAPI void *
4080 eet_node_walk(void *parent,
4081               const char *name,
4082               Eet_Node *root,
4083               Eet_Node_Walk *cb,
4084               void *user_data);
4085
4086 /*******/
4087
4088 /**
4089  * @defgroup Eet_Connection_Group Helper function to use eet over a network link
4090  *
4091  * Function that reconstruct and prepare packet of @ref Eet_Data_Group to be send.
4092  *
4093  */
4094
4095 /**
4096  * @typedef Eet_Connection
4097  * Opaque handle to track paquet for a specific connection.
4098  *
4099  * @ingroup Eet_Connection_Group
4100  */
4101 typedef struct _Eet_Connection Eet_Connection;
4102
4103 /**
4104  * @typedef Eet_Read_Cb
4105  * Called back when an @ref Eet_Data_Group has been received completly and could be used.
4106  *
4107  * @ingroup Eet_Connection_Group
4108  */
4109 typedef Eina_Bool Eet_Read_Cb (const void *eet_data, size_t size, void *user_data);
4110
4111 /**
4112  * @typedef Eet_Write_Cb
4113  * Called back when a packet containing @ref Eet_Data_Group data is ready to be send.
4114  *
4115  * @ingroup Eet_Connection_Group
4116  */
4117 typedef Eina_Bool Eet_Write_Cb (const void *data, size_t size, void *user_data);
4118
4119 /**
4120  * Instanciate a new connection to track.
4121  * @param eet_read_cb Function to call when one Eet_Data packet has been fully assemble.
4122  * @param eet_write_cb Function to call when one Eet_Data packet is ready to be send over the wire.
4123  * @param user_data Pointer provided to both functions to be used as a context handler.
4124  * @return NULL on failure, or a valid Eet_Connection handler.
4125  *
4126  * For every connection to track you will need a separate Eet_Connection provider.
4127  *
4128  * @since 1.2.4
4129  * @ingroup Eet_Connection_Group
4130  */
4131 EAPI Eet_Connection *
4132 eet_connection_new(Eet_Read_Cb *eet_read_cb,
4133                    Eet_Write_Cb *eet_write_cb,
4134                    const void *user_data);
4135
4136 /**
4137  * Process a raw packet received over the link
4138  * @param conn Connection handler to track.
4139  * @param data Raw data packet.
4140  * @param size The size of that packet.
4141  * @return 0 on complete success, any other value indicate where in the stream it got wrong (It could be before that packet).
4142  *
4143  * Every time you receive a packet related to your connection, you should pass
4144  * it to that function so that it could process and assemble packet has you
4145  * receive it. It will automatically call Eet_Read_Cb when one is fully received.
4146  *
4147  * @since 1.2.4
4148  * @ingroup Eet_Connection_Group
4149  */
4150 EAPI int
4151 eet_connection_received(Eet_Connection *conn,
4152                         const void *data,
4153                         size_t size);
4154
4155 /**
4156  * Convert a complex structure and prepare it to be send.
4157  * @param conn Connection handler to track.
4158  * @param edd The data descriptor to use when encoding.
4159  * @param data_in The pointer to the struct to encode into data.
4160  * @param cipher_key The key to use as cipher.
4161  * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
4162  *
4163  * This function serialize data_in with edd, assemble the packet and call
4164  * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
4165  * and will vanish just after the return of the callback.
4166  *
4167  * @see eet_data_descriptor_encode_cipher
4168  *
4169  * @since 1.2.4
4170  * @ingroup Eet_Connection_Group
4171  */
4172 EAPI Eina_Bool
4173 eet_connection_send(Eet_Connection *conn,
4174                     Eet_Data_Descriptor *edd,
4175                     const void *data_in,
4176                     const char *cipher_key);
4177
4178 /**
4179  * Convert a Eet_Node tree and prepare it to be send.
4180  * @param conn Connection handler to track.
4181  * @param node The data tree to use when encoding.
4182  * @param cipher_key The key to use as cipher.
4183  * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
4184  *
4185  * This function serialize node, assemble the packet and call
4186  * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
4187  * and will vanish just after the return of the callback.
4188  *
4189  * @see eet_data_node_encode_cipher
4190  *
4191  * @since 1.2.4
4192  * @ingroup Eet_Connection_Group
4193  */
4194 EAPI Eina_Bool
4195 eet_connection_node_send(Eet_Connection *conn,
4196                          Eet_Node *node,
4197                          const char *cipher_key);
4198
4199 /**
4200  * Close a connection and lost its track.
4201  * @param conn Connection handler to close.
4202  * @param on_going Signal if a partial packet wasn't completed.
4203  * @return the user_data passed to both callback.
4204  *
4205  * @since 1.2.4
4206  * @ingroup Eet_Connection_Group
4207  */
4208 EAPI void *
4209 eet_connection_close(Eet_Connection *conn,
4210                      Eina_Bool *on_going);
4211
4212 /***************************************************************************/
4213
4214 #ifdef __cplusplus
4215 }
4216 #endif /* ifdef __cplusplus */
4217
4218 #endif /* ifndef _EET_H */