1 /* EIO - EFL data type library
2  * Copyright (C) 2010 Enlightenment Developers:
3  *           Cedric Bail <cedric.bail@free.fr>
4  *           Vincent "caro" Torri  <vtorri at univ-evry dot fr>
5  *           Stephen "okra" Houston <UnixTitan@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library;
19  * if not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "eio_private.h"
23 #include "Eio.h"
24 
25 /*============================================================================*
26  *                                  Local                                     *
27  *============================================================================*/
28 
29 /**
30  * @cond LOCAL
31  */
32 
33 static void
_eio_eet_open_job(void * data,Ecore_Thread * thread)34 _eio_eet_open_job(void *data, Ecore_Thread *thread)
35 {
36    Eio_Eet_Open *eet = data;
37 
38    eet->result = eet_open(eet->filename, eet->mode);
39    if (!eet->result) eio_file_thread_error(&eet->common, thread);
40 }
41 
42 static void
_eio_eet_open_free(Eio_Eet_Open * eet)43 _eio_eet_open_free(Eio_Eet_Open *eet)
44 {
45    if (eet->filename) eina_stringshare_del(eet->filename);
46    eio_file_free((Eio_File *)eet);
47 }
48 
49 static void
_eio_eet_open_end(void * data,Ecore_Thread * thread EINA_UNUSED)50 _eio_eet_open_end(void *data, Ecore_Thread *thread EINA_UNUSED)
51 {
52    Eio_Eet_Open *eet = data;
53 
54    eet->eet_cb((void*) eet->common.data, &eet->common, eet->result);
55    _eio_eet_open_free(eet);
56 }
57 
58 static void
_eio_eet_open_cancel(void * data,Ecore_Thread * thread EINA_UNUSED)59 _eio_eet_open_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
60 {
61    Eio_Eet_Open *eet = data;
62 
63    eio_file_error(&eet->common);
64    _eio_eet_open_free(eet);
65 }
66 
67 static void
_eio_eet_close_job(void * data,Ecore_Thread * thread)68 _eio_eet_close_job(void *data, Ecore_Thread *thread)
69 {
70    Eio_Eet_Simple *eet = data;
71 
72    eet->error = eet_close(eet->ef);
73    if (eet->error != EET_ERROR_NONE) eio_file_thread_error(&eet->common, thread);
74 }
75 
76 static void
_eio_eet_sync_job(void * data,Ecore_Thread * thread)77 _eio_eet_sync_job(void *data, Ecore_Thread *thread)
78 {
79    Eio_Eet_Simple *eet = data;
80 
81    eet->error = eet_sync(eet->ef);
82    if (eet->error != EET_ERROR_NONE) eio_file_thread_error(&eet->common, thread);
83 }
84 
85 static void
_eio_eet_simple_end(void * data,Ecore_Thread * thread EINA_UNUSED)86 _eio_eet_simple_end(void *data, Ecore_Thread *thread EINA_UNUSED)
87 {
88    Eio_Eet_Simple *eet = data;
89 
90    eet->common.done_cb((void*) eet->common.data, &eet->common);
91    eio_file_free((Eio_File *)eet);
92 }
93 
94 static void
_eio_eet_simple_cancel(void * data,Ecore_Thread * thread EINA_UNUSED)95 _eio_eet_simple_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
96 {
97    Eio_Eet_Simple *eet = data;
98 
99    eet->error_cb((void*) eet->common.data, &eet->common, eet->error);
100    eio_file_free((Eio_File *)eet);
101 }
102 
103 static void
_eio_eet_data_write_cipher_job(void * data,Ecore_Thread * thread)104 _eio_eet_data_write_cipher_job(void *data, Ecore_Thread *thread)
105 {
106    Eio_Eet_Write *ew = data;
107 
108    ew->result = eet_data_write_cipher(ew->ef, ew->edd,
109                                       ew->name, ew->cipher_key,
110                                       ew->write_data,
111                                       ew->compress);
112    if (ew->result == 0) eio_file_thread_error(&ew->common, thread);
113 }
114 
115 static void
_eio_eet_write_cipher_free(Eio_Eet_Write * ew)116 _eio_eet_write_cipher_free(Eio_Eet_Write *ew)
117 {
118    eina_stringshare_del(ew->name);
119    eina_stringshare_del(ew->cipher_key);
120    eio_file_free((Eio_File *)ew);
121 }
122 
123 static void
_eio_eet_data_write_cipher_end(void * data,Ecore_Thread * thread EINA_UNUSED)124 _eio_eet_data_write_cipher_end(void *data, Ecore_Thread *thread EINA_UNUSED)
125 {
126    Eio_Eet_Write *ew = data;
127 
128    ew->done_cb((void*) ew->common.data, &ew->common, ew->result);
129    _eio_eet_write_cipher_free(ew);
130 }
131 
132 static void
_eio_eet_data_write_cipher_cancel(void * data,Ecore_Thread * thread EINA_UNUSED)133 _eio_eet_data_write_cipher_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
134 {
135    Eio_Eet_Write *ew = data;
136 
137    eio_file_error(&ew->common);
138    _eio_eet_write_cipher_free(ew);
139 }
140 
141 static void
_eio_eet_image_write_job(void * data,Ecore_Thread * thread)142 _eio_eet_image_write_job(void *data, Ecore_Thread *thread)
143 {
144    Eio_Eet_Image_Write *eiw = data;
145 
146    eiw->result = eet_data_image_write_cipher(eiw->ef, eiw->name, eiw->cipher_key,
147                                              eiw->write_data,
148                                              eiw->w,
149                                              eiw->h,
150                                              eiw->alpha,
151                                              eiw->compress,
152                                              eiw->quality,
153                                              eiw->lossy);
154    if (!eiw->result) eio_file_thread_error(&eiw->common, thread);
155 }
156 
157 static void
_eio_eet_image_write_free(Eio_Eet_Image_Write * eiw)158 _eio_eet_image_write_free(Eio_Eet_Image_Write *eiw)
159 {
160    eina_stringshare_del(eiw->name);
161    eina_stringshare_del(eiw->cipher_key);
162    eio_file_free(&eiw->common);
163 }
164 
165 static void
_eio_eet_image_write_end(void * data,Ecore_Thread * thread EINA_UNUSED)166 _eio_eet_image_write_end(void *data, Ecore_Thread *thread EINA_UNUSED)
167 {
168    Eio_Eet_Image_Write *eiw = data;
169 
170    eiw->done_cb((void*) eiw->common.data, &eiw->common, eiw->result);
171    _eio_eet_image_write_free(eiw);
172 }
173 
174 static void
_eio_eet_image_write_cancel(void * data,Ecore_Thread * thread EINA_UNUSED)175 _eio_eet_image_write_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
176 {
177    Eio_Eet_Image_Write *eiw = data;
178 
179    eio_file_error(&eiw->common);
180    _eio_eet_image_write_free(eiw);
181 }
182 
183 static void
_eio_eet_write_job(void * data,Ecore_Thread * thread)184 _eio_eet_write_job(void *data, Ecore_Thread *thread)
185 {
186    Eio_Eet_Write *ew = data;
187 
188    ew->result = eet_write_cipher(ew->ef,
189                                  ew->name, ew->write_data,
190                                  ew->size, ew->compress,
191                                  ew->cipher_key);
192    if (!ew->result) eio_file_thread_error(&ew->common, thread);
193 }
194 
195 static void
_eio_eet_write_end(void * data,Ecore_Thread * thread EINA_UNUSED)196 _eio_eet_write_end(void *data, Ecore_Thread *thread EINA_UNUSED)
197 {
198    Eio_Eet_Write *ew = data;
199 
200    ew->done_cb((void*) ew->common.data, &ew->common, ew->result);
201    _eio_eet_write_cipher_free(ew);
202 }
203 
204 static void
_eio_eet_write_cancel(void * data,Ecore_Thread * thread EINA_UNUSED)205 _eio_eet_write_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
206 {
207    Eio_Eet_Write *ew = data;
208 
209    eio_file_error(&ew->common);
210    _eio_eet_write_cipher_free(ew);
211 }
212 
213 static void
_eio_eet_data_read_cipher_job(void * data,Ecore_Thread * thread)214 _eio_eet_data_read_cipher_job(void *data, Ecore_Thread *thread)
215 {
216    Eio_Eet_Read *er = data;
217 
218    er->result = eet_data_read_cipher(er->ef, er->edd,
219                                      er->name, er->cipher_key);
220    if (!er->result) eio_file_thread_error(&er->common, thread);
221 }
222 
223 static void
_eio_eet_read_free(Eio_Eet_Read * er)224 _eio_eet_read_free(Eio_Eet_Read *er)
225 {
226    eina_stringshare_del(er->name);
227    eina_stringshare_del(er->cipher_key);
228    eio_file_free(&er->common);
229 }
230 
231 static void
_eio_eet_data_read_cipher_end(void * data,Ecore_Thread * thread EINA_UNUSED)232 _eio_eet_data_read_cipher_end(void *data, Ecore_Thread *thread EINA_UNUSED)
233 {
234    Eio_Eet_Read *er = data;
235 
236    er->done_cb.eread((void*) er->common.data, &er->common, er->result);
237    _eio_eet_read_free(er);
238 }
239 
240 static void
_eio_eet_data_read_cipher_cancel(void * data,Ecore_Thread * thread EINA_UNUSED)241 _eio_eet_data_read_cipher_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
242 {
243    Eio_Eet_Read *er = data;
244 
245    eio_file_error(&er->common);
246    _eio_eet_read_free(er);
247 }
248 
249 static void
_eio_eet_read_direct_job(void * data,Ecore_Thread * thread)250 _eio_eet_read_direct_job(void *data, Ecore_Thread *thread)
251 {
252    Eio_Eet_Read *er = data;
253 
254    er->result = (void*) eet_read_direct(er->ef, er->name, &er->size);
255    if (!er->result) eio_file_thread_error(&er->common, thread);
256 }
257 
258 static void
_eio_eet_read_direct_end(void * data,Ecore_Thread * thread EINA_UNUSED)259 _eio_eet_read_direct_end(void *data, Ecore_Thread *thread EINA_UNUSED)
260 {
261    Eio_Eet_Read *er = data;
262 
263    er->done_cb.data((void*) er->common.data, &er->common,
264                     er->result, er->size);
265    _eio_eet_read_free(er);
266 }
267 
268 static void
_eio_eet_read_cancel(void * data,Ecore_Thread * thread EINA_UNUSED)269 _eio_eet_read_cancel(void *data, Ecore_Thread *thread EINA_UNUSED)
270 {
271    Eio_Eet_Read *er = data;
272 
273    eio_file_error(&er->common);
274    _eio_eet_read_free(er);
275 }
276 
277 static void
_eio_eet_read_cipher_job(void * data,Ecore_Thread * thread)278 _eio_eet_read_cipher_job(void *data, Ecore_Thread *thread)
279 {
280    Eio_Eet_Read *er = data;
281 
282    er->result = (void*) eet_read_cipher(er->ef, er->name,
283                                         &er->size, er->cipher_key);
284    if (!er->result) eio_file_thread_error(&er->common, thread);
285 }
286 
287 static void
_eio_eet_read_cipher_end(void * data,Ecore_Thread * thread EINA_UNUSED)288 _eio_eet_read_cipher_end(void *data, Ecore_Thread *thread EINA_UNUSED)
289 {
290    Eio_Eet_Read *er = data;
291 
292    er->done_cb.read((void*) er->common.data, &er->common,
293                     er->result, er->size);
294    _eio_eet_read_free(er);
295 }
296 
297 /**
298  * @endcond
299  */
300 
301 /*============================================================================*
302  *                                 Global                                     *
303  *============================================================================*/
304 
305 
306 /*============================================================================*
307  *                                   API                                      *
308  *============================================================================*/
309 
310 EAPI Eio_File *
eio_eet_open(const char * filename,Eet_File_Mode mode,Eio_Eet_Open_Cb eet_cb,Eio_Error_Cb error_cb,const void * data)311 eio_eet_open(const char *filename,
312              Eet_File_Mode mode,
313 	     Eio_Eet_Open_Cb eet_cb,
314 	     Eio_Error_Cb error_cb,
315 	     const void *data)
316 {
317    Eio_Eet_Open *eet;
318 
319    EINA_SAFETY_ON_NULL_RETURN_VAL(filename, NULL);
320    EINA_SAFETY_ON_NULL_RETURN_VAL(eet_cb, NULL);
321    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
322 
323    eet = eio_common_alloc(sizeof(Eio_Eet_Open));
324    EINA_SAFETY_ON_NULL_RETURN_VAL(eet, NULL);
325 
326    eet->eet_cb = eet_cb;
327    eet->filename = eina_stringshare_add(filename);
328    eet->mode = mode;
329    eet->result = NULL;
330 
331    if (!eio_file_set(&eet->common,
332                      NULL,
333                      error_cb,
334                      data,
335                      _eio_eet_open_job,
336                      _eio_eet_open_end,
337                      _eio_eet_open_cancel))
338      return NULL;
339    return &eet->common;
340 }
341 
342 EAPI Eio_File *
eio_eet_close(Eet_File * ef,Eio_Done_Cb done_cb,Eio_Eet_Error_Cb error_cb,const void * data)343 eio_eet_close(Eet_File *ef,
344 	      Eio_Done_Cb done_cb,
345 	      Eio_Eet_Error_Cb error_cb,
346 	      const void *data)
347 {
348    Eio_Eet_Simple *eet;
349 
350    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
351    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
352    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
353 
354    eet = eio_common_alloc(sizeof(Eio_Eet_Simple));
355    EINA_SAFETY_ON_NULL_RETURN_VAL(eet, NULL);
356 
357    eet->ef = ef;
358    eet->error_cb = error_cb;
359    eet->error = EET_ERROR_NONE;
360 
361    if (!eio_file_set(&eet->common,
362                      done_cb,
363                      NULL,
364                      data,
365                      _eio_eet_close_job,
366                      _eio_eet_simple_end,
367                      _eio_eet_simple_cancel))
368      return NULL;
369    return &eet->common;
370 }
371 
372 EAPI Eio_File *
eio_eet_flush(Eet_File * ef,Eio_Done_Cb done_cb,Eio_Eet_Error_Cb error_cb,const void * data)373 eio_eet_flush(Eet_File *ef,
374 	      Eio_Done_Cb done_cb,
375 	      Eio_Eet_Error_Cb error_cb,
376 	      const void *data)
377 {
378    Eio_Eet_Simple *eet;
379 
380    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
381    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
382    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
383 
384    eet = eio_common_alloc(sizeof(Eio_Eet_Simple));
385    EINA_SAFETY_ON_NULL_RETURN_VAL(eet, NULL);
386 
387    eet->ef = ef;
388    eet->error_cb = error_cb;
389    eet->error = EET_ERROR_NONE;
390 
391    if (!eio_file_set(&eet->common,
392                      done_cb,
393                      NULL,
394                      data,
395                      _eio_eet_sync_job,
396                      _eio_eet_simple_end,
397                      _eio_eet_simple_cancel))
398      return NULL;
399    return &eet->common;
400 }
401 
402 EAPI Eio_File *
eio_eet_sync(Eet_File * ef,Eio_Done_Cb done_cb,Eio_Eet_Error_Cb error_cb,const void * data)403 eio_eet_sync(Eet_File *ef,
404              Eio_Done_Cb done_cb,
405              Eio_Eet_Error_Cb error_cb,
406              const void *data)
407 {
408    return eio_eet_flush(ef, done_cb, error_cb, data);
409 }
410 
411 EAPI Eio_File *
eio_eet_data_write_cipher(Eet_File * ef,Eet_Data_Descriptor * edd,const char * name,const char * cipher_key,void * write_data,int compress,Eio_Done_Int_Cb done_cb,Eio_Error_Cb error_cb,const void * user_data)412 eio_eet_data_write_cipher(Eet_File *ef,
413 			  Eet_Data_Descriptor *edd,
414 			  const char *name,
415 			  const char *cipher_key,
416 			  void *write_data,
417 			  int compress,
418 			  Eio_Done_Int_Cb done_cb,
419 			  Eio_Error_Cb error_cb,
420 			  const void *user_data)
421 {
422    Eio_Eet_Write *ew;
423 
424    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
425    EINA_SAFETY_ON_NULL_RETURN_VAL(edd, NULL);
426    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
427    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
428    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
429 
430    ew = eio_common_alloc(sizeof(Eio_Eet_Write));
431    EINA_SAFETY_ON_NULL_RETURN_VAL(ew, NULL);
432 
433    ew->ef = ef;
434    ew->edd = edd;
435    ew->name = eina_stringshare_add(name);
436    ew->cipher_key = eina_stringshare_add(cipher_key);
437    ew->write_data = write_data;
438    ew->compress = compress;
439    ew->done_cb = done_cb;
440    ew->result = 0;
441 
442    if (!eio_file_set(&ew->common,
443                      NULL,
444                      error_cb,
445                      user_data,
446                      _eio_eet_data_write_cipher_job,
447                      _eio_eet_data_write_cipher_end,
448                      _eio_eet_data_write_cipher_cancel))
449      return NULL;
450    return &ew->common;
451 }
452 
453 EAPI Eio_File *
eio_eet_data_read_cipher(Eet_File * ef,Eet_Data_Descriptor * edd,const char * name,const char * cipher_key,Eio_Done_ERead_Cb done_cb,Eio_Error_Cb error_cb,const void * data)454 eio_eet_data_read_cipher(Eet_File *ef,
455 			 Eet_Data_Descriptor *edd,
456 			 const char *name,
457 			 const char *cipher_key,
458 			 Eio_Done_ERead_Cb done_cb,
459 			 Eio_Error_Cb error_cb,
460 			 const void *data)
461 {
462    Eio_Eet_Read *er;
463 
464    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
465    EINA_SAFETY_ON_NULL_RETURN_VAL(edd, NULL);
466    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
467    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
468    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
469 
470    er = eio_common_alloc(sizeof(Eio_Eet_Read));
471    EINA_SAFETY_ON_NULL_RETURN_VAL(er, NULL);
472 
473    er->ef = ef;
474    er->edd = edd;
475    er->name = eina_stringshare_add(name);
476    er->cipher_key = eina_stringshare_add(cipher_key);
477    er->done_cb.eread = done_cb;
478 
479    if (!eio_file_set(&er->common,
480                      NULL,
481                      error_cb,
482                      data,
483                      _eio_eet_data_read_cipher_job,
484                      _eio_eet_data_read_cipher_end,
485                      _eio_eet_data_read_cipher_cancel))
486      return NULL;
487 
488    return &er->common;
489 }
490 
491 EAPI Eio_File *
eio_eet_data_image_write_cipher(Eet_File * ef,const char * name,const char * cipher_key,void * write_data,unsigned int w,unsigned int h,int alpha,int compress,int quality,int lossy,Eio_Done_Int_Cb done_cb,Eio_Error_Cb error_cb,const void * user_data)492 eio_eet_data_image_write_cipher(Eet_File *ef,
493 				const char *name,
494 				const char *cipher_key,
495 				void *write_data,
496 				unsigned int w,
497 				unsigned int h,
498 				int alpha,
499 				int compress,
500 				int quality,
501 				int lossy,
502 				Eio_Done_Int_Cb done_cb,
503 				Eio_Error_Cb error_cb,
504 				const void *user_data)
505 {
506    Eio_Eet_Image_Write *eiw;
507 
508    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
509    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
510    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
511    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
512 
513    eiw = eio_common_alloc(sizeof(Eio_Eet_Image_Write));
514    EINA_SAFETY_ON_NULL_RETURN_VAL(eiw, NULL);
515 
516    eiw->ef = ef;
517    eiw->name = eina_stringshare_add(name);
518    eiw->cipher_key = eina_stringshare_add(cipher_key);
519    eiw->write_data = write_data;
520    eiw->w = w;
521    eiw->h = h;
522    eiw->alpha = alpha;
523    eiw->compress = compress;
524    eiw->quality = quality;
525    eiw->lossy = lossy;
526    eiw->done_cb = done_cb;
527    eiw->result = 0;
528 
529    if (!eio_file_set(&eiw->common,
530                      NULL,
531                      error_cb,
532                      user_data,
533                      _eio_eet_image_write_job,
534                      _eio_eet_image_write_end,
535                      _eio_eet_image_write_cancel))
536      return NULL;
537    return &eiw->common;
538 }
539 
540 EAPI Eio_File *
eio_eet_read_direct(Eet_File * ef,const char * name,Eio_Done_Data_Cb done_cb,Eio_Error_Cb error_cb,const void * data)541 eio_eet_read_direct(Eet_File *ef,
542 		    const char *name,
543 		    Eio_Done_Data_Cb done_cb,
544 		    Eio_Error_Cb error_cb,
545 		    const void *data)
546 {
547    Eio_Eet_Read *er;
548 
549    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
550    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
551    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
552    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
553 
554    er = eio_common_alloc(sizeof(Eio_Eet_Read));
555    EINA_SAFETY_ON_NULL_RETURN_VAL(er, NULL);
556 
557    er->ef = ef;
558    er->name = eina_stringshare_add(name);
559    er->cipher_key = NULL;
560    er->done_cb.data = done_cb;
561    er->result = NULL;
562 
563    if (!eio_file_set(&er->common,
564                      NULL,
565                      error_cb,
566                      data,
567                      _eio_eet_read_direct_job,
568                      _eio_eet_read_direct_end,
569                      _eio_eet_read_cancel))
570      return NULL;
571 
572    return &er->common;
573 }
574 
575 EAPI Eio_File *
eio_eet_read_cipher(Eet_File * ef,const char * name,const char * cipher_key,Eio_Done_Read_Cb done_cb,Eio_Error_Cb error_cb,const void * data)576 eio_eet_read_cipher(Eet_File *ef,
577 		    const char *name,
578 		    const char *cipher_key,
579 		    Eio_Done_Read_Cb done_cb,
580 		    Eio_Error_Cb error_cb,
581 		    const void *data)
582 {
583    Eio_Eet_Read *er;
584 
585    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
586    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
587    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
588    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
589 
590    er = eio_common_alloc(sizeof(Eio_Eet_Read));
591    EINA_SAFETY_ON_NULL_RETURN_VAL(er, NULL);
592 
593    er->ef = ef;
594    er->name = eina_stringshare_add(name);
595    er->cipher_key = eina_stringshare_add(cipher_key);
596    er->done_cb.read = done_cb;
597    er->result = NULL;
598 
599    if (!eio_file_set(&er->common,
600                      NULL,
601                      error_cb,
602                      data,
603                      _eio_eet_read_cipher_job,
604                      _eio_eet_read_cipher_end,
605                      _eio_eet_read_cancel))
606      return NULL;
607    return &er->common;
608 }
609 
610 EAPI Eio_File *
eio_eet_write_cipher(Eet_File * ef,const char * name,void * write_data,int size,int compress,const char * cipher_key,Eio_Done_Int_Cb done_cb,Eio_Error_Cb error_cb,const void * user_data)611 eio_eet_write_cipher(Eet_File *ef,
612 		     const char *name,
613 		     void *write_data,
614 		     int size,
615 		     int compress,
616 		     const char *cipher_key,
617 		     Eio_Done_Int_Cb done_cb,
618 		     Eio_Error_Cb error_cb,
619 		     const void *user_data)
620 {
621    Eio_Eet_Write *ew;
622 
623    EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
624    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
625    EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
626    EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
627 
628    ew = eio_common_alloc(sizeof(Eio_Eet_Write));
629    EINA_SAFETY_ON_NULL_RETURN_VAL(ew, NULL);
630 
631    ew->ef = ef;
632    ew->name = eina_stringshare_add(name);
633    ew->cipher_key = eina_stringshare_add(cipher_key);
634    ew->write_data = write_data;
635    ew->size = size;
636    ew->compress = compress;
637    ew->done_cb = done_cb;
638    ew->result = 0;
639 
640    if (!eio_file_set(&ew->common,
641                      NULL,
642                      error_cb,
643                      user_data,
644                      _eio_eet_write_job,
645                      _eio_eet_write_end,
646                      _eio_eet_write_cancel))
647      return NULL;
648    return &ew->common;
649 }
650