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