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