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