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