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