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