tizen 2.4 release
[framework/convergence/service/adaptors/storage-adaptor.git] / src / storage-adaptor.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <string.h>
21 #include <dirent.h>
22 #include <dlfcn.h>
23 #include <glib.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/smack.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <errno.h>
30 #include <plugin_message.h>
31
32 #include "storage-adaptor.h"
33 #include "storage-adaptor-log.h"
34
35 #define PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE            40960
36 #define PLUGIN_MESSAGE_LISTENER_CMD_APPEND_FD           "append;"
37 #define PLUGIN_MESSAGE_LISTENER_CMD_STOP                "stop;"
38
39 #define STORAGE_PLUGIN_INTERFACE_CREATE_CONTEXT         "create_context"
40 #define STORAGE_PLUGIN_INTERFACE_DESTROY_CONTEXT        "destroy_context"
41 #define STORAGE_PLUGIN_INTERFACE_MAKE_DIRECTORY         "make_directory"
42 #define STORAGE_PLUGIN_INTERFACE_GET_LIST               "get_list"
43 #define STORAGE_PLUGIN_INTERFACE_REMOVE_DIRECTORY       "remove_directory"
44 #define STORAGE_PLUGIN_INTERFACE_UPLOAD_FILE_SYNC       "upload_file_sync"
45 #define STORAGE_PLUGIN_INTERFACE_DOWNLOAD_FILE_SYNC     "download_file_sync"
46 #define STORAGE_PLUGIN_INTERFACE_DELETE_FILE            "delete_file"
47 #define STORAGE_PLUGIN_INTERFACE_MOVE_DIRECTORY         "move_directory"
48 #define STORAGE_PLUGIN_INTERFACE_MOVE_FILE              "move_file"
49 #define STORAGE_PLUGIN_INTERFACE_SET_TRANSFER_STATE     "set_transfer_state"
50 #define STORAGE_PLUGIN_INTERFACE_GET_TRANSFER_STATE     "get_transfer_state"
51 #define STORAGE_PLUGIN_INTERFACE_GET_ROOT_FOLDER_PATH   "get_root_folder_path"
52
53 /* for 2.4 public functions */
54 #define STORAGE_PLUGIN_INTERFACE_START_UPLOAD_TASK      "start_upload_task"
55 #define STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_TASK    "start_download_task"
56 #define STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_THUMB_TASK      "start_download_thumb_task"
57 #define STORAGE_PLUGIN_INTERFACE_CANCEL_UPLOAD_TASK     "cancel_upload_task"
58 #define STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_TASK   "cancel_download_task"
59 #define STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_THUMB_TASK     "cancel_download_thumb_task"
60
61 #define STORAGE_PLUGIN_CALLBACK_DOWNLOAD_FILE_ASYNC_CB  "download_async_cb"
62 #define STORAGE_PLUGIN_CALLBACK_UPLOAD_FILE_ASYNC_CB    "upload_async_cb"
63 #define STORAGE_PLUGIN_CALLBACK_PROGRESS_CB             "progress_cb"
64
65 #define IF_IS_PLUGIN_THAN_RETURN_NULL()         do {if (!g_process_identity) return NULL; } while (0)
66 #define SAFE_ADD_STRING(x)                      (x) ? (x) : ("")
67
68 typedef enum {
69         PLUGIN_TYPE_INHOUSE     = 0,
70         PLUGIN_TYPE_3RD_PARTY   = 1,
71 } storage_plugin_type_e;
72
73
74 #ifndef FORK_PLUGIN_ARCHITECTURE
75 GHashTable      *g_file_uid_list = NULL;
76 #endif
77
78 /**
79  * Storage adaptor plugin
80  */
81 typedef struct storage_adaptor_plugin_s {
82         storage_adaptor_h                       adaptor;                /* Adaptor */
83         char                                    *path;                  /* Plugin library path */
84         storage_adaptor_plugin_handle_h         handle;                 /* Plugin handle */
85         void                                    *dl_handle;             /* Plugin library handle */
86         int                                     ref_counter;            /* Plugin reference counter */
87         GMutex                                  ref_counter_mutex;      /* Plugin reference counter mutex */
88         storage_adaptor_plugin_listener_h       plugin_listener;        /* Plugin callback listener */
89         GMutex                                  plugin_listener_mutex;  /* Plugin callback listener mutex */
90
91         GMutex                                  message_mutex;
92         storage_plugin_type_e                   type;
93         int                                     pid;
94         int                                     rd;
95         int                                     wd;
96         GList                                   *contexts;
97         GMutex                                  contexts_mutex;
98 } storage_adaptor_plugin_t;
99
100 /**
101  * Storage adaptor
102  */
103 typedef struct storage_adaptor_s {
104         GMutex  storage_adaptor_mutex;          /* Adaptor mutex */
105         int     started;                        /* Started flag */
106         char    *plugins_dir;                   /* Plugins directory path */
107         GList   *plugins;                       /* List of loaded plugins */
108         GMutex  plugins_mutex;                  /* Plugin list mutex */
109         GList   *adaptor_listeners;             /* List of vservice channel listener (for now not effective) */
110         GMutex  adaptor_listeners_mutex;        /* Listener list mutex */
111
112         int     rd_cmd[2];
113         GList   *rd_list;
114         GMutex  rd_mutex;
115         pthread_t       plugin_listener;
116 } storage_adaptor_t;
117
118 static int g_process_identity = -1;
119
120 static storage_adaptor_plugin_h g_child_plugin = NULL;
121
122 /**
123  * Creates plugin
124  */
125 static storage_adaptor_plugin_h storage_adaptor_create_plugin(const char *plugin_path);
126
127 /**
128  * Destroys plugin and deletes all resources associated with it
129  */
130 static void storage_adaptor_destroy_plugin(storage_adaptor_plugin_h plugin);
131
132 /**
133  * Loads plugins from selected directory
134  */
135 static int storage_adaptor_load_plugins_from_directory(storage_adaptor_h adaptor,
136                                                 const char *dir_path);
137
138 /**
139  * Checks if plugin is loaded by selected plugin adaptor
140  */
141 static int storage_adaptor_has_plugin(storage_adaptor_h adaptor,
142                                                 storage_adaptor_plugin_h plugin);
143
144 /*      TDB Temp */
145
146 #define GET_PLUGIN_PID() getpid()
147
148 int _get_plugin_fd_from_file_uid(long long int file_uid)
149 {
150         return ((int) (0xffff & file_uid));
151 }
152
153 long long int _get_file_uid_from_plugin_fd(int plugin_fd)
154 {
155         long long int plugin_section = 0LL;
156         #ifdef FORK_PLUGIN_ARCHITECTURE
157                 /* TODO it must be changed to another index (not support 64bit) */
158                 plugin_section = ((long long int) GET_PLUGIN_PID()) << (sizeof(int)*8);
159         #endif
160
161         return (plugin_section | (long long int)plugin_fd);
162 }
163
164 /**
165  * Increases adaptor's plugin references counter
166  */
167 void storage_adaptor_plugin_ref(storage_adaptor_plugin_h);
168
169 /**
170  * Decreases adaptor's plugin references counter
171  */
172 void storage_adaptor_plugin_unref(storage_adaptor_plugin_h);
173
174
175 /* ///////////////////////////////////////////////////////////////////////////////
176    /////////////  Internal function prototype (for forked plugin)  ///////////////
177    /////////////////////////////////////////////////////////////////////////////// */
178
179
180 /* To be used by adaptor */
181 void *_storage_adaptor_plugin_message_collector(void *data);
182 void __storage_adaptor_transfer_message(const char *msg);
183 int __storage_adaptor_parse_message_cmd(storage_adaptor_h adaptor, char *msg);
184 void _storage_adaptor_send_cmd_add_fd(storage_adaptor_h adaptor, int fd);
185 void _storage_adaptor_send_cmd_stop_listen(storage_adaptor_h adaptor);
186
187 static int storage_adaptor_send_message_to_plugin_sync(storage_adaptor_plugin_h plugin,
188                                                 plugin_message_h send_message,
189                                                 plugin_message_h *receive_message);
190
191 /* To be used by adaptor (virtual plugin handle) */
192 storage_adaptor_plugin_handle_h __storage_adaptor_create_3rd_party_plugin_handle(const char *plugin_uri);
193
194 storage_error_code_t storage_plugin_send_create_context(storage_adaptor_plugin_context_h *context,
195                                                         const char *app_id,
196                                                         const char *app_secret,
197                                                         const char *access_token,
198                                                         const char *cid,
199                                                         const char *uid);
200
201 storage_error_code_t storage_plugin_send_destroy_context(storage_adaptor_plugin_context_h context);
202
203 storage_error_code_t storage_plugin_send_set_server_info(storage_adaptor_plugin_context_h context,
204                                                         GHashTable *server_info,
205                                                         void *request,
206                                                         storage_adaptor_error_code_h *error,
207                                                         void *response);
208
209 storage_error_code_t storage_plugin_send_make_directory(storage_adaptor_plugin_context_h context,
210                                                         const char *parent_folder_storage_path,
211                                                         const char *folder_name,
212                                                         void *request,
213                                                         storage_adaptor_file_info_h *file_info,
214                                                         storage_adaptor_error_code_h *error,
215                                                         void *response);
216
217 storage_error_code_t storage_plugin_send_remove_directory(storage_adaptor_plugin_context_h context,
218                                                         const char *parent_folder_storage_path,
219                                                         const char *folder_name,
220                                                         void *request,
221                                                         storage_adaptor_file_info_h *file_info,
222                                                         storage_adaptor_error_code_h *error,
223                                                         void *response);
224
225 storage_error_code_t storage_plugin_send_get_list(storage_adaptor_plugin_context_h context,
226                                                         const char *parent_folder_storage_path,
227                                                         const char *folder_name,
228                                                         void *request,
229                                                         storage_adaptor_file_info_h **file_info_list,
230                                                         int *file_info_list_len,
231                                                         storage_adaptor_error_code_h *error,
232                                                         void *response);
233
234 storage_error_code_t storage_plugin_send_upload_file_sync(storage_adaptor_plugin_context_h context,
235                                                         const char *parent_folder_storage_path,
236                                                         const char *file_name,
237                                                         const char *upload_file_local_path,
238                                                         const int publish,
239                                                         void *request,
240                                                         storage_adaptor_file_info_h *file_info,
241                                                         storage_adaptor_error_code_h *error,
242                                                         void *response);
243
244 storage_error_code_t storage_plugin_send_download_file_sync(storage_adaptor_plugin_context_h context,
245                                                         const char *parent_folder_storage_path,
246                                                         const char *file_name,
247                                                         const char *download_file_local_path,
248                                                         void *request,
249                                                         storage_adaptor_error_code_h *error,
250                                                         void *response);
251
252 storage_error_code_t storage_plugin_send_delete_file(storage_adaptor_plugin_context_h context,
253                                                         const char *parent_folder_storage_path,
254                                                         const char *file_name,
255                                                         void *request,
256                                                         storage_adaptor_file_info_h *file_info,
257                                                         storage_adaptor_error_code_h *error,
258                                                         void *response);
259
260 storage_error_code_t storage_plugin_send_move_directory(storage_adaptor_plugin_context_h context,
261                                                         const char *parent_folder_storage_path,
262                                                         const char *folder_name,
263                                                         const char *dest_parent_folder_storage_path,
264                                                         const char *new_folder_name,
265                                                         void *request,
266                                                         storage_adaptor_file_info_h *file_info,
267                                                         storage_adaptor_error_code_h *error,
268                                                         void *response);
269
270 storage_error_code_t storage_plugin_send_move_file(storage_adaptor_plugin_context_h context,
271                                                         const char *parent_folder_storage_path,
272                                                         const char *file_name,
273                                                         const char *dest_parent_folder_storage_path,
274                                                         const char *new_file_name,
275                                                         void *request,
276                                                         storage_adaptor_file_info_h *file_info,
277                                                         storage_adaptor_error_code_h *error,
278                                                         void *response);
279
280 storage_error_code_t storage_plugin_send_set_transfer_state(storage_adaptor_plugin_context_h context,
281                                                         void *transfer_request_id,
282                                                         storage_adaptor_transfer_state_e state,
283                                                         void *request,
284                                                         storage_adaptor_error_code_h *error,
285                                                         void *response);
286
287 storage_error_code_t storage_plugin_send_get_transfer_state(storage_adaptor_plugin_context_h context,
288                                                         void *transfer_request_id,
289                                                         void *request,
290                                                         storage_adaptor_transfer_state_e *state,
291                                                         storage_adaptor_error_code_h *error,
292                                                         void *response);
293
294 storage_error_code_t storage_plugin_send_get_root_folder_path(storage_adaptor_plugin_context_h context,
295                                                         void *request,
296                                                         char **root_folder_path,
297                                                         storage_adaptor_error_code_h *error,
298                                                         void *response);
299
300 storage_error_code_t storage_plugin_send_start_upload_task(storage_adaptor_plugin_context_h context,
301                                                         int fd,
302                                                         const char *upload_dir,
303                                                         const char *file_path,
304                                                         bool need_progress,
305                                                         storage_adaptor_error_code_h *error,
306                                                         void *user_data);
307
308 storage_error_code_t storage_plugin_send_start_download_task(storage_adaptor_plugin_context_h context,
309                                                         const char *storage_dir,
310                                                         const char *file_path,
311                                                         int fd,
312                                                         bool need_progress,
313                                                         storage_adaptor_error_code_h *error,
314                                                         void *user_data);
315
316 storage_error_code_t storage_plugin_send_start_download_thumb_task(storage_adaptor_plugin_context_h context,
317                                                         const char *storage_dir,
318                                                         const char *file_path,
319                                                         int fd,
320                                                         int thumbnail_size,
321                                                         bool need_progress,
322                                                         storage_adaptor_error_code_h *error,
323                                                         void *user_data);
324
325 storage_error_code_t storage_plugin_send_cancel_upload_task(storage_adaptor_plugin_context_h context,
326                                                         int fd,
327                                                         storage_adaptor_error_code_h *error);
328
329 storage_error_code_t storage_plugin_send_cancel_download_task(storage_adaptor_plugin_context_h context,
330                                                         int fd,
331                                                         storage_adaptor_error_code_h *error);
332
333 storage_error_code_t storage_plugin_send_cancel_download_thumb_task(storage_adaptor_plugin_context_h context,
334                                                         int fd,
335                                                         storage_adaptor_error_code_h *error);
336
337 /* To be used by forked plugin */
338 void *_storage_plugin_request_collector(void *data);
339 storage_adaptor_plugin_context_h __storage_plugin_get_context_by_context_id(storage_adaptor_plugin_h plugin, int context_id);
340 void __storage_plugin_progress_command(storage_adaptor_plugin_h plugin, char *order, char **result);
341
342
343 storage_adaptor_file_info_h _get_file_info_from_message_array(plugin_message_array_h message_array, int index);
344
345 int _message_array_set_file_info(plugin_message_array_h message_array, int index, storage_adaptor_file_info_h file_info);
346
347 /**
348  * Definition of callback function variables for vservice channel (= infra adaptor) (example)
349  */
350 /* private feature */
351 storage_adaptor_service_download_file_async_reply_cb    _service_adaptor_download_file_async_reply      = NULL;
352 storage_adaptor_service_upload_file_async_reply_cb      _service_adaptor_upload_file_async_reply        = NULL;
353 storage_adaptor_service_file_transfer_progress_reply_cb _service_adaptor_file_transfer_progress_reply   = NULL;
354
355 /* public feature */
356 storage_adaptor_service_download_state_changed_reply_cb _service_adaptor_download_state_changed_reply   = NULL;
357 storage_adaptor_service_upload_state_changed_reply_cb   _service_adaptor_upload_state_changed_reply     = NULL;
358 storage_adaptor_service_task_progress_reply_cb  _service_adaptor_task_progress_reply    = NULL;
359
360 /**
361  * Gets a message from plugin (callback) when a sms message is received (sample)
362  */
363 /* private feature */
364 void storage_adaptor_download_file_async_reply_cb(void *request_id,
365                                                 char *download_file_local_path,
366                                                 storage_adaptor_error_code_h error,
367                                                 void *response)
368 {
369         if (NULL != _service_adaptor_download_file_async_reply) {
370                 _service_adaptor_download_file_async_reply(request_id,
371                                 download_file_local_path, error, response);
372         }
373 }
374
375 void storage_adaptor_upload_file_async_reply_cb(void *request_id,
376                                                 storage_adaptor_file_info_h file_info,
377                                                 storage_adaptor_error_code_h error,
378                                                 void *response)
379 {
380         if (NULL != _service_adaptor_upload_file_async_reply) {
381                 _service_adaptor_upload_file_async_reply(request_id,
382                                 file_info, error, response);
383         }
384 }
385
386 void storage_adaptor_file_transfer_progress_reply_cb(void *request_id,
387                                                 unsigned long long progress_size_byte,
388                                                 unsigned long long total_size_byte,
389                                                 storage_adaptor_error_code_h error,
390                                                 void *response)
391 {
392         if (NULL != _service_adaptor_file_transfer_progress_reply) {
393                 _service_adaptor_file_transfer_progress_reply(request_id,
394                                 progress_size_byte, total_size_byte, error, response);
395         }
396 }
397
398 /* public feature */
399 void storage_adaptor_download_state_changed_reply_cb(int file_descriptor,
400                                                 storage_adaptor_transfer_state_e state,
401                                                 storage_adaptor_error_code_h error,
402                                                 void *user_data)
403 {
404         if ((state == STORAGE_ADAPTOR_TRANSFER_STATE_FINISHED)
405                         || (state == STORAGE_ADAPTOR_TRANSFER_STATE_CANCELED)
406                         || (state == STORAGE_ADAPTOR_TRANSFER_STATE_FAILED)) {
407                 close(file_descriptor);
408         }
409
410         if (NULL != _service_adaptor_download_state_changed_reply) {
411                 long long int file_uid = _get_file_uid_from_plugin_fd(file_descriptor);
412                 _service_adaptor_download_state_changed_reply(file_uid,
413                                 state, error, user_data);
414         }
415 }
416
417 void storage_adaptor_upload_state_changed_reply_cb(int file_descriptor,
418                                                 storage_adaptor_transfer_state_e state,
419                                                 storage_adaptor_file_info_h file_info,
420                                                 storage_adaptor_error_code_h error,
421                                                 void *user_data)
422 {
423         if ((state == STORAGE_ADAPTOR_TRANSFER_STATE_FINISHED)
424                         || (state == STORAGE_ADAPTOR_TRANSFER_STATE_CANCELED)
425                         || (state == STORAGE_ADAPTOR_TRANSFER_STATE_FAILED)) {
426                 close(file_descriptor);
427         }
428
429         if (NULL != _service_adaptor_upload_state_changed_reply) {
430                 long long int file_uid = _get_file_uid_from_plugin_fd(file_descriptor);
431                 _service_adaptor_upload_state_changed_reply(file_uid,
432                                 state, file_info, error, user_data);
433         }
434 }
435
436 void storage_adaptor_task_progress_reply_cb(int file_descriptor,
437                                                 unsigned long long progress_size_byte,
438                                                 unsigned long long total_size_byte,
439                                                 storage_adaptor_error_code_h error,
440                                                 void *user_data)
441 {
442         if (NULL != _service_adaptor_task_progress_reply) {
443                 long long int file_uid = _get_file_uid_from_plugin_fd(file_descriptor);
444                 _service_adaptor_task_progress_reply(file_uid,
445                                 progress_size_byte, total_size_byte);
446         }
447 }
448
449 /* //------------------------------------------------------------------------
450    // Functions implementations
451    //------------------------------------------------------------------------ */
452
453 /* //////////////////////////////////////////////////////////
454    // Adaptor Defined Plugin Function
455    ////////////////////////////////////////////////////////// */
456
457 storage_error_code_t storage_plugin_open_file(storage_adaptor_plugin_context_h context,
458                                                 const char *file_path,
459                                                 storage_adaptor_file_access_mode_e mode,
460                                                 int *file_descriptor,
461                                                 storage_adaptor_error_code_h *error)
462 {
463         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
464
465         if ((NULL == file_descriptor) || (NULL == file_path)) {
466                 if (NULL != error) {
467                         *error = storage_adaptor_create_error_code((int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
468                                         "Invalid parameter");
469                 }
470                 ret = STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
471         } else {
472                 int fd;
473                 if (STORAGE_ADAPTOR_FILE_ACCESS_READ == mode) {
474                         fd = open(file_path, mode);
475                 } else if (STORAGE_ADAPTOR_FILE_ACCESS_WRITE == mode) {
476                         fd = open(file_path, mode, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
477                 } else {
478                         if (NULL != error) {
479                                 *error = storage_adaptor_create_error_code((int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
480                                                 "Invalid parameter (file mode)");
481                         }
482                         ret = STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
483                         return ret;
484                 }
485
486                 if (fd < 0) {
487                         ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
488                         int64_t error_code;
489                         if (EEXIST == errno) {
490                                 error_code = (int64_t) STORAGE_PLUGIN_ERROR_FILE_AREADY_EXIST;
491                         } else if (EACCES == errno) {
492                                 error_code = (int64_t) STORAGE_PLUGIN_ERROR_FILE_ACCESS_DENIED;
493                         } else {
494                                 error_code = (int64_t) STORAGE_PLUGIN_ERROR_FILE_OPEN_FAILED;
495                         }
496                         if (NULL != error) {
497                                 *error = storage_adaptor_create_error_code(error_code,
498                                                 "File open failed");
499                         }
500                 } else {
501                         *file_descriptor = fd;
502                 }
503         }
504         return ret;
505 }
506
507 storage_error_code_t storage_plugin_close_file(storage_adaptor_plugin_context_h context,
508                                                 int file_descriptor,
509                                                 storage_adaptor_error_code_h *error)
510 {
511         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
512
513         int r = close(file_descriptor);
514         if (r) {
515                 storage_adaptor_debug("close ret : %d", r);
516         }
517
518         return ret;
519 }
520
521
522 /* //////////////////////////////////////////////////////
523    // Mandatory: External adaptor management function
524    ////////////////////////////////////////////////////// */
525 storage_adaptor_h storage_adaptor_create(const char *plugins_dir)
526 {
527         if (NULL == plugins_dir) {
528                 storage_adaptor_error("Invalid argument""(plugins_dir: %p", plugins_dir);
529                 return NULL;
530         }
531
532         storage_adaptor_h storage_adaptor = (storage_adaptor_h) malloc(sizeof(storage_adaptor_t));
533
534         if (NULL == storage_adaptor) {
535                 storage_adaptor_error("Critical : Memory allocation failed");
536                 return NULL;
537         }
538
539         /* for forked plugin */
540         if (pipe(storage_adaptor->rd_cmd) == -1) {
541                 free(storage_adaptor);
542                 return NULL;
543         }
544         g_mutex_init(&storage_adaptor->rd_mutex);
545         storage_adaptor->rd_list = NULL;
546
547         storage_adaptor->started = 0;
548         storage_adaptor->plugins_dir = strdup(plugins_dir);
549
550         g_mutex_init(&storage_adaptor->storage_adaptor_mutex);
551         g_mutex_init(&storage_adaptor->plugins_mutex);
552         g_mutex_init(&storage_adaptor->adaptor_listeners_mutex);
553
554         g_mutex_lock(&storage_adaptor->adaptor_listeners_mutex);
555         storage_adaptor->adaptor_listeners = NULL;
556         g_mutex_unlock(&storage_adaptor->adaptor_listeners_mutex);
557
558         g_mutex_lock(&storage_adaptor->plugins_mutex);
559         storage_adaptor->plugins = NULL;
560         g_mutex_unlock(&storage_adaptor->plugins_mutex);
561
562         #ifndef FORK_PLUGIN_ARCHITECTURE
563                 g_file_uid_list = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, free);
564         #endif
565
566         return storage_adaptor;
567 }
568
569 void storage_adaptor_destroy(storage_adaptor_h adaptor)
570 {
571         if (NULL == adaptor) {
572                 storage_adaptor_error("Invalid argument""(adaptor: %p)", adaptor);
573                 return ;
574         }
575
576         g_mutex_lock(&adaptor->storage_adaptor_mutex);
577         if (0 != adaptor->started) {
578                 storage_adaptor_error("Storage adaptor is running. Forcing stop before destroy");
579                 storage_adaptor_stop(adaptor);
580         }
581
582         g_mutex_lock(&adaptor->plugins_mutex);
583         if (NULL != adaptor->plugins) {
584                 g_list_free_full(adaptor->plugins, (GDestroyNotify) storage_adaptor_plugin_unref);
585                 adaptor->plugins = NULL;
586         }
587         g_mutex_unlock(&adaptor->plugins_mutex);
588
589         g_mutex_lock(&adaptor->adaptor_listeners_mutex);
590         if (NULL != adaptor->adaptor_listeners) {
591                 g_list_free(adaptor->adaptor_listeners);
592                 adaptor->adaptor_listeners = NULL;
593         }
594         g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
595
596         _service_adaptor_download_file_async_reply      = NULL;
597         _service_adaptor_upload_file_async_reply        = NULL;
598         _service_adaptor_file_transfer_progress_reply   = NULL;
599         _service_adaptor_download_state_changed_reply   = NULL;
600         _service_adaptor_upload_state_changed_reply     = NULL;
601         _service_adaptor_task_progress_reply    = NULL;
602
603         free(adaptor->plugins_dir);
604         adaptor->plugins_dir = NULL;
605
606         g_mutex_unlock(&adaptor->storage_adaptor_mutex);
607
608         #ifndef FORK_PLUGIN_ARCHITECTURE
609                 g_hash_table_destroy(g_file_uid_list);
610         #endif
611
612         /* For forked plugin */
613         g_list_free(adaptor->rd_list);
614         close(adaptor->rd_cmd[0]);
615         close(adaptor->rd_cmd[1]);
616
617         free(adaptor);
618 }
619
620 int storage_adaptor_start(storage_adaptor_h adaptor)
621 {
622         storage_adaptor_debug("Starting storage adaptor");
623         if (NULL == adaptor) {
624                 storage_adaptor_error("Invalid argument""(adaptor: %p)", adaptor);
625                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
626         }
627
628         g_mutex_lock(&adaptor->storage_adaptor_mutex);
629         int result = STORAGE_ADAPTOR_ERROR_NONE;
630         if (0 != adaptor->started) {
631                 storage_adaptor_error("Storage adaptor is already started");
632                 result = STORAGE_ADAPTOR_ERROR_START;
633         } else {
634                 adaptor->started = 1;
635
636                 pthread_t pid;
637                 if (pthread_create(&pid, NULL, _storage_adaptor_plugin_message_collector, (void *)adaptor)) {
638                         adaptor->started = 0;
639                         storage_adaptor_error("Could not create 3rd party plugin listener");
640                         result = STORAGE_ADAPTOR_ERROR_NOT_FOUND;
641                 } else if (STORAGE_ADAPTOR_ERROR_NONE != (result = storage_adaptor_load_plugins_from_directory(adaptor, adaptor->plugins_dir))) {
642                         _storage_adaptor_send_cmd_stop_listen(adaptor);
643                         adaptor->started = 0;
644                         storage_adaptor_error("Could not load plugins from directory");
645                         result = STORAGE_ADAPTOR_ERROR_NOT_FOUND;
646                 } else {
647                         adaptor->plugin_listener = pid;
648                         storage_adaptor_info("Storage adaptor started successfully");
649                 }
650         }
651         g_mutex_unlock(&adaptor->storage_adaptor_mutex);
652
653         return result;
654 }
655
656 int storage_adaptor_stop(storage_adaptor_h adaptor)
657 {
658         if (NULL == adaptor) {
659                 storage_adaptor_error("Invalid argument""(adaptor: %p)", adaptor);
660                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
661         }
662
663         g_mutex_lock(&adaptor->storage_adaptor_mutex);
664
665         /* For forked plugin */
666         storage_adaptor_debug("stop plugin listener");
667         _storage_adaptor_send_cmd_stop_listen(adaptor);
668         pthread_join(adaptor->plugin_listener, NULL);
669
670         int result = STORAGE_ADAPTOR_ERROR_NONE;
671         if (0 == adaptor->started) {
672                 result = STORAGE_ADAPTOR_ERROR_START;
673         } else {
674                 if (NULL != adaptor->plugins) {
675                         g_mutex_lock(&adaptor->plugins_mutex);
676                         g_list_free_full(adaptor->plugins, (GDestroyNotify) storage_adaptor_plugin_unref);
677                         adaptor->plugins = NULL;
678                         g_mutex_unlock(&adaptor->plugins_mutex);
679                 }
680                 adaptor->started = 0;
681                 storage_adaptor_debug("Storage adaptor stopped");
682         }
683
684         g_mutex_unlock(&adaptor->storage_adaptor_mutex);
685         return result;
686 }
687
688 int storage_adaptor_register_listener(storage_adaptor_h adaptor,
689                                                 storage_adaptor_listener_h listener)
690 {
691         if ((NULL == adaptor) || (NULL == listener)) {
692                 storage_adaptor_error("Invalid argument""(adaptor: %p, listener: %p)", adaptor, listener);
693                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
694         }
695
696         g_mutex_lock(&adaptor->adaptor_listeners_mutex);
697
698         adaptor->adaptor_listeners = g_list_append(adaptor->adaptor_listeners, listener);
699
700         g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
701
702         _service_adaptor_download_file_async_reply =
703                         (storage_adaptor_service_download_file_async_reply_cb) listener->download_file_async_reply;
704         _service_adaptor_upload_file_async_reply =
705                         (storage_adaptor_service_upload_file_async_reply_cb) listener->upload_file_async_reply;
706         _service_adaptor_file_transfer_progress_reply =
707                         (storage_adaptor_service_file_transfer_progress_reply_cb) listener->file_transfer_progress_reply;
708         _service_adaptor_download_state_changed_reply =
709                         (storage_adaptor_service_download_state_changed_reply_cb) listener->download_state_changed_reply;
710         _service_adaptor_upload_state_changed_reply =
711                         (storage_adaptor_service_upload_state_changed_reply_cb) listener->upload_state_changed_reply;
712         _service_adaptor_task_progress_reply =
713                         (storage_adaptor_service_task_progress_reply_cb) listener->task_progress_reply;
714
715         return STORAGE_ADAPTOR_ERROR_NONE;
716 }
717
718 int storage_adaptor_unregister_listener(storage_adaptor_h adaptor,
719                                                 storage_adaptor_listener_h listener)
720 {
721         if ((NULL == adaptor) || (NULL == listener)) {
722                 storage_adaptor_error("Invalid argument""(adaptor: %p, listener: %p)", adaptor, listener);
723                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
724         }
725
726         g_mutex_lock(&adaptor->adaptor_listeners_mutex);
727
728         if (NULL == g_list_find(adaptor->adaptor_listeners, listener)) {
729                 g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
730                 storage_adaptor_error("Could not find listener");
731                 return STORAGE_ADAPTOR_ERROR_NOT_FOUND;
732         }
733
734         adaptor->adaptor_listeners = g_list_remove(adaptor->adaptor_listeners, listener);
735
736         g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
737
738         _service_adaptor_download_file_async_reply      = NULL;
739         _service_adaptor_upload_file_async_reply        = NULL;
740         _service_adaptor_file_transfer_progress_reply   = NULL;
741         _service_adaptor_download_state_changed_reply   = NULL;
742         _service_adaptor_upload_state_changed_reply     = NULL;
743         _service_adaptor_task_progress_reply    = NULL;
744
745         return STORAGE_ADAPTOR_ERROR_NONE;
746 }
747
748 /* /////////////////////////////////////////////////////////////
749    // Plugin create / destroy / ref. count / get plugin name
750    ///////////////////////////////////////////////////////////// */
751 static storage_adaptor_plugin_h storage_adaptor_create_plugin(const char *plugin_path)
752 {
753         if (NULL == plugin_path) {
754                 storage_adaptor_error("Invalid argument (plugin_path is null)");
755                 return NULL;
756         }
757
758         void *dl_handle = dlopen(plugin_path, RTLD_LAZY);
759         if (NULL == dl_handle) {
760                 storage_adaptor_error("Could not load plugin %s: %s", plugin_path, dlerror());
761                 return NULL;
762         }
763
764         storage_adaptor_plugin_handle_h (*get_adaptee_handle)(void) = NULL;
765
766         get_adaptee_handle = (storage_adaptor_plugin_handle_h (*)(void)) (dlsym(dl_handle, "create_plugin_handle"));
767         if (NULL == get_adaptee_handle) {
768                 dlclose(dl_handle);
769                 storage_adaptor_error("Could not get function pointer to create_plugin_handle");
770                 return NULL;
771         }
772
773         plugin_req_enter();
774         storage_adaptor_plugin_handle_h handle = get_adaptee_handle();
775         plugin_req_exit_void();
776
777         if (NULL == handle) {
778                 dlclose(dl_handle);
779                 storage_adaptor_error("Could not get adaptee handle");
780                 return NULL;
781         }
782         /* TBD not fixed */
783         handle->open_file = storage_plugin_open_file;
784         handle->close_file = storage_plugin_close_file;
785
786         storage_adaptor_plugin_h plugin = (storage_adaptor_plugin_h) calloc(1, sizeof(storage_adaptor_plugin_t));
787         if (NULL == plugin) {
788                 dlclose(dl_handle);
789                 storage_adaptor_error("Could not create plugin object");
790                 return NULL;
791         }
792
793         storage_adaptor_plugin_listener_h listener =
794                         (storage_adaptor_plugin_listener_h) calloc(1, sizeof(storage_adaptor_plugin_listener_t));
795
796         if (NULL == listener) {
797                 free(plugin);
798                 dlclose(dl_handle);
799                 storage_adaptor_error("Could not create listener object");
800                 return NULL;
801         }
802
803         plugin->path = g_strdup(plugin_path);
804         plugin->handle = handle;
805         plugin->dl_handle = dl_handle;
806         plugin->ref_counter = 0;
807
808         plugin->type = PLUGIN_TYPE_INHOUSE;
809
810         g_mutex_init(&plugin->ref_counter_mutex);
811         g_mutex_init(&plugin->plugin_listener_mutex);
812         g_mutex_init(&plugin->contexts_mutex);
813         plugin->contexts = NULL;
814
815         listener->storage_adaptor_download_file_async_reply     = storage_adaptor_download_file_async_reply_cb;
816         listener->storage_adaptor_upload_file_async_reply       = storage_adaptor_upload_file_async_reply_cb;
817         listener->storage_adaptor_file_transfer_progress_reply  = storage_adaptor_file_transfer_progress_reply_cb;
818         listener->storage_adaptor_download_state_changed_reply  = storage_adaptor_download_state_changed_reply_cb;
819         listener->storage_adaptor_upload_state_changed_reply    = storage_adaptor_upload_state_changed_reply_cb;
820         listener->storage_adaptor_task_progress_reply   = storage_adaptor_task_progress_reply_cb;
821
822
823         plugin_req_enter();
824         plugin->handle->set_listener(listener);
825         plugin_req_exit_void();
826
827         g_mutex_lock(&plugin->plugin_listener_mutex);
828         plugin->plugin_listener = listener;
829         g_mutex_unlock(&plugin->plugin_listener_mutex);
830
831         return plugin;
832 }
833
834 static void storage_adaptor_destroy_plugin(storage_adaptor_plugin_h plugin)
835 {
836         if (NULL == plugin) {
837                 storage_adaptor_error("Invalid argument""(plugin: %p)", plugin);
838                 return;
839         }
840
841         if (NULL != plugin->handle) {
842                 plugin->handle->destroy_handle(plugin->handle);
843
844                 g_mutex_lock(&plugin->plugin_listener_mutex);
845
846                 plugin_req_enter();
847                 plugin->handle->unset_listener();
848                 plugin_req_exit_void();
849
850                 g_mutex_unlock(&plugin->plugin_listener_mutex);
851
852                 plugin->handle = NULL;
853         }
854
855         if (NULL != plugin->dl_handle) {
856                 dlclose(plugin->dl_handle);
857                 plugin->dl_handle = NULL;
858         }
859
860         free(plugin->path);
861         plugin->path = NULL;
862
863         free(plugin);
864 }
865
866 static int storage_adaptor_load_plugins_from_directory(storage_adaptor_h adaptor,
867                                                 const char *dir_path)
868 {
869         char *plugin_path = NULL;
870         DIR *dir = NULL;
871         struct dirent dir_entry, *result = NULL;
872
873         storage_adaptor_debug("Starting load plugins from directory");
874
875         if ((NULL == adaptor) || (NULL == dir_path)) {
876                 storage_adaptor_error("Invalid argument""(adaptor: %p, dir_path: %p)", adaptor, dir_path);
877                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
878         }
879
880         dir = opendir(dir_path);
881         if (NULL == dir) {
882                 storage_adaptor_error("Could not open dir path (%s)", dir_path);
883                 return STORAGE_ADAPTOR_ERROR_NOT_FOUND;
884         }
885
886         int ret = STORAGE_ADAPTOR_ERROR_NONE;
887         while (0 == (readdir_r(dir, &dir_entry, &result))) {
888
889                 if (NULL == result) {
890                         storage_adaptor_error("Could not open directory %s", plugin_path);
891                         break;
892                 }
893
894                 if (dir_entry.d_type & DT_DIR) {
895                         continue;
896                 }
897
898                 plugin_path = g_strconcat(dir_path, "/", dir_entry.d_name, NULL);
899                 storage_adaptor_plugin_h plugin = storage_adaptor_create_plugin(plugin_path);
900
901                 if (NULL != plugin) {
902                         storage_adaptor_debug("Loaded plugin: %s", plugin_path);
903                         plugin->adaptor = adaptor;
904                         storage_adaptor_plugin_ref(plugin);
905                         g_mutex_lock(&adaptor->plugins_mutex);
906                         adaptor->plugins = g_list_append(adaptor->plugins, plugin);
907                         g_mutex_unlock(&adaptor->plugins_mutex);
908                 } else {
909                         storage_adaptor_error("Could not load plugin %s", plugin_path);
910                 }
911
912                 g_free(plugin_path);
913                 plugin_path = NULL;
914         }
915
916         storage_adaptor_debug("End load plugins from directory");
917         closedir(dir);
918         return ret;
919 }
920
921 static int storage_adaptor_has_plugin(storage_adaptor_h adaptor,
922                                                 storage_adaptor_plugin_h plugin)
923 {
924         if ((NULL == adaptor) || (NULL == plugin)) {
925                 storage_adaptor_error("Invalid argument""(adaptor: %p, plugin: %p)", adaptor, plugin);
926                 return 0;
927         }
928
929         int result = 0;
930
931         g_mutex_lock(&adaptor->plugins_mutex);
932         if (NULL != g_list_find(adaptor->plugins, plugin)) {
933                 result = 1;
934         }
935         g_mutex_unlock(&adaptor->plugins_mutex);
936
937         return result;
938 }
939
940 void storage_adaptor_plugin_ref(storage_adaptor_plugin_h plugin)
941 {
942         if (NULL == plugin) {
943                 storage_adaptor_error("Invalid argument""(plugin: %p)", plugin);
944                 return;
945         }
946
947         g_mutex_lock(&plugin->ref_counter_mutex);
948         plugin->ref_counter = plugin->ref_counter + 1;
949         if (NULL != plugin->handle) {
950                 storage_adaptor_info("plugin name : %s, ref_counter: %d",
951                                 plugin->handle->plugin_uri, plugin->ref_counter);
952         } else {
953                 storage_adaptor_info("ref_counter: %d", plugin->ref_counter);
954         }
955         g_mutex_unlock(&plugin->ref_counter_mutex);
956 }
957
958 void storage_adaptor_plugin_unref(storage_adaptor_plugin_h plugin)
959 {
960         if (NULL == plugin) {
961                 storage_adaptor_error("Invalid argument""(plugin: %p)", plugin);
962                 return ;
963         }
964
965         int should_destroy = 0;
966
967         g_mutex_lock(&plugin->ref_counter_mutex);
968         plugin->ref_counter = plugin->ref_counter - 1;
969         if (NULL != plugin->handle) {
970                 storage_adaptor_info("plugin name : %s, ref_counter: %d",
971                                 plugin->handle->plugin_uri, plugin->ref_counter);
972         } else {
973                 storage_adaptor_info("ref_counter: %d", plugin->ref_counter);
974         }
975         if (0 >= plugin->ref_counter) {
976                 should_destroy = 1;
977         }
978         g_mutex_unlock(&plugin->ref_counter_mutex);
979
980         if (should_destroy) {
981                 storage_adaptor_debug("Plugin is being destroyed");
982                 storage_adaptor_destroy_plugin(plugin);
983         }
984 }
985
986 /* For 3rd party plugin packages */
987 int storage_adaptor_load_plugin_from_package(storage_adaptor_h adaptor,
988                                                 const char *package_id,
989                                                 const char *plugin_path)
990 {
991         int adaptor_fd[2];
992         int plugin_fd[2];
993
994         if (pipe(adaptor_fd) == -1) {
995                 storage_adaptor_debug("pipe creation error, can not load plugin package");
996         } else if (pipe(plugin_fd) == -1) {
997                 close(adaptor_fd[0]);
998                 close(adaptor_fd[1]);
999                 storage_adaptor_debug("pipe creation error[2], can not load plugin package");
1000         } else {
1001                 g_process_identity = fork();
1002                 if (0 == g_process_identity) {  /* child */
1003                         storage_adaptor_debug_func("[CHILD PROCESS] forked success (PID : %d, id : %d)", (int)getpid());
1004 /*                      storage_adaptor_info("set uid : %d", setuid(5000)); */
1005                         /* TODO remove temp code */
1006 /*                      change_smack_rule("org.tizen.tui4"); */
1007 /*                      smack_set_label_for_self(package_id); */
1008
1009                         storage_adaptor_plugin_h plugin = NULL;
1010                         plugin = storage_adaptor_create_plugin(plugin_path);
1011                         if (NULL == plugin) {
1012                                 storage_adaptor_error("[CHILD PROCESS] Load plugin failed");
1013                                 exit(1);
1014                         }
1015                         g_child_plugin = plugin;
1016                         plugin->rd = plugin_fd[0];
1017                         close(plugin_fd[1]);
1018                         plugin->wd = adaptor_fd[1];
1019                         close(adaptor_fd[0]);
1020                         void *temp = _storage_plugin_request_collector((void *)plugin);
1021                         storage_adaptor_debug_func("[CHILD PROCESS] exit %p", temp);
1022                         exit(0);
1023                 } else if (0 < g_process_identity) {    /* parent */
1024                         storage_adaptor_debug_func("[PARENT PROCESS] forked success (PID : %d)", (int)getpid());
1025                         storage_adaptor_plugin_h _plugin = (storage_adaptor_plugin_h) calloc(1, sizeof(storage_adaptor_plugin_t));
1026                         if (NULL == _plugin) {
1027                                 storage_adaptor_error("[PARENT PROCESS] memory allocation failed");
1028                                 exit(1);
1029                         }
1030
1031                         _plugin->ref_counter = 0;
1032                         g_mutex_init(&_plugin->ref_counter_mutex);
1033                         g_mutex_init(&_plugin->message_mutex);
1034
1035                         _plugin->handle = __storage_adaptor_create_3rd_party_plugin_handle(package_id);
1036
1037                         _plugin->type = PLUGIN_TYPE_3RD_PARTY;
1038                         _plugin->pid = g_process_identity;
1039                         _plugin->rd = adaptor_fd[0];
1040                         close(adaptor_fd[1]);
1041                         _plugin->wd = plugin_fd[1];
1042                         close(plugin_fd[0]);
1043
1044                         _storage_adaptor_send_cmd_add_fd(adaptor, _plugin->rd);
1045
1046                         _plugin->adaptor = adaptor;
1047                         storage_adaptor_plugin_ref(_plugin);
1048                         g_mutex_lock(&adaptor->plugins_mutex);
1049                         adaptor->plugins = g_list_append(adaptor->plugins, _plugin);
1050                         g_mutex_unlock(&adaptor->plugins_mutex);
1051                 } else {
1052                         close(adaptor_fd[0]);
1053                         close(adaptor_fd[1]);
1054                         close(plugin_fd[0]);
1055                         close(plugin_fd[1]);
1056                         storage_adaptor_debug("fork error, can not load plugin package");
1057                 }
1058         }
1059
1060         return 0;
1061 }
1062
1063 /* //////////////////////////////////////////////////////
1064    // Plugin context create / destroy
1065    ////////////////////////////////////////////////////// */
1066 storage_adaptor_plugin_context_h storage_adaptor_create_plugin_context(storage_adaptor_plugin_h plugin,
1067                                                 const char *app_id,
1068                                                 const char *app_secret,
1069                                                 const char *access_token,
1070                                                 const char *cid,
1071                                                 const char *uid,
1072                                                 const char *service_name)
1073 {
1074         storage_adaptor_debug("Starting storage_adaptor_create_plugin_context");
1075
1076         if (NULL == plugin) {
1077                 storage_adaptor_error("Invalid argument""(plugin: %p)", plugin);
1078                 return NULL;
1079         }
1080
1081         if (NULL != plugin->handle) {
1082                 storage_adaptor_plugin_context_h plugin_context = NULL;
1083
1084                 if (plugin->type == PLUGIN_TYPE_3RD_PARTY) {
1085                         plugin_context = (storage_adaptor_plugin_context_h) calloc(1, sizeof(storage_adaptor_plugin_context_t));
1086                         if (NULL == plugin_context) {
1087                                 return NULL;
1088                         }
1089                         plugin_context->plugin_handle = plugin;
1090                 }
1091
1092                 plugin_req_enter();
1093                 plugin->handle->create_context(&plugin_context, SAFE_ADD_STRING(app_id), SAFE_ADD_STRING(app_secret),
1094                                 SAFE_ADD_STRING(access_token), SAFE_ADD_STRING(cid), SAFE_ADD_STRING(uid));
1095                 plugin_req_exit_void();
1096
1097                 if (NULL == plugin_context) {
1098                         storage_adaptor_error("Create context failed");
1099                         return NULL;
1100                 }
1101
1102                 /* For forked plugin */
1103                 g_mutex_lock(&plugin->contexts_mutex);
1104                 plugin->contexts = g_list_append(plugin->contexts, (gpointer)plugin_context);
1105                 g_mutex_unlock(&plugin->contexts_mutex);
1106
1107                 plugin_context->plugin_uri = strdup(plugin->handle->plugin_uri);
1108                 plugin_context->service_name = strdup(service_name ? service_name : "");
1109                 return plugin_context;
1110         } else {
1111                 storage_adaptor_error("Plugin handle is null");
1112         }
1113
1114         storage_adaptor_debug("End storage_adaptor_create_plugin_context");
1115         return NULL;
1116 }
1117
1118 void storage_adaptor_destroy_plugin_context(storage_adaptor_plugin_h plugin,
1119                                                 storage_adaptor_plugin_context_h plugin_context)
1120 {
1121         if ((NULL == plugin) || (NULL == plugin_context)) {
1122                 storage_adaptor_error("Invalid argument""(plugin: %p, plugin_context: %p)", plugin, plugin_context);
1123                 return;
1124         }
1125
1126         free(plugin_context->plugin_uri);
1127         plugin_context->plugin_uri = NULL;
1128 /*      free(plugin_context->service_name); */
1129 /*      plugin_context->service_name = NULL; */
1130
1131         if (NULL != plugin->handle) {
1132                 plugin_req_enter();
1133                 plugin->handle->destroy_context(plugin_context);
1134                 plugin_req_exit_void();
1135         } else {
1136                 storage_adaptor_error("Plugin handle is null");
1137         }
1138 }
1139
1140 /* //////////////////////////////////////////////////////
1141    // Get plugin by plugin name
1142    ////////////////////////////////////////////////////// */
1143 storage_adaptor_plugin_h storage_adaptor_get_plugin_by_name(storage_adaptor_h adaptor,
1144                                                 const char *plugin_uri)
1145 {
1146         storage_adaptor_debug("Starting storage_adaptor_get_plugin_by_name");
1147
1148         if ((NULL == adaptor) || (NULL == plugin_uri)) {
1149                 storage_adaptor_error("Invalid argument""(adaptor: %p, plugin_uri: %p)", adaptor, plugin_uri);
1150                 return NULL;
1151         }
1152
1153         storage_adaptor_plugin_h plugin = NULL;
1154         g_mutex_lock(&adaptor->plugins_mutex);
1155         int count = g_list_length(adaptor->plugins);
1156         int i = 0;
1157         for (i = 0; i < count; i++) {
1158                 storage_adaptor_plugin_h temp_plugin = g_list_nth_data(adaptor->plugins, i);
1159                 if (NULL != temp_plugin) {
1160                         if (0 == strcmp(temp_plugin->handle->plugin_uri, plugin_uri)) {
1161                                 storage_adaptor_plugin_ref(temp_plugin);
1162                                 plugin = temp_plugin;
1163                                 g_mutex_unlock(&adaptor->plugins_mutex);
1164                                 return plugin;
1165                         }
1166                 }
1167         }
1168         g_mutex_unlock(&adaptor->plugins_mutex);
1169
1170         return plugin;
1171 }
1172
1173 /* //////////////////////////////////////////////////////
1174    // Plugin load / unload / get plugin list
1175    ////////////////////////////////////////////////////// */
1176 int storage_adaptor_load_plugin(storage_adaptor_h adaptor,
1177                                                 const char *plugin_path)
1178 {
1179         if ((NULL == adaptor) || (NULL == plugin_path)) {
1180                 storage_adaptor_error("Invalid argument""(adaptor: %p, plugin_path: %p)", adaptor, plugin_path);
1181                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
1182         }
1183
1184         if (0 == adaptor->started) {
1185                 storage_adaptor_error("Storage adaptor is not started");
1186                 return STORAGE_ADAPTOR_ERROR_START;
1187         }
1188
1189         storage_adaptor_plugin_h plugin = storage_adaptor_create_plugin(plugin_path);
1190         if (NULL == plugin) {
1191                 storage_adaptor_error("Could not load plugin %s", plugin_path);
1192                 return STORAGE_ADAPTOR_ERROR_CREATE;
1193         }
1194
1195         plugin->adaptor = adaptor;
1196         storage_adaptor_plugin_ref(plugin);
1197
1198         g_mutex_lock(&adaptor->plugins_mutex);
1199         adaptor->plugins = g_list_append(adaptor->plugins, plugin);
1200         g_mutex_unlock(&adaptor->plugins_mutex);
1201
1202         return STORAGE_ADAPTOR_ERROR_NONE;
1203 }
1204
1205 int storage_adaptor_unload_plugin(storage_adaptor_h adaptor,
1206                                                 storage_adaptor_plugin_h plugin)
1207 {
1208         if ((NULL == adaptor) || (NULL == plugin)) {
1209                 storage_adaptor_error("Invalid argument""(adaptor: %p, plugin: %p)", adaptor, plugin);
1210                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
1211         }
1212
1213         if (0 == adaptor->started) {
1214                 storage_adaptor_error("Storage adaptor is not started");
1215                 return STORAGE_ADAPTOR_ERROR_START;
1216         }
1217
1218         if (!storage_adaptor_has_plugin(adaptor, plugin)) {
1219                 storage_adaptor_error("Storage adaptor has no plugin");
1220                 return STORAGE_ADAPTOR_ERROR_NOT_FOUND;
1221         }
1222
1223         plugin->adaptor = NULL;
1224
1225         g_mutex_lock(&adaptor->plugins_mutex);
1226         adaptor->plugins = g_list_remove(adaptor->plugins, plugin);
1227         g_mutex_unlock(&adaptor->plugins_mutex);
1228
1229         storage_adaptor_plugin_unref(plugin);
1230
1231         return STORAGE_ADAPTOR_ERROR_NONE;
1232 }
1233
1234 GList *storage_adaptor_get_plugins(storage_adaptor_h adaptor)
1235 {
1236         if (NULL == adaptor) {
1237                 storage_adaptor_error("Invalid argument""(adaptor: %p)", adaptor);
1238                 return NULL;
1239         }
1240
1241         GList *plugins = NULL;
1242
1243         g_mutex_lock(&adaptor->plugins_mutex);
1244         int plugins_count = g_list_length(adaptor->plugins);
1245         int i = 0;
1246         for (i = 0; i < plugins_count; i++) {
1247                 storage_adaptor_plugin_h plugin = g_list_nth_data(adaptor->plugins, i);
1248                 if (NULL != plugin) {
1249                         storage_adaptor_plugin_ref(plugin);
1250                         plugins = g_list_append(plugins, plugin);
1251                 }
1252         }
1253         g_mutex_unlock(&adaptor->plugins_mutex);
1254
1255         return plugins;
1256 }
1257
1258 /* ////////////////////////////////////////////////////////////
1259    // Adaptor Etc Functions
1260    //////////////////////////////////////////////////////////// */
1261
1262 /* Get plugin name by plugin */
1263 void storage_adaptor_get_plugin_uri(storage_adaptor_plugin_h plugin,
1264                                                 char **plugin_uri)
1265 {
1266         if ((NULL == plugin) || (NULL == plugin_uri)) {
1267                 storage_adaptor_error("Invalid argument""(plugin: %p)", plugin);
1268                 return;
1269         }
1270         if ((NULL != plugin->handle) && (NULL != plugin->handle->plugin_uri)) {
1271                 *plugin_uri = strdup(plugin->handle->plugin_uri);
1272         }
1273 }
1274
1275 /**
1276  * Refresh access token
1277  */
1278 EXPORT_API
1279 storage_error_code_t storage_adaptor_refresh_access_token(storage_adaptor_plugin_context_h context,
1280                                                 const char *new_access_token)
1281 {
1282         if ((NULL == context) || (NULL == new_access_token) || (0 >= strlen(new_access_token))) {
1283                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
1284         }
1285         storage_adaptor_debug_secure("New access token : %s", new_access_token);
1286
1287         free(context->access_token);
1288         context->access_token = NULL;
1289         context->access_token = strdup(new_access_token);
1290
1291         return STORAGE_ADAPTOR_ERROR_NONE;
1292 }
1293
1294
1295 EXPORT_API
1296 storage_error_code_t storage_adaptor_refresh_uid(storage_adaptor_plugin_context_h context,
1297                                                 const char *new_uid)
1298 {
1299         if ((NULL == context) || (NULL == new_uid) || (0 >= strlen(new_uid))) {
1300                 return STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT;
1301         }
1302         storage_adaptor_debug_secure("New uid : %s", new_uid);
1303
1304         free(context->uid);
1305         context->uid = NULL;
1306         context->uid = strdup(new_uid);
1307
1308         return STORAGE_ADAPTOR_ERROR_NONE;
1309 }
1310
1311
1312
1313 storage_adaptor_error_code_h storage_adaptor_create_error_code(const int64_t code,
1314                                                 const char *msg)
1315 {
1316         if (NULL == msg) {
1317                 return NULL;
1318         }
1319         storage_adaptor_error_code_h error_code =
1320                         (storage_adaptor_error_code_h) calloc(1, sizeof(storage_adaptor_error_code_t));
1321         if (NULL != error_code) {
1322                 error_code->code = code;
1323                 error_code->msg = strdup(msg);
1324         }
1325
1326         return error_code;
1327 }
1328
1329 void storage_adaptor_destroy_error_code(storage_adaptor_error_code_h *error_code)
1330 {
1331         if ((NULL != error_code) && (NULL != (*error_code))) {
1332                 free((*error_code)->msg);
1333                 (*error_code)->msg = NULL;
1334                 free(*error_code);
1335                 *error_code = NULL;
1336         }
1337
1338 }
1339
1340 storage_adaptor_file_info_h storage_adaptor_create_file_info(void)
1341 {
1342         storage_adaptor_file_info_h _file_info = NULL;
1343         _file_info = (storage_adaptor_file_info_h) calloc(1, sizeof(storage_adaptor_file_info_t));
1344
1345         storage_adaptor_media_meta_s *_media_meta = NULL;
1346         _media_meta = (storage_adaptor_media_meta_s *) calloc(1, sizeof(storage_adaptor_media_meta_s));
1347
1348         storage_adaptor_cloud_meta_s *_cloud_meta = NULL;
1349         _cloud_meta = (storage_adaptor_cloud_meta_s *) calloc(1, sizeof(storage_adaptor_cloud_meta_s));
1350
1351         if ((NULL == _file_info) || (NULL == _media_meta) || (NULL == _cloud_meta)) {
1352                 free(_file_info);
1353                 free(_media_meta);
1354                 free(_cloud_meta);
1355
1356                 return NULL;
1357         }
1358
1359         _media_meta->mime_type          = NULL;
1360         _media_meta->title              = NULL;
1361         _media_meta->album              = NULL;
1362         _media_meta->artist             = NULL;
1363         _media_meta->genere             = NULL;
1364         _media_meta->recorded_date      = NULL;
1365         _media_meta->width              = -1;
1366         _media_meta->height             = -1;
1367         _media_meta->duration           = -1;
1368         _media_meta->copyright          = NULL;
1369         _media_meta->track_num          = NULL;
1370         _media_meta->description        = NULL;
1371         _media_meta->composer           = NULL;
1372         _media_meta->year               = NULL;
1373         _media_meta->bitrate            = -1;
1374         _media_meta->samplerate         = -1;
1375         _media_meta->channel            = -1;
1376         _media_meta->extra_media_meta   = NULL;
1377
1378         _cloud_meta->service_name       = NULL;
1379         _cloud_meta->usage_byte         = 0ULL;
1380         _cloud_meta->quota_byte         = 0ULL;
1381         _cloud_meta->extra_cloud_meta   = NULL;
1382
1383         _file_info->plugin_uri          = NULL;
1384         _file_info->object_id           = NULL;
1385         _file_info->storage_path        = NULL;
1386         _file_info->file_size           = 0ULL;
1387
1388         /* private only!! */
1389         _file_info->revision            = -1;
1390         _file_info->timestamp           = 0ULL;
1391         _file_info->type                = NULL;
1392         _file_info->deleted             = -1;
1393         _file_info->expired_time        = 0ULL;
1394         _file_info->download_count      = -0U;
1395         _file_info->max_download_count  = -0U;
1396         _file_info->file_info_index     = -1;
1397         _file_info->tag                 = NULL;
1398         _file_info->file_share_token    = NULL;
1399
1400         /* public */
1401         _file_info->created_time        = 0ULL;
1402         _file_info->modified_time       = 0ULL;
1403         _file_info->file_info_index     = -1;
1404         _file_info->content_type        = STORAGE_ADAPTOR_CONTENT_TYPE_DEFAULT;
1405         _file_info->media_meta          = _media_meta;
1406         _file_info->cloud_meta          = _cloud_meta;
1407         _file_info->extra_file_info     = NULL;
1408
1409         return _file_info;
1410 }
1411
1412 int storage_adaptor_destroy_file_info(storage_adaptor_file_info_h *file_info)
1413 {
1414         if (NULL == file_info) {
1415                 return 1;
1416         }
1417
1418         if (NULL == *file_info) {
1419                 return 0;
1420         }
1421         storage_adaptor_file_info_h _file_info = *file_info;
1422
1423         free(_file_info->plugin_uri);
1424         free(_file_info->object_id);
1425         free(_file_info->storage_path);
1426         free(_file_info->extra_file_info);
1427         free(_file_info->type);
1428         free(_file_info->tag);
1429
1430         storage_adaptor_media_meta_s *_media_meta = _file_info->media_meta;
1431
1432         if (NULL != _media_meta) {
1433                 free(_media_meta->mime_type);
1434                 free(_media_meta->title);
1435                 free(_media_meta->album);
1436                 free(_media_meta->artist);
1437                 free(_media_meta->genere);
1438                 free(_media_meta->recorded_date);
1439                 free(_media_meta->copyright);
1440                 free(_media_meta->track_num);
1441                 free(_media_meta->description);
1442                 free(_media_meta->composer);
1443                 free(_media_meta->year);
1444                 free(_media_meta->extra_media_meta);
1445         }
1446
1447         storage_adaptor_cloud_meta_s *_cloud_meta = _file_info->cloud_meta;
1448
1449         if (NULL != _cloud_meta) {
1450                 free(_cloud_meta->service_name);
1451                 free(_cloud_meta->extra_cloud_meta);
1452         }
1453
1454
1455         if (NULL != _file_info->file_share_token) {
1456                 free(_file_info->file_share_token->public_token);
1457                 _file_info->file_share_token->public_token = NULL;
1458
1459                 free(_file_info->file_share_token->auth_code);
1460                 _file_info->file_share_token->auth_code = NULL;
1461
1462                 free(_file_info->file_share_token);
1463         }
1464
1465         _file_info->plugin_uri          = NULL;
1466         _file_info->object_id           = NULL;
1467         _file_info->storage_path        = NULL;
1468         _file_info->revision            = -1;
1469         _file_info->timestamp           = 0ULL;
1470         _file_info->type                = NULL;
1471         _file_info->file_size           = 0ULL;
1472         _file_info->deleted             = -1;
1473         _file_info->expired_time        = 0ULL;
1474         _file_info->download_count      = 0U;
1475         _file_info->max_download_count  = 0U;
1476         _file_info->file_info_index     = -1;
1477         _file_info->tag                 = NULL;
1478         _file_info->file_share_token    = NULL;
1479
1480
1481         free((*file_info)->media_meta);
1482         free((*file_info)->cloud_meta);
1483         free(*file_info);
1484         *file_info = NULL;
1485
1486         return STORAGE_ADAPTOR_ERROR_NONE;
1487 }
1488
1489 void __assign_error_code(storage_adaptor_error_code_h *error, const int64_t code, const char *msg)
1490 {
1491         if (NULL != error) {
1492                 *error = storage_adaptor_create_error_code(code, msg);
1493         }
1494 }
1495
1496 /* ////////////////////////////////////////////////////////////
1497    // Adaptor Plugin call Functions
1498    //////////////////////////////////////////////////////////// */
1499
1500
1501
1502 /* ////////////////////// Public feature //////////////////////////// */
1503
1504 EXPORT_API
1505 storage_error_code_t storage_adaptor_open_file(storage_adaptor_plugin_h plugin,
1506                                                 storage_adaptor_plugin_context_h context,
1507                                                 const char *file_path,
1508                                                 storage_adaptor_file_access_mode_e mode,
1509                                                 long long int *file_uid,
1510                                                 storage_adaptor_error_code_h *error)
1511 {
1512         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1513                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1514
1515         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1516                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1517
1518         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1519                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1520
1521
1522         storage_adaptor_check_param_equal(NULL, file_uid, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1523                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (file_uid)"));
1524
1525
1526         storage_adaptor_check_param_equal(NULL, plugin->handle->open_file, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1527                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (open file)"));
1528
1529         int plugin_fd = 0;
1530         storage_error_code_t ret = plugin->handle->open_file(context, file_path, mode, &plugin_fd, error);
1531         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
1532                 *file_uid = _get_file_uid_from_plugin_fd(plugin_fd);
1533
1534                 #ifndef FORK_PLUGIN_ARCHITECTURE
1535                 long long int *buf = (long long int *) calloc(1, sizeof(long long int));
1536                 if (NULL != buf) {
1537                         *buf = *file_uid;
1538                         g_hash_table_insert(g_file_uid_list, (void *)&plugin_fd, (void *)buf);
1539                 }
1540                 #endif
1541
1542                 #ifdef DEBUG_ADAPTOR_PARAMS
1543                         storage_adaptor_debug_func("plugin fd (%d), file uid(%lld)", plugin_fd, *file_uid);
1544                 #endif
1545         }
1546
1547         return ret;
1548 }
1549
1550 EXPORT_API
1551 storage_error_code_t storage_adaptor_close_file(storage_adaptor_plugin_h plugin,
1552                                                 storage_adaptor_plugin_context_h context,
1553                                                 long long int file_uid,
1554                                                 storage_adaptor_error_code_h *error)
1555 {
1556         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1557                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1558
1559         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1560                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1561
1562         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1563                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1564
1565
1566         storage_adaptor_check_param_equal(NULL, plugin->handle->close_file, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1567                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (close file)"));
1568
1569         int plugin_fd = _get_plugin_fd_from_file_uid(file_uid);
1570         storage_error_code_t ret = plugin->handle->close_file(context, plugin_fd, error);
1571
1572         #ifndef FORK_PLUGIN_ARCHITECTURE
1573                 g_hash_table_remove(g_file_uid_list, (void *)&plugin_fd);
1574         #endif
1575
1576         #ifdef DEBUG_ADAPTOR_PARAMS
1577                 storage_adaptor_debug_func("plugin fd (%d), file uid(%lld)", plugin_fd, file_uid);
1578         #endif
1579
1580         return ret;
1581 }
1582
1583 EXPORT_API
1584 storage_error_code_t storage_adaptor_start_upload_task(storage_adaptor_plugin_h plugin,
1585                                                 storage_adaptor_plugin_context_h context,
1586                                                 long long int src_file_descriptor,              /* read only opened */
1587                                                 const char *upload_dir_path,
1588                                                 const char *file_name,
1589                                                 bool need_progress,
1590                                                 storage_adaptor_error_code_h *error,
1591                                                 void *user_data)
1592 {
1593         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1594                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1595
1596         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1597                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1598
1599         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1600                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1601
1602
1603         storage_adaptor_check_param_equal(NULL, plugin->handle->start_upload_task, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1604                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (start_upload_task)"));
1605
1606         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
1607
1608 #ifdef DEBUG_ADAPTOR_PARAMS
1609         storage_adaptor_debug_func("========== %s START ==========", __FUNCTION__);
1610         storage_adaptor_debug_func("[in] file_uid (%lld)", src_file_descriptor);
1611         storage_adaptor_debug_func("[in] path (%s / %s)", upload_dir_path, file_name);
1612         storage_adaptor_debug_func("[in] need progress (%d)", need_progress ? 1 : 0);
1613 #endif
1614
1615         int plugin_fd = _get_plugin_fd_from_file_uid(src_file_descriptor);
1616         plugin_req_enter();
1617         ret = plugin->handle->start_upload_task(context, plugin_fd,
1618                         upload_dir_path, file_name, need_progress, error, user_data);
1619         plugin_req_exit(ret, plugin, error);
1620
1621         return ret;
1622 }
1623
1624 EXPORT_API
1625 storage_error_code_t storage_adaptor_start_download_task(storage_adaptor_plugin_h plugin,
1626                                                 storage_adaptor_plugin_context_h context,
1627                                                 const char *storage_dir_path,
1628                                                 const char *file_name,
1629                                                 long long int dst_file_descriptor,              /* write only opened */
1630                                                 bool need_progress,
1631                                                 storage_adaptor_error_code_h *error,
1632                                                 void *user_data)
1633 {
1634         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1635                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1636
1637         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1638                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1639
1640         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1641                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1642
1643
1644         storage_adaptor_check_param_equal(NULL, plugin->handle->start_download_task, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1645                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (start_download_task)"));
1646
1647         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
1648
1649 #ifdef DEBUG_ADAPTOR_PARAMS
1650         storage_adaptor_debug_func("========== %s START ==========", __FUNCTION__);
1651         storage_adaptor_debug_func("[in] file_uid (%lld)", dst_file_descriptor);
1652         storage_adaptor_debug_func("[in] path (%s / %s)", storage_dir_path, file_name);
1653         storage_adaptor_debug_func("[in] need progress (%d)", need_progress ? 1 : 0);
1654 #endif
1655
1656         int plugin_fd = _get_plugin_fd_from_file_uid(dst_file_descriptor);
1657         plugin_req_enter();
1658         ret = plugin->handle->start_download_task(context, storage_dir_path, file_name,
1659                         plugin_fd, need_progress, error, user_data);
1660         plugin_req_exit(ret, plugin, error);
1661
1662         return ret;
1663 }
1664
1665 EXPORT_API
1666 storage_error_code_t storage_adaptor_start_download_thumb_task(storage_adaptor_plugin_h plugin,
1667                                                 storage_adaptor_plugin_context_h context,
1668                                                 const char *storage_dir_path,
1669                                                 const char *file_name,
1670                                                 long long int dst_file_descriptor,              /* write only opened */
1671                                                 int thumbnail_size,                     /* level (defined plugin SPEC) */
1672                                                 bool need_progress,
1673                                                 storage_adaptor_error_code_h *error,
1674                                                 void *user_data)
1675 {
1676         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1677                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1678
1679         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1680                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1681
1682         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1683                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1684
1685
1686         storage_adaptor_check_param_equal(NULL, plugin->handle->start_download_thumb_task, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1687                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (start_download_thumb_task)"));
1688
1689         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
1690
1691 #ifdef DEBUG_ADAPTOR_PARAMS
1692         storage_adaptor_debug_func("========== %s START ==========", __FUNCTION__);
1693         storage_adaptor_debug_func("[in] file_uid (%lld)", dst_file_descriptor);
1694         storage_adaptor_debug_func("[in] path (%s / %s)", storage_dir_path, file_name);
1695         storage_adaptor_debug_func("[in] need progress (%d)", need_progress ? 1 : 0);
1696 #endif
1697
1698         int plugin_fd = _get_plugin_fd_from_file_uid(dst_file_descriptor);
1699         plugin_req_enter();
1700         ret = plugin->handle->start_download_thumb_task(context, storage_dir_path, file_name,
1701                         plugin_fd, thumbnail_size, need_progress, error, user_data);
1702         plugin_req_exit(ret, plugin, error);
1703
1704         return ret;
1705 }
1706
1707
1708 EXPORT_API
1709 storage_error_code_t storage_adaptor_cancel_upload_task(storage_adaptor_plugin_h plugin,
1710                                                 storage_adaptor_plugin_context_h context,
1711                                                 long long int file_uid,
1712                                                 storage_adaptor_error_code_h *error)
1713 {
1714         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1715                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1716
1717         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1718                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1719
1720         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1721                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1722
1723
1724         storage_adaptor_check_param_equal(NULL, plugin->handle->cancel_upload_task, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1725                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (cancel_upload_task)"));
1726
1727         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
1728
1729         int plugin_fd = _get_plugin_fd_from_file_uid(file_uid);
1730         plugin_req_enter();
1731         ret = plugin->handle->cancel_upload_task(context, plugin_fd, error);
1732         plugin_req_exit(ret, plugin, error);
1733
1734         return ret;
1735 }
1736
1737 EXPORT_API
1738 storage_error_code_t storage_adaptor_cancel_download_task(storage_adaptor_plugin_h plugin,
1739                                                 storage_adaptor_plugin_context_h context,
1740                                                 long long int file_uid,
1741                                                 storage_adaptor_error_code_h *error)
1742 {
1743         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1744                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1745
1746         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1747                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1748
1749         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1750                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1751
1752
1753         storage_adaptor_check_param_equal(NULL, plugin->handle->cancel_download_task, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1754                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (cancel_download_task)"));
1755
1756         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
1757
1758         int plugin_fd = _get_plugin_fd_from_file_uid(file_uid);
1759         plugin_req_enter();
1760         ret = plugin->handle->cancel_download_task(context, plugin_fd, error);
1761         plugin_req_exit(ret, plugin, error);
1762
1763         return ret;
1764
1765 }
1766
1767 EXPORT_API
1768 storage_error_code_t storage_adaptor_cancel_download_thumb_task(storage_adaptor_plugin_h plugin,
1769                                                 storage_adaptor_plugin_context_h context,
1770                                                 long long int file_uid,
1771                                                 storage_adaptor_error_code_h *error)
1772 {
1773         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1774                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1775
1776         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1777                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1778
1779         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1780                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1781
1782
1783         storage_adaptor_check_param_equal(NULL, plugin->handle->cancel_download_thumb_task, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1784                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (cancel_download_thumb_task)"));
1785
1786         storage_error_code_t ret = STORAGE_ADAPTOR_ERROR_NONE;
1787
1788         int plugin_fd = _get_plugin_fd_from_file_uid(file_uid);
1789         plugin_req_enter();
1790         ret = plugin->handle->cancel_download_thumb_task(context, plugin_fd, error);
1791         plugin_req_exit(ret, plugin, error);
1792
1793         return ret;
1794
1795 }
1796
1797 /* ////////////////////// Common feature //////////////////////////// */
1798
1799 /**
1800 * @brief Set server information for Storage Plugin
1801 *
1802 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
1803 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
1804 * @param[in]    server_info                     specifies server information for Storage Plugin
1805 * @param[in]    request                         specifies optional parameter
1806 * @param[out]   error                           specifies error code
1807 * @param[out]   response                        specifies optional parameter
1808 * @return 0 on success, otherwise a positive error value
1809 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
1810 */
1811 EXPORT_API
1812 storage_error_code_t storage_adaptor_set_server_info(storage_adaptor_plugin_h plugin,
1813                                                 storage_adaptor_plugin_context_h context,
1814                                                 GHashTable *server_info,
1815                                                 void *request,
1816                                                 storage_adaptor_error_code_h *error,
1817                                                 void *response)
1818 {
1819         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1820                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1821
1822         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1823                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1824
1825         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1826                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1827
1828
1829         storage_adaptor_check_param_equal(NULL, plugin->handle->set_server_info, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1830                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (set_server_info)"));
1831
1832 #ifdef DEBUG_ADAPTOR_PARAMS
1833         storage_adaptor_debug_func("========== %s START ==========", __FUNCTION__);
1834         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
1835                         context->app_id, context->access_token, context->uid);
1836         storage_adaptor_debug_func("[in] server_info [addr(%p)]", server_info);
1837         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
1838 #endif
1839
1840         plugin_req_enter();
1841         storage_error_code_t ret = plugin->handle->set_server_info(
1842                         context, server_info, request, error, response);
1843         plugin_req_exit(ret, plugin, error);
1844
1845 #ifdef DEBUG_ADAPTOR_PARAMS
1846         storage_adaptor_debug_func("[out] return code (%d)", ret);
1847         if ((NULL != error) && (NULL != *error)) {
1848                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
1849                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
1850         }
1851         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
1852         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
1853 #endif
1854
1855         return ret;
1856 }
1857
1858 /**
1859 * @brief Makes a directory at cloud
1860 * @param[in]    upload_file_local_path          specifies local path of the file to be uploaded
1861 *
1862 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
1863 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
1864 * @param[in]    parent_folder_storage_path      specifies path to locate the folder you want to create
1865 * @param[in]    folder_name                     specifies folder name to be created at cloud
1866 * @param[in]    request                         specifies optional parameter
1867 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
1868 * @param[out]   error                           specifies error code
1869 * @param[out]   response                        specifies optional parameter
1870 * @return 0 on success, otherwise a negative error value
1871 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
1872 */
1873 storage_error_code_t storage_adaptor_make_directory(storage_adaptor_plugin_h plugin,
1874                                                 storage_adaptor_plugin_context_h context,
1875                                                 const char *parent_folder_storage_path,
1876                                                 const char *folder_name,
1877                                                 void *request,
1878                                                 storage_adaptor_file_info_h *file_info,
1879                                                 storage_adaptor_error_code_h *error,
1880                                                 void *response)
1881 {
1882         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1883                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1884
1885         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1886                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1887
1888         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1889                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1890
1891
1892         storage_adaptor_check_param_equal(NULL, plugin->handle->make_directory, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1893                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (make_directory)"));
1894
1895 #ifdef DEBUG_ADAPTOR_PARAMS
1896         storage_adaptor_debug_func("========== %s START ==========", __FUNCTION__);
1897         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
1898                         context->app_id, context->access_token, context->uid);
1899         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
1900         storage_adaptor_debug_func("[in] folder_name (%s)", folder_name);
1901         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
1902 #endif
1903
1904         plugin_req_enter();
1905         storage_error_code_t ret = plugin->handle->make_directory(
1906                         context, parent_folder_storage_path, folder_name, request, file_info, error, response);
1907         plugin_req_exit(ret, plugin, error);
1908
1909 #ifdef DEBUG_ADAPTOR_PARAMS
1910         storage_adaptor_debug_func("[out] return code (%d)", ret);
1911         if ((NULL != file_info) && (NULL != (*file_info))) {
1912                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
1913         }
1914         if ((NULL != error) && (NULL != *error)) {
1915                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
1916                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
1917         }
1918         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
1919         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
1920 #endif
1921
1922         return ret;
1923 }
1924
1925 /**
1926 * @brief Removes a directory at cloud
1927 *
1928 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
1929 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
1930 * @param[in]    parent_folder_storage_path      specifies parent folder path of folder you want to delete
1931 * @param[in]    folder_name                     specifies folder name to be deleted from cloud
1932 * @param[in]    request                         specifies optional parameter
1933 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
1934 * @param[out]   error                           specifies error code
1935 * @param[out]   response                        specifies optional parameter
1936 * @return 0 on success, otherwise a negative error value
1937 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
1938 */
1939 storage_error_code_t storage_adaptor_remove_directory(storage_adaptor_plugin_h plugin,
1940                                                 storage_adaptor_plugin_context_h context,
1941                                                 const char *parent_folder_storage_path,
1942                                                 const char *folder_name,
1943                                                 void *request,
1944                                                 storage_adaptor_file_info_h *file_info,
1945                                                 storage_adaptor_error_code_h *error,
1946                                                 void *response)
1947 {
1948         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1949                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
1950
1951         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
1952                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
1953
1954         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
1955                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
1956
1957
1958         storage_adaptor_check_param_equal(NULL, plugin->handle->remove_directory, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
1959                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (remove_directory)"));
1960
1961 #ifdef DEBUG_ADAPTOR_PARAMS
1962         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
1963         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
1964                         context->app_id, context->access_token, context->uid);
1965         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
1966         storage_adaptor_debug_func("[in] folder_name (%s)", folder_name);
1967         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
1968 #endif
1969
1970         plugin_req_enter();
1971         storage_error_code_t ret = plugin->handle->remove_directory(context, parent_folder_storage_path,
1972                         folder_name, request, file_info, error, response);
1973         plugin_req_exit(ret, plugin, error);
1974
1975 #ifdef DEBUG_ADAPTOR_PARAMS
1976         storage_adaptor_debug_func("[out] return code (%d)", ret);
1977         if ((NULL != file_info) && (NULL != (*file_info))) {
1978                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
1979         }
1980         if ((NULL != error) && (NULL != *error)) {
1981                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
1982                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
1983         }
1984         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
1985         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
1986 #endif
1987
1988         return ret;
1989 }
1990
1991 /**
1992 * @brief Requests folder and file list in a folder
1993 *
1994 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
1995 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
1996 * @param[in]    parent_folder_storage_path      specifies parent folder path of folder you want to get list
1997 * @param[in]    folder_name                     specifies folder name you want to get list
1998 * @param[in]    request                         specifies optional parameter
1999 * @param[out]   file_info_list                  specifies Storage Adaptor File Info handle
2000 * @param[out]   file_info_list_len              specifies length of the file_info_list
2001 * @param[out]   error                           specifies error code
2002 * @param[out]   response                        specifies optional parameter
2003 * @return 0 on success, otherwise a negative error value
2004 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2005 */
2006 storage_error_code_t storage_adaptor_list(storage_adaptor_plugin_h plugin,
2007                                                 storage_adaptor_plugin_context_h context,
2008                                                 const char *parent_folder_storage_path,
2009                                                 const char *folder_name,
2010                                                 void *request,
2011                                                 storage_adaptor_file_info_h **file_info_list,
2012                                                 int *file_info_list_len,
2013                                                 storage_adaptor_error_code_h *error,
2014                                                 void *response)
2015 {
2016         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2017                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2018
2019         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2020                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2021
2022         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2023                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2024
2025
2026         storage_adaptor_check_param_equal(NULL, plugin->handle->list, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2027                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (list)"));
2028
2029 #ifdef DEBUG_ADAPTOR_PARAMS
2030         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2031         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2032                         context->app_id, context->access_token, context->uid);
2033         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2034         storage_adaptor_debug_func("[in] folder_name (%s)", folder_name);
2035         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2036 #endif
2037
2038         plugin_req_enter();
2039         storage_error_code_t ret = plugin->handle->list(context, parent_folder_storage_path,
2040                         folder_name, request, file_info_list, file_info_list_len, error, response);
2041         plugin_req_exit(ret, plugin, error);
2042
2043 #ifdef DEBUG_ADAPTOR_PARAMS
2044         storage_adaptor_debug_func("[out] return code (%d)", ret);
2045         storage_adaptor_debug_func("[out] file_info_list_len (%d)", *file_info_list_len);
2046         if ((NULL != error) && (NULL != *error)) {
2047                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2048                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2049         }
2050         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2051         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2052 #endif
2053
2054         return ret;
2055 }
2056
2057 /**
2058 * @brief Uploads a file to cloud (Sync)
2059 *
2060 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2061 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2062 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to upload
2063 * @param[in]    file_name                       specifies file name to be uploaded to cloud
2064 * @param[in]    upload_file_local_path          specifies local path of the file to be uploaded
2065 * @param[in]    publish                         specifies Allow to share file with no authentication
2066 * @param[in]    request                         specifies optional parameter
2067 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2068 * @param[out]   error                           specifies error code
2069 * @param[out]   response                        specifies optional parameter
2070 * @return 0 on success, otherwise a negative error value
2071 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2072 */
2073 storage_error_code_t storage_adaptor_upload_file_sync(storage_adaptor_plugin_h plugin,
2074                                                 storage_adaptor_plugin_context_h context,
2075                                                 const char *parent_folder_storage_path,
2076                                                 const char *file_name,
2077                                                 const char *upload_file_local_path,
2078                                                 const int publish,
2079                                                 void *request,
2080                                                 storage_adaptor_file_info_h *file_info,
2081                                                 storage_adaptor_error_code_h *error,
2082                                                 void *response)
2083 {
2084         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2085                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2086
2087         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2088                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2089
2090         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2091                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2092
2093
2094         storage_adaptor_check_param_equal(NULL, plugin->handle->upload_file_sync, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2095                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (upload_file_sync)"));
2096
2097 #ifdef DEBUG_ADAPTOR_PARAMS
2098         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2099         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2100                         context->app_id, context->access_token, context->uid);
2101         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2102         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2103         storage_adaptor_debug_func("[in] upload_file_local_path (%s)", upload_file_local_path);
2104         storage_adaptor_debug_func("[in] publish (%d)", publish);
2105         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2106 #endif
2107
2108         plugin_req_enter();
2109         storage_error_code_t ret = plugin->handle->upload_file_sync(context, parent_folder_storage_path,
2110                         file_name, upload_file_local_path, publish, request, file_info, error, response);
2111         plugin_req_exit(ret, plugin, error);
2112
2113 #ifdef DEBUG_ADAPTOR_PARAMS
2114         storage_adaptor_debug_func("[out] return code (%d)", ret);
2115         if ((NULL != file_info) && (NULL != (*file_info))) {
2116                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
2117                 if ((1 == publish) && (NULL != (*file_info)->file_share_token)) {
2118                         storage_adaptor_debug_func("[out] file_info->file_share_token->public_token (%s)",
2119                                         (*file_info)->file_share_token->public_token);
2120                         storage_adaptor_debug_func("[out] file_info->file_share_token->auth_code (%s)",
2121                                         (*file_info)->file_share_token->auth_code);
2122                 }
2123         }
2124         if ((NULL != error) && (NULL != *error)) {
2125                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2126                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2127         }
2128         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2129         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2130 #endif
2131
2132         return ret;
2133 }
2134
2135 /**
2136 * @brief Downloads a file to local (Sync)
2137 *
2138 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2139 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2140 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to download
2141 * @param[in]    file_name                       specifies file name to be downloaded to local
2142 * @param[in]    download_file_local_path        specifies local path to download
2143 * @param[in]    request                         specifies optional parameter
2144 * @param[out]   error                           specifies error code
2145 * @param[out]   response                        specifies optional parameter
2146 * @return 0 on success, otherwise a negative error value
2147 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2148 */
2149 storage_error_code_t storage_adaptor_download_file_sync(storage_adaptor_plugin_h plugin,
2150                                                 storage_adaptor_plugin_context_h context,
2151                                                 const char *parent_folder_storage_path,
2152                                                 const char *file_name,
2153                                                 const char *download_file_local_path,
2154                                                 void *request,
2155                                                 storage_adaptor_error_code_h *error,
2156                                                 void *response)
2157 {
2158         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2159                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2160
2161         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2162                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2163
2164         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2165                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2166
2167
2168         storage_adaptor_check_param_equal(NULL, plugin->handle->download_file_sync, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2169                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (download_file_sync)"));
2170
2171 #ifdef DEBUG_ADAPTOR_PARAMS
2172         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2173         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2174                         context->app_id, context->access_token, context->uid);
2175         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2176         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2177         storage_adaptor_debug_func("[in] download_file_local_path (%s)", download_file_local_path);
2178         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2179 #endif
2180
2181         plugin_req_enter();
2182         storage_error_code_t ret = plugin->handle->download_file_sync(context, parent_folder_storage_path,
2183                         file_name, download_file_local_path, request, error, response);
2184         plugin_req_exit(ret, plugin, error);
2185
2186 #ifdef DEBUG_ADAPTOR_PARAMS
2187         storage_adaptor_debug_func("[out] return code (%d)", ret);
2188         if ((NULL != error) && (NULL != *error)) {
2189                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2190                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2191         }
2192         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2193         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2194 #endif
2195
2196         return ret;
2197 }
2198
2199 storage_error_code_t storage_adaptor_download_thumbnail(storage_adaptor_plugin_h plugin,
2200                                                 storage_adaptor_plugin_context_h context,
2201                                                 const char *folder_path,
2202                                                 const char *file_name,
2203                                                 const char *download_path,
2204                                                 int thumbnail_size,
2205                                                 void *request,
2206                                                 storage_adaptor_error_code_h *error,
2207                                                 void *response)
2208 {
2209         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2210                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2211
2212         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2213                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2214
2215         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2216                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2217
2218
2219         storage_adaptor_check_param_equal(NULL, plugin->handle->download_thumbnail, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2220                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (download_thumbnail)"));
2221
2222 #ifdef DEBUG_ADAPTOR_PARAMS
2223         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2224         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2225                         context->app_id, context->access_token, context->uid);
2226         storage_adaptor_debug_func("[in] folder_path (%s)", folder_path);
2227         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2228         storage_adaptor_debug_func("[in] download_path (%s)", download_path);
2229         storage_adaptor_debug_func("[in] thumbnail_size (%d)", thumbnail_size);
2230         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2231 #endif
2232
2233         plugin_req_enter();
2234         storage_error_code_t ret = plugin->handle->download_thumbnail(context, folder_path,
2235                         file_name, download_path, thumbnail_size, request, error, response);
2236         plugin_req_exit(ret, plugin, error);
2237
2238 #ifdef DEBUG_ADAPTOR_PARAMS
2239         storage_adaptor_debug_func("[out] return code (%d)", ret);
2240         if ((NULL != error) && (NULL != *error)) {
2241                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2242                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2243         }
2244         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2245         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2246 #endif
2247
2248         return ret;
2249 }
2250
2251
2252
2253 /**
2254 * @brief Removes a file at cloud
2255 *
2256 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2257 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2258 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to delete
2259 * @param[in]    file_name                       specifies file name to be deleted from cloud
2260 * @param[in]    request                         specifies optional parameter
2261 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2262 * @param[out]   error                           specifies error code
2263 * @param[out]   response                        specifies optional parameter
2264 * @return 0 on success, otherwise a negative error value
2265 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2266 */
2267 storage_error_code_t storage_adaptor_delete_file(storage_adaptor_plugin_h plugin,
2268                                                 storage_adaptor_plugin_context_h context,
2269                                                 const char *parent_folder_storage_path,
2270                                                 const char *file_name,
2271                                                 void *request,
2272                                                 storage_adaptor_file_info_h *file_info,
2273                                                 storage_adaptor_error_code_h *error,
2274                                                 void *response)
2275 {
2276         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2277                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2278
2279         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2280                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2281
2282         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2283                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2284
2285
2286         storage_adaptor_check_param_equal(NULL, plugin->handle->delete_file, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2287                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (delete_file)"));
2288
2289 #ifdef DEBUG_ADAPTOR_PARAMS
2290         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2291         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2292                         context->app_id, context->access_token, context->uid);
2293         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2294         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2295         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2296 #endif
2297
2298         plugin_req_enter();
2299         storage_error_code_t ret = plugin->handle->delete_file(context, parent_folder_storage_path,
2300                         file_name, request, file_info, error, response);
2301         plugin_req_exit(ret, plugin, error);
2302
2303 #ifdef DEBUG_ADAPTOR_PARAMS
2304         storage_adaptor_debug_func("[out] return code (%d)", ret);
2305         if ((NULL != file_info) && (NULL != (*file_info))) {
2306                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
2307         }
2308         if ((NULL != error) && (NULL != *error)) {
2309                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2310                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2311         }
2312         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2313         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2314 #endif
2315
2316         return ret;
2317 }
2318
2319 /**
2320 * @brief Move a folder into destination folder
2321 *
2322 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2323 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2324 * @param[in]    parent_folder_storage_path      specifies parent folder path of folder you want to move
2325 * @param[in]    folder_name                     specifies folder name to be moved
2326 * @param[in]    dest_parent_folder_storage_path specifies new parent folder path
2327 * @param[in]    new_folder_name                 specifies new folder name
2328 * @param[in]    request                         specifies optional parameter
2329 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2330 * @param[out]   error                           specifies error code
2331 * @param[out]   response                        specifies optional parameter
2332 * @return 0 on success, otherwise a positive error value
2333 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2334 */
2335 storage_error_code_t storage_adaptor_move_directory(storage_adaptor_plugin_h plugin,
2336                                                 storage_adaptor_plugin_context_h context,
2337                                                 const char *parent_folder_storage_path,
2338                                                 const char *folder_name,
2339                                                 const char *dest_parent_folder_storage_path,
2340                                                 const char *new_folder_name,
2341                                                 void *request,
2342                                                 storage_adaptor_file_info_h *file_info,
2343                                                 storage_adaptor_error_code_h *error,
2344                                                 void *response)
2345 {
2346         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2347                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2348
2349         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2350                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2351
2352         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2353                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2354
2355
2356         storage_adaptor_check_param_equal(NULL, plugin->handle->move_directory, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2357                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (move_directory)"));
2358
2359 #ifdef DEBUG_ADAPTOR_PARAMS
2360         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2361         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2362                         context->app_id, context->access_token, context->uid);
2363         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2364         storage_adaptor_debug_func("[in] folder_name (%s)", folder_name);
2365         storage_adaptor_debug_func("[in] dest_parent_folder_storage_path (%s)", dest_parent_folder_storage_path);
2366         storage_adaptor_debug_func("[in] new_folder_name (%s)", new_folder_name);
2367         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2368 #endif
2369
2370         plugin_req_enter();
2371         storage_error_code_t ret = plugin->handle->move_directory(context, parent_folder_storage_path,
2372                         folder_name, dest_parent_folder_storage_path, new_folder_name, request, file_info, error, response);
2373         plugin_req_exit(ret, plugin, error);
2374
2375 #ifdef DEBUG_ADAPTOR_PARAMS
2376         storage_adaptor_debug_func("[out] return code (%d)", ret);
2377         if ((NULL != file_info) && (NULL != (*file_info))) {
2378                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
2379         }
2380         if ((NULL != error) && (NULL != *error)) {
2381                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2382                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2383         }
2384         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2385         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2386 #endif
2387
2388         return ret;
2389 }
2390
2391 /**
2392 * @brief Move a file into destination folder
2393 *
2394 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2395 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2396 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to move
2397 * @param[in]    file_name                       specifies file name to be moved
2398 * @param[in]    dest_parent_folder_storage_path specifies new folder path
2399 * @param[in]    new_file_name                   specifies new file name
2400 * @param[in]    request                         specifies optional parameter
2401 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2402 * @param[out]   error                           specifies error code
2403 * @param[out]   response                        specifies optional parameter
2404 * @return 0 on success, otherwise a positive error value
2405 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2406 */
2407 storage_error_code_t storage_adaptor_move_file(storage_adaptor_plugin_h plugin,
2408                                                 storage_adaptor_plugin_context_h context,
2409                                                 const char *parent_folder_storage_path,
2410                                                 const char *file_name,
2411                                                 const char *dest_parent_folder_storage_path,
2412                                                 const char *new_file_name,
2413                                                 void *request,
2414                                                 storage_adaptor_file_info_h *file_info,
2415                                                 storage_adaptor_error_code_h *error,
2416                                                 void *response)
2417 {
2418         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2419                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2420
2421         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2422                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2423
2424         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2425                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2426
2427
2428         storage_adaptor_check_param_equal(NULL, plugin->handle->move_file, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2429                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (move_file)"));
2430
2431 #ifdef DEBUG_ADAPTOR_PARAMS
2432         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2433         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2434                         context->app_id, context->access_token, context->uid);
2435         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2436         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2437         storage_adaptor_debug_func("[in] dest_parent_folder_storage_path (%s)", dest_parent_folder_storage_path);
2438         storage_adaptor_debug_func("[in] new_file_name (%s)", new_file_name);
2439         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2440 #endif
2441
2442         plugin_req_enter();
2443         storage_error_code_t ret = plugin->handle->move_file(context, parent_folder_storage_path,
2444                         file_name, dest_parent_folder_storage_path, new_file_name, request, file_info, error, response);
2445         plugin_req_exit(ret, plugin, error);
2446
2447 #ifdef DEBUG_ADAPTOR_PARAMS
2448         storage_adaptor_debug_func("[out] return code (%d)", ret);
2449         if ((NULL != file_info) && (NULL != (*file_info))) {
2450                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
2451         }
2452         if ((NULL != error) && (NULL != *error)) {
2453                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2454                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2455         }
2456         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2457         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2458 #endif
2459
2460         return ret;
2461 }
2462
2463 /**
2464 * @brief Get state of file transfer request
2465 *
2466 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2467 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2468 * @param[in]    transfer_request_id             specifies unique id for file transfer request
2469 * @param[in]    request                         specifies optional parameter
2470 * @param[out]   state                          specifies current state of transfer request
2471 * @param[out]   error                           specifies error code
2472 * @param[out]   response                        specifies optional parameter
2473 * @return 0 on success, otherwise a positive error value
2474 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2475 */
2476 storage_error_code_t storage_adaptor_get_transfer_state(storage_adaptor_plugin_h plugin,
2477                                                 storage_adaptor_plugin_context_h context,
2478                                                 void *transfer_request_id,
2479                                                 void *request,
2480                                                 storage_adaptor_transfer_state_e *state,
2481                                                 storage_adaptor_error_code_h *error,
2482                                                 void *response)
2483 {
2484         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2485                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2486
2487         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2488                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2489
2490         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2491                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2492
2493
2494         storage_adaptor_check_param_equal(NULL, plugin->handle->get_transfer_state, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2495                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_transfer_state)"));
2496
2497 #ifdef DEBUG_ADAPTOR_PARAMS
2498         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2499         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
2500                         context->app_id, context->access_token, context->cid, context->uid);
2501         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2502 #endif
2503
2504         plugin_req_enter();
2505         storage_error_code_t ret = plugin->handle->get_transfer_state(context,  transfer_request_id,
2506                         request, state, error, response);
2507         plugin_req_exit(ret, plugin, error);
2508
2509 #ifdef DEBUG_ADAPTOR_PARAMS
2510         storage_adaptor_debug_func("[out] return code (%d)", ret);
2511         if (NULL != state) {
2512                 storage_adaptor_debug_func("[out] state (%d)", *state);
2513         }
2514         if ((NULL != error) && (NULL != *error)) {
2515                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2516                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2517         }
2518         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2519         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2520 #endif
2521
2522         return ret;
2523 }
2524
2525 /**
2526 * @brief Set state of file transfer request
2527 *
2528 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2529 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2530 * @param[in]    transfer_request_id             specifies unique id for file transfer request
2531 * @param[in]    state                          specifies state to set
2532 * @param[in]    request                         specifies optional parameter
2533 * @param[out]   error                           specifies error code
2534 * @param[out]   response                        specifies optional parameter
2535 * @return 0 on success, otherwise a positive error value
2536 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2537 */
2538 storage_error_code_t storage_adaptor_set_transfer_state(storage_adaptor_plugin_h plugin,
2539                                                 storage_adaptor_plugin_context_h context,
2540                                                 void *transfer_request_id,
2541                                                 storage_adaptor_transfer_state_e state,
2542                                                 void *request,
2543                                                 storage_adaptor_error_code_h *error,
2544                                                 void *response)
2545 {
2546         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2547                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2548
2549         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2550                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2551
2552         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2553                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2554
2555
2556         storage_adaptor_check_param_equal(NULL, plugin->handle->set_transfer_state, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2557                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (set_transfer_state)"));
2558
2559 #ifdef DEBUG_ADAPTOR_PARAMS
2560         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2561         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2562                         context->app_id, context->access_token, context->uid);
2563         storage_adaptor_debug_func("[in] state(%d)", state);
2564         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2565 #endif
2566
2567         plugin_req_enter();
2568         storage_error_code_t ret = plugin->handle->set_transfer_state(context, transfer_request_id,
2569                         state, request, error, response);
2570         plugin_req_exit(ret, plugin, error);
2571
2572 #ifdef DEBUG_ADAPTOR_PARAMS
2573         storage_adaptor_debug_func("[out] return code (%d)", ret);
2574         if ((NULL != error) && (NULL != *error)) {
2575                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2576                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2577         }
2578         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2579         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2580 #endif
2581
2582         return ret;
2583 }
2584
2585 storage_error_code_t storage_adaptor_get_root_folder_path(storage_adaptor_plugin_h plugin,
2586                                                 storage_adaptor_plugin_context_h context,
2587                                                 void *request,
2588                                                 char **root_folder_path,
2589                                                 storage_adaptor_error_code_h *error,
2590                                                 void *response)
2591 {
2592         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2593                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2594
2595         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2596                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2597
2598         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2599                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2600
2601
2602         storage_adaptor_check_param_equal(NULL, root_folder_path, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2603                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (root_folder_path)"));
2604
2605
2606         storage_adaptor_check_param_equal(NULL, plugin->handle->get_root_folder_path, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2607                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_root_folder_path)"));
2608
2609 #ifdef DEBUG_ADAPTOR_PARAMS
2610         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2611         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) uid(%s)]",
2612                         context->app_id, context->access_token, context->uid);
2613         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2614 #endif
2615
2616         plugin_req_enter();
2617         storage_error_code_t ret = plugin->handle->get_root_folder_path(context, request, root_folder_path, error, response);
2618         plugin_req_exit(ret, plugin, error);
2619
2620 #ifdef DEBUG_ADAPTOR_PARAMS
2621         storage_adaptor_debug_func("[out] return code (%d)", ret);
2622         if (NULL != *root_folder_path) {
2623                 storage_adaptor_debug_func("[out] root_folder_path (%s)", *root_folder_path);
2624         }
2625         if ((NULL != error) && (NULL != *error)) {
2626                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2627                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2628         }
2629         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2630         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2631 #endif
2632
2633         return ret;
2634 }
2635
2636 /* ////////////////////// Private feature //////////////////////////// */
2637
2638 /**
2639 * @brief Uploads a file to cloud (Async)
2640 *
2641 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2642 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2643 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to upload
2644 * @param[in]    file_name                       specifies file name to be uploaded to cloud
2645 * @param[in]    upload_file_local_path          specifies local path of the file to be uploaded
2646 * @param[in]    publish                         specifies Allow to share file with no authentication
2647 * @param[in]    request                         specifies optional parameter
2648 * @param[out]   transfer_request_id             specifies
2649 * @param[out]   error                           specifies error code
2650 * @return 0 on success, otherwise a negative error value
2651 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2652 */
2653 storage_error_code_t storage_adaptor_upload_file_async(storage_adaptor_plugin_h plugin,
2654                                                 storage_adaptor_plugin_context_h context,
2655                                                 const char *parent_folder_storage_path,
2656                                                 const char *file_name,
2657                                                 const char *upload_file_local_path,
2658                                                 const int publish,
2659                                                 void *request,
2660                                                 void *transfer_request_id,
2661                                                 storage_adaptor_error_code_h *error)
2662 {
2663         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2664                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2665
2666         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2667                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2668
2669         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2670                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2671
2672
2673         storage_adaptor_check_param_equal(NULL, plugin->handle->upload_file_async, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2674                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (upload_file_async)"));
2675
2676 #ifdef DEBUG_ADAPTOR_PARAMS
2677         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2678         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
2679                         context->app_id, context->access_token, context->cid, context->uid);
2680         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2681         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2682         storage_adaptor_debug_func("[in] upload_file_local_path (%s)", upload_file_local_path);
2683         storage_adaptor_debug_func("[in] publish (%d)", publish);
2684         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2685 #endif
2686
2687         plugin_req_enter();
2688         storage_error_code_t ret = plugin->handle->upload_file_async(context, parent_folder_storage_path,
2689                         file_name, upload_file_local_path, publish, request, transfer_request_id);
2690         plugin_req_exit(ret, plugin, error);
2691
2692 #ifdef DEBUG_ADAPTOR_PARAMS
2693         storage_adaptor_debug_func("[out] return code (%d)", ret);
2694         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2695 #endif
2696
2697         return ret;
2698 }
2699
2700 /**
2701 * @brief Downloads a file to local (Async)
2702 *
2703 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2704 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2705 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to download
2706 * @param[in]    file_name                       specifies file name to be downloaded to local
2707 * @param[in]    download_file_local_path        specifies local path to download
2708 * @param[in]    request                         specifies optional parameter
2709 * @param[out]   transfer_request_id             specifies
2710 * @param[out]   error                           specifies error code
2711 * @return 0 on success, otherwise a negative error value
2712 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2713 */
2714 storage_error_code_t storage_adaptor_download_file_async(storage_adaptor_plugin_h plugin,
2715                                                 storage_adaptor_plugin_context_h context,
2716                                                 const char *parent_folder_storage_path,
2717                                                 const char *file_name,
2718                                                 const char *download_file_local_path,
2719                                                 void *request,
2720                                                 void *transfer_request_id,
2721                                                 storage_adaptor_error_code_h *error)
2722 {
2723         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2724                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2725
2726         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2727                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2728
2729         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2730                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2731
2732
2733         storage_adaptor_check_param_equal(NULL, plugin->handle->download_file_async, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2734                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (download_file_async)"));
2735
2736 #ifdef DEBUG_ADAPTOR_PARAMS
2737         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2738         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
2739                         context->app_id, context->access_token, context->cid, context->uid);
2740         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2741         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2742         storage_adaptor_debug_func("[in] download_file_local_path (%s)", download_file_local_path);
2743         storage_adaptor_debug_func("[in] request (addr : %p)", request);
2744         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2745 #endif
2746
2747         plugin_req_enter();
2748         storage_error_code_t ret = plugin->handle->download_file_async(context, parent_folder_storage_path,
2749                         file_name, download_file_local_path, request, transfer_request_id);
2750         plugin_req_exit(ret, plugin, error);
2751
2752 #ifdef DEBUG_ADAPTOR_PARAMS
2753         storage_adaptor_debug_func("[out] return code (%d)", ret);
2754         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2755 #endif
2756
2757         return ret;
2758 }
2759
2760
2761 /**
2762 * @brief Sets metadata of file at cloud
2763 *
2764 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2765 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2766 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to set meta data
2767 * @param[in]    file_name                       specifies file name to be updated meta data
2768 * @param[in]    meta_data                       specifies meta data (A pair of Key, Value)
2769 * @param[in]    request                         specifies optional parameter
2770 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2771 * @param[out]   error                           specifies error code
2772 * @param[out]   response                        specifies optional parameter
2773 * @return 0 on success, otherwise a negative error value
2774 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2775 */
2776 storage_error_code_t storage_adaptor_set_meta(storage_adaptor_plugin_h plugin,
2777                                                 storage_adaptor_plugin_context_h context,
2778                                                 const char *parent_folder_storage_path,
2779                                                 const char *file_name,
2780                                                 const void *meta_data,
2781                                                 void *request,
2782                                                 storage_adaptor_file_info_h *file_info,
2783                                                 storage_adaptor_error_code_h *error,
2784                                                 void *response)
2785 {
2786         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2787                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2788
2789         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2790                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2791
2792         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2793                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2794
2795
2796         storage_adaptor_check_param_equal(NULL, plugin->handle->set_meta, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2797                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (set_meta)"));
2798
2799 #ifdef DEBUG_ADAPTOR_PARAMS
2800         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2801         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
2802                         context->app_id, context->access_token, context->cid, context->uid);
2803         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2804         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2805         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2806 #endif
2807
2808         plugin_req_enter();
2809         storage_error_code_t ret = plugin->handle->set_meta(context, parent_folder_storage_path,
2810                         file_name, meta_data, request, file_info, error, response);
2811         plugin_req_exit(ret, plugin, error);
2812
2813 #ifdef DEBUG_ADAPTOR_PARAMS
2814         storage_adaptor_debug_func("[out] return code (%d)", ret);
2815         if ((NULL != file_info) && (NULL != (*file_info))) {
2816                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
2817         }
2818         if ((NULL != error) && (NULL != *error)) {
2819                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2820                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2821         }
2822         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2823         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2824 #endif
2825
2826         return ret;
2827 }
2828
2829 /**
2830 * @brief Gets metatdata of file at cloud
2831 *
2832 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2833 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2834 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to get meta data
2835 * @param[in]    file_name                       specifies file name
2836 * @param[in]    request                         specifies optional parameter
2837 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2838 * @param[out]   meta_data                       specifies meta data (A pair of Key, Value)
2839 * @param[out]   error                           specifies error code
2840 * @param[out]   response                        specifies optional parameter
2841 * @return 0 on success, otherwise a negative error value
2842 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2843 */
2844 storage_error_code_t storage_adaptor_get_meta(storage_adaptor_plugin_h plugin,
2845                                                 storage_adaptor_plugin_context_h context,
2846                                                 const char *parent_folder_storage_path,
2847                                                 const char *file_name,
2848                                                 void *request,
2849                                                 storage_adaptor_file_info_h *file_info,
2850                                                 void **meta_data,
2851                                                 storage_adaptor_error_code_h *error,
2852                                                 void *response)
2853 {
2854         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2855                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2856
2857         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2858                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2859
2860         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2861                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2862
2863
2864         storage_adaptor_check_param_equal(NULL, plugin->handle->get_meta, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2865                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_meta)"));
2866
2867 #ifdef DEBUG_ADAPTOR_PARAMS
2868         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2869         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
2870                         context->app_id, context->access_token, context->cid, context->uid);
2871         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
2872         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2873         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2874 #endif
2875
2876         plugin_req_enter();
2877         storage_error_code_t ret = plugin->handle->get_meta(context, parent_folder_storage_path,
2878                         file_name, request, file_info, meta_data, error, response);
2879         plugin_req_exit(ret, plugin, error);
2880
2881 #ifdef DEBUG_ADAPTOR_PARAMS
2882         storage_adaptor_debug_func("[out] return code (%d)", ret);
2883         if ((NULL != file_info) && (NULL != (*file_info))) {
2884                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
2885         }
2886         if ((NULL != error) && (NULL != *error)) {
2887                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2888                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2889         }
2890         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2891         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2892 #endif
2893
2894         return ret;
2895 }
2896
2897 /**
2898 * @brief Set up Multi Channel Upload
2899 *
2900 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2901 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2902 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to upload
2903 * @param[in]    file_name                       specifies file name to be uploaded to cloud
2904 * @param[in]    upload_file_local_path          specifies local path of the file to be uploaded
2905 * @param[in]    chunk_size_byte                 specifies size of chunk
2906 * @param[in]    request                         specifies optional parameter
2907 * @param[out]   mupload_key                     specifies Multi Channel Upload key
2908 * @param[out]   chunk_count                     specifies total number of chunks
2909 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2910 * @param[out]   error                           specifies error code
2911 * @param[out]   response                        specifies optional parameter
2912 * @return 0 on success, otherwise a negative error value
2913 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2914 */
2915 storage_error_code_t storage_adaptor_start_mupload(storage_adaptor_plugin_h plugin,
2916                                                 storage_adaptor_plugin_context_h context,
2917                                                 const char *parent_folder_storage_path,
2918                                                 const char *file_name,
2919                                                 const char *upload_file_local_path,
2920                                                 const unsigned long long chunk_size,
2921                                                 void *request,
2922                                                 char **mupload_key,
2923                                                 int *chunk_count,
2924                                                 storage_adaptor_file_info_h *file_info,
2925                                                 storage_adaptor_error_code_h *error,
2926                                                 void *response)
2927 {
2928         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2929                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2930
2931         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2932                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
2933
2934         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
2935                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
2936
2937         storage_adaptor_check_param_equal(NULL, plugin->handle->start_mupload, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
2938                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (start_mupload)"));
2939
2940
2941 #ifdef DEBUG_ADAPTOR_PARAMS
2942         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
2943         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
2944                         context->app_id, context->access_token, context->cid, context->uid);
2945         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
2946         storage_adaptor_debug_func("[in] chunk_size (%llu)", chunk_size);
2947         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
2948 #endif
2949
2950         plugin_req_enter();
2951         storage_error_code_t ret = plugin->handle->start_mupload(context, parent_folder_storage_path,
2952                         file_name, upload_file_local_path, chunk_size, request, mupload_key, chunk_count,
2953                         file_info, error, response);
2954         plugin_req_exit(ret, plugin, error);
2955
2956 #ifdef DEBUG_ADAPTOR_PARAMS
2957         storage_adaptor_debug_func("[out] return code (%d)", ret);
2958         if ((NULL != file_info) && (NULL != (*file_info))) {
2959                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
2960         }
2961         if ((NULL != error) && (NULL != *error)) {
2962                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
2963                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
2964         }
2965         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
2966         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
2967 #endif
2968
2969         return ret;
2970 }
2971
2972 /**
2973 * @brief Uploads a chunk to cloud
2974 *
2975 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
2976 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
2977 * @param[in]    mupload_key                     specifies Multi Channel Upload key
2978 * @param[in]    chunk_number                    specifies number of chunk (Starting at 1)
2979 * @param[in]    request                         specifies optional parameter
2980 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
2981 * @param[out]   error                           specifies error code
2982 * @param[out]   response                        specifies optional parameter
2983 * @return 0 on success, otherwise a negative error value
2984 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
2985 */
2986 storage_error_code_t storage_adaptor_upload_mupload(storage_adaptor_plugin_h plugin,
2987                                                 storage_adaptor_plugin_context_h context,
2988                                                 const char *mupload_key,
2989                                                 const int chunk_number,
2990                                                 void *request,
2991                                                 storage_adaptor_file_info_h *file_info,
2992                                                 storage_adaptor_error_code_h *error,
2993                                                 void *response)
2994 {
2995         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2996                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
2997
2998         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
2999                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3000
3001         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3002                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3003
3004
3005         storage_adaptor_check_param_equal(NULL, plugin->handle->upload_mupload, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3006                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (upload_mupload)"));
3007
3008 #ifdef DEBUG_ADAPTOR_PARAMS
3009         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3010         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3011                         context->app_id, context->access_token, context->cid, context->uid);
3012         storage_adaptor_debug_func("[in] mupload_key (%s)", mupload_key);
3013         storage_adaptor_debug_func("[in] chunk_number (%d)", chunk_number);
3014         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3015 #endif
3016
3017         plugin_req_enter();
3018         storage_error_code_t ret = plugin->handle->upload_mupload(context, mupload_key,
3019                         chunk_number, request, file_info, error, response);
3020         plugin_req_exit(ret, plugin, error);
3021
3022 #ifdef DEBUG_ADAPTOR_PARAMS
3023         storage_adaptor_debug_func("[out] return code (%d)", ret);
3024         if ((NULL != file_info) && (NULL != (*file_info))) {
3025                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
3026         }
3027         if ((NULL != error) && (NULL != *error)) {
3028                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3029                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3030         }
3031         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3032         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3033 #endif
3034
3035         return ret;
3036 }
3037
3038 /**
3039 * @brief Ends Multi channel Upload
3040 *
3041 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3042 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3043 * @param[in]    mupload_key                     specifies Multi Channel Upload key
3044 * @param[in]    publish                         specifies Allow to share file with no authentication
3045 * @param[in]    request                         specifies optional parameter
3046 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
3047 * @param[out]   error                           specifies error code
3048 * @param[out]   response                        specifies optional parameter
3049 * @return 0 on success, otherwise a negative error value
3050 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3051 */
3052 storage_error_code_t storage_adaptor_end_mupload(storage_adaptor_plugin_h plugin,
3053                                                 storage_adaptor_plugin_context_h context,
3054                                                 const char *mupload_key,
3055                                                 const int publish,
3056                                                 void *request,
3057                                                 storage_adaptor_file_info_h *file_info,
3058                                                 storage_adaptor_error_code_h *error,
3059                                                 void *response)
3060 {
3061         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3062                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3063
3064         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3065                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3066
3067         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3068                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3069
3070
3071         storage_adaptor_check_param_equal(NULL, plugin->handle->end_mupload, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3072                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (end_mupoad)"));
3073
3074 #ifdef DEBUG_ADAPTOR_PARAMS
3075         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3076         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3077                         context->app_id, context->access_token, context->cid, context->uid);
3078         storage_adaptor_debug_func("[in] mupload_key (%s)", mupload_key);
3079         storage_adaptor_debug_func("[in] publish (%d)", publish);
3080         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3081 #endif
3082
3083         plugin_req_enter();
3084         storage_error_code_t ret = plugin->handle->end_mupload(context, mupload_key,
3085                         publish, request, file_info, error, response);
3086         plugin_req_exit(ret, plugin, error);
3087
3088 #ifdef DEBUG_ADAPTOR_PARAMS
3089         storage_adaptor_debug_func("[out] return code (%d)", ret);
3090         if ((NULL != file_info) && (NULL != (*file_info))) {
3091                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
3092         }
3093         if ((NULL != error) && (NULL != *error)) {
3094                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3095                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3096         }
3097         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3098         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3099 #endif
3100
3101         return ret;
3102 }
3103
3104 /**
3105 * @brief Requests list of chunks uploaded
3106 *
3107 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3108 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3109 * @param[in]    mupload_key                     specifies Multi Channel Upload key
3110 * @param[in]    request                         specifies optional parameter
3111 * @param[out]   file_info_list                  specifies Storage Adaptor File Info handle
3112 * @param[out]   file_info_list_len              specifies length of the file_info_list
3113 * @param[out]   error                           specifies error code
3114 * @param[out]   response                        specifies optional parameter
3115 * @return 0 on success, otherwise a negative error value
3116 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3117 */
3118 storage_error_code_t storage_adaptor_list_mupload(storage_adaptor_plugin_h plugin,
3119                                                 storage_adaptor_plugin_context_h context,
3120                                                 const char *mupload_key,
3121                                                 void *request,
3122                                                 storage_adaptor_file_info_h **file_info_list,
3123                                                 int *file_info_list_len,
3124                                                 storage_adaptor_error_code_h *error,
3125                                                 void *response)
3126 {
3127         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3128                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3129
3130         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3131                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3132
3133         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3134                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3135
3136
3137         storage_adaptor_check_param_equal(NULL, plugin->handle->list_mupload, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3138                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (list_mupload)"));
3139
3140 #ifdef DEBUG_ADAPTOR_PARAMS
3141         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3142         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3143                         context->app_id, context->access_token, context->cid, context->uid);
3144         storage_adaptor_debug_func("[in] mupload_key (%s)", mupload_key);
3145         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3146 #endif
3147
3148         plugin_req_enter();
3149         storage_error_code_t ret = plugin->handle->list_mupload(context, mupload_key,
3150                         request, file_info_list, file_info_list_len, error, response);
3151         plugin_req_exit(ret, plugin, error);
3152
3153 #ifdef DEBUG_ADAPTOR_PARAMS
3154         storage_adaptor_debug_func("[out] return code (%d)", ret);
3155         if (NULL != file_info_list_len) {
3156                 storage_adaptor_debug_func("[out] file_info_list_len (%d)", *file_info_list_len);
3157         }
3158         if ((NULL != error) && (NULL != *error)) {
3159                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3160                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3161         }
3162         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3163         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3164 #endif
3165
3166         return ret;
3167 }
3168
3169 /**
3170 * @brief Cancels all operations
3171 *
3172 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3173 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3174 * @param[in]    mupload_key                     specifies Multi Channel Upload key
3175 * @param[in]    request                         specifies optional parameter
3176 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
3177 * @param[out]   error                           specifies error code
3178 * @param[out]   response                        specifies optional parameter
3179 * @return 0 on success, otherwise a negative error value
3180 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3181 */
3182 storage_error_code_t storage_adaptor_cancel_mupload(storage_adaptor_plugin_h plugin,
3183                                                 storage_adaptor_plugin_context_h context,
3184                                                 const char *mupload_key,
3185                                                 void *request,
3186                                                 storage_adaptor_file_info_h *file_info,
3187                                                 storage_adaptor_error_code_h *error,
3188                                                 void *response)
3189 {
3190         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3191                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3192
3193         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3194                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3195
3196         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3197                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3198
3199
3200         storage_adaptor_check_param_equal(NULL, plugin->handle->cancel_mupload, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3201                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (cancel_mupload)"));
3202
3203 #ifdef DEBUG_ADAPTOR_PARAMS
3204         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3205         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3206                         context->app_id, context->access_token, context->cid, context->uid);
3207         storage_adaptor_debug_func("[in] mupload_key (%s)", mupload_key);
3208         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3209 #endif
3210
3211         plugin_req_enter();
3212         storage_error_code_t ret = plugin->handle->cancel_mupload(context, mupload_key,
3213                         request, file_info, error, response);
3214         plugin_req_exit(ret, plugin, error);
3215
3216 #ifdef DEBUG_ADAPTOR_PARAMS
3217         storage_adaptor_debug_func("[out] return code (%d)", ret);
3218         if ((NULL != file_info) && (NULL != (*file_info))) {
3219                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
3220         }
3221         if ((NULL != error) && (NULL != *error)) {
3222                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3223                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3224         }
3225         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3226         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3227 #endif
3228
3229         return ret;
3230 }
3231
3232 /**
3233 * @brief Starts Transaction
3234 *
3235 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3236 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3237 * @param[in]    request                         specifies optional parameter
3238 * @param[out]   tx_key                          specifies Transaction key
3239 * @param[out]   error                           specifies error code
3240 * @param[out]   response                        specifies optional parameter
3241 * @return 0 on success, otherwise a negative error value
3242 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3243 */
3244 storage_error_code_t storage_adaptor_start_transaction(storage_adaptor_plugin_h plugin,
3245                                                 storage_adaptor_plugin_context_h context,
3246                                                 void *request,
3247                                                 char **tx_key,
3248                                                 storage_adaptor_error_code_h *error,
3249                                                 void *response)
3250 {
3251         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3252                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3253
3254         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3255                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3256
3257         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3258                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3259
3260
3261         storage_adaptor_check_param_equal(NULL, plugin->handle->start_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3262                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (start_transacion)"));
3263
3264 #ifdef DEBUG_ADAPTOR_PARAMS
3265         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3266         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3267                         context->app_id, context->access_token, context->cid, context->uid);
3268         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3269 #endif
3270
3271         plugin_req_enter();
3272         storage_error_code_t ret = plugin->handle->start_transaction(context, request,
3273                         tx_key, error, response);
3274         plugin_req_exit(ret, plugin, error);
3275
3276 #ifdef DEBUG_ADAPTOR_PARAMS
3277         storage_adaptor_debug_func("[out] return code (%d)", ret);
3278         if (NULL != tx_key) {
3279                 storage_adaptor_debug_func("[out] tx_key (%s)", *tx_key);
3280         }
3281         if ((NULL != error) && (NULL != *error)) {
3282                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3283                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3284         }
3285         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3286         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3287 #endif
3288
3289         return ret;
3290 }
3291
3292 /**
3293 * @brief Uploads a file
3294 *
3295 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3296 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3297 * @param[in]    tx_key                          specifies Transaction key
3298 * @param[in]    tx_seq                          specifies Transaction sequesnce (Starting at 1)
3299 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to upload
3300 * @param[in]    file_name                       specifies file name to be uploaded to cloud
3301 * @param[in]    upload_file_local_path          specifies local path of the file to be uploaded
3302 * @param[in]    request                         specifies optional parameter
3303 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
3304 * @param[out]   error                           specifies error code
3305 * @param[out]   response                        specifies optional parameter
3306 * @return 0 on success, otherwise a negative error value
3307 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3308 */
3309 storage_error_code_t storage_adaptor_upload_file_transaction(storage_adaptor_plugin_h plugin,
3310                                                 storage_adaptor_plugin_context_h context,
3311                                                 const char *tx_key,
3312                                                 const int tx_seq,
3313                                                 const char *parent_folder_storage_path,
3314                                                 const char *file_name,
3315                                                 const char *upload_file_local_path,
3316                                                 void *request,
3317                                                 storage_adaptor_file_info_h *file_info,
3318                                                 storage_adaptor_error_code_h *error,
3319                                                 void *response)
3320 {
3321         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3322                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3323
3324         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3325                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3326
3327         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3328                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3329
3330
3331         storage_adaptor_check_param_equal(NULL, plugin->handle->upload_file_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3332                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (upload_file_transaction)"));
3333
3334 #ifdef DEBUG_ADAPTOR_PARAMS
3335         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3336         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3337                         context->app_id, context->access_token, context->cid, context->uid);
3338         storage_adaptor_debug_func("[in] tx_key (%s)", tx_key);
3339         storage_adaptor_debug_func("[in] tx_seq (%d)", tx_seq);
3340         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
3341         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
3342         storage_adaptor_debug_func("[in] upload_file_local_path (%s)", upload_file_local_path);
3343         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3344 #endif
3345
3346         plugin_req_enter();
3347         storage_error_code_t ret = plugin->handle->upload_file_transaction(context, tx_key,
3348                         tx_seq, parent_folder_storage_path, file_name, upload_file_local_path, request, file_info, error, response);
3349         plugin_req_exit(ret, plugin, error);
3350
3351 #ifdef DEBUG_ADAPTOR_PARAMS
3352         storage_adaptor_debug_func("[out] return code (%d)", ret);
3353         if ((NULL != file_info) && (NULL != (*file_info))) {
3354                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
3355
3356         }
3357         if ((NULL != error) && (NULL != *error)) {
3358                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3359                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3360         }
3361         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3362         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3363 #endif
3364
3365         return ret;
3366 }
3367
3368 /**
3369 * @brief Updates a folder
3370 *
3371 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3372 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3373 * @param[in]    tx_key                          specifies Transaction key
3374 * @param[in]    tx_seq                          specifies Transaction sequesnce (Starting at 1)
3375 * @param[in]    parent_folder_storage_path      specifies folder path of folder you want to update
3376 * @param[in]    folder_name                     specifies folder name to be updated
3377 * @param[in]    request                         specifies optional parameter
3378 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
3379 * @param[out]   error                           specifies error code
3380 * @param[out]   response                        specifies optional parameter
3381 * @return 0 on success, otherwise a negative error value
3382 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3383 */
3384 storage_error_code_t storage_adaptor_set_dir_transaction(storage_adaptor_plugin_h plugin,
3385                                                 storage_adaptor_plugin_context_h context,
3386                                                 const char *tx_key,
3387                                                 const int tx_seq,
3388                                                 const char *parent_folder_storage_path,
3389                                                 const char *folder_name,
3390                                                 void *request,
3391                                                 storage_adaptor_file_info_h *file_info,
3392                                                 storage_adaptor_error_code_h *error,
3393                                                 void *response)
3394 {
3395         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3396                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3397
3398         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3399                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3400
3401         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3402                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3403
3404
3405         storage_adaptor_check_param_equal(NULL, plugin->handle->set_dir_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3406                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (set_dir_transaction)"));
3407
3408 #ifdef DEBUG_ADAPTOR_PARAMS
3409         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3410         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3411                         context->app_id, context->access_token, context->cid, context->uid);
3412         storage_adaptor_debug_func("[in] tx_key (%s)", tx_key);
3413         storage_adaptor_debug_func("[in] tx_seq (%d)", tx_seq);
3414         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
3415         storage_adaptor_debug_func("[in] folder_name (%s)", folder_name);
3416         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3417 #endif
3418
3419         plugin_req_enter();
3420         storage_error_code_t ret = plugin->handle->set_dir_transaction(context, tx_key,
3421                         tx_seq, parent_folder_storage_path, folder_name, request, file_info, error, response);
3422         plugin_req_exit(ret, plugin, error);
3423
3424 #ifdef DEBUG_ADAPTOR_PARAMS
3425         storage_adaptor_debug_func("[out] return code (%d)", ret);
3426         if ((NULL != file_info) && (NULL != (*file_info))) {
3427                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
3428         }
3429         if ((NULL != error) && (NULL != *error)) {
3430                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3431                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3432         }
3433         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3434         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3435 #endif
3436
3437         return ret;
3438 }
3439
3440 /**
3441 * @brief Removes a file
3442 *
3443 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3444 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3445 * @param[in]    tx_key                          specifies Transaction key
3446 * @param[in]    tx_seq                          specifies Transaction sequesnce (Starting at 1)
3447 * @param[in]    parent_folder_storage_path      specifies folder path of file you want to delete
3448 * @param[in]    file_name                       specifies file name to be deleted from cloud
3449 * @param[in]    request                         specifies optional parameter
3450 * @param[in]    upload_file_local_path          specifies local path of the file to be uploaded
3451 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
3452 * @param[out]   error                           specifies error code
3453 * @param[out]   response                        specifies optional parameter
3454 * @return 0 on success, otherwise a negative error value
3455 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3456 */
3457 storage_error_code_t storage_adaptor_delete_file_transaction(storage_adaptor_plugin_h plugin,
3458                                                 storage_adaptor_plugin_context_h context,
3459                                                 const char *tx_key,
3460                                                 const int tx_seq,
3461                                                 const char *parent_folder_storage_path,
3462                                                 const char *file_name,
3463                                                 void *request,
3464                                                 storage_adaptor_file_info_h *file_info,
3465                                                 storage_adaptor_error_code_h *error,
3466                                                 void *response)
3467 {
3468         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3469                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3470
3471         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3472                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3473
3474         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3475                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3476
3477
3478         storage_adaptor_check_param_equal(NULL, plugin->handle->delete_file_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3479                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (delete_file_transaction)"));
3480
3481 #ifdef DEBUG_ADAPTOR_PARAMS
3482         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3483         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3484                         context->app_id, context->access_token, context->cid, context->uid);
3485         storage_adaptor_debug_func("[in] tx_key (%s)", tx_key);
3486         storage_adaptor_debug_func("[in] tx_seq (%d)", tx_seq);
3487         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
3488         storage_adaptor_debug_func("[in] file_name (%s)", file_name);
3489         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3490 #endif
3491
3492         plugin_req_enter();
3493         storage_error_code_t ret = plugin->handle->delete_file_transaction(context, tx_key,
3494                         tx_seq, parent_folder_storage_path, file_name, request, file_info, error, response);
3495         plugin_req_exit(ret, plugin, error);
3496
3497 #ifdef DEBUG_ADAPTOR_PARAMS
3498         storage_adaptor_debug_func("[out] return code (%d)", ret);
3499         if ((NULL != file_info) && (NULL != (*file_info))) {
3500                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
3501         }
3502         if ((NULL != error) && (NULL != *error)) {
3503                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3504                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3505         }
3506         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3507         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3508 #endif
3509
3510         return ret;
3511 }
3512
3513 /**
3514 * @brief Removes a folder
3515 *
3516 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3517 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3518 * @param[in]    tx_key                          specifies Transaction key
3519 * @param[in]    tx_seq                          specifies Transaction sequesnce (Starting at 1)
3520 * @param[in]    parent_folder_storage_path      specifies folder path of folder you want to delete
3521 * @param[in]    folder_name                     specifies folder name to be deleted
3522 * @param[in]    request                         specifies optional parameter
3523 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
3524 * @param[out]   error                           specifies error code
3525 * @param[out]   response                        specifies optional parameter
3526 * @return 0 on success, otherwise a negative error value
3527 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3528 */
3529 storage_error_code_t storage_adaptor_delete_dir_transaction(storage_adaptor_plugin_h plugin,
3530                                                 storage_adaptor_plugin_context_h context,
3531                                                 const char *tx_key,
3532                                                 const int tx_seq,
3533                                                 const char *parent_folder_storage_path,
3534                                                 const char *folder_name,
3535                                                 void *request,
3536                                                 storage_adaptor_file_info_h *file_info,
3537                                                 storage_adaptor_error_code_h *error,
3538                                                 void *response)
3539 {
3540         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3541                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3542
3543         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3544                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3545
3546         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3547                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3548
3549
3550         storage_adaptor_check_param_equal(NULL, plugin->handle->delete_dir_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3551                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (delete_dir_transaction)"));
3552
3553 #ifdef DEBUG_ADAPTOR_PARAMS
3554         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3555         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3556                         context->app_id, context->access_token, context->cid, context->uid);
3557         storage_adaptor_debug_func("[in] tx_key (%s)", tx_key);
3558         storage_adaptor_debug_func("[in] tx_seq (%d)", tx_seq);
3559         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
3560         storage_adaptor_debug_func("[in] folder_name (%s)", folder_name);
3561         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3562 #endif
3563
3564         plugin_req_enter();
3565         storage_error_code_t ret = plugin->handle->delete_dir_transaction(context, tx_key,
3566                         tx_seq, parent_folder_storage_path, folder_name, request, file_info, error, response);
3567         plugin_req_exit(ret, plugin, error);
3568
3569 #ifdef DEBUG_ADAPTOR_PARAMS
3570         storage_adaptor_debug_func("[out] return code (%d)", ret);
3571         if ((NULL != file_info) && (NULL != (*file_info))) {
3572                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
3573         }
3574         if ((NULL != error) && (NULL != *error)) {
3575                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3576                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3577         }
3578         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3579         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3580 #endif
3581
3582         return ret;
3583 }
3584
3585 /**
3586 * @brief Ends Transaction
3587 *
3588 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3589 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3590 * @param[in]    tx_key                          specifies Transaction key
3591 * @param[in]    tx_count                        specifies Transaction order count
3592 * @param[in]    request                         specifies optional parameter
3593 * @param[out]   file_info_list                  specifies Storage Adaptor File Info handle
3594 * @param[out]   file_info_list_len              specifies length of the file_info_list
3595 * @param[out]   error                           specifies error code
3596 * @param[out]   response                        specifies optional parameter
3597 * @return 0 on success, otherwise a negative error value
3598 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3599 */
3600 storage_error_code_t storage_adaptor_end_transaction(storage_adaptor_plugin_h plugin,
3601                                                 storage_adaptor_plugin_context_h context,
3602                                                 const char *tx_key,
3603                                                 const int tx_count,
3604                                                 void *request,
3605                                                 storage_adaptor_file_info_h **file_info_list,
3606                                                 int *file_info_list_len,
3607                                                 storage_adaptor_error_code_h *error,
3608                                                 void *response)
3609 {
3610         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3611                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3612
3613         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3614                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3615
3616         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3617                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3618
3619
3620         storage_adaptor_check_param_equal(NULL, plugin->handle->end_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3621                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (end_transaction)"));
3622
3623 #ifdef DEBUG_ADAPTOR_PARAMS
3624         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3625         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3626                         context->app_id, context->access_token, context->cid, context->uid);
3627         storage_adaptor_debug_func("[in] tx_key (%s)", tx_key);
3628         storage_adaptor_debug_func("[in] tx_count (%d)", tx_count);
3629         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3630 #endif
3631
3632         plugin_req_enter();
3633         storage_error_code_t ret = plugin->handle->end_transaction(context, tx_key,
3634                         tx_count, request, file_info_list, file_info_list_len, error, response);
3635         plugin_req_exit(ret, plugin, error);
3636
3637 #ifdef DEBUG_ADAPTOR_PARAMS
3638         storage_adaptor_debug_func("[out] return code (%d)", ret);
3639         if (NULL != file_info_list_len) {
3640                 storage_adaptor_debug_func("[out] file_info_list_len (%d)", *file_info_list_len);
3641         }
3642         if ((NULL != error) && (NULL != *error)) {
3643                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3644                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3645         }
3646         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3647         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3648 #endif
3649
3650         return ret;
3651 }
3652
3653 /**
3654 * @brief Requests Transaction list
3655 *
3656 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3657 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3658 * @param[in]    tx_key                          specifies Transaction key
3659 * @param[in]    request                         specifies optional parameter
3660 * @param[out]   file_info_list                  specifies Storage Adaptor File Info handle
3661 * @param[out]   file_info_list_len              specifies length of the file_info_list
3662 * @param[out]   error                           specifies error code
3663 * @param[out]   response                        specifies optional parameter
3664 * @return 0 on success, otherwise a negative error value
3665 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3666 */
3667 storage_error_code_t storage_adaptor_list_transaction(storage_adaptor_plugin_h plugin,
3668                                                 storage_adaptor_plugin_context_h context,
3669                                                 const char *tx_key,
3670                                                 void *request,
3671                                                 storage_adaptor_file_info_h **file_info_list,
3672                                                 int *file_info_list_len,
3673                                                 storage_adaptor_error_code_h *error,
3674                                                 void *response)
3675 {
3676         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3677                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3678
3679         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3680                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3681
3682         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3683                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3684
3685
3686         storage_adaptor_check_param_equal(NULL, plugin->handle->list_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3687                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (list_transaction)"));
3688
3689 #ifdef DEBUG_ADAPTOR_PARAMS
3690         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3691         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3692                         context->app_id, context->access_token, context->cid, context->uid);
3693         storage_adaptor_debug_func("[in] tx_key (%s)", tx_key);
3694         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3695 #endif
3696
3697         plugin_req_enter();
3698         storage_error_code_t ret = plugin->handle->list_transaction(context, tx_key,
3699                         request, file_info_list, file_info_list_len, error, response);
3700         plugin_req_exit(ret, plugin, error);
3701
3702 #ifdef DEBUG_ADAPTOR_PARAMS
3703         storage_adaptor_debug_func("[out] return code (%d)", ret);
3704         if (NULL != file_info_list_len) {
3705                 storage_adaptor_debug_func("[out] file_info_list_len (%d)", *file_info_list_len);
3706         }
3707         if ((NULL != error) && (NULL != *error)) {
3708                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3709                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3710         }
3711         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3712         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3713 #endif
3714
3715         return ret;
3716 }
3717
3718 /**
3719 * @brief Cancels all transactions
3720 *
3721 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3722 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3723 * @param[in]    tx_key                          specifies Transaction key
3724 * @param[in]    request                         specifies optional parameter
3725 * @param[out]   file_info_list                  specifies Storage Adaptor File Info handle
3726 * @param[out]   file_info_list_len              specifies length of the file_info_list
3727 * @param[out]   error                           specifies error code
3728 * @param[out]   response                        specifies optional parameter
3729 * @return 0 on success, otherwise a negative error value
3730 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3731 */
3732 storage_error_code_t storage_adaptor_cancel_transaction(storage_adaptor_plugin_h plugin,
3733                                                 storage_adaptor_plugin_context_h context,
3734                                                 const char *tx_key,
3735                                                 void *request,
3736                                                 storage_adaptor_file_info_h **file_info_list,
3737                                                 int *file_info_list_len,
3738                                                 storage_adaptor_error_code_h *error,
3739                                                 void *response)
3740 {
3741         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3742                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3743
3744         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3745                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3746
3747         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3748                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3749
3750
3751         storage_adaptor_check_param_equal(NULL, plugin->handle->cancel_transaction, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3752                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (cancel_transaction)"));
3753
3754 #ifdef DEBUG_ADAPTOR_PARAMS
3755         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3756         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3757                         context->app_id, context->access_token, context->cid, context->uid);
3758         storage_adaptor_debug_func("[in] tx_key (%s)", tx_key);
3759         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3760 #endif
3761
3762         plugin_req_enter();
3763         storage_error_code_t ret = plugin->handle->cancel_transaction(context, tx_key,
3764                         request, file_info_list, file_info_list_len, error, response);
3765         plugin_req_exit(ret, plugin, error);
3766
3767 #ifdef DEBUG_ADAPTOR_PARAMS
3768         storage_adaptor_debug_func("[out] return code (%d)", ret);
3769         if (NULL != file_info_list_len) {
3770                 storage_adaptor_debug_func("[out] file_info_list_len (%d)", *file_info_list_len);
3771         }
3772         if ((NULL != error) && (NULL != *error)) {
3773                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3774                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3775         }
3776         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3777         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3778 #endif
3779
3780         return ret;
3781 }
3782
3783 /**
3784 * @brief Uploads multiple files to cloud
3785 *
3786 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3787 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3788 * @param[in]    parent_folder_storage_path      specifies folder path of files you want to upload
3789 * @param[in]    upload_file_local_path_list     specifies local path list of the files to be uploaded
3790 * @param[in]    upload_list_len                 specifies total number of files to be uploaded
3791 * @param[in]    request                         specifies optional parameter
3792 * @param[out]   error                           specifies error code
3793 * @param[out]   response                        specifies optional parameter
3794 * @return 0 on success, otherwise a positive error value
3795 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3796 */
3797 storage_error_code_t storage_adaptor_multi_file_upload(storage_adaptor_plugin_h plugin,
3798                                                 storage_adaptor_plugin_context_h context,
3799                                                 const char *parent_folder_storage_path,
3800                                                 const char **upload_file_local_path_list,
3801                                                 const int upload_list_len,
3802                                                 void *request,
3803                                                 storage_adaptor_error_code_h *error,
3804                                                 void *response)
3805 {
3806         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3807                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3808
3809         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3810                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3811
3812         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3813                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3814
3815
3816         storage_adaptor_check_param_equal(NULL, plugin->handle->multi_file_upload, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3817                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (multi_file_upload)"));
3818
3819 #ifdef DEBUG_ADAPTOR_PARAMS
3820         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3821         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3822                         context->app_id, context->access_token, context->cid, context->uid);
3823         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
3824         storage_adaptor_debug_func("[in] upload_list_len (%d)", upload_list_len);
3825         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3826 #endif
3827
3828         plugin_req_enter();
3829         storage_error_code_t ret = plugin->handle->multi_file_upload(context, parent_folder_storage_path,
3830                         upload_file_local_path_list, upload_list_len, request, error, response);
3831         plugin_req_exit(ret, plugin, error);
3832
3833 #ifdef DEBUG_ADAPTOR_PARAMS
3834         storage_adaptor_debug_func("[out] return code (%d)", ret);
3835         if ((NULL != error) && (NULL != *error)) {
3836                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3837                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3838         }
3839         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3840         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3841 #endif
3842
3843         return ret;
3844 }
3845
3846 /**
3847 * @brief Downloads multiple files in a folder
3848 *
3849 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3850 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3851 * @param[in]    parent_folder_storage_path      specifies folder path of files you want to download
3852 * @param[in]    file_name_list                  specifies file name list to be downloaded
3853 * @param[in]    file_name_list_len              specifies total number of files to be downloaded
3854 * @param[in]    download_folder_local_path      specifies local folder path to download files
3855 * @param[in]    request                         specifies optional parameter
3856 * @param[out]   file_info_list                  specifies Storage Adaptor File Info handle
3857 * @param[out]   file_info_list_len              specifies length of the file_info_list
3858 * @param[out]   error                           specifies error code
3859 * @param[out]   response                        specifies optional parameter
3860 * @return 0 on success, otherwise a positive error value
3861 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3862 */
3863 storage_error_code_t storage_adaptor_multi_file_download(storage_adaptor_plugin_h plugin,
3864                                                 storage_adaptor_plugin_context_h context,
3865                                                 const char *parent_folder_storage_path,
3866                                                 const char *file_name_list,
3867                                                 const int file_name_list_len,
3868                                                 const char *download_folder_local_path,
3869                                                 void *request,
3870                                                 storage_adaptor_file_info_h **file_info_list,
3871                                                 int *file_info_list_len,
3872                                                 storage_adaptor_error_code_h *error,
3873                                                 void *response)
3874 {
3875         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3876                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3877
3878         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3879                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3880
3881         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3882                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3883
3884
3885         storage_adaptor_check_param_equal(NULL, plugin->handle->multi_file_download, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3886                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (multi_file_download)"));
3887
3888 #ifdef DEBUG_ADAPTOR_PARAMS
3889         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3890         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3891                         context->app_id, context->access_token, context->cid, context->uid);
3892         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
3893         storage_adaptor_debug_func("[in] download_list_len (%d)", file_name_list_len);
3894         storage_adaptor_debug_func("[in] download_folder_local_path (%s)", download_folder_local_path);
3895         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3896 #endif
3897
3898         plugin_req_enter();
3899         storage_error_code_t ret = plugin->handle->multi_file_download(context, parent_folder_storage_path,
3900                         file_name_list, file_name_list_len, download_folder_local_path, request, file_info_list,
3901                         file_info_list_len, error, response);
3902         plugin_req_exit(ret, plugin, error);
3903
3904 #ifdef DEBUG_ADAPTOR_PARAMS
3905         storage_adaptor_debug_func("[out] return code (%d)", ret);
3906         if (NULL != file_info_list_len) {
3907                 storage_adaptor_debug_func("[out] file_info_list_len (%d)", *file_info_list_len);
3908         }
3909         if ((NULL != error) && (NULL != *error)) {
3910                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3911                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3912         }
3913         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3914         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3915 #endif
3916
3917         return ret;
3918 }
3919
3920 /**
3921 * @brief Requests current server timestamp
3922 *
3923 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3924 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3925 * @param[in]    request                         specifies optional parameter
3926 * @param[out]   timestamp                       specifies server timestamp
3927 * @param[out]   error                           specifies error code
3928 * @param[out]   response                        specifies optional parameter
3929 * @return 0 on success, otherwise a positive error value
3930 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3931 */
3932 storage_error_code_t storage_adaptor_get_timestamp(storage_adaptor_plugin_h plugin,
3933                                                 storage_adaptor_plugin_context_h context,
3934                                                 void *request,
3935                                                 unsigned long long *timestamp,
3936                                                 storage_adaptor_error_code_h *error,
3937                                                 void *response)
3938 {
3939         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3940                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
3941
3942         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
3943                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
3944
3945         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
3946                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
3947
3948
3949         storage_adaptor_check_param_equal(NULL, plugin->handle->get_timestamp, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
3950                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_timestamp)"));
3951
3952 #ifdef DEBUG_ADAPTOR_PARAMS
3953         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
3954         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
3955                         context->app_id, context->access_token, context->cid, context->uid);
3956         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
3957 #endif
3958
3959         plugin_req_enter();
3960         storage_error_code_t ret = plugin->handle->get_timestamp(context, request,
3961                         timestamp, error, response);
3962         plugin_req_exit(ret, plugin, error);
3963
3964 #ifdef DEBUG_ADAPTOR_PARAMS
3965         storage_adaptor_debug_func("[out] return code (%d)", ret);
3966         if (NULL != timestamp) {
3967                 storage_adaptor_debug_func("[out] timestamp (%llu)", *timestamp);
3968         }
3969         if ((NULL != error) && (NULL != *error)) {
3970                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
3971                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
3972         }
3973         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
3974         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
3975 #endif
3976
3977         return ret;
3978 }
3979
3980 /**
3981 * @brief Requests a file info by public token
3982 *
3983 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
3984 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
3985 * @param[in]    public_token                    specifies token for Download, Get API
3986                                                 (when terminal upload file and add publish=true parameter, or
3987 * @param[in]    auth_code                       specifies Authentication code for public APIs
3988 * @param[in]    request                         specifies optional parameter
3989 * @param[out]   file_info                       specifies Storage Adaptor File Info handle
3990 * @param[out]   error                           specifies error code
3991 * @param[out]   response                        specifies optional parameter
3992 * @return 0 on success, otherwise a positive error value
3993 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
3994 */
3995 storage_error_code_t storage_adaptor_get_file_info_by_public_token(storage_adaptor_plugin_h plugin,
3996                                                 storage_adaptor_plugin_context_h context,
3997                                                 const char *public_token,
3998                                                 const char *auth_code,
3999                                                 void *request,
4000                                                 storage_adaptor_file_info_h *file_info,
4001                                                 storage_adaptor_error_code_h *error,
4002                                                 void *response)
4003 {
4004         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4005                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4006
4007         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4008                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4009
4010         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4011                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4012
4013
4014         storage_adaptor_check_param_equal(NULL, plugin->handle->get_file_info_by_public_token, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4015                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_file_info_by_public_token)"));
4016
4017 #ifdef DEBUG_ADAPTOR_PARAMS
4018         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4019         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4020                         context->app_id, context->access_token, context->cid, context->uid);
4021         storage_adaptor_debug_func("[in] public_token (%s)", public_token);
4022         storage_adaptor_debug_func("[in] auth_code (%s)", auth_code);
4023         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4024 #endif
4025
4026         plugin_req_enter();
4027         storage_error_code_t ret = plugin->handle->get_file_info_by_public_token(context, public_token,
4028                         auth_code, request, file_info, error, response);
4029         plugin_req_exit(ret, plugin, error);
4030
4031 #ifdef DEBUG_ADAPTOR_PARAMS
4032         storage_adaptor_debug_func("[out] return code (%d)", ret);
4033         if ((NULL != file_info) && (NULL != (*file_info))) {
4034                 storage_adaptor_debug_func("[out] file_info->storage_path (%s)", (*file_info)->storage_path);
4035         }
4036         if ((NULL != error) && (NULL != *error)) {
4037                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4038                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4039         }
4040         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4041         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4042 #endif
4043
4044         return ret;
4045 }
4046
4047 /**
4048 * @brief Downloads a file by public token (Sync)
4049 *
4050 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4051 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4052 * @param[in]    public_token                    specifies token for Download, Get API
4053                                                 (when terminal upload file and add publish=true parameter, or
4054 * @param[in]    auth_code                       specifies Authentication code for public APIs
4055 * @param[in]    download_file_local_path        specifies local path to download
4056 * @param[in]    request                         specifies optional parameter
4057 * @param[out]   error                           specifies error code
4058 * @param[out]   response                        specifies optional parameter
4059 * @return 0 on success, otherwise a positive error value
4060 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4061 */
4062 storage_error_code_t storage_adaptor_download_file_sync_by_public_token(storage_adaptor_plugin_h plugin,
4063                                                 storage_adaptor_plugin_context_h context,
4064                                                 const char *public_token,
4065                                                 const char *auth_code,
4066                                                 const char *download_file_local_path,
4067                                                 void *request,
4068                                                 storage_adaptor_error_code_h *error,
4069                                                 void *response)
4070 {
4071         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4072                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4073
4074         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4075                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4076
4077         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4078                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4079
4080
4081         storage_adaptor_check_param_equal(NULL, plugin->handle->download_file_sync_by_public_token, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4082                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (download_file_sync_by_public_token)"));
4083
4084 #ifdef DEBUG_ADAPTOR_PARAMS
4085         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4086         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4087                         context->app_id, context->access_token, context->cid, context->uid);
4088         storage_adaptor_debug_func("[in] public_token (%s)", public_token);
4089         storage_adaptor_debug_func("[in] auth_code (%s)", auth_code);
4090         storage_adaptor_debug_func("[in] download_file_local_path (%s)", download_file_local_path);
4091         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4092 #endif
4093
4094         plugin_req_enter();
4095         storage_error_code_t ret = plugin->handle->download_file_sync_by_public_token(context, public_token,
4096                         auth_code, download_file_local_path, request, error, response);
4097         plugin_req_exit(ret, plugin, error);
4098
4099 #ifdef DEBUG_ADAPTOR_PARAMS
4100         storage_adaptor_debug_func("[out] return code (%d)", ret);
4101         if ((NULL != error) && (NULL != *error)) {
4102                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4103                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4104         }
4105         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4106         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4107 #endif
4108
4109         return ret;
4110 }
4111
4112 /**
4113 * @brief Downloads a file by public token (Async)
4114 *
4115 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4116 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4117 * @param[in]    public_token                    specifies token for Download, Get API
4118                                                 (when terminal upload file and add publish=true parameter, or
4119 * @param[in]    auth_code                       specifies Authentication code for public APIs
4120 * @param[in]    download_file_local_path        specifies local path to download
4121 * @param[in]    request                         specifies optional parameter
4122 * @param[out]   transfer_request_id             specifies
4123 * @param[out]   error                           specifies error code
4124 * @return 0 on success, otherwise a positive error value
4125 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4126 */
4127 storage_error_code_t storage_adaptor_download_file_async_by_public_token(storage_adaptor_plugin_h plugin,
4128                                                 storage_adaptor_plugin_context_h context,
4129                                                 const char *public_token,
4130                                                 const char *auth_code,
4131                                                 const char *download_file_local_path,
4132                                                 void *request,
4133                                                 void *transfer_request_id,
4134                                                 storage_adaptor_error_code_h *error)
4135 {
4136         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4137                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4138
4139         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4140                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4141
4142         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4143                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4144
4145
4146         storage_adaptor_check_param_equal(NULL, plugin->handle->download_file_async_by_public_token, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4147                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (download_file_async_by_public_token)"));
4148
4149 #ifdef DEBUG_ADAPTOR_PARAMS
4150         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4151         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4152                         context->app_id, context->access_token, context->cid, context->uid);
4153         storage_adaptor_debug_func("[in] public_token (%s)", public_token);
4154         storage_adaptor_debug_func("[in] auth_code (%s)", auth_code);
4155         storage_adaptor_debug_func("[in] download_file_local_path (%s)", download_file_local_path);
4156         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4157 #endif
4158
4159         plugin_req_enter();
4160         storage_error_code_t ret = plugin->handle->download_file_async_by_public_token(context, public_token,
4161                         auth_code, download_file_local_path, request, transfer_request_id);
4162         plugin_req_exit(ret, plugin, error);
4163
4164 #ifdef DEBUG_ADAPTOR_PARAMS
4165         storage_adaptor_debug_func("[out] return code (%d)", ret);
4166         storage_adaptor_debug_func("[out] request_id [addr(%p)]", transfer_request_id);
4167         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4168 #endif
4169
4170         return ret;
4171 }
4172
4173 /**
4174 * @brief Authenticates public auth code
4175 *
4176 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4177 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4178 * @param[in]    public_token                    specifies token for Download, Get API
4179                                                 (when terminal upload file and add publish=true parameter, or
4180 * @param[in]    auth_code                       specifies Authentication code for public APIs
4181 * @param[in]    request                         specifies optional parameter
4182 * @param[out]   error                           specifies error code
4183 * @param[out]   response                        specifies optional parameter
4184 * @return 0 on success, otherwise a positive error value
4185 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4186 */
4187 storage_error_code_t storage_adaptor_auth_public_authcode_by_public_token(storage_adaptor_plugin_h plugin,
4188                                                 storage_adaptor_plugin_context_h context,
4189                                                 const char *public_token,
4190                                                 const char *auth_code,
4191                                                 void *request,
4192                                                 storage_adaptor_error_code_h *error,
4193                                                 void *response)
4194 {
4195         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4196                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4197
4198         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4199                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4200
4201         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4202                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4203
4204
4205         storage_adaptor_check_param_equal(NULL, plugin->handle->auth_public_authcode_by_public_token, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4206                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (auth_public_authcode_by_public_token)"));
4207
4208 #ifdef DEBUG_ADAPTOR_PARAMS
4209         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4210         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4211                         context->app_id, context->access_token, context->cid, context->uid);
4212         storage_adaptor_debug_func("[in] public_token (%s)", public_token);
4213         storage_adaptor_debug_func("[in] auth_code (%s)", auth_code);
4214         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4215 #endif
4216
4217         plugin_req_enter();
4218         storage_error_code_t ret = plugin->handle->auth_public_authcode_by_public_token(context, public_token,
4219                         auth_code, request, error, response);
4220         plugin_req_exit(ret, plugin, error);
4221
4222 #ifdef DEBUG_ADAPTOR_PARAMS
4223         storage_adaptor_debug_func("[out] return code (%d)", ret);
4224         if ((NULL != error) && (NULL != *error)) {
4225                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4226                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4227         }
4228         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4229         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4230 #endif
4231
4232         return ret;
4233 }
4234
4235 /**
4236 * @brief Removes multiple files in a folder
4237 *
4238 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4239 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4240 * @param[in]    parent_folder_storage_path      specifies folder path of files you want to delete
4241 * @param[in]    file_name_list                  specifies file name list to be deleted
4242 * @param[in]    file_name_list_len              specifies total number of files to be deleted
4243 * @param[in]    request                         specifies optional parameter
4244 * @param[out]   file_info_list                  specifies Storage Adaptor File Info handle
4245 * @param[out]   file_info_list_len              specifies length of the file_info_list
4246 * @param[out]   error                           specifies error code
4247 * @param[out]   response                        specifies optional parameter
4248 * @return 0 on success, otherwise a positive error value
4249 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4250 */
4251 storage_error_code_t storage_adaptor_delete_multi_file_in_folder(storage_adaptor_plugin_h plugin,
4252                                                 storage_adaptor_plugin_context_h context,
4253                                                 const char *parent_folder_storage_path,
4254                                                 const char **file_name_list,
4255                                                 const int file_name_list_len,
4256                                                 void *request,
4257                                                 storage_adaptor_file_info_h **file_info_list,
4258                                                 int *file_info_list_len,
4259                                                 storage_adaptor_error_code_h *error,
4260                                                 void *response)
4261 {
4262         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4263                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4264
4265         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4266                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4267
4268         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4269                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4270
4271
4272         storage_adaptor_check_param_equal(NULL, plugin->handle->delete_multi_file_in_folder, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4273                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (delete_multi_file_in_folder)"));
4274
4275 #ifdef DEBUG_ADAPTOR_PARAMS
4276         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4277         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4278                         context->app_id, context->access_token, context->cid, context->uid);
4279         storage_adaptor_debug_func("[in] parent_folder_storage_path (%s)", parent_folder_storage_path);
4280         storage_adaptor_debug_func("[in] file_name_list_len (%d)", file_name_list_len);
4281         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4282 #endif
4283
4284         plugin_req_enter();
4285         storage_error_code_t ret = plugin->handle->delete_multi_file_in_folder(context, parent_folder_storage_path,
4286                         file_name_list, file_name_list_len, request, file_info_list, file_info_list_len, error, response);
4287         plugin_req_exit(ret, plugin, error);
4288
4289 #ifdef DEBUG_ADAPTOR_PARAMS
4290         storage_adaptor_debug_func("[out] return code (%d)", ret);
4291         if (NULL != file_info_list_len) {
4292                 storage_adaptor_debug_func("[out] file_info_list_len (%d)", *file_info_list_len);
4293         }
4294         if ((NULL != error) && (NULL != *error)) {
4295                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4296                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4297         }
4298         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4299         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4300 #endif
4301
4302         return ret;
4303 }
4304
4305 /**
4306 * @brief Requests policy for upload
4307 *
4308 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4309 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4310 * @param[in]    request                         specifies optional parameter
4311 * @param[out]   allowed_extension               specifies
4312 * @param[out]   allowed_extension_len           specifies length of allowed_extension
4313 * @param[out]   error                           specifies error code
4314 * @param[out]   response                        specifies optional parameter
4315 * @return 0 on success, otherwise a positive error value
4316 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4317 */
4318 storage_error_code_t storage_adaptor_get_policy(storage_adaptor_plugin_h plugin,
4319                                                 storage_adaptor_plugin_context_h context,
4320                                                 void *request,
4321                                                 char ***allowed_extension,
4322                                                 int *allowed_extension_len,
4323                                                 storage_adaptor_error_code_h *error,
4324                                                 void *response)
4325 {
4326         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4327                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4328
4329         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4330                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4331
4332         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4333                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4334
4335
4336         storage_adaptor_check_param_equal(NULL, plugin->handle->get_policy, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4337                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_policy)"));
4338
4339 #ifdef DEBUG_ADAPTOR_PARAMS
4340         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4341         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4342                         context->app_id, context->access_token, context->cid, context->uid);
4343         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4344 #endif
4345
4346         plugin_req_enter();
4347         storage_error_code_t ret = plugin->handle->get_policy(context, request,
4348                         allowed_extension, allowed_extension_len, error, response);
4349         plugin_req_exit(ret, plugin, error);
4350
4351 #ifdef DEBUG_ADAPTOR_PARAMS
4352         storage_adaptor_debug_func("[out] return code (%d)", ret);
4353         if (NULL != allowed_extension_len) {
4354                 storage_adaptor_debug_func("[out] allowed_extension_len (%d)", *allowed_extension_len);
4355         }
4356         if ((NULL != error) && (NULL != *error)) {
4357                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4358                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4359         }
4360         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4361         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4362 #endif
4363
4364         return ret;
4365 }
4366
4367 /**
4368 * @brief Requests quota of user
4369 *
4370 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4371 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4372 * @param[in]    request                         specifies optional parameter
4373 * @param[out]   total_usage                     specifies total usage of user
4374 * @param[out]   total_quota                     specifies total quota of user
4375 * @param[out]   error                           specifies error code
4376 * @param[out]   response                        specifies optional parameter
4377 * @return 0 on success, otherwise a positive error value
4378 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4379 */
4380 storage_error_code_t storage_adaptor_get_quota(storage_adaptor_plugin_h plugin,
4381                                                 storage_adaptor_plugin_context_h context,
4382                                                 void *request,
4383                                                 unsigned long long *total_usage,
4384                                                 unsigned long long *total_quota,
4385                                                 storage_adaptor_error_code_h *error,
4386                                                 void *response)
4387 {
4388         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4389                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4390
4391         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4392                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4393
4394         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4395                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4396
4397
4398         storage_adaptor_check_param_equal(NULL, plugin->handle->get_quota, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4399                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_quota)"));
4400
4401 #ifdef DEBUG_ADAPTOR_PARAMS
4402         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4403         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4404                         context->app_id, context->access_token, context->cid, context->uid);
4405         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4406 #endif
4407
4408         plugin_req_enter();
4409         storage_error_code_t ret = plugin->handle->get_quota(context, request,
4410                         total_usage, total_quota, error, response);
4411         plugin_req_exit(ret, plugin, error);
4412
4413 #ifdef DEBUG_ADAPTOR_PARAMS
4414         storage_adaptor_debug_func("[out] return code (%d)", ret);
4415         if (NULL != total_usage) {
4416                 storage_adaptor_debug_func("[out] total_usage (%llu)", *total_usage);
4417         }
4418         if (NULL != total_quota) {
4419                 storage_adaptor_debug_func("[out] total_quota (%llu)", *total_quota);
4420         }
4421         if ((NULL != error) && (NULL != *error)) {
4422                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4423                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4424         }
4425         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4426         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4427 #endif
4428
4429         return ret;
4430 }
4431
4432 /**
4433 * @brief Requests Redirect URL mapped with public token (Not yet supported)
4434 *
4435 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4436 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4437 * @param[in]    public_token                    specifies token for Download, Get API
4438                                                 (when terminal upload file and add publish=true parameter, or
4439 * @param[in]    request                         specifies optional parameter
4440 * @param[out]   error                           specifies error code
4441 * @param[out]   response                        specifies optional parameter
4442 * @return 0 on success, otherwise a positive error value
4443 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4444 */
4445 storage_error_code_t storage_adaptor_redirect_url_by_public_token(storage_adaptor_plugin_h plugin,
4446                                                 storage_adaptor_plugin_context_h context,
4447                                                 const char *public_token,
4448                                                 void *request,
4449                                                 storage_adaptor_error_code_h *error,
4450                                                 void *response)
4451 {
4452         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4453                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4454
4455         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4456                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4457
4458         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4459                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4460
4461
4462         storage_adaptor_check_param_equal(NULL, plugin->handle->redirect_url_by_public_token, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4463                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (redirect_url_by_public_token)"));
4464
4465 #ifdef DEBUG_ADAPTOR_PARAMS
4466         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4467         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4468                         context->app_id, context->access_token, context->cid, context->uid);
4469         storage_adaptor_debug_func("[in] public_token (%s)", public_token);
4470         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4471 #endif
4472
4473         plugin_req_enter();
4474         storage_error_code_t ret = plugin->handle->redirect_url_by_public_token(context, public_token,
4475                         request, error, response);
4476         plugin_req_exit(ret, plugin, error);
4477
4478 #ifdef DEBUG_ADAPTOR_PARAMS
4479         storage_adaptor_debug_func("[out] return code (%d)", ret);
4480         if ((NULL != error) && (NULL != *error)) {
4481                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4482                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4483         }
4484         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4485         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4486 #endif
4487
4488         return ret;
4489 }
4490
4491 /**
4492 * @brief Creates Upload URL (Not yet supported)
4493 *
4494 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4495 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4496 * @param[in]    parent_folder_storage_path      specifies folder path of files you want to upload
4497 * @param[in]    file_name                       specifies file name to be uploaded
4498 * @param[in]    x_upload_content_length         specifies length of content
4499 * @param[in]    request                         specifies optional parameter
4500 * @param[out]   error                           specifies error code
4501 * @param[out]   response                        specifies optional parameter
4502 * @return 0 on success, otherwise a positive error value
4503 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4504 */
4505 storage_error_code_t storage_adaptor_create_resuming_upload_url(storage_adaptor_plugin_h plugin,
4506                                                 storage_adaptor_plugin_context_h context,
4507                                                 const char *parent_folder_storage_path,
4508                                                 const char *file_name,
4509                                                 const unsigned long long x_upload_content_length,
4510                                                 void *request,
4511                                                 storage_adaptor_error_code_h *error,
4512                                                 void *response)
4513 {
4514         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4515                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4516
4517         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4518                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4519
4520         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4521                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4522
4523
4524         storage_adaptor_check_param_equal(NULL, plugin->handle->create_resuming_upload_url, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4525                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (create_resuming_upload_url)"));
4526
4527 #ifdef DEBUG_ADAPTOR_PARAMS
4528         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4529         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4530                         context->app_id, context->access_token, context->cid, context->uid);
4531         storage_adaptor_debug_func("[in] parent_folder_storage_path(%s)", parent_folder_storage_path);
4532         storage_adaptor_debug_func("[in] file_name(%s)", file_name);
4533         storage_adaptor_debug_func("[in] x_upload_content_length(%llu)", x_upload_content_length);
4534         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4535 #endif
4536
4537         plugin_req_enter();
4538         storage_error_code_t ret = plugin->handle->create_resuming_upload_url(context, parent_folder_storage_path,
4539                         file_name, x_upload_content_length, request, error, response);
4540         plugin_req_exit(ret, plugin, error);
4541
4542 #ifdef DEBUG_ADAPTOR_PARAMS
4543         storage_adaptor_debug_func("[out] return code (%d)", ret);
4544         if ((NULL != error) && (NULL != *error)) {
4545                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4546                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4547         }
4548         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4549         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4550 #endif
4551
4552         return ret;
4553 }
4554
4555 /**
4556 * @brief Creates chunk Upload URL (Not yet supported)
4557 *
4558 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4559 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4560 * @param[in]    mupload_key                     specifies Multi Channel Upload key
4561 * @param[in]    chunk_number                    specifies number of chunk (Starting at 1)
4562 * @param[in]    x_upload_content_length         specifies length of content
4563 * @param[in]    request                         specifies optional parameter
4564 * @param[out]   rupload_key                     specifies Resuming Upload key
4565 * @param[out]   error                           specifies error code
4566 * @param[out]   response                        specifies optional parameter
4567 * @return 0 on success, otherwise a positive error value
4568 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4569 */
4570 storage_error_code_t storage_adaptor_create_resuming_chunk_upload_url(storage_adaptor_plugin_h plugin,
4571                                                 storage_adaptor_plugin_context_h context,
4572                                                 const char *mupload_key,
4573                                                 const int chunk_number,
4574                                                 const unsigned long long x_upload_content_length,
4575                                                 void *request,
4576                                                 char **rupload_key,
4577                                                 storage_adaptor_error_code_h *error,
4578                                                 void *response)
4579 {
4580         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4581                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4582
4583         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4584                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4585
4586         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4587                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4588
4589
4590         storage_adaptor_check_param_equal(NULL, plugin->handle->create_resuming_chunk_upload_url, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4591                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (create_resuming_chunk_upload_url)"));
4592
4593 #ifdef DEBUG_ADAPTOR_PARAMS
4594         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4595         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4596                         context->app_id, context->access_token, context->cid, context->uid);
4597         storage_adaptor_debug_func("[in] mupload_key(%s)", mupload_key);
4598         storage_adaptor_debug_func("[in] chunk_number(%d)", chunk_number);
4599         storage_adaptor_debug_func("[in] x_upload_content_length(%llu)", x_upload_content_length);
4600         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4601 #endif
4602
4603         plugin_req_enter();
4604         storage_error_code_t ret = plugin->handle->create_resuming_chunk_upload_url(context, mupload_key,
4605                         chunk_number, x_upload_content_length, request, rupload_key, error, response);
4606         plugin_req_exit(ret, plugin, error);
4607
4608 #ifdef DEBUG_ADAPTOR_PARAMS
4609         storage_adaptor_debug_func("[out] return code (%d)", ret);
4610         if (NULL != rupload_key) {
4611                 storage_adaptor_debug_func("[out] rupload_key (%s)", *rupload_key);
4612         }
4613         if ((NULL != error) && (NULL != *error)) {
4614                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4615                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4616         }
4617         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4618         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4619 #endif
4620
4621         return ret;
4622 }
4623
4624 /**
4625 * @brief Resumes Upload (Not yet supported)
4626 *
4627 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4628 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4629 * @param[in]    rupload_key                     specifies Resuming Upload key
4630 * @param[in]    content_range                   specifies range of content
4631 * @param[in]    content_length                  specifies length of content
4632 * @param[in]    request                         specifies optional parameter
4633 * @param[out]   error                           specifies error code
4634 * @param[out]   response                        specifies optional parameter
4635 * @return 0 on success, otherwise a positive error value
4636 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4637 */
4638 storage_error_code_t storage_adaptor_resuming_upload(storage_adaptor_plugin_h plugin,
4639                                                 storage_adaptor_plugin_context_h context,
4640                                                 const char *rupload_key,
4641                                                 const char *change_range,
4642                                                 const unsigned long long content_length,
4643                                                 void *request,
4644                                                 storage_adaptor_error_code_h *error,
4645                                                 void *response)
4646 {
4647         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4648                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4649
4650         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4651                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4652
4653         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4654                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4655
4656
4657         storage_adaptor_check_param_equal(NULL, plugin->handle->resuming_upload, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4658                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (resuming_upload)"));
4659
4660 #ifdef DEBUG_ADAPTOR_PARAMS
4661         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4662         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4663                         context->app_id, context->access_token, context->cid, context->uid);
4664         storage_adaptor_debug_func("[in] rupload_key(%s)", rupload_key);
4665         storage_adaptor_debug_func("[in] change_range(%d)", change_range);
4666         storage_adaptor_debug_func("[in] content_length(%llu)", content_length);
4667         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4668 #endif
4669
4670         plugin_req_enter();
4671         storage_error_code_t ret = plugin->handle->resuming_upload(context, rupload_key,
4672                         change_range, content_length, request, error, response);
4673         plugin_req_exit(ret, plugin, error);
4674
4675 #ifdef DEBUG_ADAPTOR_PARAMS
4676         storage_adaptor_debug_func("[out] return code (%d)", ret);
4677         if ((NULL != error) && (NULL != *error)) {
4678                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4679                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4680         }
4681         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4682         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4683 #endif
4684
4685         return ret;
4686 }
4687
4688 /**
4689 * @brief Get progress of file transfer request
4690 *
4691 * @param[in]    plugin                          specifies Storage Adaptor Plugin handle
4692 * @param[in]    context                         specifies Storage Adaptor Plugin Context handle
4693 * @param[in]    transfer_request_id             specifies unique id for file transfer request
4694 * @param[in]    request                         specifies optional parameter
4695 * @param[out]   progress_size                   specifies current progress size
4696 * @param[out]   total_size                      specifies total size to transfer
4697 * @param[out]   error                           specifies error code
4698 * @param[out]   response                        specifies optional parameter
4699 * @return 0 on success, otherwise a positive error value
4700 * @retval error code defined in storage_error_code_t - STORAGE_ADAPTOR_ERROR_NONE if Successful
4701 */
4702 storage_error_code_t storage_adaptor_get_transfer_progress(storage_adaptor_plugin_h plugin,
4703                                                 storage_adaptor_plugin_context_h context,
4704                                                 void *transfer_request_id,
4705                                                 void *request,
4706                                                 unsigned long long *progress_size_byte,
4707                                                 unsigned long long *total_size_byte,
4708                                                 storage_adaptor_error_code_h *error,
4709                                                 void *response)
4710 {
4711         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4712                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (plugin)"));
4713
4714         storage_adaptor_check_param_equal(NULL, plugin, STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT,
4715                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_ARGUMENT, "Invalid argument (context)"));
4716
4717         storage_adaptor_check_param_equal(NULL, plugin->handle, STORAGE_ADAPTOR_ERROR_INVALID_HANDLE,
4718                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_INVALID_HANDLE, "Invalid plugin handle"));
4719
4720
4721         storage_adaptor_check_param_equal(NULL, plugin->handle->get_transfer_progress, STORAGE_ADAPTOR_ERROR_UNSUPPORTED,
4722                  __assign_error_code(error, (int64_t) STORAGE_ADAPTOR_ERROR_UNSUPPORTED, "Plugin does not support this API (get_transfer_progress)"));
4723
4724 #ifdef DEBUG_ADAPTOR_PARAMS
4725         storage_adaptor_debug_func("========== %s ==========", __FUNCTION__);
4726         storage_adaptor_debug_secure("[in] Context [app_id(%s) access_token(%s) cid(%s) uid(%s)]",
4727                         context->app_id, context->access_token, context->cid, context->uid);
4728         storage_adaptor_debug_func("[in] tansfer_request_id [addr(%p)]", transfer_request_id);
4729         storage_adaptor_debug_func("[in] request [addr(%p)]", request);
4730 #endif
4731
4732         plugin_req_enter();
4733         storage_error_code_t ret = plugin->handle->get_transfer_progress(context, transfer_request_id,
4734                         request, progress_size_byte, total_size_byte, error, response);
4735         plugin_req_exit(ret, plugin, error);
4736
4737 #ifdef DEBUG_ADAPTOR_PARAMS
4738         storage_adaptor_debug_func("[out] return code (%d)", ret);
4739         if (NULL != progress_size_byte) {
4740                 storage_adaptor_debug_func("[out] progress size : %10llubyte", *progress_size_byte);
4741         }
4742         if (NULL != total_size_byte) {
4743                 storage_adaptor_debug_func("[out] total    size : %10llubyte", *total_size_byte);
4744         }
4745         if ((NULL != error) && (NULL != *error)) {
4746                 storage_adaptor_debug_func("[out] error->code (%llu)", (*error)->code);
4747                 storage_adaptor_debug_func("[out] error->msg (%s)", (*error)->msg);
4748         }
4749         storage_adaptor_debug_func("[out] response [addr(%p)]", response);
4750         storage_adaptor_debug_func("========== %s END ==========", __FUNCTION__);
4751 #endif
4752
4753         return ret;
4754 }
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769 /* ///////////////////////////////////////////////////////////////////////////////
4770    ///////////////////////////////////////////////////////////////////////////////
4771    ////////////  Internal function description (for forked plugin)  //////////////
4772    ///////////////////////////////////////////////////////////////////////////////
4773    /////////////////////////////////////////////////////////////////////////////// */
4774
4775 void *_storage_adaptor_plugin_message_collector(void *data)
4776 {
4777         storage_adaptor_h adaptor = (storage_adaptor_h) data;
4778
4779         storage_adaptor_info("3rd party plugin listener run");
4780         int i, lagest_fd = -1;
4781         fd_set read_set;
4782         struct timeval tv;
4783         tv.tv_sec = 10L;                /* TODO change to define or meaningful value */
4784         char msg_buf[PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE] = {0, };
4785         int buf_size, rcv_len;
4786         GList *dead_list = NULL;
4787
4788         while (1) {
4789                 /* Clears and sets fds for select */
4790                 FD_ZERO(&read_set);
4791                 FD_SET(adaptor->rd_cmd[0], &read_set);
4792                 lagest_fd = adaptor->rd_cmd[0];
4793
4794                 /* Sets plugin fds for select */
4795                 for (i = 0; i < g_list_length(adaptor->rd_list); i++) {
4796                         int fd = (int) g_list_nth_data(adaptor->rd_list, i);
4797                         FD_SET(fd, &read_set);
4798                         if (lagest_fd < fd) {
4799                                 lagest_fd = fd;
4800                         }
4801                 }
4802
4803                 /* Select with timeout (for avoid blocking issue) */
4804                 int stmt = select((lagest_fd + 1), &read_set, NULL, NULL, &tv);
4805                 IF_IS_PLUGIN_THAN_RETURN_NULL();
4806                 if (stmt == 0) {
4807 /*                      storage_adaptor_debug("select refrech by timeout(%ld sec) [id : %d]", tv.tv_sec, g_process_identity); */
4808                         if (0L >= tv.tv_sec) {
4809 /*                              storage_adaptor_debug("Resets selector timeout sec"); */
4810                                 tv.tv_sec = 10L;
4811                         }
4812                         IF_IS_PLUGIN_THAN_RETURN_NULL();
4813                 } else if (stmt > 0) {
4814                         /* Checking message queue with Plugin processes. */
4815                         for (i = 0; i < g_list_length(adaptor->rd_list); i++) {
4816                                 IF_IS_PLUGIN_THAN_RETURN_NULL();
4817                                 int fd = (int) g_list_nth_data(adaptor->rd_list, i);
4818                                 if (FD_ISSET(fd, &read_set)) {
4819                                         IF_IS_PLUGIN_THAN_RETURN_NULL();
4820                                         /* pre-read buf size */
4821                                         rcv_len = read(fd, &buf_size, sizeof(int));
4822                                         if (0 >= rcv_len) {
4823                                                 storage_adaptor_debug("Child process dead (Remove from listening queue)");
4824                                                 dead_list = g_list_append(dead_list, (gpointer)fd);
4825                                                 continue;
4826                                         }
4827                                         /* allocates and read buf data */
4828                                         memset(msg_buf, 0, PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE);
4829                                         buf_size %= (PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE - 1);
4830                                         rcv_len = read(fd, msg_buf, buf_size);
4831                                         storage_adaptor_debug("read message [%s][%d]", msg_buf, rcv_len);
4832
4833                                         if (0 < rcv_len) {
4834                                                 /* transfer data to adaptor */
4835                                                 __storage_adaptor_transfer_message(msg_buf);
4836                                         } else {
4837                                                 storage_adaptor_debug("Child process dead (Remove from listening queue)");
4838                                                 dead_list = g_list_append(dead_list, (gpointer)fd);
4839                                         }
4840                                 }
4841                         }
4842
4843                         /* Checking message queue with Adaptor internal command. */
4844                         IF_IS_PLUGIN_THAN_RETURN_NULL();
4845                         if (FD_ISSET(adaptor->rd_cmd[0], &read_set)) {
4846                                 int fd = adaptor->rd_cmd[0];
4847                                 IF_IS_PLUGIN_THAN_RETURN_NULL();
4848                                 /* pre-read buf size */
4849                                 rcv_len = read(fd, &buf_size, sizeof(int));
4850
4851                                 if (0 >= rcv_len) {
4852                                         storage_adaptor_debug("Parent process dead : Listener break");
4853                                         break;
4854                                 }
4855
4856                                 /* allocates and read buf data */
4857                                 memset(msg_buf, 0, PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE);
4858                                 buf_size %= (PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE - 1);
4859                                 rcv_len = read(fd, msg_buf, buf_size);
4860                                 storage_adaptor_debug("read message [%s][%d]", msg_buf, rcv_len);
4861
4862                                 if (0 >= rcv_len) {
4863                                         storage_adaptor_debug("Parent process dead : Listener break");
4864                                         break;
4865                                 }
4866
4867                                 /* parse cmd message (e.g. append read_fd / change timeout sec / stop listener) */
4868                                 int cmd_ret = __storage_adaptor_parse_message_cmd(adaptor, msg_buf);
4869                                 if (0 > cmd_ret) {
4870                                         storage_adaptor_info("3rd party plugin listener stopped by adaptor cmd");
4871                                         break;
4872                                 }
4873                         }
4874
4875                         /* Remove fd with disconnected plugin. */
4876                         for (i = 0; i < g_list_length(dead_list); i++) {
4877                                 adaptor->rd_list = g_list_remove(adaptor->rd_list, (gpointer) g_list_nth_data(dead_list, i));
4878                         }
4879                         g_list_free(dead_list);
4880                         dead_list = NULL;
4881                 } else {
4882                         storage_adaptor_error("plugin message listener error (errno : %d)", errno);
4883                 }
4884         }
4885         storage_adaptor_info("3rd party plugin listener stopped");
4886
4887         return data;
4888 }
4889
4890 void __storage_adaptor_transfer_message(const char *msg)
4891 {
4892         plugin_message_h t_msg = NULL;
4893         int ret = 0;
4894         ret = plugin_message_deserialize(msg, &t_msg);
4895         if (!ret) {
4896                 pmnumber req_type, req_id;
4897                 ret = plugin_message_get_value_number(t_msg, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE, &req_type);
4898                 if (!ret && (PLUGIN_MESSAGE_TYPE_FUNCTION == req_type)) {
4899                         storage_adaptor_debug("Message function type : function");
4900                         ret = plugin_message_get_value_number(t_msg, PLUGIN_MESSAGE_ELEMENT_REQUEST_ID, &req_id);
4901                         if (!ret) {
4902                                 storage_adaptor_debug("Send plugin data to requester");
4903                                 int hooked_fd = (int) req_id;
4904                                 int len = strlen(msg);
4905                                 ret = write(hooked_fd, &len, sizeof(int));
4906                                 ret = write(hooked_fd, msg, sizeof(char) * len);
4907                         } else {
4908                                 storage_adaptor_debug("Couldn't get request id");
4909                         }
4910                 } else if (!ret && (PLUGIN_MESSAGE_TYPE_CALLBACK == req_type)) {
4911                         storage_adaptor_debug("Message function type : callback");
4912                         /*TODO call callback function */
4913                         char *callback_name = NULL;
4914                         ret = plugin_message_get_value_string(t_msg, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME, &callback_name);
4915                         storage_adaptor_error("Callback name : %s", callback_name);
4916                         if (NULL == callback_name) {
4917                                 storage_adaptor_error("Function name parsing error");
4918                         } else if (0 == strncmp(STORAGE_PLUGIN_CALLBACK_DOWNLOAD_FILE_ASYNC_CB,
4919                                                 callback_name,
4920                                                 strlen(STORAGE_PLUGIN_CALLBACK_DOWNLOAD_FILE_ASYNC_CB))) {
4921                                 pmnumber fd, state, ret_code;
4922                                 char *ret_msg = NULL;
4923                                 int param_idx = 1;
4924                                 storage_adaptor_error_code_h error = NULL;
4925                                 ret = plugin_message_get_value_number(t_msg, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
4926                                 ret = plugin_message_get_value_string(t_msg, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_msg);
4927                                 if (NULL != ret_msg) {
4928                                         error = storage_adaptor_create_error_code((int64_t) ret_code, ret_msg);
4929                                 }
4930                                 ret = plugin_message_get_param_number(t_msg, param_idx++, &fd);
4931                                 ret = plugin_message_get_param_number(t_msg, param_idx++, &state);
4932
4933                                 storage_adaptor_download_state_changed_reply_cb((int)fd, (storage_adaptor_transfer_state_e)state, error, NULL);
4934                                 storage_adaptor_destroy_error_code(&error);
4935                         } else if (0 == strncmp(STORAGE_PLUGIN_CALLBACK_UPLOAD_FILE_ASYNC_CB,
4936                                                 callback_name,
4937                                                 strlen(STORAGE_PLUGIN_CALLBACK_UPLOAD_FILE_ASYNC_CB))) {
4938                                 pmnumber fd, state, ret_code;
4939                                 char *ret_msg = NULL;
4940                                 int param_idx = 1;
4941                                 storage_adaptor_error_code_h error = NULL;
4942                                 storage_adaptor_file_info_h file_info = NULL;
4943                                 ret = plugin_message_get_value_number(t_msg, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
4944                                 ret = plugin_message_get_value_string(t_msg, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_msg);
4945                                 if (NULL != ret_msg) {
4946                                         error = storage_adaptor_create_error_code((int64_t) ret_code, ret_msg);
4947                                 }
4948                                 ret = plugin_message_get_param_number(t_msg, param_idx++, &fd);
4949                                 ret = plugin_message_get_param_number(t_msg, param_idx++, &state);
4950
4951                                 plugin_message_array_h file_info_message = NULL;
4952                                 ret = plugin_message_get_param_array(t_msg, param_idx++, &file_info_message);
4953                                 if ((0 == ret) && (NULL != file_info_message)) {
4954                                         file_info = _get_file_info_from_message_array(file_info_message, param_idx++);
4955                                 }
4956
4957                                 storage_adaptor_upload_state_changed_reply_cb((int)fd,
4958                                                 (storage_adaptor_transfer_state_e)state, file_info, error, NULL);
4959
4960                                 storage_adaptor_destroy_file_info(&file_info);
4961                                 plugin_message_array_destroy(file_info_message);
4962                                 storage_adaptor_destroy_error_code(&error);
4963                         } else if (0 == strncmp(STORAGE_PLUGIN_CALLBACK_PROGRESS_CB,
4964                                                 callback_name,
4965                                                 strlen(STORAGE_PLUGIN_CALLBACK_PROGRESS_CB))) {
4966                                 pmnumber fd, progress, total, ret_code;
4967                                 char *ret_msg = NULL;
4968                                 int param_idx = 1;
4969                                 storage_adaptor_error_code_h error = NULL;
4970                                 ret = plugin_message_get_value_number(t_msg, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
4971                                 ret = plugin_message_get_value_string(t_msg, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_msg);
4972                                 if (NULL != ret_msg) {
4973                                         error = storage_adaptor_create_error_code((int64_t) ret_code, ret_msg);
4974                                 }
4975                                 ret = plugin_message_get_param_number(t_msg, param_idx++, &fd);
4976                                 ret = plugin_message_get_param_number(t_msg, param_idx++, &progress);
4977                                 ret = plugin_message_get_param_number(t_msg, param_idx++, &total);
4978
4979                                 storage_adaptor_task_progress_reply_cb((int)fd,
4980                                                 (unsigned long long)progress, (unsigned long long)total, error, NULL);
4981                                 storage_adaptor_destroy_error_code(&error);
4982                         } else {
4983                                 storage_adaptor_error("Invalid callback name : %s", callback_name);
4984                         }
4985                         free(callback_name);
4986                 } else {
4987                         storage_adaptor_warning("Received message parsing fail.");
4988                 }
4989                 plugin_message_destroy(t_msg);
4990         }
4991 }
4992
4993 int __storage_adaptor_parse_message_cmd(storage_adaptor_h adaptor, char *msg)
4994 {
4995         char *cmd_data = NULL;
4996         if (0 == strncmp(PLUGIN_MESSAGE_LISTENER_CMD_APPEND_FD, msg, strlen(PLUGIN_MESSAGE_LISTENER_CMD_APPEND_FD))) {
4997                 cmd_data = msg + strlen(PLUGIN_MESSAGE_LISTENER_CMD_APPEND_FD);
4998                 int fd = atoi(cmd_data);
4999
5000                 adaptor->rd_list = g_list_append(adaptor->rd_list, (gpointer)fd);
5001         } else if (0 == strncmp(PLUGIN_MESSAGE_LISTENER_CMD_STOP, msg, strlen(PLUGIN_MESSAGE_LISTENER_CMD_STOP))) {
5002                 return -1;
5003         }
5004
5005         return 0;
5006 }
5007
5008
5009 void _storage_adaptor_send_cmd_add_fd(storage_adaptor_h adaptor, int fd)
5010 {
5011         char cmd_buf[256] = {0, };
5012         snprintf(cmd_buf, 255, "%s%d", PLUGIN_MESSAGE_LISTENER_CMD_APPEND_FD, fd);
5013         int len = strlen(cmd_buf);
5014         int wr_ret;
5015
5016         g_mutex_lock(&adaptor->rd_mutex);
5017         wr_ret = write(adaptor->rd_cmd[1], &len, sizeof(int));
5018         wr_ret = write(adaptor->rd_cmd[1], cmd_buf, sizeof(char) * len);
5019         g_mutex_unlock(&adaptor->rd_mutex);
5020         storage_adaptor_debug("writed (%d)(%s)", wr_ret, cmd_buf);
5021 }
5022
5023 void _storage_adaptor_send_cmd_stop_listen(storage_adaptor_h adaptor)
5024 {
5025         char cmd_buf[256] = {0, };
5026         snprintf(cmd_buf, 255, "%s", PLUGIN_MESSAGE_LISTENER_CMD_STOP);
5027         int len = strlen(cmd_buf);
5028         int wr_ret;
5029
5030         g_mutex_lock(&adaptor->rd_mutex);
5031         wr_ret = write(adaptor->rd_cmd[1], &len, sizeof(int));
5032         wr_ret = write(adaptor->rd_cmd[1], cmd_buf, sizeof(char) * len);
5033         g_mutex_unlock(&adaptor->rd_mutex);
5034         storage_adaptor_debug("writed (%d)(%s)", wr_ret, cmd_buf);
5035 }
5036
5037 static int storage_adaptor_send_message_to_plugin_sync(storage_adaptor_plugin_h plugin,
5038                                                 plugin_message_h send_message,
5039                                                 plugin_message_h *receive_message)
5040 {
5041         int io_ret = 0;
5042         int wfd = plugin->wd;
5043         int sync_hook[2];
5044
5045         if (pipe(sync_hook) != -1) {
5046                 char read_buf[PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE] = {0, };
5047
5048                 plugin_message_set_value_number(send_message, PLUGIN_MESSAGE_ELEMENT_REQUEST_ID, (pmnumber) sync_hook[1]);
5049                 char *stream = NULL;
5050                 io_ret = plugin_message_serialize(send_message, &stream);
5051                 int len = strlen(stream);
5052
5053                 g_mutex_lock(&plugin->message_mutex);
5054                 io_ret = write(wfd, &len, sizeof(len));
5055                 io_ret = write(wfd, stream, sizeof(char) * len);
5056                 g_mutex_unlock(&plugin->message_mutex);
5057                 free(stream);
5058                 stream = NULL;
5059                 len = 0;
5060
5061                 io_ret = read(sync_hook[0], &len, sizeof(len));
5062                 memset(read_buf, 0, PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE);
5063                 len %= (PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE - 1);
5064                 if (0 < len) {
5065                         io_ret = read(sync_hook[0], read_buf, len);
5066                 }
5067                 storage_adaptor_debug("io ret : %d", io_ret);
5068                 close(sync_hook[0]);
5069                 close(sync_hook[1]);
5070
5071                 plugin_message_h _rcv;
5072                 if (0 < strlen(read_buf)) {
5073                         io_ret = plugin_message_deserialize(read_buf, &_rcv);
5074                         if (!io_ret) {
5075                                 *receive_message = _rcv;
5076                         }
5077                 }
5078         } else {
5079                 io_ret = -1;
5080         }
5081
5082         return io_ret;
5083 }
5084
5085 storage_adaptor_plugin_handle_h __storage_adaptor_create_3rd_party_plugin_handle(const char *plugin_uri)
5086 {
5087         storage_adaptor_plugin_handle_h handle = (storage_adaptor_plugin_handle_h) calloc(1, sizeof(storage_adaptor_plugin_handle_t));
5088
5089         if (NULL == handle) {
5090                 return handle;
5091         }
5092
5093         handle->create_context = storage_plugin_send_create_context;
5094         handle->destroy_context = storage_plugin_send_destroy_context;
5095         handle->set_server_info = storage_plugin_send_set_server_info;
5096         handle->make_directory = storage_plugin_send_make_directory;
5097         handle->remove_directory = storage_plugin_send_remove_directory;
5098         handle->list = storage_plugin_send_get_list;
5099         handle->upload_file_sync = storage_plugin_send_upload_file_sync;
5100         handle->download_file_sync = storage_plugin_send_download_file_sync;
5101         handle->delete_file = storage_plugin_send_delete_file;
5102         handle->move_directory = storage_plugin_send_move_directory;
5103         handle->move_file = storage_plugin_send_move_file;
5104         handle->set_transfer_state = storage_plugin_send_set_transfer_state;
5105         handle->get_transfer_state = storage_plugin_send_get_transfer_state;
5106         handle->get_root_folder_path = storage_plugin_send_get_root_folder_path;
5107
5108         handle->start_upload_task = storage_plugin_send_start_upload_task;
5109         handle->start_download_task = storage_plugin_send_start_download_task;
5110         handle->start_download_thumb_task = storage_plugin_send_start_download_thumb_task;
5111         handle->cancel_upload_task = storage_plugin_send_cancel_upload_task;
5112         handle->cancel_download_task = storage_plugin_send_cancel_download_task;
5113         handle->cancel_download_thumb_task = storage_plugin_send_cancel_download_thumb_task;
5114
5115         handle->plugin_uri = strdup(plugin_uri);
5116
5117         return handle;
5118 }
5119
5120 storage_adaptor_file_info_h _get_file_info_from_message_array(plugin_message_array_h message_array, int index)
5121 {
5122         storage_adaptor_file_info_h file_info = NULL;
5123
5124         if (NULL == message_array) {
5125                 return file_info;
5126         }
5127
5128 /*
5129         //TODO
5130         _media_meta->mime_type          = NULL;
5131         _media_meta->title              = NULL;
5132         _media_meta->album              = NULL;
5133         _media_meta->artist             = NULL;
5134         _media_meta->genere             = NULL;
5135         _media_meta->recorded_date      = NULL;
5136         _media_meta->width              = -1;
5137         _media_meta->height             = -1;
5138         _media_meta->duration           = -1;
5139         _media_meta->copyright          = NULL;
5140         _media_meta->track_num          = NULL;
5141         _media_meta->description        = NULL;
5142         _media_meta->composer           = NULL;
5143         _media_meta->year               = NULL;
5144         _media_meta->bitrate            = -1;
5145         _media_meta->samplerate         = -1;
5146         _media_meta->channel            = -1;
5147         _media_meta->extra_media_meta   = NULL;
5148
5149         _cloud_meta->service_name       = NULL;
5150         _cloud_meta->usage_byte         = 0ULL;
5151         _cloud_meta->quota_byte         = 0ULL;
5152         _cloud_meta->extra_cloud_meta   = NULL;
5153 */
5154
5155         char *plugin_uri                = NULL;
5156         char *object_id                 = NULL;
5157         char *storage_path              = NULL;
5158         pmnumber file_size              = 0LL;
5159         pmnumber created_time           = 0LL;
5160         pmnumber modified_time          = 0LL;
5161         pmnumber file_info_index        = -1LL;
5162         pmnumber content_type           = (pmnumber)STORAGE_ADAPTOR_CONTENT_TYPE_DEFAULT;
5163         char *extra_file_info           = NULL;
5164
5165         int ret = 0;
5166         ret = plugin_message_array_get_element(message_array, index, &plugin_uri, &object_id, &storage_path,
5167                         &file_size, &created_time, &modified_time, &file_info_index, &content_type, &extra_file_info);
5168
5169         if (0 == ret) {
5170                 file_info = storage_adaptor_create_file_info();
5171
5172                 if (NULL != file_info) {
5173                         file_info->plugin_uri           = plugin_uri;
5174                         file_info->object_id            = object_id;
5175                         file_info->storage_path         = storage_path;
5176                         file_info->file_size            = (unsigned long long) file_size;
5177                         file_info->created_time         = (unsigned long long) created_time;
5178                         file_info->modified_time        = (unsigned long long) modified_time;
5179                         file_info->file_info_index      = (long long int) file_info_index;
5180                         file_info->content_type         = (int) content_type;
5181                         file_info->extra_file_info      = extra_file_info;
5182                 } else {
5183                         free(plugin_uri);
5184                         free(object_id);
5185                         free(extra_file_info);
5186                 }
5187         }
5188
5189         return file_info;
5190 }
5191
5192 int _message_array_set_file_info(plugin_message_array_h message_array, int index, storage_adaptor_file_info_h file_info)
5193 {
5194         int ret = STORAGE_ADAPTOR_ERROR_NONE;
5195         if ((NULL == message_array) || (NULL == file_info)) {
5196                 return -1;
5197         }
5198
5199 /*
5200         //TODO
5201         _media_meta->mime_type          = NULL;
5202         _media_meta->title              = NULL;
5203         _media_meta->album              = NULL;
5204         _media_meta->artist             = NULL;
5205         _media_meta->genere             = NULL;
5206         _media_meta->recorded_date      = NULL;
5207         _media_meta->width              = -1;
5208         _media_meta->height             = -1;
5209         _media_meta->duration           = -1;
5210         _media_meta->copyright          = NULL;
5211         _media_meta->track_num          = NULL;
5212         _media_meta->description        = NULL;
5213         _media_meta->composer           = NULL;
5214         _media_meta->year               = NULL;
5215         _media_meta->bitrate            = -1;
5216         _media_meta->samplerate         = -1;
5217         _media_meta->channel            = -1;
5218         _media_meta->extra_media_meta   = NULL;
5219
5220         _cloud_meta->service_name       = NULL;
5221         _cloud_meta->usage_byte         = 0ULL;
5222         _cloud_meta->quota_byte         = 0ULL;
5223         _cloud_meta->extra_cloud_meta   = NULL;
5224 */
5225
5226         char *plugin_uri                = SAFE_ADD_STRING(file_info->plugin_uri);
5227         char *object_id                 = SAFE_ADD_STRING(file_info->object_id);
5228         char *storage_path              = SAFE_ADD_STRING(file_info->storage_path);
5229         pmnumber file_size              = (pmnumber) file_info->file_size;
5230         pmnumber created_time           = (pmnumber) file_info->created_time;
5231         pmnumber modified_time          = (pmnumber) file_info->modified_time;
5232         pmnumber file_info_index        = (pmnumber) file_info->file_info_index;
5233         pmnumber content_type           = (pmnumber) file_info->content_type;
5234         char *extra_file_info           = SAFE_ADD_STRING(file_info->extra_file_info);
5235
5236         ret = plugin_message_array_add_element(message_array, plugin_uri, object_id, storage_path,
5237                         file_size, created_time, modified_time, file_info_index, content_type, extra_file_info);
5238
5239         return ret;
5240 }
5241
5242
5243
5244 /* TODO change */
5245 void change_smack_rule(const char *smack_label)
5246 {
5247         int ret = 0;
5248         char *label = NULL;
5249
5250         storage_adaptor_info("smack_label : %s\n", smack_label);
5251
5252         /* Check self process smack */
5253         smack_new_label_from_self(&label);
5254         storage_adaptor_info("now label(%s)\n", label);
5255         free(label);
5256         label = NULL;
5257
5258         /* Change smack label */
5259         ret = smack_set_label_for_self(smack_label);
5260         storage_adaptor_info("set label self(%d)\n", ret);
5261
5262         /* Check self process smack */
5263         smack_new_label_from_self(&label);
5264         storage_adaptor_info("now label(%s)\n", label);
5265         free(label);
5266         label = NULL;
5267 }
5268
5269
5270 storage_error_code_t storage_plugin_send_create_context(storage_adaptor_plugin_context_h *context,
5271                                                         const char *app_id,
5272                                                         const char *app_secret,
5273                                                         const char *access_token,
5274                                                         const char *cid,
5275                                                         const char *uid)
5276 {
5277         storage_adaptor_plugin_h plugin = NULL;
5278         plugin = (*context)->plugin_handle;
5279
5280         int ret = 0;
5281         plugin_message_h message = NULL;
5282         ret = plugin_message_create(&message);
5283
5284         if (ret == 0) {
5285                 (*context)->context_id = (int) (intptr_t)(*context);
5286
5287                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5288                                 (pmnumber) (*context)->context_id);
5289                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5290                                 STORAGE_PLUGIN_INTERFACE_CREATE_CONTEXT);
5291
5292                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5293                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5294
5295                 int param_index = 1;
5296                 plugin_message_set_param_string(message, param_index++, app_id);
5297                 plugin_message_set_param_string(message, param_index++, app_secret);
5298                 plugin_message_set_param_string(message, param_index++, access_token);
5299                 plugin_message_set_param_string(message, param_index++, cid);
5300                 plugin_message_set_param_string(message, param_index++, uid);
5301
5302                 plugin_message_h result_message = NULL;
5303                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5304
5305                 if (0 == ret) {
5306                         pmnumber ret_code;
5307                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5308
5309                         ret = (int) ret_code;
5310
5311                         char *ret_msg = NULL;
5312                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5313                                 storage_adaptor_debug("Create context successed");
5314                         } else {
5315                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5316                                 storage_adaptor_debug("Create context failed (%d)(%s)", ret, ret_msg);
5317                                 free(ret_msg);
5318                                 ret_msg = NULL;
5319
5320                                 free(*context);
5321                                 (*context) = NULL;
5322                         }
5323                         plugin_message_destroy(result_message);
5324                 }
5325         } else {
5326                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5327         }
5328         plugin_message_destroy(message);
5329
5330         return ret;
5331 }
5332
5333 storage_error_code_t storage_plugin_send_destroy_context(storage_adaptor_plugin_context_h context)
5334 {
5335         storage_adaptor_plugin_h plugin = NULL;
5336         plugin = context->plugin_handle;
5337
5338         int ret = 0;
5339         plugin_message_h message = NULL;
5340         ret = plugin_message_create(&message);
5341
5342         if (ret == 0) {
5343                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5344                                 (pmnumber) context->context_id);
5345                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5346                                 STORAGE_PLUGIN_INTERFACE_DESTROY_CONTEXT);
5347
5348                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5349                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5350
5351                 plugin_message_h result_message = NULL;
5352                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5353
5354                 if (0 == ret) {
5355                         pmnumber ret_code;
5356                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5357
5358                         ret = (int) ret_code;
5359
5360                         char *ret_msg = NULL;
5361                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5362                                 storage_adaptor_debug("Destroy context successed");
5363                         } else {
5364                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5365                                 storage_adaptor_debug("Destroy context failed (%d)(%s)", ret, ret_msg);
5366                                 free(ret_msg);
5367                                 ret_msg = NULL;
5368
5369                                 storage_adaptor_debug("Force release memory by adaptor process");
5370                                 free(context->access_token);
5371                                 free(context);
5372                                 context = NULL;
5373                         }
5374                         plugin_message_destroy(result_message);
5375                 }
5376         } else {
5377                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5378         }
5379         plugin_message_destroy(message);
5380
5381         return ret;
5382 }
5383
5384 storage_error_code_t storage_plugin_send_set_server_info(storage_adaptor_plugin_context_h context,
5385                                                         GHashTable *server_info,
5386                                                         void *request,
5387                                                         storage_adaptor_error_code_h *error,
5388                                                         void *response)
5389 {
5390         return STORAGE_ADAPTOR_ERROR_UNSUPPORTED;
5391 }
5392
5393 storage_error_code_t storage_plugin_send_make_directory(storage_adaptor_plugin_context_h context,
5394                                                         const char *parent_folder_storage_path,
5395                                                         const char *folder_name,
5396                                                         void *request,
5397                                                         storage_adaptor_file_info_h *file_info,
5398                                                         storage_adaptor_error_code_h *error,
5399                                                         void *response)
5400 {
5401         storage_adaptor_plugin_h plugin = NULL;
5402         plugin = context->plugin_handle;
5403
5404         int ret = 0;
5405         plugin_message_h message = NULL;
5406         ret = plugin_message_create(&message);
5407
5408         if (ret == 0) {
5409                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5410                                 (pmnumber) context->context_id);
5411                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5412                                 STORAGE_PLUGIN_INTERFACE_MAKE_DIRECTORY);
5413
5414                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5415                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5416
5417                 int param_index = 1;
5418                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5419                 plugin_message_set_param_string(message, param_index++, folder_name);
5420
5421                 plugin_message_h result_message = NULL;
5422                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5423
5424                 if (0 == ret) {
5425                         pmnumber ret_code;
5426                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5427
5428                         ret = (int) ret_code;
5429                         char *ret_msg = NULL;
5430                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5431                                 storage_adaptor_debug("Make directory successed");
5432
5433                                 if (NULL != file_info) {
5434                                         storage_adaptor_debug("Get file info");
5435                                         int param_idx = 1;
5436                                         int param_ret;
5437                                         plugin_message_array_h file_info_message = NULL;
5438                                         param_ret = plugin_message_get_param_array(result_message, param_idx++, &file_info_message);
5439                                         if ((0 == param_ret) && (NULL != file_info_message)) {
5440                                                 *file_info = _get_file_info_from_message_array(file_info_message, param_idx++);
5441                                         }
5442                                         plugin_message_array_destroy(file_info_message);
5443                                 }
5444                         } else {
5445                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5446                                 storage_adaptor_debug("Make directory failed (%d)(%s)", ret, ret_msg);
5447                                 if (NULL != error) {
5448                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5449                                         *error = error_code;
5450                                 }
5451                                 free(ret_msg);
5452                                 ret_msg = NULL;
5453                         }
5454                         plugin_message_destroy(result_message);
5455                 }
5456         } else {
5457                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5458         }
5459         plugin_message_destroy(message);
5460
5461         return ret;
5462 }
5463
5464
5465 storage_error_code_t storage_plugin_send_remove_directory(storage_adaptor_plugin_context_h context,
5466                                                         const char *parent_folder_storage_path,
5467                                                         const char *folder_name,
5468                                                         void *request,
5469                                                         storage_adaptor_file_info_h *file_info,
5470                                                         storage_adaptor_error_code_h *error,
5471                                                         void *response)
5472 {
5473         storage_adaptor_plugin_h plugin = NULL;
5474         plugin = context->plugin_handle;
5475
5476         int ret = 0;
5477         plugin_message_h message = NULL;
5478         ret = plugin_message_create(&message);
5479
5480         if (ret == 0) {
5481                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5482                                 (pmnumber) context->context_id);
5483                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5484                                 STORAGE_PLUGIN_INTERFACE_REMOVE_DIRECTORY);
5485
5486                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5487                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5488
5489                 int param_index = 1;
5490                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5491                 plugin_message_set_param_string(message, param_index++, folder_name);
5492
5493                 plugin_message_h result_message = NULL;
5494                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5495
5496                 if (0 == ret) {
5497                         pmnumber ret_code;
5498                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5499
5500                         ret = (int) ret_code;
5501                         char *ret_msg = NULL;
5502                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5503                                 storage_adaptor_debug("Remove directory successed");
5504
5505                                 if (NULL != file_info) {
5506                                         storage_adaptor_debug("Get file info");
5507                                         int param_idx = 1;
5508                                         int param_ret;
5509                                         plugin_message_array_h file_info_message = NULL;
5510                                         param_ret = plugin_message_get_param_array(result_message, param_idx++, &file_info_message);
5511                                         if ((0 == param_ret) && (NULL != file_info_message)) {
5512                                                 *file_info = _get_file_info_from_message_array(file_info_message, param_idx++);
5513                                         }
5514                                         plugin_message_array_destroy(file_info_message);
5515                                 }
5516                         } else {
5517                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5518                                 storage_adaptor_debug("Remove directory failed (%d)(%s)", ret, ret_msg);
5519                                 if (NULL != error) {
5520                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5521                                         *error = error_code;
5522                                 }
5523                                 free(ret_msg);
5524                                 ret_msg = NULL;
5525                         }
5526                         plugin_message_destroy(result_message);
5527                 }
5528         } else {
5529                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5530         }
5531         plugin_message_destroy(message);
5532
5533         return ret;
5534 }
5535
5536 storage_error_code_t storage_plugin_send_get_list(storage_adaptor_plugin_context_h context,
5537                                                         const char *parent_folder_storage_path,
5538                                                         const char *folder_name,
5539                                                         void *request,
5540                                                         storage_adaptor_file_info_h **file_info_list,
5541                                                         int *file_info_list_len,
5542                                                         storage_adaptor_error_code_h *error,
5543                                                         void *response)
5544 {
5545         storage_adaptor_plugin_h plugin = NULL;
5546         plugin = context->plugin_handle;
5547
5548         int ret = 0;
5549         plugin_message_h message = NULL;
5550         ret = plugin_message_create(&message);
5551
5552         if (ret == 0) {
5553                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5554                                 (pmnumber) context->context_id);
5555                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5556                                 STORAGE_PLUGIN_INTERFACE_REMOVE_DIRECTORY);
5557
5558                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5559                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5560
5561                 int param_index = 1;
5562                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5563                 plugin_message_set_param_string(message, param_index++, folder_name);
5564
5565                 plugin_message_h result_message = NULL;
5566                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5567
5568                 if (0 == ret) {
5569                         pmnumber ret_code;
5570                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5571
5572                         ret = (int) ret_code;
5573                         char *ret_msg = NULL;
5574                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5575                                 storage_adaptor_debug("Get list successed");
5576
5577                                 int param_ret;
5578                                 pmnumber len;
5579                                 param_ret = plugin_message_get_param_number(result_message, 2, &len);
5580                                 if ((0 == ret) && (NULL != file_info_list) && (len > 0LL)) {
5581                                         storage_adaptor_debug("Get file info");
5582                                         plugin_message_array_h file_info_message = NULL;
5583                                         param_ret = plugin_message_get_param_array(result_message, 1, &file_info_message);
5584                                         if ((0 == param_ret) && (NULL != file_info_message)) {
5585                                                 int i, l = (int) len;
5586                                                 *file_info_list = (storage_adaptor_file_info_h *) calloc(l, sizeof(storage_adaptor_file_info_h));
5587                                                 if (NULL != *file_info_list) {
5588                                                         for (i = 0; i < l; i++) {
5589                                                                 (*file_info_list)[i] = _get_file_info_from_message_array(file_info_message, (i+1));
5590                                                         }
5591                                                         if (NULL != file_info_list_len) {
5592                                                                 *file_info_list_len = l;
5593                                                         }
5594                                                 }
5595                                                 plugin_message_array_destroy(file_info_message);
5596                                         }
5597                                 }
5598                         } else {
5599                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5600                                 storage_adaptor_debug("Get list failed (%d)(%s)", ret, ret_msg);
5601                                 if (NULL != error) {
5602                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5603                                         *error = error_code;
5604                                 }
5605                                 free(ret_msg);
5606                                 ret_msg = NULL;
5607                         }
5608                         plugin_message_destroy(result_message);
5609                 }
5610         } else {
5611                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5612         }
5613         plugin_message_destroy(message);
5614
5615         return ret;
5616 }
5617
5618
5619 storage_error_code_t storage_plugin_send_upload_file_sync(storage_adaptor_plugin_context_h context,
5620                                                         const char *parent_folder_storage_path,
5621                                                         const char *file_name,
5622                                                         const char *upload_file_local_path,
5623                                                         const int publish,
5624                                                         void *request,
5625                                                         storage_adaptor_file_info_h *file_info,
5626                                                         storage_adaptor_error_code_h *error,
5627                                                         void *response)
5628 {
5629         storage_adaptor_plugin_h plugin = NULL;
5630         plugin = context->plugin_handle;
5631
5632         int ret = 0;
5633         plugin_message_h message = NULL;
5634         ret = plugin_message_create(&message);
5635
5636         if (ret == 0) {
5637                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5638                                 (pmnumber) context->context_id);
5639                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5640                                 STORAGE_PLUGIN_INTERFACE_UPLOAD_FILE_SYNC);
5641
5642                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5643                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5644
5645                 int param_index = 1;
5646                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5647                 plugin_message_set_param_string(message, param_index++, file_name);
5648                 plugin_message_set_param_string(message, param_index++, upload_file_local_path);
5649                 plugin_message_set_param_number(message, param_index++, (pmnumber) publish);
5650
5651                 plugin_message_h result_message = NULL;
5652                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5653
5654                 if (0 == ret) {
5655                         pmnumber ret_code;
5656                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5657
5658                         ret = (int) ret_code;
5659                         char *ret_msg = NULL;
5660                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5661                                 storage_adaptor_debug("Upload sync successed");
5662
5663                                 if (NULL != file_info) {
5664                                         storage_adaptor_debug("Get file info");
5665                                         int param_idx = 1;
5666                                         int param_ret;
5667                                         plugin_message_array_h file_info_message = NULL;
5668                                         param_ret = plugin_message_get_param_array(result_message, param_idx++, &file_info_message);
5669                                         if ((0 == param_ret) && (NULL != file_info_message)) {
5670                                                 *file_info = _get_file_info_from_message_array(file_info_message, param_idx++);
5671                                         }
5672                                         plugin_message_array_destroy(file_info_message);
5673                                 }
5674                         } else {
5675                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5676                                 storage_adaptor_debug("Upload sync failed (%d)(%s)", ret, ret_msg);
5677                                 if (NULL != error) {
5678                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5679                                         *error = error_code;
5680                                 }
5681                                 free(ret_msg);
5682                                 ret_msg = NULL;
5683                         }
5684                         plugin_message_destroy(result_message);
5685                 }
5686         } else {
5687                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5688         }
5689         plugin_message_destroy(message);
5690
5691         return ret;
5692 }
5693
5694
5695 storage_error_code_t storage_plugin_send_download_file_sync(storage_adaptor_plugin_context_h context,
5696                                                         const char *parent_folder_storage_path,
5697                                                         const char *file_name,
5698                                                         const char *download_file_local_path,
5699                                                         void *request,
5700                                                         storage_adaptor_error_code_h *error,
5701                                                         void *response)
5702 {
5703         storage_adaptor_plugin_h plugin = NULL;
5704         plugin = context->plugin_handle;
5705
5706         int ret = 0;
5707         plugin_message_h message = NULL;
5708         ret = plugin_message_create(&message);
5709
5710         if (ret == 0) {
5711                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5712                                 (pmnumber) context->context_id);
5713                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5714                                 STORAGE_PLUGIN_INTERFACE_DOWNLOAD_FILE_SYNC);
5715
5716                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5717                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5718
5719                 int param_index = 1;
5720                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5721                 plugin_message_set_param_string(message, param_index++, file_name);
5722                 plugin_message_set_param_string(message, param_index++, download_file_local_path);
5723
5724                 plugin_message_h result_message = NULL;
5725                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5726
5727                 if (0 == ret) {
5728                         pmnumber ret_code;
5729                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5730
5731                         ret = (int) ret_code;
5732                         char *ret_msg = NULL;
5733                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5734                                 storage_adaptor_debug("Download sync successed");
5735                         } else {
5736                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5737                                 storage_adaptor_debug("Download sync failed (%d)(%s)", ret, ret_msg);
5738                                 if (NULL != error) {
5739                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5740                                         *error = error_code;
5741                                 }
5742                                 free(ret_msg);
5743                                 ret_msg = NULL;
5744                         }
5745                         plugin_message_destroy(result_message);
5746                 }
5747         } else {
5748                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5749         }
5750         plugin_message_destroy(message);
5751
5752         return ret;
5753 }
5754
5755 storage_error_code_t storage_plugin_send_delete_file(storage_adaptor_plugin_context_h context,
5756                                                         const char *parent_folder_storage_path,
5757                                                         const char *file_name,
5758                                                         void *request,
5759                                                         storage_adaptor_file_info_h *file_info,
5760                                                         storage_adaptor_error_code_h *error,
5761                                                         void *response)
5762 {
5763         storage_adaptor_plugin_h plugin = NULL;
5764         plugin = context->plugin_handle;
5765
5766         int ret = 0;
5767         plugin_message_h message = NULL;
5768         ret = plugin_message_create(&message);
5769
5770         if (ret == 0) {
5771                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5772                                 (pmnumber) context->context_id);
5773                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5774                                 STORAGE_PLUGIN_INTERFACE_DELETE_FILE);
5775
5776                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5777                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5778
5779                 int param_index = 1;
5780                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5781                 plugin_message_set_param_string(message, param_index++, file_name);
5782
5783                 plugin_message_h result_message = NULL;
5784                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5785
5786                 if (0 == ret) {
5787                         pmnumber ret_code;
5788                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5789
5790                         ret = (int) ret_code;
5791                         char *ret_msg = NULL;
5792                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5793                                 storage_adaptor_debug("Delete file successed");
5794
5795                                 if (NULL != file_info) {
5796                                         storage_adaptor_debug("Get file info");
5797                                         int param_idx = 1;
5798                                         int param_ret;
5799                                         plugin_message_array_h file_info_message = NULL;
5800                                         param_ret = plugin_message_get_param_array(result_message, param_idx++, &file_info_message);
5801                                         if ((0 == param_ret) && (NULL != file_info_message)) {
5802                                                 *file_info = _get_file_info_from_message_array(file_info_message, param_idx++);
5803                                         }
5804                                         plugin_message_array_destroy(file_info_message);
5805                                 }
5806                         } else {
5807                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5808                                 storage_adaptor_debug("Delete file failed (%d)(%s)", ret, ret_msg);
5809                                 if (NULL != error) {
5810                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5811                                         *error = error_code;
5812                                 }
5813                                 free(ret_msg);
5814                                 ret_msg = NULL;
5815                         }
5816                         plugin_message_destroy(result_message);
5817                 }
5818         } else {
5819                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5820         }
5821         plugin_message_destroy(message);
5822
5823         return ret;
5824 }
5825
5826 storage_error_code_t storage_plugin_send_move_directory(storage_adaptor_plugin_context_h context,
5827                                                         const char *parent_folder_storage_path,
5828                                                         const char *folder_name,
5829                                                         const char *dest_parent_folder_storage_path,
5830                                                         const char *new_folder_name,
5831                                                         void *request,
5832                                                         storage_adaptor_file_info_h *file_info,
5833                                                         storage_adaptor_error_code_h *error,
5834                                                         void *response)
5835 {
5836         storage_adaptor_plugin_h plugin = NULL;
5837         plugin = context->plugin_handle;
5838
5839         int ret = 0;
5840         plugin_message_h message = NULL;
5841         ret = plugin_message_create(&message);
5842
5843         if (ret == 0) {
5844                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5845                                 (pmnumber) context->context_id);
5846                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5847                                 STORAGE_PLUGIN_INTERFACE_MOVE_DIRECTORY);
5848
5849                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5850                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5851
5852                 int param_index = 1;
5853                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5854                 plugin_message_set_param_string(message, param_index++, folder_name);
5855                 plugin_message_set_param_string(message, param_index++, dest_parent_folder_storage_path);
5856                 plugin_message_set_param_string(message, param_index++, new_folder_name);
5857
5858                 plugin_message_h result_message = NULL;
5859                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5860
5861                 if (0 == ret) {
5862                         pmnumber ret_code;
5863                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5864
5865                         ret = (int) ret_code;
5866                         char *ret_msg = NULL;
5867                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5868                                 storage_adaptor_debug("Move directory successed");
5869
5870                                 if (NULL != file_info) {
5871                                         storage_adaptor_debug("Get file info");
5872                                         int param_idx = 1;
5873                                         int param_ret;
5874                                         plugin_message_array_h file_info_message = NULL;
5875                                         param_ret = plugin_message_get_param_array(result_message, param_idx++, &file_info_message);
5876                                         if ((0 == param_ret) && (NULL != file_info_message)) {
5877                                                 *file_info = _get_file_info_from_message_array(file_info_message, param_idx++);
5878                                         }
5879                                         plugin_message_array_destroy(file_info_message);
5880                                 }
5881                         } else {
5882                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5883                                 storage_adaptor_debug("Move directory failed (%d)(%s)", ret, ret_msg);
5884                                 if (NULL != error) {
5885                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5886                                         *error = error_code;
5887                                 }
5888                                 free(ret_msg);
5889                                 ret_msg = NULL;
5890                         }
5891                         plugin_message_destroy(result_message);
5892                 }
5893         } else {
5894                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5895         }
5896         plugin_message_destroy(message);
5897
5898         return ret;
5899 }
5900
5901 storage_error_code_t storage_plugin_send_move_file(storage_adaptor_plugin_context_h context,
5902                                                         const char *parent_folder_storage_path,
5903                                                         const char *file_name,
5904                                                         const char *dest_parent_folder_storage_path,
5905                                                         const char *new_file_name,
5906                                                         void *request,
5907                                                         storage_adaptor_file_info_h *file_info,
5908                                                         storage_adaptor_error_code_h *error,
5909                                                         void *response)
5910 {
5911         storage_adaptor_plugin_h plugin = NULL;
5912         plugin = context->plugin_handle;
5913
5914         int ret = 0;
5915         plugin_message_h message = NULL;
5916         ret = plugin_message_create(&message);
5917
5918         if (ret == 0) {
5919                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5920                                 (pmnumber) context->context_id);
5921                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5922                                 STORAGE_PLUGIN_INTERFACE_MOVE_FILE);
5923
5924                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5925                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5926
5927                 int param_index = 1;
5928                 plugin_message_set_param_string(message, param_index++, parent_folder_storage_path);
5929                 plugin_message_set_param_string(message, param_index++, file_name);
5930                 plugin_message_set_param_string(message, param_index++, dest_parent_folder_storage_path);
5931                 plugin_message_set_param_string(message, param_index++, new_file_name);
5932
5933                 plugin_message_h result_message = NULL;
5934                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
5935
5936                 if (0 == ret) {
5937                         pmnumber ret_code;
5938                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
5939
5940                         ret = (int) ret_code;
5941                         char *ret_msg = NULL;
5942                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
5943                                 storage_adaptor_debug("Move file successed");
5944
5945                                 if (NULL != file_info) {
5946                                         storage_adaptor_debug("Get file info");
5947                                         int param_idx = 1;
5948                                         int param_ret;
5949                                         plugin_message_array_h file_info_message = NULL;
5950                                         param_ret = plugin_message_get_param_array(result_message, param_idx++, &file_info_message);
5951                                         if ((0 == param_ret) && (NULL != file_info_message)) {
5952                                                 *file_info = _get_file_info_from_message_array(file_info_message, param_idx++);
5953                                         }
5954                                         plugin_message_array_destroy(file_info_message);
5955                                 }
5956                         } else {
5957                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
5958                                 storage_adaptor_debug("Move file failed (%d)(%s)", ret, ret_msg);
5959                                 if (NULL != error) {
5960                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
5961                                         *error = error_code;
5962                                 }
5963                                 free(ret_msg);
5964                                 ret_msg = NULL;
5965                         }
5966                         plugin_message_destroy(result_message);
5967                 }
5968         } else {
5969                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
5970         }
5971         plugin_message_destroy(message);
5972
5973         return ret;
5974 }
5975
5976 storage_error_code_t storage_plugin_send_set_transfer_state(storage_adaptor_plugin_context_h context,
5977                                                         void *transfer_request_id,
5978                                                         storage_adaptor_transfer_state_e state,
5979                                                         void *request,
5980                                                         storage_adaptor_error_code_h *error,
5981                                                         void *response)
5982 {
5983         storage_adaptor_plugin_h plugin = NULL;
5984         plugin = context->plugin_handle;
5985
5986         int ret = 0;
5987         plugin_message_h message = NULL;
5988         ret = plugin_message_create(&message);
5989
5990         if (ret == 0) {
5991                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
5992                                 (pmnumber) context->context_id);
5993                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
5994                                 STORAGE_PLUGIN_INTERFACE_SET_TRANSFER_STATE);
5995                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
5996                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
5997
5998                 int param_index = 1;
5999                 plugin_message_set_param_number(message, param_index++, (pmnumber)(intptr_t)transfer_request_id);
6000                 plugin_message_set_param_number(message, param_index++, (pmnumber)state);
6001
6002                 plugin_message_h result_message = NULL;
6003                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6004
6005                 if (0 == ret) {
6006                         pmnumber ret_code;
6007                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6008
6009                         ret = (int) ret_code;
6010                         char *ret_msg = NULL;
6011                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6012                                 storage_adaptor_debug("Set transfer state successed");
6013                         } else {
6014                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6015                                 storage_adaptor_debug("Set transfer state failed (%d)(%s)", ret, ret_msg);
6016                                 if (NULL != error) {
6017                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6018                                         *error = error_code;
6019                                 }
6020                                 free(ret_msg);
6021                                 ret_msg = NULL;
6022                         }
6023                         plugin_message_destroy(result_message);
6024                 }
6025         } else {
6026                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6027         }
6028         plugin_message_destroy(message);
6029
6030         return ret;
6031 }
6032
6033 storage_error_code_t storage_plugin_send_get_transfer_state(storage_adaptor_plugin_context_h context,
6034                                                         void *transfer_request_id,
6035                                                         void *request,
6036                                                         storage_adaptor_transfer_state_e *state,
6037                                                         storage_adaptor_error_code_h *error,
6038                                                         void *response)
6039 {
6040         storage_adaptor_plugin_h plugin = NULL;
6041         plugin = context->plugin_handle;
6042
6043         int ret = 0;
6044         plugin_message_h message = NULL;
6045         ret = plugin_message_create(&message);
6046
6047         if (ret == 0) {
6048                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6049                                 (pmnumber) context->context_id);
6050                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6051                                 STORAGE_PLUGIN_INTERFACE_GET_TRANSFER_STATE);
6052                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6053                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6054
6055                 int param_index = 1;
6056                 plugin_message_set_param_number(message, param_index++, (pmnumber)(intptr_t)transfer_request_id);
6057
6058                 plugin_message_h result_message = NULL;
6059                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6060
6061                 if (0 == ret) {
6062                         pmnumber ret_code;
6063                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6064
6065                         ret = (int) ret_code;
6066                         char *ret_msg = NULL;
6067                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6068                                 storage_adaptor_debug("Get transfer state successed");
6069                                 pmnumber st;
6070                                 plugin_message_get_param_number(message, 1, &st);
6071                                 if (NULL != state) {
6072                                         *state = (storage_adaptor_transfer_state_e)st;
6073                                 }
6074                         } else {
6075                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6076                                 storage_adaptor_debug("Get transfer state failed (%d)(%s)", ret, ret_msg);
6077                                 if (NULL != error) {
6078                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6079                                         *error = error_code;
6080                                 }
6081                                 free(ret_msg);
6082                                 ret_msg = NULL;
6083                         }
6084                         plugin_message_destroy(result_message);
6085                 }
6086         } else {
6087                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6088         }
6089         plugin_message_destroy(message);
6090
6091         return ret;
6092 }
6093
6094 storage_error_code_t storage_plugin_send_get_root_folder_path(storage_adaptor_plugin_context_h context,
6095                                                         void *request,
6096                                                         char **root_folder_path,
6097                                                         storage_adaptor_error_code_h *error,
6098                                                         void *response)
6099 {
6100         storage_adaptor_plugin_h plugin = NULL;
6101         plugin = context->plugin_handle;
6102
6103         int ret = 0;
6104         plugin_message_h message = NULL;
6105         ret = plugin_message_create(&message);
6106
6107         if (ret == 0) {
6108                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6109                                 (pmnumber) context->context_id);
6110                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6111                                 STORAGE_PLUGIN_INTERFACE_GET_ROOT_FOLDER_PATH);
6112                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6113                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6114
6115 /*              int param_index = 1; */
6116
6117                 plugin_message_h result_message = NULL;
6118                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6119
6120                 if (0 == ret) {
6121                         pmnumber ret_code;
6122                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6123
6124                         ret = (int) ret_code;
6125                         char *ret_msg = NULL;
6126                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6127                                 storage_adaptor_debug("Get root folder path successed");
6128                                 char *path = NULL;
6129                                 plugin_message_get_param_string(message, 1, &path);
6130                                 if (NULL != root_folder_path) {
6131                                         *root_folder_path = path;
6132                                 }
6133                         } else {
6134                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6135                                 storage_adaptor_debug("Get root folder path failed (%d)(%s)", ret, ret_msg);
6136                                 if (NULL != error) {
6137                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6138                                         *error = error_code;
6139                                 }
6140                                 free(ret_msg);
6141                                 ret_msg = NULL;
6142                         }
6143                         plugin_message_destroy(result_message);
6144                 }
6145         } else {
6146                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6147         }
6148         plugin_message_destroy(message);
6149
6150         return ret;
6151 }
6152
6153 /* ///////////// for 2.4 public API */
6154 storage_error_code_t storage_plugin_send_start_upload_task(storage_adaptor_plugin_context_h context,
6155                                                         int fd,
6156                                                         const char *upload_dir,
6157                                                         const char *file_path,
6158                                                         bool need_progress,
6159                                                         storage_adaptor_error_code_h *error,
6160                                                         void *user_data)
6161 {
6162         storage_adaptor_plugin_h plugin = NULL;
6163         plugin = context->plugin_handle;
6164
6165         int ret = 0;
6166         plugin_message_h message = NULL;
6167         ret = plugin_message_create(&message);
6168
6169         if (ret == 0) {
6170                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6171                                 (pmnumber) context->context_id);
6172                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6173                                 STORAGE_PLUGIN_INTERFACE_START_UPLOAD_TASK);
6174
6175                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6176                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6177
6178                 int param_index = 1;
6179                 plugin_message_set_param_number(message, param_index++, (pmnumber)fd);
6180                 plugin_message_set_param_string(message, param_index++, upload_dir);
6181                 plugin_message_set_param_string(message, param_index++, file_path);
6182                 plugin_message_set_param_bool(message, param_index++, need_progress);
6183
6184                 param_index = 1;
6185                 plugin_message_set_opt_param_number(message, param_index++, (pmnumber)(intptr_t)user_data);
6186
6187                 plugin_message_h result_message = NULL;
6188                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6189
6190                 if ((0 == ret) && (NULL != result_message)) {
6191                         pmnumber ret_code;
6192                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6193
6194                         ret = (int) ret_code;
6195                         char *ret_msg = NULL;
6196                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6197                                 storage_adaptor_debug("Upload file async successed");
6198                         } else {
6199                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6200                                 storage_adaptor_debug("Upload file async failed (%d)(%s)", ret, ret_msg);
6201                                 if (NULL != error) {
6202                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6203                                         *error = error_code;
6204                                 }
6205                                 free(ret_msg);
6206                                 ret_msg = NULL;
6207                         }
6208                         plugin_message_destroy(result_message);
6209                 }
6210         } else {
6211                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6212         }
6213         plugin_message_destroy(message);
6214
6215         return ret;
6216 }
6217
6218 storage_error_code_t storage_plugin_send_start_download_task(storage_adaptor_plugin_context_h context,
6219                                                         const char *storage_dir,
6220                                                         const char *file_path,
6221                                                         int fd,
6222                                                         bool need_progress,
6223                                                         storage_adaptor_error_code_h *error,
6224                                                         void *user_data)
6225 {
6226         storage_adaptor_plugin_h plugin = NULL;
6227         plugin = context->plugin_handle;
6228
6229         int ret = 0;
6230         plugin_message_h message = NULL;
6231         ret = plugin_message_create(&message);
6232
6233         if (ret == 0) {
6234                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6235                                 (pmnumber) context->context_id);
6236                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6237                                 STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_TASK);
6238
6239                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6240                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6241
6242                 int param_index = 1;
6243                 plugin_message_set_param_string(message, param_index++, storage_dir);
6244                 plugin_message_set_param_string(message, param_index++, file_path);
6245                 plugin_message_set_param_number(message, param_index++, (pmnumber)fd);
6246                 plugin_message_set_param_bool(message, param_index++, need_progress);
6247
6248                 param_index = 1;
6249                 plugin_message_set_opt_param_number(message, param_index++, (pmnumber)(intptr_t)user_data);
6250
6251                 plugin_message_h result_message = NULL;
6252                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6253
6254                 if ((0 == ret) && (NULL != result_message)) {
6255                         pmnumber ret_code;
6256                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6257
6258                         ret = (int) ret_code;
6259                         char *ret_msg = NULL;
6260                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6261                                 storage_adaptor_debug("Download file async successed");
6262                         } else {
6263                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6264                                 storage_adaptor_debug("Download file async failed (%d)(%s)", ret, ret_msg);
6265                                 if (NULL != error) {
6266                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6267                                         *error = error_code;
6268                                 }
6269                                 free(ret_msg);
6270                                 ret_msg = NULL;
6271                         }
6272                         plugin_message_destroy(result_message);
6273                 }
6274         } else {
6275                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6276         }
6277         plugin_message_destroy(message);
6278
6279         return ret;
6280 }
6281
6282 storage_error_code_t storage_plugin_send_start_download_thumb_task(storage_adaptor_plugin_context_h context,
6283                                                         const char *storage_dir,
6284                                                         const char *file_path,
6285                                                         int fd,
6286                                                         int thumbnail_size,
6287                                                         bool need_progress,
6288                                                         storage_adaptor_error_code_h *error,
6289                                                         void *user_data)
6290 {
6291         storage_adaptor_plugin_h plugin = NULL;
6292         plugin = context->plugin_handle;
6293
6294         int ret = 0;
6295         plugin_message_h message = NULL;
6296         ret = plugin_message_create(&message);
6297
6298         if (ret == 0) {
6299                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6300                                 (pmnumber) context->context_id);
6301                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6302                                 STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_THUMB_TASK);
6303
6304                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6305                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6306
6307                 int param_index = 1;
6308                 plugin_message_set_param_string(message, param_index++, storage_dir);
6309                 plugin_message_set_param_string(message, param_index++, file_path);
6310                 plugin_message_set_param_number(message, param_index++, (pmnumber)fd);
6311                 plugin_message_set_param_number(message, param_index++, (pmnumber)thumbnail_size);
6312                 plugin_message_set_param_bool(message, param_index++, need_progress);
6313
6314                 param_index = 1;
6315                 plugin_message_set_opt_param_number(message, param_index++, (pmnumber)(intptr_t)user_data);
6316
6317                 plugin_message_h result_message = NULL;
6318                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6319
6320                 if ((0 == ret) && (NULL != result_message)) {
6321                         pmnumber ret_code;
6322                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6323
6324                         ret = (int) ret_code;
6325                         char *ret_msg = NULL;
6326                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6327                                 storage_adaptor_debug("Download thumbnail async successed");
6328                         } else {
6329                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6330                                 storage_adaptor_debug("Download thumbnail async failed (%d)(%s)", ret, ret_msg);
6331                                 if (NULL != error) {
6332                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6333                                         *error = error_code;
6334                                 }
6335                                 free(ret_msg);
6336                                 ret_msg = NULL;
6337                         }
6338                         plugin_message_destroy(result_message);
6339                 }
6340         } else {
6341                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6342         }
6343         plugin_message_destroy(message);
6344
6345         return ret;
6346 }
6347
6348 storage_error_code_t storage_plugin_send_cancel_upload_task(storage_adaptor_plugin_context_h context,
6349                                                         int fd,
6350                                                         storage_adaptor_error_code_h *error)
6351 {
6352         storage_adaptor_plugin_h plugin = NULL;
6353         plugin = context->plugin_handle;
6354
6355         int ret = 0;
6356         plugin_message_h message = NULL;
6357         ret = plugin_message_create(&message);
6358
6359         if (ret == 0) {
6360                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6361                                 (pmnumber) context->context_id);
6362                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6363                                 STORAGE_PLUGIN_INTERFACE_CANCEL_UPLOAD_TASK);
6364
6365                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6366                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6367
6368                 int param_index = 1;
6369                 plugin_message_set_param_number(message, param_index++, (pmnumber)fd);
6370
6371                 plugin_message_h result_message = NULL;
6372                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6373
6374                 if ((0 == ret) && (NULL != result_message)) {
6375                         pmnumber ret_code;
6376                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6377
6378                         ret = (int) ret_code;
6379                         char *ret_msg = NULL;
6380                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6381                                 storage_adaptor_debug("Upload file async successed");
6382                         } else {
6383                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6384                                 storage_adaptor_debug("Upload file async failed (%d)(%s)", ret, ret_msg);
6385                                 if (NULL != error) {
6386                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6387                                         *error = error_code;
6388                                 }
6389                                 free(ret_msg);
6390                                 ret_msg = NULL;
6391                         }
6392                         plugin_message_destroy(result_message);
6393                 }
6394         } else {
6395                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6396         }
6397         plugin_message_destroy(message);
6398
6399         return ret;
6400 }
6401
6402 storage_error_code_t storage_plugin_send_cancel_download_task(storage_adaptor_plugin_context_h context,
6403                                                         int fd,
6404                                                         storage_adaptor_error_code_h *error)
6405 {
6406         storage_adaptor_plugin_h plugin = NULL;
6407         plugin = context->plugin_handle;
6408
6409         int ret = 0;
6410         plugin_message_h message = NULL;
6411         ret = plugin_message_create(&message);
6412
6413         if (ret == 0) {
6414                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6415                                 (pmnumber) context->context_id);
6416                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6417                                 STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_TASK);
6418
6419                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6420                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6421
6422                 int param_index = 1;
6423                 plugin_message_set_param_number(message, param_index++, (pmnumber)fd);
6424
6425                 plugin_message_h result_message = NULL;
6426                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6427
6428                 if ((0 == ret) && (NULL != result_message)) {
6429                         pmnumber ret_code;
6430                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6431
6432                         ret = (int) ret_code;
6433                         char *ret_msg = NULL;
6434                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6435                                 storage_adaptor_debug("Cancel upload file successed");
6436                         } else {
6437                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6438                                 storage_adaptor_debug("Cancel upload file failed (%d)(%s)", ret, ret_msg);
6439                                 if (NULL != error) {
6440                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6441                                         *error = error_code;
6442                                 }
6443                                 free(ret_msg);
6444                                 ret_msg = NULL;
6445                         }
6446                         plugin_message_destroy(result_message);
6447                 }
6448         } else {
6449                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6450         }
6451         plugin_message_destroy(message);
6452
6453         return ret;
6454 }
6455
6456 storage_error_code_t storage_plugin_send_cancel_download_thumb_task(storage_adaptor_plugin_context_h context,
6457                                                         int fd,
6458                                                         storage_adaptor_error_code_h *error)
6459 {
6460         storage_adaptor_plugin_h plugin = NULL;
6461         plugin = context->plugin_handle;
6462
6463         int ret = 0;
6464         plugin_message_h message = NULL;
6465         ret = plugin_message_create(&message);
6466
6467         if (ret == 0) {
6468                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID,
6469                                 (pmnumber) context->context_id);
6470                 plugin_message_set_value_string(message, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME,
6471                                 STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_THUMB_TASK);
6472
6473                 plugin_message_set_value_number(message, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE,
6474                                 (pmnumber) PLUGIN_MESSAGE_TYPE_FUNCTION);
6475
6476                 int param_index = 1;
6477                 plugin_message_set_param_number(message, param_index++, (pmnumber)fd);
6478
6479                 plugin_message_h result_message = NULL;
6480                 ret = storage_adaptor_send_message_to_plugin_sync(plugin, message, &result_message);
6481
6482                 if ((0 == ret) && (NULL != result_message)) {
6483                         pmnumber ret_code;
6484                         plugin_message_get_value_number(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, &ret_code);
6485
6486                         ret = (int) ret_code;
6487                         char *ret_msg = NULL;
6488                         if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6489                                 storage_adaptor_debug("Cancel download thumbnail successed");
6490                         } else {
6491                                 plugin_message_get_value_string(result_message, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, &ret_msg);
6492                                 storage_adaptor_debug("Cancel download thumbnail failed (%d)(%s)", ret, ret_msg);
6493                                 if (NULL != error) {
6494                                         storage_adaptor_error_code_h error_code = storage_adaptor_create_error_code(ret, ret_msg);
6495                                         *error = error_code;
6496                                 }
6497                                 free(ret_msg);
6498                                 ret_msg = NULL;
6499                         }
6500                         plugin_message_destroy(result_message);
6501                 }
6502         } else {
6503                 ret = STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL;
6504         }
6505         plugin_message_destroy(message);
6506
6507         return ret;
6508 }
6509
6510 void storage_plugin_receive_download_state_changed_cb(int file_descriptor,
6511                                                 storage_adaptor_transfer_state_e state,
6512                                                 storage_adaptor_error_code_h error,
6513                                                 void *user_data)
6514 {
6515         int ret = 0;
6516         plugin_message_h m_callback = NULL;
6517
6518         if ((0 != plugin_message_create(&m_callback)) || (NULL == m_callback)) {
6519                 LOGE("[%s/%d] Callback message create failed", __FUNCTION__, __LINE__);
6520                 return;
6521         }
6522
6523         const char *func_name = STORAGE_PLUGIN_CALLBACK_DOWNLOAD_FILE_ASYNC_CB;
6524
6525         plugin_message_set_value_string(m_callback, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME, func_name);
6526         plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE, PLUGIN_MESSAGE_TYPE_CALLBACK);
6527
6528         if (NULL == error) {
6529                 plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)STORAGE_ADAPTOR_ERROR_NONE);
6530         } else {
6531                 LOGD("[%s/%d] Callback's error value (%lld, %s)", __FUNCTION__, __LINE__, (long long int)error->code, error->msg);
6532                 plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, (pmnumber)error->code);
6533                 plugin_message_set_value_string(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, error->msg);
6534         }
6535
6536         int param_idx = 1;
6537         plugin_message_set_param_number(m_callback, param_idx++, (pmnumber)file_descriptor);
6538         plugin_message_set_param_number(m_callback, param_idx++, (pmnumber)state);
6539
6540         char *result = NULL;
6541         int rcv_len;
6542
6543         ret = plugin_message_serialize(m_callback, &result);
6544
6545         if ((0 == ret) && (NULL != result)) {
6546                 LOGD("[%s/%d] Send callback data message to adaptor", __FUNCTION__, __LINE__);
6547                 int res_len = strlen(result);
6548                 rcv_len = write(g_child_plugin->wd, &res_len, sizeof(int));
6549                 rcv_len = write(g_child_plugin->wd, result, sizeof(char) * res_len);
6550                 if (rcv_len <= 0) {
6551                         LOGE("[%s/%d] pipe socket writing error", __FUNCTION__, __LINE__);
6552                 }
6553         } else {
6554                 LOGE("[%s/%d] Callback data message serialization failed", __FUNCTION__, __LINE__);
6555         }
6556
6557         plugin_message_destroy(m_callback);
6558 }
6559
6560 void storage_plugin_receive_upload_state_changed_cb(int file_descriptor,
6561                                                 storage_adaptor_transfer_state_e state,
6562                                                 storage_adaptor_file_info_h file_info,
6563                                                 storage_adaptor_error_code_h error,
6564                                                 void *user_data)
6565 {
6566         int ret = 0;
6567         plugin_message_h m_callback = NULL;
6568
6569         if ((0 != plugin_message_create(&m_callback)) || (NULL == m_callback)) {
6570                 LOGE("[%s/%d] Callback message create failed", __FUNCTION__, __LINE__);
6571                 return;
6572         }
6573
6574         const char *func_name = STORAGE_PLUGIN_CALLBACK_UPLOAD_FILE_ASYNC_CB;
6575
6576         plugin_message_set_value_string(m_callback, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME, func_name);
6577         plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE, PLUGIN_MESSAGE_TYPE_CALLBACK);
6578
6579         if (NULL == error) {
6580                 plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)STORAGE_ADAPTOR_ERROR_NONE);
6581         } else {
6582                 LOGD("[%s/%d] Callback's error value (%lld, %s)", __FUNCTION__, __LINE__, (long long int)error->code, error->msg);
6583                 plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, (pmnumber)error->code);
6584                 plugin_message_set_value_string(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, error->msg);
6585         }
6586
6587         int param_idx = 1;
6588         plugin_message_set_param_number(m_callback, param_idx++, (pmnumber)file_descriptor);
6589         plugin_message_set_param_number(m_callback, param_idx++, (pmnumber)state);
6590
6591         if (NULL != file_info) {
6592                 LOGD("Insert file info to pipe message");
6593                 int param_ret;
6594                 plugin_message_array_h file_info_message = NULL;
6595                 char message_array_type[20] = {0, };
6596                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
6597                                                         PLUGIN_DATA_TYPE_STRING,
6598                                                         PLUGIN_DATA_TYPE_STRING,
6599                                                         PLUGIN_DATA_TYPE_NUM,
6600                                                         PLUGIN_DATA_TYPE_NUM,
6601                                                         PLUGIN_DATA_TYPE_NUM,
6602                                                         PLUGIN_DATA_TYPE_NUM,
6603                                                         PLUGIN_DATA_TYPE_NUM,
6604                                                         PLUGIN_DATA_TYPE_STRING);
6605                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
6606                 if (0 == param_ret) {
6607                         _message_array_set_file_info(file_info_message, 1, file_info);
6608                         param_ret = plugin_message_set_param_array(m_callback, param_idx++, file_info_message);
6609                         plugin_message_array_destroy(file_info_message);
6610                 }
6611         }
6612
6613         char *result = NULL;
6614
6615         ret = plugin_message_serialize(m_callback, &result);
6616
6617         if ((0 == ret) && (NULL != result)) {
6618                 LOGD("[%s/%d] Send callback data message to adaptor", __FUNCTION__, __LINE__);
6619                 int res_len = strlen(result);
6620                 int rcv_len = write(g_child_plugin->wd, &res_len, sizeof(int));
6621                 rcv_len = write(g_child_plugin->wd, result, sizeof(char) * res_len);
6622                 if (rcv_len <= 0) {
6623                         LOGE("[%s/%d] pipe socket writing error", __FUNCTION__, __LINE__);
6624                 }
6625         } else {
6626                 LOGE("[%s/%d] Callback data message serialization failed", __FUNCTION__, __LINE__);
6627         }
6628
6629         plugin_message_destroy(m_callback);
6630
6631 }
6632
6633 void storage_plugin_receive_file_progress_cb(int file_descriptor,
6634                                                 unsigned long long progress_size_byte,
6635                                                 unsigned long long total_size_byte,
6636                                                 storage_adaptor_error_code_h error,
6637                                                 void *user_data)
6638 {
6639         int ret = 0;
6640         plugin_message_h m_callback = NULL;
6641
6642         if ((0 != plugin_message_create(&m_callback)) || (NULL == m_callback)) {
6643                 LOGE("[%s/%d] Callback message create failed", __FUNCTION__, __LINE__);
6644                 return;
6645         }
6646
6647         const char *func_name = STORAGE_PLUGIN_CALLBACK_PROGRESS_CB;
6648
6649         plugin_message_set_value_string(m_callback, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME, func_name);
6650         plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE, PLUGIN_MESSAGE_TYPE_CALLBACK);
6651
6652         if (NULL == error) {
6653                 plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)STORAGE_ADAPTOR_ERROR_NONE);
6654         } else {
6655                 LOGD("[%s/%d] Callback's error value (%lld, %s)", __FUNCTION__, __LINE__, (long long int)error->code, error->msg);
6656                 plugin_message_set_value_number(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, (pmnumber)error->code);
6657                 plugin_message_set_value_string(m_callback, PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE, error->msg);
6658         }
6659
6660         int param_idx = 1;
6661         plugin_message_set_param_number(m_callback, param_idx++, (pmnumber)file_descriptor);
6662         plugin_message_set_param_number(m_callback, param_idx++, (pmnumber)progress_size_byte);
6663         plugin_message_set_param_number(m_callback, param_idx++, (pmnumber)total_size_byte);
6664
6665         char *result = NULL;
6666
6667         ret = plugin_message_serialize(m_callback, &result);
6668
6669         if ((0 == ret) && (NULL != result)) {
6670                 LOGD("[%s/%d] Send callback data message to adaptor", __FUNCTION__, __LINE__);
6671                 int res_len = strlen(result);
6672                 int rcv_len = write(g_child_plugin->wd, &res_len, sizeof(int));
6673                 rcv_len = write(g_child_plugin->wd, result, sizeof(char) * res_len);
6674                 if (rcv_len <= 0) {
6675                         LOGE("[%s/%d] pipe socket writing error", __FUNCTION__, __LINE__);
6676                 }
6677         } else {
6678                 LOGE("[%s/%d] Callback data message serialization failed", __FUNCTION__, __LINE__);
6679         }
6680
6681         plugin_message_destroy(m_callback);
6682
6683 }
6684
6685
6686 /* For forked plugin */
6687 void *_storage_plugin_request_collector(void *data)
6688 {
6689         storage_adaptor_plugin_h plugin = (storage_adaptor_plugin_h) data;
6690
6691         int rcv_len, buf_size;
6692         char msg_buf[PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE] = {0, };
6693
6694         while (1) {
6695                 /* pre-read buf size */
6696                 rcv_len = read(plugin->rd, &buf_size, sizeof(int));
6697
6698                 if (rcv_len <= 0) {
6699                         LOGD("shutdown by adaptor disconnected");
6700                         return NULL;
6701                 }
6702
6703                 /* allocates and read buf data */
6704                 memset(msg_buf, 0, PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE);
6705                 buf_size %= (PLUGIN_MESSAGE_PROTOCOL_MAX_BUF_SIZE - 1);
6706                 rcv_len = read(plugin->rd, msg_buf, buf_size);
6707                 LOGD("read message [%s][len: %d]", msg_buf, rcv_len);
6708
6709                 if (rcv_len <= 0) {
6710                         LOGD("shutdown by adaptor disconnected");
6711                         return NULL;
6712                 }
6713
6714                 char *result = NULL;
6715                 __storage_plugin_progress_command(plugin, msg_buf, &result);
6716
6717                 if (NULL != result) {
6718                         int res_len = strlen(result);
6719                         rcv_len = write(plugin->wd, &res_len, sizeof(int));
6720                         rcv_len = write(plugin->wd, result, sizeof(char) * res_len);
6721                 }
6722                 /* transfer data to adaptor */
6723         }
6724         return data;
6725 }
6726
6727 storage_adaptor_plugin_context_h __storage_plugin_get_context_by_context_id(storage_adaptor_plugin_h plugin, int context_id)
6728 {
6729         if (NULL == plugin) {
6730                 return NULL;
6731         }
6732
6733         /* For forked plugin */
6734         storage_adaptor_plugin_context_h ctx = NULL;
6735         int i, len;
6736         len = g_list_length(plugin->contexts);
6737
6738         for (i = 0; i < len; i++) {
6739                 ctx = (storage_adaptor_plugin_context_h) g_list_nth_data(plugin->contexts, i);
6740
6741                 if (context_id == ctx->context_id) {
6742                         return ctx;
6743                 }
6744         }
6745         return NULL;
6746 }
6747
6748 void __storage_plugin_progress_command(storage_adaptor_plugin_h plugin, char *order, char **result)
6749 {
6750         int ret = 0;
6751         plugin_message_h m_order = NULL;
6752         plugin_message_h m_result = NULL;
6753
6754         if ((NULL == order) || (plugin_message_deserialize(order, &m_order))) {
6755                 LOGE("[%s/%d] Message parse error", __FUNCTION__, __LINE__);
6756                 return;
6757         } else if (plugin_message_create(&m_result)) {
6758                 plugin_message_destroy(m_order);
6759                 m_order = NULL;
6760
6761                 LOGE("[%s/%d] Message parse error", __FUNCTION__, __LINE__);
6762                 return;
6763         }
6764
6765         char *func_name = NULL;
6766         int context_id = 0;
6767
6768         pmnumber ctx, req, type;
6769
6770         plugin_message_get_value_number(m_order, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID, &ctx);
6771         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_CONTEXT_ID, ctx);
6772         plugin_message_get_value_number(m_order, PLUGIN_MESSAGE_ELEMENT_REQUEST_ID, &req);
6773         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_REQUEST_ID, req);
6774         plugin_message_get_value_string(m_order, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME, &func_name);
6775         plugin_message_set_value_string(m_result, PLUGIN_MESSAGE_ELEMENT_FUNCTION_NAME, func_name);
6776         plugin_message_get_value_number(m_order, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE, &type);
6777         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_MESSAGE_TYPE, type);
6778         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)STORAGE_ADAPTOR_ERROR_NONE);
6779         context_id = (int) ctx;
6780         storage_adaptor_plugin_context_h context = __storage_plugin_get_context_by_context_id(plugin, context_id);
6781
6782         storage_adaptor_error_code_h error_code = NULL;
6783         storage_adaptor_file_info_h file_info = NULL;
6784
6785         if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_CREATE_CONTEXT,
6786                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_CREATE_CONTEXT))) {
6787                 LOGD(">>>>>> %s func start", func_name);
6788                 char *app_id = NULL;
6789                 char *app_secret = NULL;
6790                 char *access_token = NULL;
6791                 char *cid = NULL;
6792                 char *uid = NULL;
6793                 char *service_name = NULL;
6794
6795                 int param_idx = 1;
6796                 plugin_message_get_param_string(m_order, param_idx++, &app_id);
6797                 plugin_message_get_param_string(m_order, param_idx++, &app_secret);
6798                 plugin_message_get_param_string(m_order, param_idx++, &access_token);
6799                 plugin_message_get_param_string(m_order, param_idx++, &cid);
6800                 plugin_message_get_param_string(m_order, param_idx++, &uid);
6801
6802                 LOGD("Call library function");
6803                 context = storage_adaptor_create_plugin_context(plugin,
6804                                 app_id, app_secret, access_token, cid, uid, "");
6805
6806                 if (NULL == context) {
6807                         LOGE("[%s<%s>/%d] Could not create context", __FUNCTION__, func_name, __LINE__);
6808 /*                      error_code = storage_adaptor_create_error_code((int64_t)STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL, */
6809 /*                                      "Could not create context"); */
6810                         plugin_message_set_value_number(m_result,
6811                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
6812                                         (pmnumber)STORAGE_ADAPTOR_ERROR_PLUGIN_INTERNAL);
6813                         plugin_message_set_value_string(m_result,
6814                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
6815                                         "Could not create context");
6816                 } else {
6817                         LOGD("[%s<%s>/%d] Created context successfuly", __FUNCTION__, func_name, __LINE__);
6818                         context->context_id = context_id;
6819
6820                         plugin_message_set_value_number(m_result,
6821                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
6822                                         (pmnumber)STORAGE_ADAPTOR_ERROR_NONE);
6823                 }
6824
6825
6826                 free(app_id);
6827                 free(app_secret);
6828                 free(access_token);
6829                 free(uid);
6830                 free(service_name);
6831                 LOGD("<<<<<< %s func end", func_name);
6832         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_DESTROY_CONTEXT,
6833                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_DESTROY_CONTEXT))) {
6834                 LOGD(">>>>>> %s func start", func_name);
6835                 if (NULL == context) {
6836                         LOGE("[%s<%s>/%d] Could not found context", __FUNCTION__, func_name, __LINE__);
6837                 } else {
6838                         LOGD("[%s<%s>/%d] function success", __FUNCTION__, func_name, __LINE__);
6839                         storage_adaptor_destroy_plugin_context(plugin, context);
6840
6841                         plugin_message_set_value_number(m_result,
6842                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
6843                                         (pmnumber)STORAGE_ADAPTOR_ERROR_NONE);
6844                 }
6845                 LOGD("<<<<<< %s func end", func_name);
6846         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_MAKE_DIRECTORY,
6847                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_MAKE_DIRECTORY))) {
6848                 LOGD(">>>>>> %s func start", func_name);
6849                 char *parent_path = NULL;
6850                 char *folder_path = NULL;
6851
6852                 int param_idx = 1;
6853                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
6854                 plugin_message_get_param_string(m_order, param_idx++, &folder_path);
6855
6856                 LOGD("Call library function");
6857                 ret = plugin->handle->make_directory(context, parent_path, folder_path,
6858                                 NULL, &file_info, &error_code, NULL);
6859
6860                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6861                         LOGD("API success");
6862                         int param_idx = 1;
6863
6864                         if (NULL != file_info) {
6865                                 LOGD("Insert file info to pipe message");
6866                                 int param_ret;
6867                                 plugin_message_array_h file_info_message = NULL;
6868                                 char message_array_type[20] = {0, };
6869                                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
6870                                                                         PLUGIN_DATA_TYPE_STRING,
6871                                                                         PLUGIN_DATA_TYPE_STRING,
6872                                                                         PLUGIN_DATA_TYPE_NUM,
6873                                                                         PLUGIN_DATA_TYPE_NUM,
6874                                                                         PLUGIN_DATA_TYPE_NUM,
6875                                                                         PLUGIN_DATA_TYPE_NUM,
6876                                                                         PLUGIN_DATA_TYPE_NUM,
6877                                                                         PLUGIN_DATA_TYPE_STRING);
6878                                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
6879                                 if (0 == param_ret) {
6880                                         _message_array_set_file_info(file_info_message, 1, file_info);
6881                                         param_ret = plugin_message_set_param_array(m_result, param_idx++, file_info_message);
6882                                         plugin_message_array_destroy(file_info_message);
6883                                 }
6884                         }
6885                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
6886                 } else if (NULL != error_code) {
6887                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
6888                         plugin_message_set_value_number(m_result,
6889                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
6890                                         (pmnumber)error_code->code);
6891                         plugin_message_set_value_string(m_result,
6892                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
6893                                         error_code->msg ? error_code->msg : "");
6894                         free(error_code->msg);
6895                         free(error_code);
6896                 } else {
6897                         LOGD("API failed ret_code[%d]", ret);
6898                         plugin_message_set_value_number(m_result,
6899                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
6900                 }
6901
6902                 free(parent_path);
6903                 free(folder_path);
6904                 LOGD("<<<<<< %s func end", func_name);
6905         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_REMOVE_DIRECTORY,
6906                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_REMOVE_DIRECTORY))) {
6907                 LOGD(">>>>>> %s func start", func_name);
6908                 char *parent_path = NULL;
6909                 char *folder_path = NULL;
6910
6911                 int param_idx = 1;
6912                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
6913                 plugin_message_get_param_string(m_order, param_idx++, &folder_path);
6914
6915                 LOGD("Call library function");
6916                 ret = plugin->handle->remove_directory(context, parent_path, folder_path,
6917                                 NULL, &file_info, &error_code, NULL);
6918
6919                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6920                         LOGD("API success");
6921                         int param_idx = 1;
6922
6923                         if (NULL != file_info) {
6924                                 LOGD("Insert file info to pipe message");
6925                                 int param_ret;
6926                                 plugin_message_array_h file_info_message = NULL;
6927                                 char message_array_type[20] = {0, };
6928                                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
6929                                                                         PLUGIN_DATA_TYPE_STRING,
6930                                                                         PLUGIN_DATA_TYPE_STRING,
6931                                                                         PLUGIN_DATA_TYPE_NUM,
6932                                                                         PLUGIN_DATA_TYPE_NUM,
6933                                                                         PLUGIN_DATA_TYPE_NUM,
6934                                                                         PLUGIN_DATA_TYPE_NUM,
6935                                                                         PLUGIN_DATA_TYPE_NUM,
6936                                                                         PLUGIN_DATA_TYPE_STRING);
6937                                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
6938                                 if (0 == param_ret) {
6939                                         _message_array_set_file_info(file_info_message, 1, file_info);
6940                                         param_ret = plugin_message_set_param_array(m_result, param_idx++, file_info_message);
6941                                         plugin_message_array_destroy(file_info_message);
6942                                 }
6943                         }
6944                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
6945                 } else if (NULL != error_code) {
6946                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
6947                         plugin_message_set_value_number(m_result,
6948                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
6949                                         (pmnumber)error_code->code);
6950                         plugin_message_set_value_string(m_result,
6951                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
6952                                         error_code->msg ? error_code->msg : "");
6953                         free(error_code->msg);
6954                         free(error_code);
6955                 } else {
6956                         LOGD("API failed ret_code[%d]", ret);
6957                         plugin_message_set_value_number(m_result,
6958                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
6959                 }
6960
6961                 free(parent_path);
6962                 free(folder_path);
6963                 LOGD("<<<<<< %s func end", func_name);
6964         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_GET_LIST,
6965                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_GET_LIST))) {
6966                 LOGD(">>>>>> %s func start", func_name);
6967                 char *parent_path = NULL;
6968                 char *folder_path = NULL;
6969
6970                 int param_idx = 1;
6971                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
6972                 plugin_message_get_param_string(m_order, param_idx++, &folder_path);
6973
6974                 storage_adaptor_file_info_h *file_list = NULL;
6975                 int file_list_len = 0;
6976                 LOGD("Call library function");
6977                 ret = plugin->handle->list(context, parent_path, folder_path,
6978                                 NULL, &file_list, &file_list_len, &error_code, NULL);
6979
6980                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
6981                         int param_idx = 1;
6982
6983                         if ((NULL != file_list) && (0 < file_list_len)) {
6984                                 LOGD("Insert file list to pipe message (length : %d)", file_list_len);
6985                                 int param_ret, i;
6986                                 plugin_message_array_h file_info_message = NULL;
6987                                 char message_array_type[20] = {0, };
6988                                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
6989                                                                         PLUGIN_DATA_TYPE_STRING,
6990                                                                         PLUGIN_DATA_TYPE_STRING,
6991                                                                         PLUGIN_DATA_TYPE_NUM,
6992                                                                         PLUGIN_DATA_TYPE_NUM,
6993                                                                         PLUGIN_DATA_TYPE_NUM,
6994                                                                         PLUGIN_DATA_TYPE_NUM,
6995                                                                         PLUGIN_DATA_TYPE_NUM,
6996                                                                         PLUGIN_DATA_TYPE_STRING);
6997                                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
6998                                 if (0 == param_ret) {
6999                                         for (i = 0; i < file_list_len; i++) {
7000                                                 _message_array_set_file_info(file_info_message, (i + 1), file_list[i]);
7001                                                 storage_adaptor_destroy_file_info(&(file_list[i]));
7002                                         }
7003                                         free(file_list);
7004                                         file_list = NULL;
7005                                         param_ret = plugin_message_set_param_array(m_result, param_idx++, file_info_message);
7006                                         param_ret = plugin_message_set_param_number(m_result, param_idx++, (pmnumber)file_list_len);
7007                                         plugin_message_array_destroy(file_info_message);
7008                                 }
7009                         }
7010                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7011                 } else if (NULL != error_code) {
7012                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7013                         plugin_message_set_value_number(m_result,
7014                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7015                                         (pmnumber)error_code->code);
7016                         plugin_message_set_value_string(m_result,
7017                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7018                                         error_code->msg ? error_code->msg : "");
7019                         free(error_code->msg);
7020                         free(error_code);
7021                 } else {
7022                         LOGD("API failed ret_code[%d]", ret);
7023                         plugin_message_set_value_number(m_result,
7024                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7025                 }
7026
7027                 free(parent_path);
7028                 free(folder_path);
7029                 LOGD("<<<<<< %s func end", func_name);
7030         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_UPLOAD_FILE_SYNC,
7031                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_UPLOAD_FILE_SYNC))) {
7032                 LOGD(">>>>>> %s func start", func_name);
7033                 char *parent_path = NULL;
7034                 char *folder_path = NULL;
7035                 char *local_path = NULL;
7036                 pmnumber publish;
7037
7038                 int param_idx = 1;
7039                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7040                 plugin_message_get_param_string(m_order, param_idx++, &folder_path);
7041                 plugin_message_get_param_string(m_order, param_idx++, &local_path);
7042                 plugin_message_get_param_number(m_order, param_idx++, &publish);
7043
7044                 LOGD("Call library function");
7045                 ret = plugin->handle->upload_file_sync(context, parent_path, folder_path, local_path, (int)publish,
7046                                 NULL, &file_info, &error_code, NULL);
7047
7048                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7049                         LOGD("API success");
7050                         int param_idx = 1;
7051
7052                         if (NULL != file_info) {
7053                                 LOGD("Insert file info to pipe message");
7054                                 int param_ret;
7055                                 plugin_message_array_h file_info_message = NULL;
7056                                 char message_array_type[20] = {0, };
7057                                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
7058                                                                         PLUGIN_DATA_TYPE_STRING,
7059                                                                         PLUGIN_DATA_TYPE_STRING,
7060                                                                         PLUGIN_DATA_TYPE_NUM,
7061                                                                         PLUGIN_DATA_TYPE_NUM,
7062                                                                         PLUGIN_DATA_TYPE_NUM,
7063                                                                         PLUGIN_DATA_TYPE_NUM,
7064                                                                         PLUGIN_DATA_TYPE_NUM,
7065                                                                         PLUGIN_DATA_TYPE_STRING);
7066                                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
7067                                 if (0 == param_ret) {
7068                                         _message_array_set_file_info(file_info_message, 1, file_info);
7069                                         param_ret = plugin_message_set_param_array(m_result, param_idx++, file_info_message);
7070                                         plugin_message_array_destroy(file_info_message);
7071                                 }
7072                         }
7073                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7074                 } else if (NULL != error_code) {
7075                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7076                         plugin_message_set_value_number(m_result,
7077                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7078                                         (pmnumber)error_code->code);
7079                         plugin_message_set_value_string(m_result,
7080                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7081                                         error_code->msg ? error_code->msg : "");
7082                         free(error_code->msg);
7083                         free(error_code);
7084                 } else {
7085                         LOGD("API failed ret_code[%d]", ret);
7086                         plugin_message_set_value_number(m_result,
7087                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7088                 }
7089
7090                 free(parent_path);
7091                 free(folder_path);
7092                 free(local_path);
7093                 LOGD("<<<<<< %s func end", func_name);
7094         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_DOWNLOAD_FILE_SYNC,
7095                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_DOWNLOAD_FILE_SYNC))) {
7096                 LOGD(">>>>>> %s func start", func_name);
7097                 char *parent_path = NULL;
7098                 char *folder_path = NULL;
7099                 char *local_path = NULL;
7100
7101                 int param_idx = 1;
7102                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7103                 plugin_message_get_param_string(m_order, param_idx++, &folder_path);
7104                 plugin_message_get_param_string(m_order, param_idx++, &local_path);
7105
7106                 LOGD("Call library function");
7107                 ret = plugin->handle->download_file_sync(context, parent_path, folder_path, local_path,
7108                                 NULL, &error_code, NULL);
7109
7110                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7111                         LOGD("API success");
7112                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7113                 } else if (NULL != error_code) {
7114                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7115                         plugin_message_set_value_number(m_result,
7116                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7117                                         (pmnumber)error_code->code);
7118                         plugin_message_set_value_string(m_result,
7119                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7120                                         error_code->msg ? error_code->msg : "");
7121                         free(error_code->msg);
7122                         free(error_code);
7123                 } else {
7124                         LOGD("API failed ret_code[%d]", ret);
7125                         plugin_message_set_value_number(m_result,
7126                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7127                 }
7128
7129                 free(parent_path);
7130                 free(folder_path);
7131                 free(local_path);
7132                 LOGD("<<<<<< %s func end", func_name);
7133         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_DELETE_FILE,
7134                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_DELETE_FILE))) {
7135                 LOGD(">>>>>> %s func start", func_name);
7136                 char *parent_path = NULL;
7137                 char *folder_path = NULL;
7138
7139                 int param_idx = 1;
7140                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7141                 plugin_message_get_param_string(m_order, param_idx++, &folder_path);
7142
7143                 LOGD("Call library function");
7144                 ret = plugin->handle->delete_file(context, parent_path, folder_path,
7145                                 NULL, &file_info, &error_code, NULL);
7146
7147                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7148                         LOGD("API success");
7149                         int param_idx = 1;
7150
7151                         if (NULL != file_info) {
7152                                 LOGD("Insert file info to pipe message");
7153                                 int param_ret;
7154                                 plugin_message_array_h file_info_message = NULL;
7155                                 char message_array_type[20] = {0, };
7156                                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
7157                                                                         PLUGIN_DATA_TYPE_STRING,
7158                                                                         PLUGIN_DATA_TYPE_STRING,
7159                                                                         PLUGIN_DATA_TYPE_NUM,
7160                                                                         PLUGIN_DATA_TYPE_NUM,
7161                                                                         PLUGIN_DATA_TYPE_NUM,
7162                                                                         PLUGIN_DATA_TYPE_NUM,
7163                                                                         PLUGIN_DATA_TYPE_NUM,
7164                                                                         PLUGIN_DATA_TYPE_STRING);
7165                                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
7166                                 if (0 == param_ret) {
7167                                         _message_array_set_file_info(file_info_message, 1, file_info);
7168                                         param_ret = plugin_message_set_param_array(m_result, param_idx++, file_info_message);
7169                                         plugin_message_array_destroy(file_info_message);
7170                                 }
7171                         }
7172                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7173                 } else if (NULL != error_code) {
7174                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7175                         plugin_message_set_value_number(m_result,
7176                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7177                                         (pmnumber)error_code->code);
7178                         plugin_message_set_value_string(m_result,
7179                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7180                                         error_code->msg ? error_code->msg : "");
7181                         free(error_code->msg);
7182                         free(error_code);
7183                 } else {
7184                         LOGD("API failed ret_code[%d]", ret);
7185                         plugin_message_set_value_number(m_result,
7186                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7187                 }
7188
7189                 free(parent_path);
7190                 free(folder_path);
7191                 LOGD("<<<<<< %s func end", func_name);
7192         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_MOVE_DIRECTORY,
7193                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_MOVE_DIRECTORY))) {
7194                 LOGD(">>>>>> %s func start", func_name);
7195                 char *parent_path = NULL;
7196                 char *folder_path = NULL;
7197                 char *dst_parent_path = NULL;
7198                 char *dst_folder_path = NULL;
7199
7200                 int param_idx = 1;
7201                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7202                 plugin_message_get_param_string(m_order, param_idx++, &folder_path);
7203                 plugin_message_get_param_string(m_order, param_idx++, &dst_parent_path);
7204                 plugin_message_get_param_string(m_order, param_idx++, &dst_folder_path);
7205
7206                 LOGD("Call library function");
7207                 ret = plugin->handle->move_directory(context, parent_path, folder_path, dst_parent_path, dst_folder_path,
7208                                 NULL, &file_info, &error_code, NULL);
7209
7210                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7211                         LOGD("API success");
7212                         int param_idx = 1;
7213
7214                         if (NULL != file_info) {
7215                                 LOGD("Insert file info to pipe message");
7216                                 int param_ret;
7217                                 plugin_message_array_h file_info_message = NULL;
7218                                 char message_array_type[20] = {0, };
7219                                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
7220                                                                         PLUGIN_DATA_TYPE_STRING,
7221                                                                         PLUGIN_DATA_TYPE_STRING,
7222                                                                         PLUGIN_DATA_TYPE_NUM,
7223                                                                         PLUGIN_DATA_TYPE_NUM,
7224                                                                         PLUGIN_DATA_TYPE_NUM,
7225                                                                         PLUGIN_DATA_TYPE_NUM,
7226                                                                         PLUGIN_DATA_TYPE_NUM,
7227                                                                         PLUGIN_DATA_TYPE_STRING);
7228                                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
7229                                 if (0 == param_ret) {
7230                                         _message_array_set_file_info(file_info_message, 1, file_info);
7231                                         param_ret = plugin_message_set_param_array(m_result, param_idx++, file_info_message);
7232                                         plugin_message_array_destroy(file_info_message);
7233                                 }
7234                         }
7235                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7236                 } else if (NULL != error_code) {
7237                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7238                         plugin_message_set_value_number(m_result,
7239                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7240                                         (pmnumber)error_code->code);
7241                         plugin_message_set_value_string(m_result,
7242                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7243                                         error_code->msg ? error_code->msg : "");
7244                         free(error_code->msg);
7245                         free(error_code);
7246                 } else {
7247                         LOGD("API failed ret_code[%d]", ret);
7248                         plugin_message_set_value_number(m_result,
7249                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7250                 }
7251
7252                 free(parent_path);
7253                 free(folder_path);
7254                 free(dst_parent_path);
7255                 free(dst_folder_path);
7256                 LOGD("<<<<<< %s func end", func_name);
7257         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_MOVE_FILE,
7258                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_MOVE_FILE))) {
7259                 LOGD(">>>>>> %s func start", func_name);
7260                 char *parent_path = NULL;
7261                 char *file_path = NULL;
7262                 char *dst_parent_path = NULL;
7263                 char *dst_file_path = NULL;
7264
7265                 int param_idx = 1;
7266                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7267                 plugin_message_get_param_string(m_order, param_idx++, &file_path);
7268                 plugin_message_get_param_string(m_order, param_idx++, &dst_parent_path);
7269                 plugin_message_get_param_string(m_order, param_idx++, &dst_file_path);
7270
7271                 LOGD("Call library function");
7272                 ret = plugin->handle->move_file(context, parent_path, file_path, dst_parent_path, dst_file_path,
7273                                 NULL, &file_info, &error_code, NULL);
7274
7275                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7276                         LOGD("API success");
7277                         int param_idx = 1;
7278
7279                         if (NULL != file_info) {
7280                                 LOGD("Insert file info to pipe message");
7281                                 int param_ret;
7282                                 plugin_message_array_h file_info_message = NULL;
7283                                 char message_array_type[20] = {0, };
7284                                 snprintf(message_array_type, 19, "%c%c%c%c%c%c%c%c%c", PLUGIN_DATA_TYPE_STRING,
7285                                                                         PLUGIN_DATA_TYPE_STRING,
7286                                                                         PLUGIN_DATA_TYPE_STRING,
7287                                                                         PLUGIN_DATA_TYPE_NUM,
7288                                                                         PLUGIN_DATA_TYPE_NUM,
7289                                                                         PLUGIN_DATA_TYPE_NUM,
7290                                                                         PLUGIN_DATA_TYPE_NUM,
7291                                                                         PLUGIN_DATA_TYPE_NUM,
7292                                                                         PLUGIN_DATA_TYPE_STRING);
7293                                 param_ret = plugin_message_array_create(message_array_type, &file_info_message);
7294                                 if (0 == param_ret) {
7295                                         _message_array_set_file_info(file_info_message, 1, file_info);
7296                                         param_ret = plugin_message_set_param_array(m_result, param_idx++, file_info_message);
7297                                         plugin_message_array_destroy(file_info_message);
7298                                 }
7299                         }
7300                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7301                 } else if (NULL != error_code) {
7302                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7303                         plugin_message_set_value_number(m_result,
7304                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7305                                         (pmnumber)error_code->code);
7306                         plugin_message_set_value_string(m_result,
7307                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7308                                         error_code->msg ? error_code->msg : "");
7309                         free(error_code->msg);
7310                         free(error_code);
7311                 } else {
7312                         LOGD("API failed ret_code[%d]", ret);
7313                         plugin_message_set_value_number(m_result,
7314                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7315                 }
7316
7317                 free(parent_path);
7318                 free(file_path);
7319                 free(dst_parent_path);
7320                 free(dst_file_path);
7321                 LOGD("<<<<<< %s func end", func_name);
7322         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_START_UPLOAD_TASK,
7323                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_START_UPLOAD_TASK))) {
7324                 LOGD(">>>>>> %s func start", func_name);
7325                 pmnumber fd, user_data;
7326                 char *parent_path = NULL;
7327                 char *file_name = NULL;
7328                 bool need_progress = false;
7329
7330                 int param_idx = 1;
7331                 plugin_message_get_param_number(m_order, param_idx++, &fd);
7332                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7333                 plugin_message_get_param_string(m_order, param_idx++, &file_name);
7334                 plugin_message_get_param_bool(m_order, param_idx++, &need_progress);
7335
7336                 param_idx = 1;
7337                 plugin_message_get_param_number(m_order, param_idx++, &user_data);
7338
7339                 LOGD("Call library function");
7340                 ret = plugin->handle->start_upload_task(context, (int)fd, parent_path, file_name, need_progress,
7341                                 &error_code, (void *)(intptr_t)user_data);
7342
7343                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7344                         LOGD("API success");
7345
7346                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7347                 } else if (NULL != error_code) {
7348                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7349                         plugin_message_set_value_number(m_result,
7350                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7351                                         (pmnumber)error_code->code);
7352                         plugin_message_set_value_string(m_result,
7353                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7354                                         error_code->msg ? error_code->msg : "");
7355                         free(error_code->msg);
7356                         free(error_code);
7357                 } else {
7358                         LOGD("API failed ret_code[%d]", ret);
7359                         plugin_message_set_value_number(m_result,
7360                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7361                 }
7362
7363                 free(parent_path);
7364                 free(file_name);
7365                 LOGD("<<<<<< %s func end", func_name);
7366         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_TASK,
7367                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_TASK))) {
7368                 LOGD(">>>>>> %s func start", func_name);
7369                 pmnumber fd, user_data;
7370                 char *parent_path = NULL;
7371                 char *file_name = NULL;
7372                 bool need_progress = false;
7373
7374                 int param_idx = 1;
7375                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7376                 plugin_message_get_param_string(m_order, param_idx++, &file_name);
7377                 plugin_message_get_param_number(m_order, param_idx++, &fd);
7378                 plugin_message_get_param_bool(m_order, param_idx++, &need_progress);
7379
7380                 param_idx = 1;
7381                 plugin_message_get_param_number(m_order, param_idx++, &user_data);
7382
7383                 LOGD("Call library function");
7384                 ret = plugin->handle->start_download_task(context, parent_path, file_name, (int)fd, need_progress,
7385                                 &error_code, (void *)(intptr_t)user_data);
7386
7387                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7388                         LOGD("API success");
7389
7390                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7391                 } else if (NULL != error_code) {
7392                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7393                         plugin_message_set_value_number(m_result,
7394                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7395                                         (pmnumber)error_code->code);
7396                         plugin_message_set_value_string(m_result,
7397                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7398                                         error_code->msg ? error_code->msg : "");
7399                         free(error_code->msg);
7400                         free(error_code);
7401                 } else {
7402                         LOGD("API failed ret_code[%d]", ret);
7403                         plugin_message_set_value_number(m_result,
7404                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7405                 }
7406
7407                 free(parent_path);
7408                 free(file_name);
7409                 LOGD("<<<<<< %s func end", func_name);
7410         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_THUMB_TASK,
7411                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_START_DOWNLOAD_THUMB_TASK))) {
7412                 LOGD(">>>>>> %s func start", func_name);
7413                 pmnumber fd, thumb_size, user_data;
7414                 char *parent_path = NULL;
7415                 char *file_name = NULL;
7416                 bool need_progress = false;
7417
7418                 int param_idx = 1;
7419                 plugin_message_get_param_string(m_order, param_idx++, &parent_path);
7420                 plugin_message_get_param_string(m_order, param_idx++, &file_name);
7421                 plugin_message_get_param_number(m_order, param_idx++, &fd);
7422                 plugin_message_get_param_number(m_order, param_idx++, &thumb_size);
7423                 plugin_message_get_param_bool(m_order, param_idx++, &need_progress);
7424
7425                 param_idx = 1;
7426                 plugin_message_get_param_number(m_order, param_idx++, &user_data);
7427
7428                 LOGD("Call library function");
7429                 ret = plugin->handle->start_download_thumb_task(context, parent_path, file_name, (int)fd, (int)thumb_size, need_progress,
7430                                 &error_code, (void *)(intptr_t)user_data);
7431
7432                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7433                         LOGD("API success");
7434
7435                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7436                 } else if (NULL != error_code) {
7437                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7438                         plugin_message_set_value_number(m_result,
7439                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7440                                         (pmnumber)error_code->code);
7441                         plugin_message_set_value_string(m_result,
7442                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7443                                         error_code->msg ? error_code->msg : "");
7444                         free(error_code->msg);
7445                         free(error_code);
7446                 } else {
7447                         LOGD("API failed ret_code[%d]", ret);
7448                         plugin_message_set_value_number(m_result,
7449                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7450                 }
7451
7452                 free(parent_path);
7453                 free(file_name);
7454                 LOGD("<<<<<< %s func end", func_name);
7455         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_CANCEL_UPLOAD_TASK,
7456                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_CANCEL_UPLOAD_TASK))) {
7457                 LOGD(">>>>>> %s func start", func_name);
7458                 pmnumber fd;
7459
7460                 int param_idx = 1;
7461                 plugin_message_get_param_number(m_order, param_idx++, &fd);
7462
7463                 LOGD("Call library function");
7464                 ret = plugin->handle->cancel_upload_task(context, (int)fd, &error_code);
7465
7466                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7467                         LOGD("API success");
7468
7469                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7470                 } else if (NULL != error_code) {
7471                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7472                         plugin_message_set_value_number(m_result,
7473                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7474                                         (pmnumber)error_code->code);
7475                         plugin_message_set_value_string(m_result,
7476                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7477                                         error_code->msg ? error_code->msg : "");
7478                         free(error_code->msg);
7479                         free(error_code);
7480                 } else {
7481                         LOGD("API failed ret_code[%d]", ret);
7482                         plugin_message_set_value_number(m_result,
7483                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7484                 }
7485
7486                 LOGD("<<<<<< %s func end", func_name);
7487         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_TASK,
7488                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_TASK))) {
7489                 LOGD(">>>>>> %s func start", func_name);
7490                 pmnumber fd;
7491
7492                 int param_idx = 1;
7493                 plugin_message_get_param_number(m_order, param_idx++, &fd);
7494
7495                 LOGD("Call library function");
7496                 ret = plugin->handle->cancel_download_task(context, (int)fd, &error_code);
7497
7498                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7499                         LOGD("API success");
7500
7501                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7502                 } else if (NULL != error_code) {
7503                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7504                         plugin_message_set_value_number(m_result,
7505                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7506                                         (pmnumber)error_code->code);
7507                         plugin_message_set_value_string(m_result,
7508                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7509                                         error_code->msg ? error_code->msg : "");
7510                         free(error_code->msg);
7511                         free(error_code);
7512                 } else {
7513                         LOGD("API failed ret_code[%d]", ret);
7514                         plugin_message_set_value_number(m_result,
7515                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7516                 }
7517
7518                 LOGD("<<<<<< %s func end", func_name);
7519         } else if (0 == strncmp(STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_THUMB_TASK,
7520                         func_name, strlen(STORAGE_PLUGIN_INTERFACE_CANCEL_DOWNLOAD_THUMB_TASK))) {
7521                 LOGD(">>>>>> %s func start", func_name);
7522                 pmnumber fd;
7523
7524                 int param_idx = 1;
7525                 plugin_message_get_param_number(m_order, param_idx++, &fd);
7526
7527                 LOGD("Call library function");
7528                 ret = plugin->handle->cancel_download_thumb_task(context, (int)fd, &error_code);
7529
7530                 if (STORAGE_ADAPTOR_ERROR_NONE == ret) {
7531                         LOGD("API success");
7532
7533                         plugin_message_set_value_number(m_result, PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7534                 } else if (NULL != error_code) {
7535                         LOGD("API failed, error_code[%lld / %s]", (long long int)error_code->code, error_code->msg);
7536                         plugin_message_set_value_number(m_result,
7537                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7538                                         (pmnumber)error_code->code);
7539                         plugin_message_set_value_string(m_result,
7540                                         PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7541                                         error_code->msg ? error_code->msg : "");
7542                         free(error_code->msg);
7543                         free(error_code);
7544                 } else {
7545                         LOGD("API failed ret_code[%d]", ret);
7546                         plugin_message_set_value_number(m_result,
7547                                         PLUGIN_MESSAGE_ELEMENT_RESULT_CODE, (pmnumber)ret);
7548                 }
7549
7550                 LOGD("<<<<<< %s func end", func_name);
7551         } else { /* TODO Next */
7552                 LOGD(">>>>>> %s func start", func_name);
7553                 plugin_message_set_value_number(m_result,
7554                                 PLUGIN_MESSAGE_ELEMENT_RESULT_CODE,
7555                                 (pmnumber)STORAGE_ADAPTOR_ERROR_UNSUPPORTED);
7556                 plugin_message_set_value_string(m_result,
7557                                 PLUGIN_MESSAGE_ELEMENT_RESULT_MESSAGE,
7558                                 "Unsupported operation");
7559                 LOGD("<<<<<< %s func end", func_name);
7560         }
7561
7562         storage_adaptor_destroy_file_info(&file_info);
7563         free(func_name);
7564
7565         char *result_data = NULL;
7566         plugin_message_serialize(m_result, &result_data);
7567         plugin_message_destroy(m_result);
7568         plugin_message_destroy(m_order);
7569
7570         *result = result_data;
7571 }