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