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