* eet: fix bad allocation case triggered by edje new file format.
[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 4
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       void      * (*array_alloc)(size_t size); /**< how to allocate memory for array (usually malloc()) */
1782       void        (*array_free)(void *mem); /**< how to free memory for array (usually malloc()) */
1783    } func;
1784 };
1785
1786 /**
1787  * @}
1788  */
1789
1790 /**
1791  * Create a new empty data structure descriptor.
1792  * @param name The string name of this data structure (most be a
1793  *        global constant and never change).
1794  * @param size The size of the struct (in bytes).
1795  * @param func_list_next The function to get the next list node.
1796  * @param func_list_append The function to append a member to a list.
1797  * @param func_list_data The function to get the data from a list node.
1798  * @param func_list_free The function to free an entire linked list.
1799  * @param func_hash_foreach The function to iterate through all
1800  *        hash table entries.
1801  * @param func_hash_add The function to add a member to a hash table.
1802  * @param func_hash_free The function to free an entire hash table.
1803  * @return A new empty data descriptor.
1804  *
1805  * This function creates a new data descriptore and returns a handle to the
1806  * new data descriptor. On creation it will be empty, containing no contents
1807  * describing anything other than the shell of the data structure.
1808  *
1809  * You add structure members to the data descriptor using the macros
1810  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
1811  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
1812  * adding to the description.
1813  *
1814  * Once you have described all the members of a struct you want loaded, or
1815  * saved eet can load and save those members for you, encode them into
1816  * endian-independant serialised data chunks for transmission across a
1817  * a network or more.
1818  *
1819  * The function pointers to the list and hash table functions are only
1820  * needed if you use those data types, else you can pass NULL instead.
1821  *
1822  * @since 1.0.0
1823  * @ingroup Eet_Data_Group
1824  *
1825  * @deprecated use eet_data_descriptor_stream_new() or
1826  *             eet_data_descriptor_file_new()
1827  */
1828 EINA_DEPRECATED EAPI Eet_Data_Descriptor *    eet_data_descriptor_new(const char *name,
1829                                                                       int size,
1830                                                                       void *(*func_list_next)(void *l),
1831                                                                       void *(*func_list_append)(void *l, void *d),
1832                                                                       void *(*func_list_data)(void *l),
1833                                                                       void *(*func_list_free)(void *l),
1834                                                                       void (*func_hash_foreach)(void *h, int (*func)(void       *h,
1835                                                                                                                      const char *k,
1836                                                                                                                      void       *dt,
1837                                                                                                                      void       *fdt), void *fdt),
1838                                                                       void *(*func_hash_add)(void *h, const char *k, void *d),
1839                                                                       void (*func_hash_free)(void *h));
1840 /*
1841  * FIXME:
1842  *
1843  * moving to this api from the old above. this will break things when the
1844  * move happens - but be warned
1845  */
1846 EINA_DEPRECATED EAPI Eet_Data_Descriptor *    eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc);
1847 EINA_DEPRECATED EAPI Eet_Data_Descriptor *    eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc);
1848
1849 /**
1850  * This function creates a new data descriptore and returns a handle to the
1851  * new data descriptor. On creation it will be empty, containing no contents
1852  * describing anything other than the shell of the data structure.
1853  * @param eddc The data descriptor to free.
1854  *
1855  * You add structure members to the data descriptor using the macros
1856  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
1857  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
1858  * adding to the description.
1859  *
1860  * Once you have described all the members of a struct you want loaded, or
1861  * saved eet can load and save those members for you, encode them into
1862  * endian-independant serialised data chunks for transmission across a
1863  * a network or more.
1864  *
1865  * This function specially ignore str_direct_alloc and str_direct_free. It
1866  * is usefull when the eet_data you are reading don't have a dictionnary
1867  * like network stream or ipc. It also mean that all string will be allocated
1868  * and duplicated in memory.
1869  *
1870  * @since 1.2.3
1871  * @ingroup Eet_Data_Group
1872  */
1873 EAPI Eet_Data_Descriptor *                    eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc);
1874
1875 /**
1876  * This function creates a new data descriptore and returns a handle to the
1877  * new data descriptor. On creation it will be empty, containing no contents
1878  * describing anything other than the shell of the data structure.
1879  * @param eddc The data descriptor to free.
1880  *
1881  * You add structure members to the data descriptor using the macros
1882  * EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
1883  * EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
1884  * adding to the description.
1885  *
1886  * Once you have described all the members of a struct you want loaded, or
1887  * saved eet can load and save those members for you, encode them into
1888  * endian-independant serialised data chunks for transmission across a
1889  * a network or more.
1890  *
1891  * This function use str_direct_alloc and str_direct_free. It is
1892  * usefull when the eet_data you are reading come from a file and
1893  * have a dictionnary. This will reduce memory use, improve the
1894  * possibility for the OS to page this string out. But be carrefull
1895  * all EET_T_STRING are pointer to a mmapped area and it will point
1896  * to nowhere if you close the file. So as long as you use this
1897  * strings, you need to have the Eet_File open.
1898  *
1899  * @since 1.2.3
1900  * @ingroup Eet_Data_Group
1901  */
1902 EAPI Eet_Data_Descriptor *                    eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc);
1903
1904 /**
1905  * This function is an helper that set all the parameter of an
1906  * Eet_Data_Descriptor_Class correctly when you use Eina data type
1907  * with a stream.
1908  * @param eddc The Eet_Data_Descriptor_Class you want to set.
1909  * @param name The name of the structure described by this class.
1910  * @param size The size of the structure described by this class.
1911  * @return EINA_TRUE if the structure was correctly set (The only
1912  *         reason that could make it fail is if you did give wrong
1913  *         parameter).
1914  *
1915  * @since 1.2.3
1916  * @ingroup Eet_Data_Group
1917  */
1918 EAPI Eina_Bool                                eet_eina_stream_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
1919                                                                                         unsigned int               eddc_size,
1920                                                                                         const char                *name,
1921                                                                                         int                        size);
1922
1923 /**
1924  * This macro is an helper that set all the parameter of an
1925  * Eet_Data_Descriptor_Class correctly when you use Eina data type
1926  * with stream.
1927  * @param Clas The Eet_Data_Descriptor_Class you want to set.
1928  * @param Type The type of the structure described by this class.
1929  * @return EINA_TRUE if the structure was correctly set (The only
1930  *         reason that could make it fail is if you did give wrong
1931  *         parameter).
1932  *
1933  * @since 1.2.3
1934  * @ingroup Eet_Data_Group
1935  */
1936 #define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(clas, type)\
1937    (eet_eina_stream_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
1938
1939 /**
1940  * This function is an helper that set all the parameter of an
1941  * Eet_Data_Descriptor_Class correctly when you use Eina data type
1942  * with a file.
1943  * @param eddc The Eet_Data_Descriptor_Class you want to set.
1944  * @param name The name of the structure described by this class.
1945  * @param size The size of the structure described by this class.
1946  * @return EINA_TRUE if the structure was correctly set (The only
1947  *         reason that could make it fail is if you did give wrong
1948  *         parameter).
1949  *
1950  * @since 1.2.3
1951  * @ingroup Eet_Data_Group
1952  */
1953 EAPI Eina_Bool      eet_eina_file_data_descriptor_class_set(Eet_Data_Descriptor_Class *eddc,
1954                                                             unsigned int               eddc_size,
1955                                                             const char                *name,
1956                                                             int                        size);
1957
1958 /**
1959  * This macro is an helper that set all the parameter of an
1960  * Eet_Data_Descriptor_Class correctly when you use Eina data type
1961  * with file.
1962  * @param Clas The Eet_Data_Descriptor_Class you want to set.
1963  * @param Type The type of the structure described by this class.
1964  * @return EINA_TRUE if the structure was correctly set (The only
1965  *         reason that could make it fail is if you did give wrong
1966  *         parameter).
1967  *
1968  * @since 1.2.3
1969  * @ingroup Eet_Data_Group
1970  */
1971 #define EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(clas, type)\
1972   (eet_eina_file_data_descriptor_class_set(clas, sizeof (*(clas)), # type, sizeof(type)))
1973
1974 /**
1975  * This function frees a data descriptor when it is not needed anymore.
1976  * @param edd The data descriptor to free.
1977  *
1978  * This function takes a data descriptor handle as a parameter and frees all
1979  * data allocated for the data descriptor and the handle itself. After this
1980  * call the descriptor is no longer valid.
1981  *
1982  * @since 1.0.0
1983  * @ingroup Eet_Data_Group
1984  */
1985 EAPI void      eet_data_descriptor_free(Eet_Data_Descriptor *edd);
1986
1987 /**
1988  * This function is an internal used by macros.
1989  *
1990  * This function is used by macros EET_DATA_DESCRIPTOR_ADD_BASIC(),
1991  * EET_DATA_DESCRIPTOR_ADD_SUB() and EET_DATA_DESCRIPTOR_ADD_LIST(). It is
1992  * complex to use by hand and should be left to be used by the macros, and
1993  * thus is not documented.
1994  *
1995  * @param edd The data descriptor handle to add element (member).
1996  * @param name The name of element to be serialized.
1997  * @param type The type of element to be serialized, like
1998  *        #EET_T_INT. If #EET_T_UNKNOW, then it is considered to be a
1999  *        group, list or hash.
2000  * @param group_type If element type is #EET_T_UNKNOW, then the @p
2001  *        group_type will speficy if it is a list (#EET_G_LIST),
2002  *        array (#EET_G_ARRAY) and so on. If #EET_G_UNKNOWN, then
2003  *        the member is a subtype (pointer to another type defined by
2004  *        another #Eet_Data_Descriptor).
2005  * @param offset byte offset inside the source memory to be serialized.
2006  * @param count number of elements (if #EET_G_ARRAY or #EET_G_VAR_ARRAY).
2007  * @param counter_name variable that defines the name of number of elements.
2008  * @param subtype If contains a subtype, then its data descriptor.
2009  *
2010  * @since 1.0.0
2011  * @ingroup Eet_Data_Group
2012  */
2013 EAPI void      eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
2014                                                const char          *name,
2015                                                int                  type,
2016                                                int                  group_type,
2017                                                int                  offset,
2018      /* int count_offset, */
2019                                                int                  count,
2020                                                const char          *counter_name,
2021                                                Eet_Data_Descriptor *subtype);
2022
2023 /**
2024  * Read a data structure from an eet file and decodes it.
2025  * @param ef The eet file handle to read from.
2026  * @param edd The data descriptor handle to use when decoding.
2027  * @param name The key the data is stored under in the eet file.
2028  * @return A pointer to the decoded data structure.
2029  *
2030  * This function decodes a data structure stored in an eet file, returning
2031  * a pointer to it if it decoded successfully, or NULL on failure. This
2032  * can save a programmer dozens of hours of work in writing configuration
2033  * file parsing and writing code, as eet does all that work for the program
2034  * and presents a program-friendly data structure, just as the programmer
2035  * likes. Eet can handle members being added or deleted from the data in
2036  * storage and safely zero-fills unfilled members if they were not found
2037  * in the data. It checks sizes and headers whenever it reads data, allowing
2038  * the programmer to not worry about corrupt data.
2039  *
2040  * Once a data structure has been described by the programmer with the
2041  * fields they wish to save or load, storing or retrieving a data structure
2042  * from an eet file, or from a chunk of memory is as simple as a single
2043  * function call.
2044  *
2045  * @see eet_data_read_cipher()
2046  *
2047  * @since 1.0.0
2048  * @ingroup Eet_Data_Group
2049  */
2050 EAPI void *    eet_data_read(Eet_File            *ef,
2051                              Eet_Data_Descriptor *edd,
2052                              const char          *name);
2053
2054 /**
2055  * Write a data structure from memory and store in an eet file.
2056  * @param ef The eet file handle to write to.
2057  * @param edd The data descriptor to use when encoding.
2058  * @param name The key to store the data under in the eet file.
2059  * @param data A pointer to the data structure to ssave and encode.
2060  * @param compress Compression flags for storage.
2061  * @return bytes written on successful write, 0 on failure.
2062  *
2063  * This function is the reverse of eet_data_read(), saving a data structure
2064  * to an eet file.
2065  *
2066  * @see eet_data_write_cipher()
2067  *
2068  * @since 1.0.0
2069  * @ingroup Eet_Data_Group
2070  */
2071 EAPI int       eet_data_write(Eet_File            *ef,
2072                               Eet_Data_Descriptor *edd,
2073                               const char          *name,
2074                               const void          *data,
2075                               int                  compress);
2076
2077 /**
2078  * Dump an eet encoded data structure into ascii text
2079  * @param data_in The pointer to the data to decode into a struct.
2080  * @param size_in The size of the data pointed to in bytes.
2081  * @param dumpfunc The function to call passed a string when new
2082  *        data is converted to text
2083  * @param dumpdata The data to pass to the @p dumpfunc callback.
2084  * @return 1 on success, 0 on failure
2085  *
2086  * This function will take a chunk of data encoded by
2087  * eet_data_descriptor_encode() and convert it into human readable
2088  * ascii text.  It does this by calling the @p dumpfunc callback
2089  * for all new text that is generated. This callback should append
2090  * to any existing text buffer and will be passed the pointer @p
2091  * dumpdata as a parameter as well as a string with new text to be
2092  * appended.
2093  *
2094  * Example:
2095  *
2096  * @code
2097  * void output(void *data, const char *string)
2098  * {
2099  *   printf("%s", string);
2100  * }
2101  *
2102  * void dump(const char *file)
2103  * {
2104  *   FILE *f;
2105  *   int len;
2106  *   void *data;
2107  *
2108  *   f = fopen(file, "r");
2109  *   fseek(f, 0, SEEK_END);
2110  *   len = ftell(f);
2111  *   rewind(f);
2112  *   data = malloc(len);
2113  *   fread(data, len, 1, f);
2114  *   fclose(f);
2115  *   eet_data_text_dump(data, len, output, NULL);
2116  * }
2117  * @endcode
2118  *
2119  * @see eet_data_text_dump_cipher()
2120  *
2121  * @since 1.0.0
2122  * @ingroup Eet_Data_Group
2123  */
2124 EAPI int       eet_data_text_dump(const void *data_in,
2125                                   int size_in,
2126                                   void (*dumpfunc)(void *data, const char *str),
2127                                   void *dumpdata);
2128
2129 /**
2130  * Take an ascii encoding from eet_data_text_dump() and re-encode in binary.
2131  * @param text The pointer to the string data to parse and encode.
2132  * @param textlen The size of the string in bytes (not including 0
2133  *        byte terminator).
2134  * @param size_ret This gets filled in with the encoded data blob
2135  *        size in bytes.
2136  * @return The encoded data on success, NULL on failure.
2137  *
2138  * This function will parse the string pointed to by @p text and return
2139  * an encoded data lump the same way eet_data_descriptor_encode() takes an
2140  * in-memory data struct and encodes into a binary blob. @p text is a normal
2141  * C string.
2142  *
2143  * @see eet_data_text_undump_cipher()
2144  *
2145  * @since 1.0.0
2146  * @ingroup Eet_Data_Group
2147  */
2148 EAPI void *    eet_data_text_undump(const char *text,
2149                                     int         textlen,
2150                                     int        *size_ret);
2151
2152 /**
2153  * Dump an eet encoded data structure from an eet file into ascii text
2154  * @param ef A valid eet file handle.
2155  * @param name Name of the entry. eg: "/base/file_i_want".
2156  * @param dumpfunc The function to call passed a string when new
2157  *        data is converted to text
2158  * @param dumpdata The data to pass to the @p dumpfunc callback.
2159  * @return 1 on success, 0 on failure
2160  *
2161  * This function will take an open and valid eet file from
2162  * eet_open() request the data encoded by
2163  * eet_data_descriptor_encode() corresponding to the key @p name
2164  * and convert it into human readable ascii text. It does this by
2165  * calling the @p dumpfunc callback for all new text that is
2166  * generated. This callback should append to any existing text
2167  * buffer and will be passed the pointer @p dumpdata as a parameter
2168  * as well as a string with new text to be appended.
2169  *
2170  * @see eet_data_dump_cipher()
2171  *
2172  * @since 1.0.0
2173  * @ingroup Eet_Data_Group
2174  */
2175 EAPI int       eet_data_dump(Eet_File *ef,
2176                              const char *name,
2177                              void (*dumpfunc)(void *data, const char *str),
2178                              void *dumpdata);
2179
2180 /**
2181  * Take an ascii encoding from eet_data_dump() and re-encode in binary.
2182  * @param ef A valid eet file handle.
2183  * @param name Name of the entry. eg: "/base/file_i_want".
2184  * @param text The pointer to the string data to parse and encode.
2185  * @param textlen The size of the string in bytes (not including 0
2186  *        byte terminator).
2187  * @param compress Compression flags (1 == compress, 0 = don't compress).
2188  * @return 1 on success, 0 on failure
2189  *
2190  * This function will parse the string pointed to by @p text,
2191  * encode it the same way eet_data_descriptor_encode() takes an
2192  * in-memory data struct and encodes into a binary blob.
2193  *
2194  * The data (optionally compressed) will be in ram, pending a flush to
2195  * disk (it will stay in ram till the eet file handle is closed though).
2196  *
2197  * @see eet_data_undump_cipher()
2198  *
2199  * @since 1.0.0
2200  * @ingroup Eet_Data_Group
2201  */
2202 EAPI int       eet_data_undump(Eet_File   *ef,
2203                                const char *name,
2204                                const char *text,
2205                                int         textlen,
2206                                int         compress);
2207
2208 /**
2209  * Decode a data structure from an arbitary location in memory.
2210  * @param edd The data  descriptor to use when decoding.
2211  * @param data_in The pointer to the data to decode into a struct.
2212  * @param size_in The size of the data pointed to in bytes.
2213  * @return NULL on failure, or a valid decoded struct pointer on success.
2214  *
2215  * This function will decode a data structure that has been encoded using
2216  * eet_data_descriptor_encode(), and return a data structure with all its
2217  * elements filled out, if successful, or NULL on failure.
2218  *
2219  * The data to be decoded is stored at the memory pointed to by @p data_in,
2220  * and is described by the descriptor pointed to by @p edd. The data size is
2221  * passed in as the value to @p size_in, ande must be greater than 0 to
2222  * succeed.
2223  *
2224  * This function is useful for decoding data structures delivered to the
2225  * application by means other than an eet file, such as an IPC or socket
2226  * connection, raw files, shared memory etc.
2227  *
2228  * Please see eet_data_read() for more information.
2229  *
2230  * @see eet_data_descriptor_decode_cipher()
2231  *
2232  * @since 1.0.0
2233  * @ingroup Eet_Data_Group
2234  */
2235 EAPI void *    eet_data_descriptor_decode(Eet_Data_Descriptor *edd,
2236                                           const void          *data_in,
2237                                           int                  size_in);
2238
2239 /**
2240  * Encode a dsata struct to memory and return that encoded data.
2241  * @param edd The data  descriptor to use when encoding.
2242  * @param data_in The pointer to the struct to encode into data.
2243  * @param size_ret pointer to the an int to be filled with the decoded size.
2244  * @return NULL on failure, or a valid encoded data chunk on success.
2245  *
2246  * This function takes a data structutre in memory and encodes it into a
2247  * serialised chunk of data that can be decoded again by
2248  * eet_data_descriptor_decode(). This is useful for being able to transmit
2249  * data structures across sockets, pipes, IPC or shared file mechanisms,
2250  * without having to worry about memory space, machine type, endianess etc.
2251  *
2252  * The parameter @p edd must point to a valid data descriptor, and
2253  * @p data_in must point to the right data structure to encode. If not, the
2254  * encoding may fail.
2255  *
2256  * On success a non NULL valid pointer is returned and what @p size_ret
2257  * points to is set to the size of this decoded data, in bytes. When the
2258  * encoded data is no longer needed, call free() on it. On failure NULL is
2259  * returned and what @p size_ret points to is set to 0.
2260  *
2261  * Please see eet_data_write() for more information.
2262  *
2263  * @see eet_data_descriptor_encode_cipher()
2264  *
2265  * @since 1.0.0
2266  * @ingroup Eet_Data_Group
2267  */
2268 EAPI void *    eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
2269                                           const void          *data_in,
2270                                           int                 *size_ret);
2271
2272 /**
2273  * Add a basic data element to a data descriptor.
2274  * @param edd The data descriptor to add the type to.
2275  * @param struct_type The type of the struct.
2276  * @param name The string name to use to encode/decode this member
2277  *        (must be a constant global and never change).
2278  * @param member The struct member itself to be encoded.
2279  * @param type The type of the member to encode.
2280  *
2281  * This macro is a convenience macro provided to add a member to
2282  * the data descriptor @p edd. The type of the structure is
2283  * provided as the @p struct_type parameter (for example: struct
2284  * my_struct). The @p name parameter defines a string that will be
2285  * used to uniquely name that member of the struct (it is suggested
2286  * to use the struct member itself).  The @p member parameter is
2287  * the actual struct member itself (for eet_dictionary_string_check
2288  * example: values), and @p type is the basic data type of the
2289  * member which must be one of: EET_T_CHAR, EET_T_SHORT, EET_T_INT,
2290  * EET_T_LONG_LONG, EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR,
2291  * EET_T_USHORT, EET_T_UINT, EET_T_ULONG_LONG or EET_T_STRING.
2292  *
2293  * @since 1.0.0
2294  * @ingroup Eet_Data_Group
2295  */
2296 #define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type)\
2297    do {\
2298         struct_type ___ett;\
2299         eet_data_descriptor_element_add(edd, name, type, EET_G_UNKNOWN,\
2300                                         (char *)(& (___ett.member)) -\
2301                                         (char *)(& (___ett)),\
2302                                         0, /* 0,  */ NULL, NULL);\
2303      } while(0)
2304
2305 /**
2306  * Add a sub-element type to a data descriptor
2307  * @param edd The data descriptor to add the type to.
2308  * @param struct_type The type of the struct.
2309  * @param name The string name to use to encode/decode this member
2310  *        (must be a constant global and never change).
2311  * @param member The struct member itself to be encoded.
2312  * @param subtype The type of sub-type struct to add.
2313  *
2314  * This macro lets you easily add a sub-type (a struct that's pointed to
2315  * by this one). All the parameters are the same as for
2316  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception.
2317  * This must be the data descriptor of the struct that is pointed to by
2318  * this element.
2319  *
2320  * @since 1.0.0
2321  * @ingroup Eet_Data_Group
2322  */
2323 #define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype)\
2324    do {\
2325         struct_type ___ett;\
2326 \
2327         eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNKNOWN,\
2328                                         (char *)(& (___ett.member)) -\
2329                                         (char *)(& (___ett)),\
2330                                         0, /* 0,  */ NULL, subtype);\
2331      } while (0)
2332
2333 /**
2334  * Add a linked list type to a data descriptor
2335  * @param edd The data descriptor to add the type to.
2336  * @param struct_type The type of the struct.
2337  * @param name The string name to use to encode/decode this member
2338  *        (must be a constant global and never change).
2339  * @param member The struct member itself to be encoded.
2340  * @param subtype The type of linked list member to add.
2341  *
2342  * This macro lets you easily add a linked list of other data types. All the
2343  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
2344  * @p subtype being the exception. This must be the data descriptor of the
2345  * element that is in each member of the linked list to be stored.
2346  *
2347  * @since 1.0.0
2348  * @ingroup Eet_Data_Group
2349  */
2350 #define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype)\
2351    do {\
2352         struct_type ___ett;\
2353 \
2354         eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_LIST,\
2355                                         (char *)(& (___ett.member)) -\
2356                                         (char *)(& (___ett)),\
2357                                         0, /* 0,  */ NULL, subtype);\
2358      } while (0)
2359
2360 /**
2361  * Add a hash type to a data descriptor
2362  * @param edd The data descriptor to add the type to.
2363  * @param struct_type The type of the struct.
2364  * @param name The string name to use to encode/decode this member
2365  *        (must be a constant global and never change).
2366  * @param member The struct member itself to be encoded.
2367  * @param subtype The type of hash member to add.
2368  *
2369  * This macro lets you easily add a hash of other data types. All the
2370  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
2371  * @p subtype being the exception. This must be the data descriptor of the
2372  * element that is in each member of the hash to be stored.
2373  *
2374  * @since 1.0.0
2375  * @ingroup Eet_Data_Group
2376  */
2377 #define EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype)\
2378    do {\
2379         struct_type ___ett;\
2380 \
2381         eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_HASH,\
2382                                         (char *)(& (___ett.member)) -\
2383                                         (char *)(& (___ett)),\
2384                                         0, /* 0,  */ NULL, subtype);\
2385      } while (0)
2386
2387 /**
2388  * Add a hash of string to a data descriptor
2389  * @param edd The data descriptor to add the type to.
2390  * @param struct_type The type of the struct.
2391  * @param name The string name to use to encode/decode this member
2392  *        (must be a constant global and never change).
2393  * @param member The struct member itself to be encoded.
2394  *
2395  * This macro lets you easily add a hash of string. All the
2396  * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC().
2397  *
2398  * @since 1.3.4
2399  * @ingroup Eet_Data_Group
2400  */
2401 #define EET_DATA_DESCRIPTOR_ADD_HASH_STRING(edd, struct_type, name, member)\
2402    do {\
2403         struct_type ___ett;\
2404 \
2405         eet_data_descriptor_element_add(edd, name, EET_T_STRING, EET_G_HASH,\
2406                                         (char *)(& (___ett.member)) -\
2407                                         (char *)(& (___ett)),\
2408                                         0, /* 0,  */ NULL, NULL);\
2409      } while (0)
2410
2411 /**
2412  * Add a fixed size array type to a data descriptor
2413  * @param edd The data descriptor to add the type to.
2414  * @param struct_type The type of the struct.
2415  * @param name The string name to use to encode/decode this member
2416  *        (must be a constant global and never change).
2417  * @param member The struct member itself to be encoded.
2418  * @param subtype The type of hash member to add.
2419  *
2420  * This macro lets you easily add a fixed size array of other data
2421  * types. All the parameters are the same as for
2422  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
2423  * exception. This must be the data descriptor of the element that
2424  * is in each member of the hash to be stored.
2425  *
2426  * @since 1.0.2
2427  * @ingroup Eet_Data_Group
2428  */
2429 #define EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, struct_type, name, member, subtype)\
2430    do {\
2431         struct_type ___ett;\
2432 \
2433         eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_ARRAY,\
2434                                         (char *)(& (___ett.member)) -\
2435                                         (char *)(& (___ett)),\
2436                                         /* 0,  */ sizeof(___ett.member) /\
2437                                         sizeof(___ett.member[0]), NULL, subtype);\
2438      } while (0)
2439
2440 /**
2441  * Add a variable size array type to a data descriptor
2442  * @param edd The data descriptor to add the type to.
2443  * @param struct_type The type of the struct.
2444  * @param name The string name to use to encode/decode this member
2445  *        (must be a constant global and never change).
2446  * @param member The struct member itself to be encoded.
2447  * @param subtype The type of hash member to add.
2448  *
2449  * This macro lets you easily add a fixed size array of other data
2450  * types. All the parameters are the same as for
2451  * EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the
2452  * exception. This must be the data descriptor of the element that
2453  * is in each member of the hash to be stored.
2454  *
2455  * @since 1.0.2
2456  * @ingroup Eet_Data_Group
2457  */
2458 #define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd,\
2459                                           struct_type,\
2460                                           name,\
2461                                           member,\
2462                                           subtype)\
2463    do {\
2464         struct_type ___ett;\
2465 \
2466         eet_data_descriptor_element_add(edd,\
2467                                         name,\
2468                                         EET_T_UNKNOW,\
2469                                         EET_G_VAR_ARRAY,\
2470                                         (char *)(& (___ett.member)) -\
2471                                         (char *)(& (___ett)),\
2472                                         (char *)(& (___ett.member ## _count)) -\
2473                                         (char *)(& (___ett)),\
2474                                         /* 0,  */ NULL,\
2475                                         subtype);\
2476      } while (0)
2477
2478 /**
2479  * Add an union type to a data descriptor
2480  * @param edd The data descriptor to add the type to.
2481  * @param struct_type The type of the struct.
2482  * @param name The string name to use to encode/decode this member
2483  *        (must be a constant global and never change).
2484  * @param member The struct member itself to be encoded.
2485  * @param type_member The member that give hints on what is in the union.
2486  * @param unified_type Describe all possible type the union could handle.
2487  *
2488  * This macro lets you easily add an union with a member that specify what is inside.
2489  * The @p unified_type is an Eet_Data_Descriptor, but only the entry that match the name
2490  * returned by type_get will be used for each serialized data. The type_get and type_set
2491  * callback of unified_type should be defined.
2492  *
2493  * @since 1.2.4
2494  * @ingroup Eet_Data_Group
2495  * @see Eet_Data_Descriptor_Class
2496  */
2497 #define EET_DATA_DESCRIPTOR_ADD_UNION(edd,\
2498                                       struct_type,\
2499                                       name,\
2500                                       member,\
2501                                       type_member,\
2502                                       unified_type)\
2503    do {\
2504         struct_type ___ett;\
2505 \
2506         eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_UNION,\
2507                                         (char *)(& (___ett.member)) -\
2508                                         (char *)(& (___ett)),\
2509                                         (char *)(& (___ett.type_member)) -\
2510                                         (char *)(& (___ett)),\
2511                                         NULL, unified_type);\
2512      } while (0)
2513
2514 /**
2515  * Add a automatically selectable type to a data descriptor
2516  * @param edd The data descriptor to add the type to.
2517  * @param struct_type The type of the struct.
2518  * @param name The string name to use to encode/decode this member
2519  *        (must be a constant global and never change).
2520  * @param member The struct member itself to be encoded.
2521  * @param type_member The member that give hints on what is in the union.
2522  * @param unified_type Describe all possible type the union could handle.
2523  *
2524  * This macro lets you easily define what the content of @p member points to depending of
2525  * the content of @p type_member. The type_get and type_set callback of unified_type should
2526  * be defined. If the the type is not know at the time of restoring it, eet will still call
2527  * type_set of @p unified_type but the pointer will be set to a serialized binary representation
2528  * of what eet know. This make it possible, to save this pointer again by just returning the string
2529  * given previously and telling it by setting unknow to EINA_TRUE.
2530  *
2531  * @since 1.2.4
2532  * @ingroup Eet_Data_Group
2533  * @see Eet_Data_Descriptor_Class
2534  */
2535 #define EET_DATA_DESCRIPTOR_ADD_VARIANT(edd,\
2536                                         struct_type,\
2537                                         name,\
2538                                         member,\
2539                                         type_member,\
2540                                         unified_type)\
2541    do {\
2542         struct_type ___ett;\
2543 \
2544         eet_data_descriptor_element_add(edd, name, EET_T_UNKNOW, EET_G_VARIANT,\
2545                                         (char *)(& (___ett.member)) -\
2546                                         (char *)(& (___ett)),\
2547                                         (char *)(& (___ett.type_member)) -\
2548                                         (char *)(& (___ett)),\
2549                                         NULL, unified_type);\
2550      } while (0)
2551
2552 /**
2553  * Add a mapping to a data descriptor that will be used by union, variant or inherited type
2554  * @param unified_type The data descriptor to add the mapping to.
2555  * @param name The string name to get/set type.
2556  * @param subtype The matching data descriptor.
2557  *
2558  * @since 1.2.4
2559  * @ingroup Eet_Data_Group
2560  * @see Eet_Data_Descriptor_Class
2561  */
2562 #define EET_DATA_DESCRIPTOR_ADD_MAPPING(unified_type, name, subtype)\
2563    eet_data_descriptor_element_add(unified_type,\
2564                                    name,\
2565                                    EET_T_UNKNOW,\
2566                                    EET_G_UNKNOWN,\
2567                                    0,\
2568                                    0,\
2569                                    NULL,\
2570                                    subtype)
2571
2572 /**
2573  * @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
2574  *
2575  * Most of the @ref Eet_Data_Group have alternative versions that
2576  * accounts for ciphers to protect their content.
2577  *
2578  * @see @ref Eet_Cipher_Group
2579  *
2580  * @ingroup Eet_Data_Group
2581  */
2582
2583 /**
2584  * Read a data structure from an eet file and decodes it using a cipher.
2585  * @param ef The eet file handle to read from.
2586  * @param edd The data descriptor handle to use when decoding.
2587  * @param name The key the data is stored under in the eet file.
2588  * @param cipher_key The key to use as cipher.
2589  * @return A pointer to the decoded data structure.
2590  *
2591  * This function decodes a data structure stored in an eet file, returning
2592  * a pointer to it if it decoded successfully, or NULL on failure. This
2593  * can save a programmer dozens of hours of work in writing configuration
2594  * file parsing and writing code, as eet does all that work for the program
2595  * and presents a program-friendly data structure, just as the programmer
2596  * likes. Eet can handle members being added or deleted from the data in
2597  * storage and safely zero-fills unfilled members if they were not found
2598  * in the data. It checks sizes and headers whenever it reads data, allowing
2599  * the programmer to not worry about corrupt data.
2600  *
2601  * Once a data structure has been described by the programmer with the
2602  * fields they wish to save or load, storing or retrieving a data structure
2603  * from an eet file, or from a chunk of memory is as simple as a single
2604  * function call.
2605  *
2606  * @see eet_data_read()
2607  *
2608  * @since 1.0.0
2609  * @ingroup Eet_Data_Cipher_Group
2610  */
2611 EAPI void *    eet_data_read_cipher(Eet_File            *ef,
2612                                     Eet_Data_Descriptor *edd,
2613                                     const char          *name,
2614                                     const char          *cipher_key);
2615
2616 /**
2617  * Write a data structure from memory and store in an eet file
2618  * using a cipher.
2619  * @param ef The eet file handle to write to.
2620  * @param edd The data descriptor to use when encoding.
2621  * @param name The key to store the data under in the eet file.
2622  * @param cipher_key The key to use as cipher.
2623  * @param data A pointer to the data structure to ssave and encode.
2624  * @param compress Compression flags for storage.
2625  * @return bytes written on successful write, 0 on failure.
2626  *
2627  * This function is the reverse of eet_data_read(), saving a data structure
2628  * to an eet file.
2629  *
2630  * @see eet_data_write_cipher()
2631  *
2632  * @since 1.0.0
2633  * @ingroup Eet_Data_Cipher_Group
2634  */
2635 EAPI int       eet_data_write_cipher(Eet_File            *ef,
2636                                      Eet_Data_Descriptor *edd,
2637                                      const char          *name,
2638                                      const char          *cipher_key,
2639                                      const void          *data,
2640                                      int                  compress);
2641
2642 /**
2643  * Dump an eet encoded data structure into ascii text using a cipher.
2644  * @param data_in The pointer to the data to decode into a struct.
2645  * @param cipher_key The key to use as cipher.
2646  * @param size_in The size of the data pointed to in bytes.
2647  * @param dumpfunc The function to call passed a string when new
2648  *        data is converted to text
2649  * @param dumpdata The data to pass to the @p dumpfunc callback.
2650  * @return 1 on success, 0 on failure
2651  *
2652  * This function will take a chunk of data encoded by
2653  * eet_data_descriptor_encode() and convert it into human readable
2654  * ascii text.  It does this by calling the @p dumpfunc callback
2655  * for all new text that is generated. This callback should append
2656  * to any existing text buffer and will be passed the pointer @p
2657  * dumpdata as a parameter as well as a string with new text to be
2658  * appended.
2659  *
2660  * Example:
2661  *
2662  * @code
2663  * void output(void *data, const char *string)
2664  * {
2665  *   printf("%s", string);
2666  * }
2667  *
2668  * void dump(const char *file)
2669  * {
2670  *   FILE *f;
2671  *   int len;
2672  *   void *data;
2673  *
2674  *   f = fopen(file, "r");
2675  *   fseek(f, 0, SEEK_END);
2676  *   len = ftell(f);
2677  *   rewind(f);
2678  *   data = malloc(len);
2679  *   fread(data, len, 1, f);
2680  *   fclose(f);
2681  *   eet_data_text_dump_cipher(data, cipher_key, len, output, NULL);
2682  * }
2683  * @endcode
2684  *
2685  * @see eet_data_text_dump()
2686  *
2687  * @since 1.0.0
2688  * @ingroup Eet_Data_Cipher_Group
2689  */
2690 EAPI int      eet_data_text_dump_cipher(const void *data_in,
2691                                         const char *cipher_key,
2692                                         int size_in,
2693                                         void (*dumpfunc)(void *data, const char *str),
2694                                         void *dumpdata);
2695
2696 /**
2697  * Take an ascii encoding from eet_data_text_dump() and re-encode
2698  * in binary using a cipher.
2699  * @param text The pointer to the string data to parse and encode.
2700  * @param cipher_key The key to use as cipher.
2701  * @param textlen The size of the string in bytes (not including 0
2702  *        byte terminator).
2703  * @param size_ret This gets filled in with the encoded data blob
2704  *        size in bytes.
2705  * @return The encoded data on success, NULL on failure.
2706  *
2707  * This function will parse the string pointed to by @p text and return
2708  * an encoded data lump the same way eet_data_descriptor_encode() takes an
2709  * in-memory data struct and encodes into a binary blob. @p text is a normal
2710  * C string.
2711  *
2712  * @see eet_data_text_undump()
2713  *
2714  * @since 1.0.0
2715  * @ingroup Eet_Data_Cipher_Group
2716  */
2717 EAPI void *    eet_data_text_undump_cipher(const char *text,
2718                                            const char *cipher_key,
2719                                            int         textlen,
2720                                            int        *size_ret);
2721
2722 /**
2723  * Dump an eet encoded data structure from an eet file into ascii
2724  * text using a cipher.
2725  * @param ef A valid eet file handle.
2726  * @param name Name of the entry. eg: "/base/file_i_want".
2727  * @param cipher_key The key to use as cipher.
2728  * @param dumpfunc The function to call passed a string when new
2729  *        data is converted to text
2730  * @param dumpdata The data to pass to the @p dumpfunc callback.
2731  * @return 1 on success, 0 on failure
2732  *
2733  * This function will take an open and valid eet file from
2734  * eet_open() request the data encoded by
2735  * eet_data_descriptor_encode() corresponding to the key @p name
2736  * and convert it into human readable ascii text. It does this by
2737  * calling the @p dumpfunc callback for all new text that is
2738  * generated. This callback should append to any existing text
2739  * buffer and will be passed the pointer @p dumpdata as a parameter
2740  * as well as a string with new text to be appended.
2741  *
2742  * @see eet_data_dump()
2743  *
2744  * @since 1.0.0
2745  * @ingroup Eet_Data_Cipher_Group
2746  */
2747 EAPI int       eet_data_dump_cipher(Eet_File *ef,
2748                                     const char *name,
2749                                     const char *cipher_key,
2750                                     void (*dumpfunc)(void *data, const char *str),
2751                                     void *dumpdata);
2752
2753 /**
2754  * Take an ascii encoding from eet_data_dump() and re-encode in
2755  * binary using a cipher.
2756  * @param ef A valid eet file handle.
2757  * @param name Name of the entry. eg: "/base/file_i_want".
2758  * @param cipher_key The key to use as cipher.
2759  * @param text The pointer to the string data to parse and encode.
2760  * @param textlen The size of the string in bytes (not including 0
2761  *        byte terminator).
2762  * @param compress Compression flags (1 == compress, 0 = don't compress).
2763  * @return 1 on success, 0 on failure
2764  *
2765  * This function will parse the string pointed to by @p text,
2766  * encode it the same way eet_data_descriptor_encode() takes an
2767  * in-memory data struct and encodes into a binary blob.
2768  *
2769  * The data (optionally compressed) will be in ram, pending a flush to
2770  * disk (it will stay in ram till the eet file handle is closed though).
2771  *
2772  * @see eet_data_undump()
2773  *
2774  * @since 1.0.0
2775  * @ingroup Eet_Data_Cipher_Group
2776  */
2777 EAPI int      eet_data_undump_cipher(Eet_File   *ef,
2778                                      const char *name,
2779                                      const char *cipher_key,
2780                                      const char *text,
2781                                      int         textlen,
2782                                      int         compress);
2783
2784 /**
2785  * Decode a data structure from an arbitary location in memory
2786  * using a cipher.
2787  * @param edd The data  descriptor to use when decoding.
2788  * @param data_in The pointer to the data to decode into a struct.
2789  * @param cipher_key The key to use as cipher.
2790  * @param size_in The size of the data pointed to in bytes.
2791  * @return NULL on failure, or a valid decoded struct pointer on success.
2792  *
2793  * This function will decode a data structure that has been encoded using
2794  * eet_data_descriptor_encode(), and return a data structure with all its
2795  * elements filled out, if successful, or NULL on failure.
2796  *
2797  * The data to be decoded is stored at the memory pointed to by @p data_in,
2798  * and is described by the descriptor pointed to by @p edd. The data size is
2799  * passed in as the value to @p size_in, ande must be greater than 0 to
2800  * succeed.
2801  *
2802  * This function is useful for decoding data structures delivered to the
2803  * application by means other than an eet file, such as an IPC or socket
2804  * connection, raw files, shared memory etc.
2805  *
2806  * Please see eet_data_read() for more information.
2807  *
2808  * @see eet_data_descriptor_decode()
2809  *
2810  * @since 1.0.0
2811  * @ingroup Eet_Data_Cipher_Group
2812  */
2813 EAPI void *    eet_data_descriptor_decode_cipher(Eet_Data_Descriptor *edd,
2814                                                  const void          *data_in,
2815                                                  const char          *cipher_key,
2816                                                  int                  size_in);
2817
2818 /**
2819  * Encode a data struct to memory and return that encoded data
2820  * using a cipher.
2821  * @param edd The data  descriptor to use when encoding.
2822  * @param data_in The pointer to the struct to encode into data.
2823  * @param cipher_key The key to use as cipher.
2824  * @param size_ret pointer to the an int to be filled with the decoded size.
2825  * @return NULL on failure, or a valid encoded data chunk on success.
2826  *
2827  * This function takes a data structutre in memory and encodes it into a
2828  * serialised chunk of data that can be decoded again by
2829  * eet_data_descriptor_decode(). This is useful for being able to transmit
2830  * data structures across sockets, pipes, IPC or shared file mechanisms,
2831  * without having to worry about memory space, machine type, endianess etc.
2832  *
2833  * The parameter @p edd must point to a valid data descriptor, and
2834  * @p data_in must point to the right data structure to encode. If not, the
2835  * encoding may fail.
2836  *
2837  * On success a non NULL valid pointer is returned and what @p size_ret
2838  * points to is set to the size of this decoded data, in bytes. When the
2839  * encoded data is no longer needed, call free() on it. On failure NULL is
2840  * returned and what @p size_ret points to is set to 0.
2841  *
2842  * Please see eet_data_write() for more information.
2843  *
2844  * @see eet_data_descriptor_encode()
2845  *
2846  * @since 1.0.0
2847  * @ingroup Eet_Data_Cipher_Group
2848  */
2849 EAPI void *    eet_data_descriptor_encode_cipher(Eet_Data_Descriptor *edd,
2850                                                  const void          *data_in,
2851                                                  const char          *cipher_key,
2852                                                  int                 *size_ret);
2853
2854 /**
2855  * @defgroup Eet_Node_Group Low-level Serialization Structures.
2856  *
2857  * Functions that create, destroy and manipulate serialization nodes
2858  * used by @ref Eet_Data_Group.
2859  *
2860  * @{
2861  */
2862
2863 /**
2864  * @typedef Eet_Node
2865  * Opaque handle to manage serialization node.
2866  */
2867 typedef struct _Eet_Node        Eet_Node;
2868
2869 /**
2870  * @typedef Eet_Node_Data
2871  * Contains an union that can fit any kind of node.
2872  */
2873 typedef struct _Eet_Node_Data   Eet_Node_Data;
2874
2875 /**
2876  * @struct _Eet_Node_Data
2877  * Contains an union that can fit any kind of node.
2878  */
2879 struct _Eet_Node_Data
2880 {
2881    union {
2882       char               c;
2883       short              s;
2884       int                i;
2885       long long          l;
2886       float              f;
2887       double             d;
2888       unsigned char      uc;
2889       unsigned short     us;
2890       unsigned int       ui;
2891       unsigned long long ul;
2892       const char        *str;
2893    } value;
2894 };
2895
2896 /**
2897  * @}
2898  */
2899
2900 /**
2901  * TODO FIX ME
2902  * @ingroup Eet_Node_Group
2903  */
2904 EAPI Eet_Node *    eet_node_char_new(const char *name,
2905                                      char        c);
2906
2907 /**
2908  * TODO FIX ME
2909  * @ingroup Eet_Node_Group
2910  */
2911 EAPI Eet_Node *    eet_node_short_new(const char *name,
2912                                       short       s);
2913
2914 /**
2915  * TODO FIX ME
2916  * @ingroup Eet_Node_Group
2917  */
2918 EAPI Eet_Node *    eet_node_int_new(const char *name,
2919                                     int         i);
2920
2921 /**
2922  * TODO FIX ME
2923  * @ingroup Eet_Node_Group
2924  */
2925 EAPI Eet_Node *    eet_node_long_long_new(const char *name,
2926                                           long long   l);
2927
2928 /**
2929  * TODO FIX ME
2930  * @ingroup Eet_Node_Group
2931  */
2932 EAPI Eet_Node *    eet_node_float_new(const char *name,
2933                                       float       f);
2934
2935 /**
2936  * TODO FIX ME
2937  * @ingroup Eet_Node_Group
2938  */
2939 EAPI Eet_Node *    eet_node_double_new(const char *name,
2940                                        double      d);
2941
2942 /**
2943  * TODO FIX ME
2944  * @ingroup Eet_Node_Group
2945  */
2946 EAPI Eet_Node *    eet_node_unsigned_char_new(const char   *name,
2947                                               unsigned char uc);
2948
2949 /**
2950  * TODO FIX ME
2951  * @ingroup Eet_Node_Group
2952  */
2953 EAPI Eet_Node *    eet_node_unsigned_short_new(const char    *name,
2954                                                unsigned short us);
2955
2956 /**
2957  * TODO FIX ME
2958  * @ingroup Eet_Node_Group
2959  */
2960 EAPI Eet_Node *    eet_node_unsigned_int_new(const char  *name,
2961                                              unsigned int ui);
2962
2963 /**
2964  * TODO FIX ME
2965  * @ingroup Eet_Node_Group
2966  */
2967 EAPI Eet_Node *    eet_node_unsigned_long_long_new(const char        *name,
2968                                                    unsigned long long l);
2969
2970 /**
2971  * TODO FIX ME
2972  * @ingroup Eet_Node_Group
2973  */
2974 EAPI Eet_Node *    eet_node_string_new(const char *name,
2975                                        const char *str);
2976
2977 /**
2978  * TODO FIX ME
2979  * @ingroup Eet_Node_Group
2980  */
2981 EAPI Eet_Node *    eet_node_inlined_string_new(const char *name,
2982                                                const char *str);
2983
2984 /**
2985  * TODO FIX ME
2986  * @ingroup Eet_Node_Group
2987  */
2988 EAPI Eet_Node *    eet_node_null_new(const char *name);
2989
2990 /**
2991  * TODO FIX ME
2992  * @ingroup Eet_Node_Group
2993  */
2994 EAPI Eet_Node *    eet_node_list_new(const char *name,
2995                                      Eina_List  *nodes);
2996
2997 /**
2998  * TODO FIX ME
2999  * @ingroup Eet_Node_Group
3000  */
3001 EAPI Eet_Node *    eet_node_array_new(const char *name,
3002                                       int         count,
3003                                       Eina_List  *nodes);
3004
3005 /**
3006  * TODO FIX ME
3007  * @ingroup Eet_Node_Group
3008  */
3009 EAPI Eet_Node *    eet_node_var_array_new(const char *name,
3010                                           Eina_List  *nodes);
3011
3012 /**
3013  * TODO FIX ME
3014  * @ingroup Eet_Node_Group
3015  */
3016 EAPI Eet_Node *    eet_node_hash_new(const char *name,
3017                                      const char *key,
3018                                      Eet_Node   *node);
3019
3020 /**
3021  * TODO FIX ME
3022  * @ingroup Eet_Node_Group
3023  */
3024 EAPI Eet_Node *    eet_node_struct_new(const char *name,
3025                                        Eina_List  *nodes);
3026
3027 /**
3028  * TODO FIX ME
3029  * @ingroup Eet_Node_Group
3030  */
3031 EAPI Eet_Node *    eet_node_struct_child_new(const char *parent,
3032                                              Eet_Node   *child);
3033
3034 /**
3035  * TODO FIX ME
3036  * @ingroup Eet_Node_Group
3037  */
3038 EAPI void          eet_node_list_append(Eet_Node   *parent,
3039                                         const char *name,
3040                                         Eet_Node   *child);
3041
3042 /**
3043  * TODO FIX ME
3044  * @ingroup Eet_Node_Group
3045  */
3046 EAPI void          eet_node_struct_append(Eet_Node   *parent,
3047                                           const char *name,
3048                                           Eet_Node   *child);
3049
3050 /**
3051  * TODO FIX ME
3052  * @ingroup Eet_Node_Group
3053  */
3054 EAPI void          eet_node_hash_add(Eet_Node   *parent,
3055                                      const char *name,
3056                                      const char *key,
3057                                      Eet_Node   *child);
3058
3059 /**
3060  * TODO FIX ME
3061  * @ingroup Eet_Node_Group
3062  */
3063 EAPI void          eet_node_dump(Eet_Node *n,
3064                                  int dumplevel,
3065                                  void (*dumpfunc)(void *data, const char *str),
3066                                  void *dumpdata);
3067
3068 /**
3069  * TODO FIX ME
3070  * @ingroup Eet_Node_Group
3071  */
3072 EAPI void          eet_node_del(Eet_Node *n);
3073
3074 /**
3075  * TODO FIX ME
3076  * @ingroup Eet_Node_Group
3077  */
3078 EAPI void *        eet_data_node_encode_cipher(Eet_Node   *node,
3079                                                const char *cipher_key,
3080                                                int        *size_ret);
3081
3082 /**
3083  * TODO FIX ME
3084  * @ingroup Eet_Node_Group
3085  */
3086 EAPI Eet_Node *    eet_data_node_decode_cipher(const void *data_in,
3087                                                const char *cipher_key,
3088                                                int         size_in);
3089
3090 /**
3091  * TODO FIX ME
3092  * @ingroup Eet_Node_Group
3093  */
3094 EAPI Eet_Node *    eet_data_node_read_cipher(Eet_File   *ef,
3095                                              const char *name,
3096                                              const char *cipher_key);
3097
3098 /**
3099  * TODO FIX ME
3100  * @ingroup Eet_Node_Group
3101  */
3102 EAPI int           eet_data_node_write_cipher(Eet_File   *ef,
3103                                               const char *name,
3104                                               const char *cipher_key,
3105                                               Eet_Node   *node,
3106                                               int         compress);
3107
3108 /* EXPERIMENTAL: THIS API MAY CHANGE IN THE FUTURE, USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING. */
3109
3110 /**
3111  * @typedef Eet_Node_Walk
3112  * Describes how to walk trees of #Eet_Node.
3113  */
3114 typedef struct _Eet_Node_Walk   Eet_Node_Walk;
3115
3116 /**
3117  * @struct _Eet_Node_Walk
3118  * Describes how to walk trees of #Eet_Node.
3119  */
3120 struct _Eet_Node_Walk
3121 {
3122    void *(*struct_alloc)(const char *type, void *user_data);
3123    void  (*struct_add)(void *parent, const char *name, void *child, void *user_data);
3124    void *(*array)(Eina_Bool variable, const char *name, int count, void *user_data);
3125    void  (*insert)(void *array, int index, void *child, void *user_data);
3126    void *(*list)(const char *name, void *user_data);
3127    void  (*append)(void *list, void *child, void *user_data);
3128    void *(*hash)(void *parent, const char *name, const char *key, void *value, void *user_data);
3129    void *(*simple)(int type, Eet_Node_Data *data, void *user_data);
3130 };
3131
3132 EAPI void *    eet_node_walk(void          *parent,
3133                              const char    *name,
3134                              Eet_Node      *root,
3135                              Eet_Node_Walk *cb,
3136                              void          *user_data);
3137
3138 /*******/
3139
3140 /**
3141  * @defgroup Eet_Connection_Group Helper function to use eet over a network link
3142  *
3143  * Function that reconstruct and prepare packet of @ref Eet_Data_Group to be send.
3144  *
3145  */
3146
3147 /**
3148  * @typedef Eet_Connection
3149  * Opaque handle to track paquet for a specific connection.
3150  *
3151  * @ingroup Eet_Connection_Group
3152  */
3153 typedef struct _Eet_Connection   Eet_Connection;
3154
3155 /**
3156  * @typedef Eet_Read_Cb
3157  * Called back when an @ref Eet_Data_Group has been received completly and could be used.
3158  *
3159  * @ingroup Eet_Connection_Group
3160  */
3161 typedef Eina_Bool                Eet_Read_Cb (const void *eet_data, size_t size, void *user_data);
3162
3163 /**
3164  * @typedef Eet_Write_Cb
3165  * Called back when a packet containing @ref Eet_Data_Group data is ready to be send.
3166  *
3167  * @ingroup Eet_Connection_Group
3168  */
3169 typedef Eina_Bool                Eet_Write_Cb (const void *data, size_t size, void *user_data);
3170
3171 /**
3172  * Instanciate a new connection to track.
3173  * @oaram eet_read_cb Function to call when one Eet_Data packet has been fully assemble.
3174  * @param eet_write_cb Function to call when one Eet_Data packet is ready to be send over the wire.
3175  * @param user_data Pointer provided to both functions to be used as a context handler.
3176  * @return NULL on failure, or a valid Eet_Connection handler.
3177  *
3178  * For every connection to track you will need a separate Eet_Connection provider.
3179  *
3180  * @since 1.2.4
3181  * @ingroup Eet_Connection_Group
3182  */
3183 EAPI Eet_Connection *    eet_connection_new(Eet_Read_Cb  *eet_read_cb,
3184                                             Eet_Write_Cb *eet_write_cb,
3185                                             const void   *user_data);
3186
3187 /**
3188  * Process a raw packet received over the link
3189  * @oaram conn Connection handler to track.
3190  * @param data Raw data packet.
3191  * @param size The size of that packet.
3192  * @return 0 on complete success, any other value indicate where in the stream it got wrong (It could be before that packet).
3193  *
3194  * Every time you receive a packet related to your connection, you should pass
3195  * it to that function so that it could process and assemble packet has you
3196  * receive it. It will automatically call Eet_Read_Cb when one is fully received.
3197  *
3198  * @since 1.2.4
3199  * @ingroup Eet_Connection_Group
3200  */
3201 EAPI int                 eet_connection_received(Eet_Connection *conn,
3202                                                  const void     *data,
3203                                                  size_t          size);
3204
3205 /**
3206  * Convert a complex structure and prepare it to be send.
3207  * @oaram conn Connection handler to track.
3208  * @param edd The data descriptor to use when encoding.
3209  * @param data_in The pointer to the struct to encode into data.
3210  * @param cipher_key The key to use as cipher.
3211  * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
3212  *
3213  * This function serialize data_in with edd, assemble the packet and call
3214  * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
3215  * and will vanish just after the return of the callback.
3216  *
3217  * @see eet_data_descriptor_encode_cipher
3218  *
3219  * @since 1.2.4
3220  * @ingroup Eet_Connection_Group
3221  */
3222 EAPI Eina_Bool           eet_connection_send(Eet_Connection      *conn,
3223                                              Eet_Data_Descriptor *edd,
3224                                              const void          *data_in,
3225                                              const char          *cipher_key);
3226
3227 /**
3228  * Convert a Eet_Node tree and prepare it to be send.
3229  * @oaram conn Connection handler to track.
3230  * @param node The data tree to use when encoding.
3231  * @param cipher_key The key to use as cipher.
3232  * @return EINA_TRUE if the data where correctly send, EINA_FALSE if they don't.
3233  *
3234  * This function serialize node, assemble the packet and call
3235  * Eet_Write_Cb when ready. The data passed Eet_Write_Cb are temporary allocated
3236  * and will vanish just after the return of the callback.
3237  *
3238  * @see eet_data_node_encode_cipher
3239  *
3240  * @since 1.2.4
3241  * @ingroup Eet_Connection_Group
3242  */
3243 EAPI Eina_Bool           eet_connection_node_send(Eet_Connection *conn,
3244                                                   Eet_Node       *node,
3245                                                   const char     *cipher_key);
3246
3247 /**
3248  * Close a connection and lost its track.
3249  * @oaram conn Connection handler to close.
3250  * @param on_going Signal if a partial packet wasn't completed.
3251  * @return the user_data passed to both callback.
3252  *
3253  * @since 1.2.4
3254  * @ingroup Eet_Connection_Group
3255  */
3256 EAPI void *              eet_connection_close(Eet_Connection *conn,
3257                                               Eina_Bool      *on_going);
3258
3259 /***************************************************************************/
3260
3261 #ifdef __cplusplus
3262 }
3263 #endif /* ifdef __cplusplus */
3264
3265 #endif /* ifndef _EET_H */