svn update: 60246 (latest:60246)
[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 <Eina.h>
1882  * #include <Eet.h>
1883  *
1884  * typedef struct _blah2
1885  * {
1886  *    char *string;
1887  * } Blah2;
1888  *
1889  * typedef struct _blah3
1890  * {
1891  *    char *string;
1892  * } Blah3;
1893  *
1894  * typedef struct _blah
1895  * {
1896  *    char character;
1897  *    short sixteen;
1898  *    int integer;
1899  *    long long lots;
1900  *    float floating;
1901  *    double floating_lots;
1902  *    char *string;
1903  *    Blah2 *blah2;
1904  *    Eina_List *blah3;
1905  * } Blah;
1906  *
1907  * int
1908  * main(int argc, char **argv)
1909  * {
1910  *    Blah blah;
1911  *    Blah2 blah2;
1912  *    Blah3 blah3;
1913  *    Eet_Data_Descriptor *edd, *edd2, *edd3;
1914  *    Eet_Data_Descriptor_Class eddc, eddc2, eddc3;
1915  *    void *data;
1916  *    int size;
1917  *    FILE *f;
1918  *    Blah *blah_in;
1919  *
1920  *    eet_init();
1921  *
1922  *    EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc3, Blah3);
1923  *    edd3 = eet_data_descriptor_stream_new(&eddc3);
1924  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING);
1925  *
1926  *    EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc2, Blah2);
1927  *    edd2 = eet_data_descriptor_stream_new(&eddc2);
1928  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING);
1929  *
1930  *    EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Blah);
1931  *    edd = eet_data_descriptor_stream_new(&eddc);
1932  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "character", character, EET_T_CHAR);
1933  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "sixteen", sixteen, EET_T_SHORT);
1934  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "integer", integer, EET_T_INT);
1935  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "lots", lots, EET_T_LONG_LONG);
1936  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating", floating, EET_T_FLOAT);
1937  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating_lots", floating_lots, EET_T_DOUBLE);
1938  *    EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "string", string, EET_T_STRING);
1939  *    EET_DATA_DESCRIPTOR_ADD_SUB(edd, Blah, "blah2", blah2, edd2);
1940  *    EET_DATA_DESCRIPTOR_ADD_LIST(edd, Blah, "blah3", blah3, edd3);
1941  *
1942  *    blah3.string = "PANTS";
1943  *
1944  *    blah2.string = "subtype string here!";
1945  *
1946  *    blah.character = '7';
1947  *    blah.sixteen = 0x7777;
1948  *    blah.integer = 0xc0def00d;
1949  *    blah.lots = 0xdeadbeef31337777;
1950  *    blah.floating = 3.141592654;
1951  *    blah.floating_lots = 0.777777777777777;
1952  *    blah.string = "bite me like a turnip";
1953  *    blah.blah2 = &blah2;
1954  *    blah.blah3 = eina_list_append(NULL, &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  *    blah.blah3 = eina_list_append(blah.blah3, &blah3);
1961  *
1962  *    data = eet_data_descriptor_encode(edd, &blah, &size);
1963  *    printf("-----DECODING\n");
1964  *    blah_in = eet_data_descriptor_decode(edd, data, size);
1965  *
1966  *    printf("-----DECODED!\n");
1967  *    printf("%c\n", blah_in->character);
1968  *    printf("%x\n", (int)blah_in->sixteen);
1969  *    printf("%x\n", blah_in->integer);
1970  *    printf("%lx\n", blah_in->lots);
1971  *    printf("%f\n", (double)blah_in->floating);
1972  *    printf("%f\n", (double)blah_in->floating_lots);
1973  *    printf("%s\n", blah_in->string);
1974  *    printf("%p\n", blah_in->blah2);
1975  *    printf("  %s\n", blah_in->blah2->string);
1976  *      {
1977  *         Eina_List *l;
1978  *         Blah3 *blah3_in;
1979  *
1980  *         EINA_LIST_FOREACH(blah_in->blah3, l, blah3_in)
1981  *           {
1982  *              printf("%p\n", blah3_in);
1983  *              printf("  %s\n", blah3_in->string);
1984  *           }
1985  *      }
1986  *    eet_data_descriptor_free(edd);
1987  *    eet_data_descriptor_free(edd2);
1988  *    eet_data_descriptor_free(edd3);
1989  *
1990  *    eet_shutdown();
1991  *
1992  *   return 0;
1993  * }
1994  * @endcode
1995  *
1996  * @{
1997  */
1998 #define EET_T_UNKNOW         0 /**< Unknown data encoding type */
1999 #define EET_T_CHAR           1 /**< Data type: char */
2000 #define EET_T_SHORT          2 /**< Data type: short */
2001 #define EET_T_INT            3 /**< Data type: int */
2002 #define EET_T_LONG_LONG      4 /**< Data type: long long */
2003 #define EET_T_FLOAT          5 /**< Data type: float */
2004 #define EET_T_DOUBLE         6 /**< Data type: double */
2005 #define EET_T_UCHAR          7 /**< Data type: unsigned char */
2006 #define EET_T_USHORT         8 /**< Data type: unsigned short */
2007 #define EET_T_UINT           9 /**< Data type: unsigned int */
2008 #define EET_T_ULONG_LONG     10 /**< Data type: unsigned long long */
2009 #define EET_T_STRING         11 /**< Data type: char * */
2010 #define EET_T_INLINED_STRING 12 /**< Data type: char * (but compressed inside the resulting eet) */
2011 #define EET_T_NULL           13 /**< Data type: (void *) (only use it if you know why) */
2012 #define EET_T_F32P32         14 /**< Data type: fixed point 32.32 */
2013 #define EET_T_F16P16         15 /**< Data type: fixed point 16.16 */
2014 #define EET_T_F8P24          16 /**< Data type: fixed point 8.24 */
2015 #define EET_T_LAST           18 /**< Last data type */
2016
2017 #define EET_G_UNKNOWN        100 /**< Unknown group data encoding type */
2018 #define EET_G_ARRAY          101 /**< Fixed size array group type */
2019 #define EET_G_VAR_ARRAY      102 /**< Variable size array group type */
2020 #define EET_G_LIST           103 /**< Linked list group type */
2021 #define EET_G_HASH           104 /**< Hash table group type */
2022 #define EET_G_UNION          105 /**< Union group type */
2023 #define EET_G_VARIANT        106 /**< Selectable subtype group */
2024 #define EET_G_LAST           107 /**< Last group type */
2025
2026 #define EET_I_LIMIT          128 /**< Other type exist but are reserved for internal purpose. */
2027
2028 /**
2029  * @typedef Eet_Data_Descriptor
2030  *
2031  * Opaque handle that have information on a type members.
2032  *
2033  * The members are added by means of
2034  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB(),
2035  * EET_DATA_DESCRIPTOR_ADD_LIST(), EET_DATA_DESCRIPTOR_ADD_HASH()
2036  * or eet_data_descriptor_element_add().
2037  *
2038  * @see eet_data_descriptor_stream_new()
2039  * @see eet_data_descriptor_file_new()
2040  * @see eet_data_descriptor_free()
2041  */
2042 typedef struct _Eet_Data_Descriptor         Eet_Data_Descriptor;
2043
2044 /**
2045  * @def EET_DATA_DESCRIPTOR_CLASS_VERSION
2046  * The version of #Eet_Data_Descriptor_Class at the time of the
2047  * distribution of the sources. One should define this to its
2048  * version member so it is compatible with abi changes, or at least
2049  * will not crash with them.
2050  */
2051 #define EET_DATA_DESCRIPTOR_CLASS_VERSION 4
2052
2053 /**
2054  * @typedef Eet_Data_Descriptor_Class
2055  *
2056  * Instructs Eet about memory management for different needs under
2057  * serialization and parse process.
2058  */
2059 typedef struct _Eet_Data_Descriptor_Class   Eet_Data_Descriptor_Class;
2060
2061 typedef int         (*Eet_Descriptor_Hash_Foreach_Callback_Callback)(void *h, const char *k, void *dt, void *fdt);
2062   
2063 typedef void       *(*Eet_Descriptor_Mem_Alloc_Callback)(size_t size);
2064 typedef void        (*Eet_Descriptor_Mem_Free_Callback)(void *mem);
2065 typedef char       *(*Eet_Descriptor_Str_Alloc_Callback)(const char *str);
2066 typedef void        (*Eet_Descriptor_Str_Free_Callback)(const char *str);
2067 typedef void       *(*Eet_Descriptor_List_Next_Callback)(void *l);
2068 typedef void       *(*Eet_Descriptor_List_Append_Callback)(void *l, void *d);
2069 typedef void       *(*Eet_Descriptor_List_Data_Callback)(void *l);
2070 typedef void       *(*Eet_Descriptor_List_Free_Callback)(void *l);
2071 typedef void        (*Eet_Descriptor_Hash_Foreach_Callback)(void *h, Eet_Descriptor_Hash_Foreach_Callback_Callback func, void *fdt);
2072 typedef void       *(*Eet_Descriptor_Hash_Add_Callback)(void *h, const char *k, void *d);
2073 typedef void        (*Eet_Descriptor_Hash_Free_Callback)(void *h);
2074 typedef char       *(*Eet_Descriptor_Str_Direct_Alloc_Callback)(const char *str);
2075 typedef void        (*Eet_Descriptor_Str_Direct_Free_Callback)(const char *str);
2076 typedef const char *(*Eet_Descriptor_Type_Get_Callback)(const void *data, Eina_Bool *unknow);
2077 typedef Eina_Bool   (*Eet_Descriptor_Type_Set_Callback)(const char *type, void *data, Eina_Bool unknow);
2078 typedef void       *(*Eet_Descriptor_Array_Alloc_Callback)(size_t size);
2079 typedef void        (*Eet_Descriptor_Array_Free_Callback)(void *mem);
2080 /**
2081  * @struct _Eet_Data_Descriptor_Class
2082  *
2083  * Instructs Eet about memory management for different needs under
2084  * serialization and parse process.
2085  *
2086  * If using Eina data types, it is advised to use the helpers
2087  * EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET() and
2088  * EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET().
2089  */
2090 struct _Eet_Data_Descriptor_Class
2091 {
2092    int         version;  /**< ABI version as #EET_DATA_DESCRIPTOR_CLASS_VERSION */
2093    const char *name;  /**< Name of data type to be serialized */
2094    int         size;  /**< Size in bytes of data type to be serialized */
2095    struct {
2096      Eet_Descriptor_Mem_Alloc_Callback mem_alloc; /**< how to allocate memory (usually malloc()) */
2097      Eet_Descriptor_Mem_Free_Callback mem_free; /**< how to free memory (usually free()) */
2098      Eet_Descriptor_Str_Alloc_Callback str_alloc; /**< how to allocate a string */
2099      Eet_Descriptor_Str_Free_Callback str_free; /**< how to free a string */
2100      Eet_Descriptor_List_Next_Callback list_next; /**< how to iterate to the next element of a list. Receives and should return the list node. */
2101      Eet_Descriptor_List_Append_Callback list_append; /**< how to append data @p d to list which head node is @p l */
2102      Eet_Descriptor_List_Data_Callback list_data; /**< retrieves the data from node @p l */
2103      Eet_Descriptor_List_Free_Callback list_free; /**< free all the nodes from the list which head node is @p l */
2104      Eet_Descriptor_Hash_Foreach_Callback hash_foreach; /**< iterates over all elements in the hash @p h in no specific order */
2105      Eet_Descriptor_Hash_Add_Callback hash_add; /**< add a new data @p d as key @p k in hash @p h */
2106      Eet_Descriptor_Hash_Free_Callback hash_free; /**< free all entries from the hash @p h */
2107      Eet_Descriptor_Str_Direct_Alloc_Callback str_direct_alloc; /**< how to allocate a string directly from file backed/mmaped region pointed by @p str */
2108      Eet_Descriptor_Str_Direct_Free_Callback str_direct_free; /**< how to free a string returned by str_direct_alloc */
2109      Eet_Descriptor_Type_Get_Callback type_get; /**< convert any kind of data type to a name that define an Eet_Data_Element. */
2110      Eet_Descriptor_Type_Set_Callback type_set; /**< set the type at a particular address */
2111      Eet_Descriptor_Array_Alloc_Callback array_alloc; /**< how to allocate memory for array (usually malloc()) */
2112      Eet_Descriptor_Array_Free_Callback array_free; /**< how to free memory for array (usually free()) */
2113    } func;
2114 };
2115
2116 /**
2117  * @}
2118  */
2119
2120   
2121 /**
2122  * Create a new empty data structure descriptor.
2123  * @param name The string name of this data structure (most be a
2124  *        global constant and never change).
2125  * @param size The size of the struct (in bytes).
2126  * @param func_list_next The function to get the next list node.
2127  * @param func_list_append The function to append a member to a list.
2128  * @param func_list_data The function to get the data from a list node.
2129  * @param func_list_free The function to free an entire linked list.
2130  * @param func_hash_foreach The function to iterate through all
2131  *        hash table entries.
2132  * @param func_hash_add The function to add a member to a hash table.
2133  * @param func_hash_free The function to free an entire hash table.
2134  * @return A new empty data descriptor.
2135  *
2136  * This function creates a new data descriptore and returns a handle to the
2137  * new data descriptor. On creation it will be empty, containing no contents
2138  * describing anything other than the shell of the data structure.
2139  *
2140  * You add structure members to the data descriptor using the macros
2141  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2142  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2143  * adding to the description.
2144  *
2145  * Once you have described all the members of a struct you want loaded, or
2146  * saved eet can load and save those members for you, encode them into
2147  * endian-independent serialised data chunks for transmission across a
2148  * a network or more.
2149  *
2150  * The function pointers to the list and hash table functions are only
2151  * needed if you use those data types, else you can pass NULL instead.
2152  *
2153  * @since 1.0.0
2154  * @ingroup Eet_Data_Group
2155  *
2156  * @deprecated use eet_data_descriptor_stream_new() or
2157  *             eet_data_descriptor_file_new()
2158  */
2159 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2160 eet_data_descriptor_new(const char *name,
2161                         int size,
2162                         Eet_Descriptor_List_Next_Callback func_list_next,
2163                         Eet_Descriptor_List_Append_Callback func_list_append,
2164                         Eet_Descriptor_List_Data_Callback func_list_data,
2165                         Eet_Descriptor_List_Free_Callback func_list_free,
2166                         Eet_Descriptor_Hash_Foreach_Callback func_hash_foreach,
2167                         Eet_Descriptor_Hash_Add_Callback func_hash_add,
2168                         Eet_Descriptor_Hash_Free_Callback func_hash_free);
2169 /*
2170  * FIXME:
2171  *
2172  * moving to this api from the old above. this will break things when the
2173  * move happens - but be warned
2174  */
2175 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2176 eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc);
2177 EINA_DEPRECATED EAPI Eet_Data_Descriptor *
2178 eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc);
2179
2180 /**
2181  * This function creates a new data descriptore and returns a handle to the
2182  * new data descriptor. On creation it will be empty, containing no contents
2183  * describing anything other than the shell of the data structure.
2184  * @param eddc The data descriptor to free.
2185  *
2186  * You add structure members to the data descriptor using the macros
2187  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2188  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2189  * adding to the description.
2190  *
2191  * Once you have described all the members of a struct you want loaded, or
2192  * saved eet can load and save those members for you, encode them into
2193  * endian-independent serialised data chunks for transmission across a
2194  * a network or more.
2195  *
2196  * This function specially ignore str_direct_alloc and str_direct_free. It
2197  * is useful when the eet_data you are reading don't have a dictionnary
2198  * like network stream or ipc. It also mean that all string will be allocated
2199  * and duplicated in memory.
2200  *
2201  * @since 1.2.3
2202  * @ingroup Eet_Data_Group
2203  */
2204 EAPI Eet_Data_Descriptor *
2205 eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc);
2206
2207 /**
2208  * This function creates a new data descriptore and returns a handle to the
2209  * new data descriptor. On creation it will be empty, containing no contents
2210  * describing anything other than the shell of the data structure.
2211  * @param eddc The data descriptor to free.
2212  *
2213  * You add structure members to the data descriptor using the macros
2214  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
2215  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
2216  * adding to the description.
2217  *
2218  * Once you have described all the members of a struct you want loaded, or
2219  * saved eet can load and save those members for you, encode them into
2220  * endian-independent serialised data chunks for transmission across a
2221  * a network or more.
2222  *
2223  * This function use str_direct_alloc and str_direct_free. It is
2224  * useful when the eet_data you are reading come from a file and
2225  * have a dictionnary. This will reduce memory use, improve the
2226  * possibility for the OS to page this string out. But be carrefull
2227  * all EET_T_STRING are pointer to a mmapped area and it will point
2228  * to nowhere if you close the file. So as long as you use this
2229  * strings, you need to have the Eet_File open.
2230  *
2231  * @since 1.2.3
2232  * @ingroup Eet_Data_Group
2233  */
2234 EAPI Eet_Data_Descriptor *
2235 eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc);
2236
2237 /**
2238  * This function is an helper that set all the parameter of an
2239  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2240  * with a stream.
2241  * @param eddc The Eet_Data_Descriptor_Class you want to set.
2242  * @param name The name of the structure described by this class.
2243  * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2244  * @param size The size of the structure described by this class.
2245  * @return EINA_TRUE if the structure was correctly set (The only
2246  *         reason that could make it fail is if you did give wrong
2247  *         parameter).
2248  *
2249  * @since 1.2.3
2250  * @ingroup Eet_Data_Group
2251  */
2252 EAPI Eina_Bool
2253 eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2254                                           unsigned int               eddc_size,
2255                                           const char                *name,
2256                                           int                        size);
2257
2258 /**
2259  * This macro is an helper that set all the parameter of an
2260  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2261  * with stream.
2262  * @param clas The Eet_Data_Descriptor_Class you want to set.
2263  * @param type The type of the structure described by this class.
2264  * @return EINA_TRUE if the structure was correctly set (The only
2265  *         reason that could make it fail is if you did give wrong
2266  *         parameter).
2267  *
2268  * @since 1.2.3
2269  * @ingroup Eet_Data_Group
2270  */
2271 #define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(clas, type)\
2272    (eet_eina_stream_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2273
2274 /**
2275  * This function is an helper that set all the parameter of an
2276  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2277  * with a file.
2278  * @param eddc The Eet_Data_Descriptor_Class you want to set.
2279  * @param eddc_size The size of the Eet_Data_Descriptor_Class at the compilation time.
2280  * @param name The name of the structure described by this class.
2281  * @param size The size of the structure described by this class.
2282  * @return EINA_TRUE if the structure was correctly set (The only
2283  *         reason that could make it fail is if you did give wrong
2284  *         parameter).
2285  *
2286  * @since 1.2.3
2287  * @ingroup Eet_Data_Group
2288  */
2289 EAPI Eina_Bool
2290 eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
2291                                         unsigned int               eddc_size,
2292                                         const char                *name,
2293                                         int                        size);
2294
2295 /**
2296  * This macro is an helper that set all the parameter of an
2297  * Eet_Data_Descriptor_Class correctly when you use Eina data type
2298  * with file.
2299  * @param clas The Eet_Data_Descriptor_Class you want to set.
2300  * @param type The type of the structure described by this class.
2301  * @return EINA_TRUE if the structure was correctly set (The only
2302  *         reason that could make it fail is if you did give wrong
2303  *         parameter).
2304  *
2305  * @since 1.2.3
2306  * @ingroup Eet_Data_Group
2307  */
2308 #define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(clas, type)\
2309   (eet_eina_file_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
2310
2311 /**
2312  * This function frees a data descriptor when it is not needed anymore.
2313  * @param edd The data descriptor to free.
2314  *
2315  * This function takes a data descriptor handle as a parameter and frees all
2316  * data allocated for the data descriptor and the handle itself. After this
2317  * call the descriptor is no longer valid.
2318  *
2319  * @since 1.0.0
2320  * @ingroup Eet_Data_Group
2321  */
2322 EAPI void
2323 eet_data_descriptor_free(Eet_Data_Descriptor *edd);
2324
2325 /**
2326  * This function is an internal used by macros.
2327  *
2328  * This function is used by macros EET_DATA_DESCRIPTOR_ADD_BASIC(),
2329  * EET_DATA_DESCRIPTOR_ADD_SUB() and EET_DATA_DESCRIPTOR_ADD_LIST(). It is
2330  * complex to use by hand and should be left to be used by the macros, and
2331  * thus is not documented.
2332  *
2333  * @param edd The data descriptor handle to add element (member).
2334  * @param name The name of element to be serialized.
2335  * @param type The type of element to be serialized, like
2336  *        #EET_T_INT. If #EET_T_UNKNOW, then it is considered to be a
2337  *        group, list or hash.
2338  * @param group_type If element type is #EET_T_UNKNOW, then the @p
2339  *        group_type will speficy if it is a list (#EET_G_LIST),
2340  *        array (#EET_G_ARRAY) and so on. If #EET_G_UNKNOWN, then
2341  *        the member is a subtype (pointer to another type defined by
2342  *        another #Eet_Data_Descriptor).
2343  * @param offset byte offset inside the source memory to be serialized.
2344  * @param count number of elements (if #EET_G_ARRAY or #EET_G_VAR_ARRAY).
2345  * @param counter_name variable that defines the name of number of elements.
2346  * @param subtype If contains a subtype, then its data descriptor.
2347  *
2348  * @since 1.0.0
2349  * @ingroup Eet_Data_Group
2350  */
2351 EAPI void
2352 eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
2353                                 const char          *name,
2354                                 int                  type,
2355                                 int                  group_type,
2356                                 int                  offset,
2357                                 /* int                  count_offset, */
2358                                 int                  count,
2359                                 const char          *counter_name,
2360                                 Eet_Data_Descriptor *subtype);
2361
2362 /**
2363  * Read a data structure from an eet file and decodes it.
2364  * @param ef The eet file handle to read from.
2365  * @param edd The data descriptor handle to use when decoding.
2366  * @param name The key the data is stored under in the eet file.
2367  * @return A pointer to the decoded data structure.
2368  *
2369  * This function decodes a data structure stored in an eet file, returning
2370  * a pointer to it if it decoded successfully, or NULL on failure. This
2371  * can save a programmer dozens of hours of work in writing configuration
2372  * file parsing and writing code, as eet does all that work for the program
2373  * and presents a program-friendly data structure, just as the programmer
2374  * likes. Eet can handle members being added or deleted from the data in
2375  * storage and safely zero-fills unfilled members if they were not found
2376  * in the data. It checks sizes and headers whenever it reads data, allowing
2377  * the programmer to not worry about corrupt data.
2378  *
2379  * Once a data structure has been described by the programmer with the
2380  * fields they wish to save or load, storing or retrieving a data structure
2381  * from an eet file, or from a chunk of memory is as simple as a single
2382  * function call.
2383  *
2384  * @see eet_data_read_cipher()
2385  *
2386  * @since 1.0.0
2387  * @ingroup Eet_Data_Group
2388  */
2389 EAPI void *
2390 eet_data_read(Eet_File            *ef,
2391               Eet_Data_Descriptor *edd,
2392               const char          *name);
2393
2394 /**
2395  * Write a data structure from memory and store in an eet file.
2396  * @param ef The eet file handle to write to.
2397  * @param edd The data descriptor to use when encoding.
2398  * @param name The key to store the data under in the eet file.
2399  * @param data A pointer to the data structure to ssave and encode.
2400  * @param compress Compression flags for storage.
2401  * @return bytes written on successful write, 0 on failure.
2402  *
2403  * This function is the reverse of eet_data_read(), saving a data structure
2404  * to an eet file.
2405  *
2406  * @see eet_data_write_cipher()
2407  *
2408  * @since 1.0.0
2409  * @ingroup Eet_Data_Group
2410  */
2411 EAPI int
2412 eet_data_write(Eet_File            *ef,
2413                Eet_Data_Descriptor *edd,
2414                const char          *name,
2415                const void          *data,
2416                int                  compress);
2417
2418 typedef void (*Eet_Dump_Callback)(void *data, const char *str);
2419
2420 /**
2421  * Dump an eet encoded data structure into ascii text
2422  * @param data_in The pointer to the data to decode into a struct.
2423  * @param size_in The size of the data pointed to in bytes.
2424  * @param dumpfunc The function to call passed a string when new
2425  *        data is converted to text
2426  * @param dumpdata The data to pass to the @p dumpfunc callback.
2427  * @return 1 on success, 0 on failure
2428  *
2429  * This function will take a chunk of data encoded by
2430  * eet_data_descriptor_encode() and convert it into human readable
2431  * ascii text.  It does this by calling the @p dumpfunc callback
2432  * for all new text that is generated. This callback should append
2433  * to any existing text buffer and will be passed the pointer @p
2434  * dumpdata as a parameter as well as a string with new text to be
2435  * appended.
2436  *
2437  * Example:
2438  *
2439  * @code
2440  * void output(void *data, const char *string)
2441  * {
2442  *   printf("%s", string);
2443  * }
2444  *
2445  * void dump(const char *file)
2446  * {
2447  *   FILE *f;
2448  *   int len;
2449  *   void *data;
2450  *
2451  *   f = fopen(file, "r");
2452  *   fseek(f, 0, SEEK_END);
2453  *   len = ftell(f);
2454  *   rewind(f);
2455  *   data = malloc(len);
2456  *   fread(data, len, 1, f);
2457  *   fclose(f);
2458  *   eet_data_text_dump(data, len, output, NULL);
2459  * }
2460  * @endcode
2461  *
2462  * @see eet_data_text_dump_cipher()
2463  *
2464  * @since 1.0.0
2465  * @ingroup Eet_Data_Group
2466  */
2467 EAPI int
2468 eet_data_text_dump(const void  *data_in,
2469                    int          size_in,
2470                    Eet_Dump_Callback dumpfunc,
2471                    void        *dumpdata);
2472
2473 /**
2474  * Take an ascii encoding from eet_data_text_dump() and re-encode in binary.
2475  * @param text The pointer to the string data to parse and encode.
2476  * @param textlen The size of the string in bytes (not including 0
2477  *        byte terminator).
2478  * @param size_ret This gets filled in with the encoded data blob
2479  *        size in bytes.
2480  * @return The encoded data on success, NULL on failure.
2481  *
2482  * This function will parse the string pointed to by @p text and return
2483  * an encoded data lump the same way eet_data_descriptor_encode() takes an
2484  * in-memory data struct and encodes into a binary blob. @p text is a normal
2485  * C string.
2486  *
2487  * @see eet_data_text_undump_cipher()
2488  *
2489  * @since 1.0.0
2490  * @ingroup Eet_Data_Group
2491  */
2492 EAPI void *
2493 eet_data_text_undump(const char *text,
2494                      int         textlen,
2495                      int        *size_ret);
2496
2497 /**
2498  * Dump an eet encoded data structure from an eet file into ascii text
2499  * @param ef A valid eet file handle.
2500  * @param name Name of the entry. eg: "/base/file_i_want".
2501  * @param dumpfunc The function to call passed a string when new
2502  *        data is converted to text
2503  * @param dumpdata The data to pass to the @p dumpfunc callback.
2504  * @return 1 on success, 0 on failure
2505  *
2506  * This function will take an open and valid eet file from
2507  * eet_open() request the data encoded by
2508  * eet_data_descriptor_encode() corresponding to the key @p name
2509  * and convert it into human readable ascii text. It does this by
2510  * calling the @p dumpfunc callback for all new text that is
2511  * generated. This callback should append to any existing text
2512  * buffer and will be passed the pointer @p dumpdata as a parameter
2513  * as well as a string with new text to be appended.
2514  *
2515  * @see eet_data_dump_cipher()
2516  *
2517  * @since 1.0.0
2518  * @ingroup Eet_Data_Group
2519  */
2520 EAPI int
2521 eet_data_dump(Eet_File    *ef,
2522               const char  *name,
2523               Eet_Dump_Callback dumpfunc,
2524               void        *dumpdata);
2525
2526 /**
2527  * Take an ascii encoding from eet_data_dump() and re-encode in binary.
2528  * @param ef A valid eet file handle.
2529  * @param name Name of the entry. eg: "/base/file_i_want".
2530  * @param text The pointer to the string data to parse and encode.
2531  * @param textlen The size of the string in bytes (not including 0
2532  *        byte terminator).
2533  * @param compress Compression flags (1 == compress, 0 = don't compress).
2534  * @return 1 on success, 0 on failure
2535  *
2536  * This function will parse the string pointed to by @p text,
2537  * encode it the same way eet_data_descriptor_encode() takes an
2538  * in-memory data struct and encodes into a binary blob.
2539  *
2540  * The data (optionally compressed) will be in ram, pending a flush to
2541  * disk (it will stay in ram till the eet file handle is closed though).
2542  *
2543  * @see eet_data_undump_cipher()
2544  *
2545  * @since 1.0.0
2546  * @ingroup Eet_Data_Group
2547  */
2548 EAPI int
2549 eet_data_undump(Eet_File   *ef,
2550                 const char *name,
2551                 const char *text,
2552                 int         textlen,
2553                 int         compress);
2554
2555 /**
2556  * Decode a data structure from an arbitrary location in memory.
2557  * @param edd The data  descriptor to use when decoding.
2558  * @param data_in The pointer to the data to decode into a struct.
2559  * @param size_in The size of the data pointed to in bytes.
2560  * @return NULL on failure, or a valid decoded struct pointer on success.
2561  *
2562  * This function will decode a data structure that has been encoded using
2563  * eet_data_descriptor_encode(), and return a data structure with all its
2564  * elements filled out, if successful, or NULL on failure.
2565  *
2566  * The data to be decoded is stored at the memory pointed to by @p data_in,
2567  * and is described by the descriptor pointed to by @p edd. The data size is
2568  * passed in as the value to @p size_in, ande must be greater than 0 to
2569  * succeed.
2570  *
2571  * This function is useful for decoding data structures delivered to the
2572  * application by means other than an eet file, such as an IPC or socket
2573  * connection, raw files, shared memory etc.
2574  *
2575  * Please see eet_data_read() for more information.
2576  *
2577  * @see eet_data_descriptor_decode_cipher()
2578  *
2579  * @since 1.0.0
2580  * @ingroup Eet_Data_Group
2581  */
2582 EAPI void *
2583 eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
2584                            const void          *data_in,
2585                            int                  size_in);
2586
2587 /**
2588  * Encode a dsata struct to memory and return that encoded data.
2589  * @param edd The data  descriptor to use when encoding.
2590  * @param data_in The pointer to the struct to encode into data.
2591  * @param size_ret pointer to the an int to be filled with the decoded size.
2592  * @return NULL on failure, or a valid encoded data chunk on success.
2593  *
2594  * This function takes a data structutre in memory and encodes it into a
2595  * serialised chunk of data that can be decoded again by
2596  * eet_data_descriptor_decode(). This is useful for being able to transmit
2597  * data structures across sockets, pipes, IPC or shared file mechanisms,
2598  * without having to worry about memory space, machine type, endianess etc.
2599  *
2600  * The parameter @p edd must point to a valid data descriptor, and
2601  * @p data_in must point to the right data structure to encode. If not, the
2602  * encoding may fail.
2603  *
2604  * On success a non NULL valid pointer is returned and what @p size_ret
2605  * points to is set to the size of this decoded data, in bytes. When the
2606  * encoded data is no longer needed, call free() on it. On failure NULL is
2607  * returned and what @p size_ret points to is set to 0.
2608  *
2609  * Please see eet_data_write() for more information.
2610  *
2611  * @see eet_data_descriptor_encode_cipher()
2612  *
2613  * @since 1.0.0
2614  * @ingroup Eet_Data_Group
2615  */
2616 EAPI void *
2617 eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
2618                            const void          *data_in,
2619                            int                 *size_ret);
2620
2621 /**
2622  * Add a basic data element to a data descriptor.
2623  * @param edd The data descriptor to add the type to.
2624  * @param struct_type The type of the struct.
2625  * @param name The string name to use to encode/decode this member
2626  *        (must be a constant global and never change).
2627  * @param member The struct member itself to be encoded.
2628  * @param type The type of the member to encode.
2629  *
2630  * This macro is a convenience macro provided to add a member to
2631  * the data descriptor @p edd. The type of the structure is
2632  * provided as the @p struct_type parameter (for example: struct
2633  * my_struct). The @p name parameter defines a string that will be
2634  * used to uniquely name that member of the struct (it is suggested
2635  * to use the struct member itself).  The @p member parameter is
2636  * the actual struct member itself (for eet_dictionary_string_check
2637  * example: values), and @p type is the basic data type of the
2638  * member which must be one of: EET_T_CHAR, EET_T_SHORT, EET_T_INT,
2639  * EET_T_LONG_LONG, EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR,
2640  * EET_T_USHORT, EET_T_UINT, EET_T_ULONG_LONG or EET_T_STRING.
2641  *
2642  * @since 1.0.0
2643  * @ingroup Eet_Data_Group
2644  */
2645 #define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type) \
2646    do { \
2647       struct_type ___ett; \
2648       eet_data_descriptor_element_add(edd, name, type, EET_G_UNKNOWN, \
2649                                       (char *)(& (___ett.member)) - \
2650                                       (char *)(& (___ett)), \
2651                                       0, /* 0,  */ NULL, NULL); \
2652    } while(0)
2653
2654 /**
2655  * Add a sub-element type to a data descriptor
2656  * @param edd The data descriptor to add the type to.
2657  * @param struct_type The type of the struct.
2658  * @param name The string name to use to encode/decode this member
2659  *        (must be a constant global and never change).
2660  * @param member The struct member itself to be encoded.
2661  * @param subtype The type of sub-type struct to add.
2662  *
2663  * This macro lets you easily add a sub-type (a struct that's pointed to
2664  * by this one). All the parameters are the same as for
2665  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception.
2666  * This must be the data descriptor of the struct that is pointed to by
2667  * this element.
2668  *
2669  * @since 1.0.0
2670  * @ingroup Eet_Data_Group
2671  */
2672 #define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype) \
2673    do { \
2674       struct_type ___ett; \
2675       eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNKNOWN, \
2676                                       (char *)(& (___ett.member)) - \
2677                                       (char *)(& (___ett)), \
2678                                       0, /* 0,  */ NULL, subtype); \
2679    } while (0)
2680
2681 /**
2682  * Add a linked list type to a data descriptor
2683  * @param edd The data descriptor to add the type to.
2684  * @param struct_type The type of the struct.
2685  * @param name The string name to use to encode/decode this member
2686  *        (must be a constant global and never change).
2687  * @param member The struct member itself to be encoded.
2688  * @param subtype The type of linked list member to add.
2689  *
2690  * This macro lets you easily add a linked list of other data types. All the
2691  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
2692  * @p subtype being the exception. This must be the data descriptor of the
2693  * element that is in each member of the linked list to be stored.
2694  *
2695  * @since 1.0.0
2696  * @ingroup Eet_Data_Group
2697  */
2698 #define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype) \
2699    do { \
2700       struct_type ___ett; \
2701       eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_LIST, \
2702                                       (char *)(& (___ett.member)) - \
2703                                       (char *)(& (___ett)), \
2704                                       0, /* 0,  */ NULL, subtype); \
2705    } while (0)
2706
2707 /**
2708  * Add a linked list of string to a data descriptor
2709  * @param edd The data descriptor to add the type to.
2710  * @param struct_type The type of the struct.
2711  * @param name The string name to use to encode/decode this member
2712  *        (must be a constant global and never change).
2713  * @param member The struct member itself to be encoded.
2714  *
2715  * This macro lets you easily add a linked list of char *. All the
2716  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
2717  *
2718  * @since 1.5.0
2719  * @ingroup Eet_Data_Group
2720  */
2721 #define EET_DATA_DESCRIPTOR_ADD_LIST_STRING(edd, struct_type, name, member) \
2722    do { \
2723       struct_type ___ett; \
2724       eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_LIST, \
2725                                       (char *)(& (___ett.member)) - \
2726                                       (char *)(& (___ett)), \
2727                                       0, /* 0,  */ NULL, NULL); \
2728    } while (0)
2729
2730 /**
2731  * Add a hash type to a data descriptor
2732  * @param edd The data descriptor to add the type to.
2733  * @param struct_type The type of the struct.
2734  * @param name The string name to use to encode/decode this member
2735  *        (must be a constant global and never change).
2736  * @param member The struct member itself to be encoded.
2737  * @param subtype The type of hash member to add.
2738  *
2739  * This macro lets you easily add a hash of other data types. All the
2740  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
2741  * @p subtype being the exception. This must be the data descriptor of the
2742  * element that is in each member of the hash to be stored.
2743  *
2744  * @since 1.0.0
2745  * @ingroup Eet_Data_Group
2746  */
2747 #define EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype) \
2748    do { \
2749       struct_type ___ett; \
2750       eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_HASH, \
2751                                       (char *)(& (___ett.member)) - \
2752                                       (char *)(& (___ett)), \
2753                                       0, /* 0,  */ NULL, subtype); \
2754    } while (0)
2755
2756 /**
2757  * Add a hash of string to a data descriptor
2758  * @param edd The data descriptor to add the type to.
2759  * @param struct_type The type of the struct.
2760  * @param name The string name to use to encode/decode this member
2761  *        (must be a constant global and never change).
2762  * @param member The struct member itself to be encoded.
2763  *
2764  * This macro lets you easily add a hash of string. All the
2765  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
2766  *
2767  * @since 1.3.4
2768  * @ingroup Eet_Data_Group
2769  */
2770 #define EET_DATA_DESCRIPTOR_ADD_HASH_STRING(edd, struct_type, name, member) \
2771    do { \
2772       struct_type ___ett; \
2773       eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_HASH, \
2774                                       (char *)(& (___ett.member)) - \
2775                                       (char *)(& (___ett)), \
2776                                       0, /* 0,  */ NULL, NULL); \
2777    } while (0)
2778
2779 /**
2780  * Add a fixed size array type to a data descriptor
2781  * @param edd The data descriptor to add the type to.
2782  * @param struct_type The type of the struct.
2783  * @param name The string name to use to encode/decode this member
2784  *        (must be a constant global and never change).
2785  * @param member The struct member itself to be encoded.
2786  * @param subtype The type of hash member to add.
2787  *
2788  * This macro lets you easily add a fixed size array of other data
2789  * types. All the parameters are the same as for
2790  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
2791  * exception. This must be the data descriptor of the element that
2792  * is in each member of the hash to be stored.
2793  *
2794  * @since 1.0.2
2795  * @ingroup Eet_Data_Group
2796  */
2797 #define EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, struct_type, name, member, subtype) \
2798    do { \
2799       struct_type ___ett; \
2800       eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_ARRAY, \
2801                                       (char *)(& (___ett.member)) - \
2802                                       (char *)(& (___ett)), \
2803                                       /* 0,  */ sizeof(___ett.member) / \
2804                                       sizeof(___ett.member[0]), NULL, subtype); \
2805    } while (0)
2806
2807 /**
2808  * Add a variable size array type to a data descriptor
2809  * @param edd The data descriptor to add the type to.
2810  * @param struct_type The type of the struct.
2811  * @param name The string name to use to encode/decode this member
2812  *        (must be a constant global and never change).
2813  * @param member The struct member itself to be encoded.
2814  * @param subtype The type of hash member to add.
2815  *
2816  * This macro lets you easily add a fixed size array of other data
2817  * types. All the parameters are the same as for
2818  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
2819  * exception. This must be the data descriptor of the element that
2820  * is in each member of the hash to be stored. This assumes you have
2821  * a struct member (of type EET_T_INT) called member_count (note the
2822  * _count appended to the member) that holds the number of items in
2823  * the array. This array will be allocated separately to the struct it
2824  * is in.
2825  *
2826  * @since 1.0.2
2827  * @ingroup Eet_Data_Group
2828  */
2829 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, struct_type, name, member, subtype) \
2830    do { \
2831       struct_type ___ett; \
2832       eet_data_descriptor_element_add(edd, \
2833                                       name, \
2834                                       EET_T_UNKNOW, \
2835                                       EET_G_VAR_ARRAY, \
2836                                       (char *)(& (___ett.member)) - \
2837                                       (char *)(& (___ett)), \
2838                                       (char *)(& (___ett.member ## _count)) - \
2839                                       (char *)(& (___ett)), \
2840                                       /* 0,  */ NULL, \
2841                                       subtype); \
2842    } while (0)
2843
2844 /**
2845  * Add a variable size array type to a data descriptor
2846  * @param edd The data descriptor to add the type to.
2847  * @param struct_type The type of the struct.
2848  * @param name The string name to use to encode/decode this member
2849  *        (must be a constant global and never change).
2850  * @param member The struct member itself to be encoded.
2851  *
2852  * This macro lets you easily add a fixed size array of string. All
2853  * the parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
2854  *
2855  * @since 1.4.0
2856  * @ingroup Eet_Data_Group
2857  */
2858 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY_STRING(edd, struct_type, name, member) \
2859    do { \
2860       struct_type ___ett; \
2861       eet_data_descriptor_element_add(edd, \
2862                                       name, \
2863                                       EET_T_STRING, \
2864                                       EET_G_VAR_ARRAY, \
2865                                       (char *)(& (___ett.member)) - \
2866                                       (char *)(& (___ett)), \
2867                                       (char *)(& (___ett.member ## _count)) - \
2868                                       (char *)(& (___ett)), \
2869                                       /* 0,  */ NULL, \
2870                                       NULL); \
2871    } while (0)
2872
2873 /**
2874  * Add an union type to a data descriptor
2875  * @param edd The data descriptor to add the type to.
2876  * @param struct_type The type of the struct.
2877  * @param name The string name to use to encode/decode this member
2878  *        (must be a constant global and never change).
2879  * @param member The struct member itself to be encoded.
2880  * @param type_member The member that give hints on what is in the union.
2881  * @param unified_type Describe all possible type the union could handle.
2882  *
2883  * This macro lets you easily add an union with a member that specify what is inside.
2884  * The @p unified_type is an Eet_Data_Descriptor, but only the entry that match the name
2885  * returned by type_get will be used for each serialized data. The type_get and type_set
2886  * callback of unified_type should be defined.
2887  *
2888  * @since 1.2.4
2889  * @ingroup Eet_Data_Group
2890  * @see Eet_Data_Descriptor_Class
2891  */
2892 #define EET_DATA_DESCRIPTOR_ADD_UNION(edd, struct_type, name, member, type_member, unified_type) \
2893    do { \
2894       struct_type ___ett; \
2895       eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNION, \
2896                                       (char *)(& (___ett.member)) - \
2897                                       (char *)(& (___ett)), \
2898                                       (char *)(& (___ett.type_member)) - \
2899                                       (char *)(& (___ett)), \
2900                                       NULL, unified_type); \
2901    } while (0)
2902    
2903 /**
2904  * Add a automatically selectable type to a data descriptor
2905  * @param edd The data descriptor to add the type to.
2906  * @param struct_type The type of the struct.
2907  * @param name The string name to use to encode/decode this member
2908  *        (must be a constant global and never change).
2909  * @param member The struct member itself to be encoded.
2910  * @param type_member The member that give hints on what is in the union.
2911  * @param unified_type Describe all possible type the union could handle.
2912  *
2913  * This macro lets you easily define what the content of @p member points to depending of
2914  * the content of @p type_member. The type_get and type_set callback of unified_type should
2915  * be defined. If the the type is not know at the time of restoring it, eet will still call
2916  * type_set of @p unified_type but the pointer will be set to a serialized binary representation
2917  * of what eet know. This make it possible, to save this pointer again by just returning the string
2918  * given previously and telling it by setting unknow to EINA_TRUE.
2919  *
2920  * @since 1.2.4
2921  * @ingroup Eet_Data_Group
2922  * @see Eet_Data_Descriptor_Class
2923  */
2924 #define EET_DATA_DESCRIPTOR_ADD_VARIANT(edd, struct_type, name, member, type_member, unified_type) \
2925    do { \
2926       struct_type ___ett; \
2927       eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_VARIANT, \
2928                                       (char *)(& (___ett.member)) - \
2929                                       (char *)(& (___ett)), \
2930                                       (char *)(& (___ett.type_member)) - \
2931                                       (char *)(& (___ett)), \
2932                                       NULL, unified_type); \
2933    } while (0)
2934    
2935 /**
2936  * Add a mapping to a data descriptor that will be used by union, variant or inherited type
2937  * @param unified_type The data descriptor to add the mapping to.
2938  * @param name The string name to get/set type.
2939  * @param subtype The matching data descriptor.
2940  *
2941  * @since 1.2.4
2942  * @ingroup Eet_Data_Group
2943  * @see Eet_Data_Descriptor_Class
2944  */
2945 #define EET_DATA_DESCRIPTOR_ADD_MAPPING(unified_type, name, subtype) \
2946    eet_data_descriptor_element_add(unified_type, \
2947                                    name, \
2948                                    EET_T_UNKNOW, \
2949                                    EET_G_UNKNOWN, \
2950                                    0, \
2951                                    0, \
2952                                    NULL, \
2953                                    subtype)
2954
2955 /**
2956  * @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
2957  *
2958  * Most of the @ref Eet_Data_Group have alternative versions that
2959  * accounts for ciphers to protect their content.
2960  *
2961  * @see @ref Eet_Cipher_Group
2962  *
2963  * @ingroup Eet_Data_Group
2964  */
2965
2966 /**
2967  * Read a data structure from an eet file and decodes it using a cipher.
2968  * @param ef The eet file handle to read from.
2969  * @param edd The data descriptor handle to use when decoding.
2970  * @param name The key the data is stored under in the eet file.
2971  * @param cipher_key The key to use as cipher.
2972  * @return A pointer to the decoded data structure.
2973  *
2974  * This function decodes a data structure stored in an eet file, returning
2975  * a pointer to it if it decoded successfully, or NULL on failure. This
2976  * can save a programmer dozens of hours of work in writing configuration
2977  * file parsing and writing code, as eet does all that work for the program
2978  * and presents a program-friendly data structure, just as the programmer
2979  * likes. Eet can handle members being added or deleted from the data in
2980  * storage and safely zero-fills unfilled members if they were not found
2981  * in the data. It checks sizes and headers whenever it reads data, allowing
2982  * the programmer to not worry about corrupt data.
2983  *
2984  * Once a data structure has been described by the programmer with the
2985  * fields they wish to save or load, storing or retrieving a data structure
2986  * from an eet file, or from a chunk of memory is as simple as a single
2987  * function call.
2988  *
2989  * @see eet_data_read()
2990  *
2991  * @since 1.0.0
2992  * @ingroup Eet_Data_Cipher_Group
2993  */
2994 EAPI void *
2995 eet_data_read_cipher(Eet_File            *ef,
2996                      Eet_Data_Descriptor *edd,
2997                      const char          *name,
2998                      const char          *cipher_key);
2999
3000 /**
3001  * Write a data structure from memory and store in an eet file
3002  * using a cipher.
3003  * @param ef The eet file handle to write to.
3004  * @param edd The data descriptor to use when encoding.
3005  * @param name The key to store the data under in the eet file.
3006  * @param cipher_key The key to use as cipher.
3007  * @param data A pointer to the data structure to ssave and encode.
3008  * @param compress Compression flags for storage.
3009  * @return bytes written on successful write, 0 on failure.
3010  *
3011  * This function is the reverse of eet_data_read(), saving a data structure
3012  * to an eet file.
3013  *
3014  * @see eet_data_write_cipher()
3015  *
3016  * @since 1.0.0
3017  * @ingroup Eet_Data_Cipher_Group
3018  */
3019 EAPI int
3020 eet_data_write_cipher(Eet_File            *ef,
3021                       Eet_Data_Descriptor *edd,
3022                       const char          *name,
3023                       const char          *cipher_key,
3024                       const void          *data,
3025                       int                  compress);
3026
3027 /**
3028  * Dump an eet encoded data structure into ascii text using a cipher.
3029  * @param data_in The pointer to the data to decode into a struct.
3030  * @param cipher_key The key to use as cipher.
3031  * @param size_in The size of the data pointed to in bytes.
3032  * @param dumpfunc The function to call passed a string when new
3033  *        data is converted to text
3034  * @param dumpdata The data to pass to the @p dumpfunc callback.
3035  * @return 1 on success, 0 on failure
3036  *
3037  * This function will take a chunk of data encoded by
3038  * eet_data_descriptor_encode() and convert it into human readable
3039  * ascii text.  It does this by calling the @p dumpfunc callback
3040  * for all new text that is generated. This callback should append
3041  * to any existing text buffer and will be passed the pointer @p
3042  * dumpdata as a parameter as well as a string with new text to be
3043  * appended.
3044  *
3045  * Example:
3046  *
3047  * @code
3048  * void output(void *data, const char *string)
3049  * {
3050  *   printf("%s", string);
3051  * }
3052  *
3053  * void dump(const char *file)
3054  * {
3055  *   FILE *f;
3056  *   int len;
3057  *   void *data;
3058  *
3059  *   f = fopen(file, "r");
3060  *   fseek(f, 0, SEEK_END);
3061  *   len = ftell(f);
3062  *   rewind(f);
3063  *   data = malloc(len);
3064  *   fread(data, len, 1, f);
3065  *   fclose(f);
3066  *   eet_data_text_dump_cipher(data, cipher_key, len, output, NULL);
3067  * }
3068  * @endcode
3069  *
3070  * @see eet_data_text_dump()
3071  *
3072  * @since 1.0.0
3073  * @ingroup Eet_Data_Cipher_Group
3074  */
3075 EAPI int
3076 eet_data_text_dump_cipher(const void *data_in,
3077                           const char *cipher_key,
3078                           int size_in,
3079                           Eet_Dump_Callback dumpfunc,
3080                           void *dumpdata);
3081
3082 /**
3083  * Take an ascii encoding from eet_data_text_dump() and re-encode
3084  * in binary using a cipher.
3085  * @param text The pointer to the string data to parse and encode.
3086  * @param cipher_key The key to use as cipher.
3087  * @param textlen The size of the string in bytes (not including 0
3088  *        byte terminator).
3089  * @param size_ret This gets filled in with the encoded data blob
3090  *        size in bytes.
3091  * @return The encoded data on success, NULL on failure.
3092  *
3093  * This function will parse the string pointed to by @p text and return
3094  * an encoded data lump the same way eet_data_descriptor_encode() takes an
3095  * in-memory data struct and encodes into a binary blob. @p text is a normal
3096  * C string.
3097  *
3098  * @see eet_data_text_undump()
3099  *
3100  * @since 1.0.0
3101  * @ingroup Eet_Data_Cipher_Group
3102  */
3103 EAPI void *
3104 eet_data_text_undump_cipher(const char *text,
3105                             const char *cipher_key,
3106                             int         textlen,
3107                             int        *size_ret);
3108
3109 /**
3110  * Dump an eet encoded data structure from an eet file into ascii
3111  * text using a cipher.
3112  * @param ef A valid eet file handle.
3113  * @param name Name of the entry. eg: "/base/file_i_want".
3114  * @param cipher_key The key to use as cipher.
3115  * @param dumpfunc The function to call passed a string when new
3116  *        data is converted to text
3117  * @param dumpdata The data to pass to the @p dumpfunc callback.
3118  * @return 1 on success, 0 on failure
3119  *
3120  * This function will take an open and valid eet file from
3121  * eet_open() request the data encoded by
3122  * eet_data_descriptor_encode() corresponding to the key @p name
3123  * and convert it into human readable ascii text. It does this by
3124  * calling the @p dumpfunc callback for all new text that is
3125  * generated. This callback should append to any existing text
3126  * buffer and will be passed the pointer @p dumpdata as a parameter
3127  * as well as a string with new text to be appended.
3128  *
3129  * @see eet_data_dump()
3130  *
3131  * @since 1.0.0
3132  * @ingroup Eet_Data_Cipher_Group
3133  */
3134 EAPI int
3135 eet_data_dump_cipher(Eet_File    *ef,
3136                      const char  *name,
3137                      const char  *cipher_key,
3138                      Eet_Dump_Callback dumpfunc,
3139                      void        *dumpdata);
3140
3141 /**
3142  * Take an ascii encoding from eet_data_dump() and re-encode in
3143  * binary using a cipher.
3144  * @param ef A valid eet file handle.
3145  * @param name Name of the entry. eg: "/base/file_i_want".
3146  * @param cipher_key The key to use as cipher.
3147  * @param text The pointer to the string data to parse and encode.
3148  * @param textlen The size of the string in bytes (not including 0
3149  *        byte terminator).
3150  * @param compress Compression flags (1 == compress, 0 = don't compress).
3151  * @return 1 on success, 0 on failure
3152  *
3153  * This function will parse the string pointed to by @p text,
3154  * encode it the same way eet_data_descriptor_encode() takes an
3155  * in-memory data struct and encodes into a binary blob.
3156  *
3157  * The data (optionally compressed) will be in ram, pending a flush to
3158  * disk (it will stay in ram till the eet file handle is closed though).
3159  *
3160  * @see eet_data_undump()
3161  *
3162  * @since 1.0.0
3163  * @ingroup Eet_Data_Cipher_Group
3164  */
3165 EAPI int
3166 eet_data_undump_cipher(Eet_File   *ef,
3167                        const char *name,
3168                        const char *cipher_key,
3169                        const char *text,
3170                        int         textlen,
3171                        int         compress);
3172
3173 /**
3174  * Decode a data structure from an arbitrary location in memory
3175  * using a cipher.
3176  * @param edd The data  descriptor to use when decoding.
3177  * @param data_in The pointer to the data to decode into a struct.
3178  * @param cipher_key The key to use as cipher.
3179  * @param size_in The size of the data pointed to in bytes.
3180  * @return NULL on failure, or a valid decoded struct pointer on success.
3181  *
3182  * This function will decode a data structure that has been encoded using
3183  * eet_data_descriptor_encode(), and return a data structure with all its
3184  * elements filled out, if successful, or NULL on failure.
3185  *
3186  * The data to be decoded is stored at the memory pointed to by @p data_in,
3187  * and is described by the descriptor pointed to by @p edd. The data size is
3188  * passed in as the value to @p size_in, ande must be greater than 0 to
3189  * succeed.
3190  *
3191  * This function is useful for decoding data structures delivered to the
3192  * application by means other than an eet file, such as an IPC or socket
3193  * connection, raw files, shared memory etc.
3194  *
3195  * Please see eet_data_read() for more information.
3196  *
3197  * @see eet_data_descriptor_decode()
3198  *
3199  * @since 1.0.0
3200  * @ingroup Eet_Data_Cipher_Group
3201  */
3202 EAPI void *
3203 eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
3204                                   const void          *data_in,
3205                                   const char          *cipher_key,
3206                                   int                  size_in);
3207
3208 /**
3209  * Encode a data struct to memory and return that encoded data
3210  * using a cipher.
3211  * @param edd The data  descriptor to use when encoding.
3212  * @param data_in The pointer to the struct to encode into data.
3213  * @param cipher_key The key to use as cipher.
3214  * @param size_ret pointer to the an int to be filled with the decoded size.
3215  * @return NULL on failure, or a valid encoded data chunk on success.
3216  *
3217  * This function takes a data structutre in memory and encodes it into a
3218  * serialised chunk of data that can be decoded again by
3219  * eet_data_descriptor_decode(). This is useful for being able to transmit
3220  * data structures across sockets, pipes, IPC or shared file mechanisms,
3221  * without having to worry about memory space, machine type, endianess etc.
3222  *
3223  * The parameter @p edd must point to a valid data descriptor, and
3224  * @p data_in must point to the right data structure to encode. If not, the
3225  * encoding may fail.
3226  *
3227  * On success a non NULL valid pointer is returned and what @p size_ret
3228  * points to is set to the size of this decoded data, in bytes. When the
3229  * encoded data is no longer needed, call free() on it. On failure NULL is
3230  * returned and what @p size_ret points to is set to 0.
3231  *
3232  * Please see eet_data_write() for more information.
3233  *
3234  * @see eet_data_descriptor_encode()
3235  *
3236  * @since 1.0.0
3237  * @ingroup Eet_Data_Cipher_Group
3238  */
3239 EAPI void *
3240 eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
3241                                   const void          *data_in,
3242                                   const char          *cipher_key,
3243                                   int                 *size_ret);
3244
3245 /**
3246  * @defgroup Eet_Node_Group Low-level Serialization Structures.
3247  *
3248  * Functions that create, destroy and manipulate serialization nodes
3249  * used by @ref Eet_Data_Group.
3250  *
3251  * @{
3252  */
3253
3254 /**
3255  * @typedef Eet_Node
3256  * Opaque handle to manage serialization node.
3257  */
3258 typedef struct _Eet_Node        Eet_Node;
3259
3260 /**
3261  * @typedef Eet_Node_Data
3262  * Contains an union that can fit any kind of node.
3263  */
3264 typedef struct _Eet_Node_Data   Eet_Node_Data;
3265
3266 /**
3267  * @struct _Eet_Node_Data
3268  * Contains an union that can fit any kind of node.
3269  */
3270 struct _Eet_Node_Data
3271 {
3272    union {
3273       char                c;
3274       short               s;
3275       int                 i;
3276       long long           l;
3277       float               f;
3278       double              d;
3279       unsigned char       uc;
3280       unsigned short      us;
3281       unsigned int        ui;
3282       unsigned long long  ul;
3283       const char         *str;
3284    } value;
3285 };
3286
3287 /**
3288  * @}
3289  */
3290
3291 /**
3292  * TODO FIX ME
3293  * @ingroup Eet_Node_Group
3294  */
3295 EAPI Eet_Node *
3296  eet_node_char_new(const char *name,
3297                    char        c);
3298
3299 /**
3300  * TODO FIX ME
3301  * @ingroup Eet_Node_Group
3302  */
3303 EAPI Eet_Node *
3304 eet_node_short_new(const char *name,
3305                    short       s);
3306
3307 /**
3308  * TODO FIX ME
3309  * @ingroup Eet_Node_Group
3310  */
3311 EAPI Eet_Node *
3312 eet_node_int_new(const char *name,
3313                  int         i);
3314
3315 /**
3316  * TODO FIX ME
3317  * @ingroup Eet_Node_Group
3318  */
3319 EAPI Eet_Node *
3320 eet_node_long_long_new(const char *name,
3321                        long long   l);
3322
3323 /**
3324  * TODO FIX ME
3325  * @ingroup Eet_Node_Group
3326  */
3327 EAPI Eet_Node *
3328 eet_node_float_new(const char *name,
3329                    float       f);
3330
3331 /**
3332  * TODO FIX ME
3333  * @ingroup Eet_Node_Group
3334  */
3335 EAPI Eet_Node *
3336 eet_node_double_new(const char *name,
3337                     double      d);
3338
3339 /**
3340  * TODO FIX ME
3341  * @ingroup Eet_Node_Group
3342  */
3343 EAPI Eet_Node *
3344 eet_node_unsigned_char_new(const char    *name,
3345                            unsigned char  uc);
3346
3347 /**
3348  * TODO FIX ME
3349  * @ingroup Eet_Node_Group
3350  */
3351 EAPI Eet_Node *
3352 eet_node_unsigned_short_new(const char     *name,
3353                             unsigned short  us);
3354
3355 /**
3356  * TODO FIX ME
3357  * @ingroup Eet_Node_Group
3358  */
3359 EAPI Eet_Node *
3360 eet_node_unsigned_int_new(const char   *name,
3361                           unsigned int  ui);
3362
3363 /**
3364  * TODO FIX ME
3365  * @ingroup Eet_Node_Group
3366  */
3367 EAPI Eet_Node *
3368 eet_node_unsigned_long_long_new(const char         *name,
3369                                 unsigned long long  l);
3370
3371 /**
3372  * TODO FIX ME
3373  * @ingroup Eet_Node_Group
3374  */
3375 EAPI Eet_Node *
3376 eet_node_string_new(const char *name,
3377                     const char *str);
3378
3379 /**
3380  * TODO FIX ME
3381  * @ingroup Eet_Node_Group
3382  */
3383 EAPI Eet_Node *
3384 eet_node_inlined_string_new(const char *name,
3385                             const char *str);
3386
3387 /**
3388  * TODO FIX ME
3389  * @ingroup Eet_Node_Group
3390  */
3391 EAPI Eet_Node *
3392 eet_node_null_new(const char *name);
3393
3394 /**
3395  * TODO FIX ME
3396  * @ingroup Eet_Node_Group
3397  */
3398 EAPI Eet_Node *
3399 eet_node_list_new(const char *name,
3400                   Eina_List  *nodes);
3401
3402 /**
3403  * TODO FIX ME
3404  * @ingroup Eet_Node_Group
3405  */
3406 EAPI Eet_Node *
3407 eet_node_array_new(const char *name,
3408                    int         count,
3409                    Eina_List  *nodes);
3410
3411 /**
3412  * TODO FIX ME
3413  * @ingroup Eet_Node_Group
3414  */
3415 EAPI Eet_Node *
3416 eet_node_var_array_new(const char *name,
3417                        Eina_List  *nodes);
3418
3419 /**
3420  * TODO FIX ME
3421  * @ingroup Eet_Node_Group
3422  */
3423 EAPI Eet_Node *
3424 eet_node_hash_new(const char *name,
3425                   const char *key,
3426                   Eet_Node   *node);
3427
3428 /**
3429  * TODO FIX ME
3430  * @ingroup Eet_Node_Group
3431  */
3432 EAPI Eet_Node *
3433 eet_node_struct_new(const char *name,
3434                     Eina_List  *nodes);
3435
3436 /**
3437  * TODO FIX ME
3438  * @ingroup Eet_Node_Group
3439  */
3440 EAPI Eet_Node *
3441 eet_node_struct_child_new(const char *parent,
3442                           Eet_Node   *child);
3443
3444 /**
3445  * TODO FIX ME
3446  * @ingroup Eet_Node_Group
3447  */
3448 EAPI void
3449 eet_node_list_append(Eet_Node   *parent,
3450                      const char *name,
3451                      Eet_Node   *child);
3452
3453 /**
3454  * TODO FIX ME
3455  * @ingroup Eet_Node_Group
3456  */
3457 EAPI void
3458 eet_node_struct_append(Eet_Node   *parent,
3459                        const char *name,
3460                        Eet_Node   *child);
3461
3462 /**
3463  * TODO FIX ME
3464  * @ingroup Eet_Node_Group
3465  */
3466 EAPI void
3467 eet_node_hash_add(Eet_Node   *parent,
3468                   const char *name,
3469                   const char *key,
3470                   Eet_Node   *child);
3471
3472 /**
3473  * TODO FIX ME
3474  * @ingroup Eet_Node_Group
3475  */
3476 EAPI void
3477 eet_node_dump(Eet_Node  *n,
3478               int        dumplevel,
3479               Eet_Dump_Callback dumpfunc,
3480               void      *dumpdata);
3481
3482 /**
3483  * TODO FIX ME
3484  * @ingroup Eet_Node_Group
3485  */
3486 EAPI void
3487 eet_node_del(Eet_Node *n);
3488
3489 /**
3490  * TODO FIX ME
3491  * @ingroup Eet_Node_Group
3492  */
3493 EAPI void *
3494 eet_data_node_encode_cipher(Eet_Node   *node,
3495                             const char *cipher_key,
3496                             int        *size_ret);
3497
3498 /**
3499  * TODO FIX ME
3500  * @ingroup Eet_Node_Group
3501  */
3502 EAPI Eet_Node *
3503 eet_data_node_decode_cipher(const void *data_in,
3504                             const char *cipher_key,
3505                             int         size_in);
3506
3507 /**
3508  * TODO FIX ME
3509  * @ingroup Eet_Node_Group
3510  */
3511 EAPI Eet_Node *
3512 eet_data_node_read_cipher(Eet_File   *ef,
3513                           const char *name,
3514                           const char *cipher_key);
3515
3516 /**
3517  * TODO FIX ME
3518  * @ingroup Eet_Node_Group
3519  */
3520 EAPI int
3521 eet_data_node_write_cipher(Eet_File   *ef,
3522                            const char *name,
3523                            const char *cipher_key,
3524                            Eet_Node   *node,
3525                            int         compress);
3526
3527 /* EXPERIMENTAL: THIS API MAY CHANGE IN THE FUTURE, USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING. */
3528
3529 /**
3530  * @typedef Eet_Node_Walk
3531  * Describes how to walk trees of #Eet_Node.
3532  */
3533 typedef struct _Eet_Node_Walk   Eet_Node_Walk;
3534
3535 typedef void *(*Eet_Node_Walk_Struct_Alloc_Callback)(const char *type, void *user_data);
3536 typedef void  (*Eet_Node_Walk_Struct_Add_Callback)(void *parent, const char *name, void *child, void *user_data);
3537 typedef void *(*Eet_Node_Walk_Array_Callback)(Eina_Bool variable, const char *name, int count, void *user_data);
3538 typedef void  (*Eet_Node_Walk_Insert_Callback)(void *array, int index, void *child, void *user_data);
3539 typedef void *(*Eet_Node_Walk_List_Callback)(const char *name, void *user_data);
3540 typedef void  (*Eet_Node_Walk_Append_Callback)(void *list, void *child, void *user_data);
3541 typedef void *(*Eet_Node_Walk_Hash_Callback)(void *parent, const char *name, const char *key, void *value, void *user_data);
3542 typedef void *(*Eet_Node_Walk_Simple_Callback)(int type, Eet_Node_Data *data, void *user_data);
3543   
3544 /**
3545  * @struct _Eet_Node_Walk
3546  * Describes how to walk trees of #Eet_Node.
3547  */
3548 struct _Eet_Node_Walk
3549 {
3550    Eet_Node_Walk_Struct_Alloc_Callback struct_alloc;
3551    Eet_Node_Walk_Struct_Add_Callback struct_add;
3552    Eet_Node_Walk_Array_Callback array;
3553    Eet_Node_Walk_Insert_Callback insert;
3554    Eet_Node_Walk_List_Callback list;
3555    Eet_Node_Walk_Append_Callback append;
3556    Eet_Node_Walk_Hash_Callback hash;
3557    Eet_Node_Walk_Simple_Callback simple;
3558 };
3559
3560 EAPI void *
3561 eet_node_walk(void          *parent,
3562               const char    *name,
3563               Eet_Node      *root,
3564               Eet_Node_Walk *cb,
3565               void          *user_data);
3566
3567 /*******/
3568
3569 /**
3570  * @defgroup Eet_Connection_Group Helper function to use eet over a network link
3571  *
3572  * Function that reconstruct and prepare packet of @ref Eet_Data_Group to be send.
3573  *
3574  */
3575
3576 /**
3577  * @typedef Eet_Connection
3578  * Opaque handle to track paquet for a specific connection.
3579  *
3580  * @ingroup Eet_Connection_Group
3581  */
3582 typedef struct _Eet_Connection   Eet_Connection;
3583
3584 /**
3585  * @typedef Eet_Read_Cb
3586  * Called back when an @ref Eet_Data_Group has been received completly and could be used.
3587  *
3588  * @ingroup Eet_Connection_Group
3589  */
3590 typedef Eina_Bool Eet_Read_Cb (const void *eet_data, size_t size, void *user_data);
3591
3592 /**
3593  * @typedef Eet_Write_Cb
3594  * Called back when a packet containing @ref Eet_Data_Group data is ready to be send.
3595  *
3596  * @ingroup Eet_Connection_Group
3597  */
3598 typedef Eina_Bool Eet_Write_Cb (const void *data, size_t size, void *user_data);
3599
3600 /**
3601  * Instanciate a new connection to track.
3602  * @param eet_read_cb Function to call when one Eet_Data packet has been fully assemble.
3603  * @param eet_write_cb Function to call when one Eet_Data packet is ready to be send over the wire.
3604  * @param user_data Pointer provided to both functions to be used as a context handler.
3605  * @return NULL on failure, or a valid Eet_Connection handler.
3606  *
3607  * For every connection to track you will need a separate Eet_Connection provider.
3608  *
3609  * @since 1.2.4
3610  * @ingroup Eet_Connection_Group
3611  */
3612 EAPI Eet_Connection *
3613 eet_connection_new(Eet_Read_Cb  *eet_read_cb,
3614                    Eet_Write_Cb *eet_write_cb,
3615                    const void   *user_data);
3616
3617 /**
3618  * Process a raw packet received over the link
3619  * @param conn Connection handler to track.
3620  * @param data Raw data packet.
3621  * @param size The size of that packet.
3622  * @return 0 on complete success, any other value indicate where in the stream it got wrong (It could be before that packet).
3623  *
3624  * Every time you receive a packet related to your connection, you should pass
3625  * it to that function so that it could process and assemble packet has you
3626  * receive it. It will automatically call Eet_Read_Cb when one is fully received.
3627  *
3628  * @since 1.2.4
3629  * @ingroup Eet_Connection_Group
3630  */
3631 EAPI int
3632 eet_connection_received(Eet_Connection *conn,
3633                         const void     *data,
3634                         size_t          size);
3635
3636 /**
3637  * Convert a complex structure and prepare it to be send.
3638  * @param conn Connection handler to track.
3639  * @param edd The data descriptor to use when encoding.
3640  * @param data_in The pointer to the struct to encode into data.
3641  * @param cipher_key The key to use as cipher.
3642  * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
3643  *
3644  * This function serialize data_in with edd, assemble the packet and call
3645  * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
3646  * and will vanish just after the return of the callback.
3647  *
3648  * @see eet_data_descriptor_encode_cipher
3649  *
3650  * @since 1.2.4
3651  * @ingroup Eet_Connection_Group
3652  */
3653 EAPI Eina_Bool
3654 eet_connection_send(Eet_Connection      *conn,
3655                     Eet_Data_Descriptor *edd,
3656                     const void          *data_in,
3657                     const char          *cipher_key);
3658
3659 /**
3660  * Convert a Eet_Node tree and prepare it to be send.
3661  * @param conn Connection handler to track.
3662  * @param node The data tree to use when encoding.
3663  * @param cipher_key The key to use as cipher.
3664  * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
3665  *
3666  * This function serialize node, assemble the packet and call
3667  * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
3668  * and will vanish just after the return of the callback.
3669  *
3670  * @see eet_data_node_encode_cipher
3671  *
3672  * @since 1.2.4
3673  * @ingroup Eet_Connection_Group
3674  */
3675 EAPI Eina_Bool
3676 eet_connection_node_send(Eet_Connection *conn,
3677                          Eet_Node       *node,
3678                          const char     *cipher_key);
3679
3680 /**
3681  * Close a connection and lost its track.
3682  * @param conn Connection handler to close.
3683  * @param on_going Signal if a partial packet wasn't completed.
3684  * @return the user_data passed to both callback.
3685  *
3686  * @since 1.2.4
3687  * @ingroup Eet_Connection_Group
3688  */
3689 EAPI void *
3690 eet_connection_close(Eet_Connection *conn,
3691                      Eina_Bool      *on_going);
3692
3693 /***************************************************************************/
3694
3695 #ifdef __cplusplus
3696 }
3697 #endif /* ifdef __cplusplus */
3698
3699 #endif /* ifndef _EET_H */