Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / service-adapter / sa_command.c
1 /*
2  * oma-ds-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /**
19  *   @SA_Command.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of functions for command structure which is used in Service Adapter
22  */
23
24 #include <stdlib.h>
25
26 #include <sync_agent.h>
27
28 #include "service-adapter/sa_command.h"
29 #include "service-adapter/sa_command_internal.h"
30 #include "service-adapter/sa_elements.h"
31 #include "service-adapter/sa_elements_internal.h"
32 #include "service-adapter/sa_session.h"
33 #include "service-adapter/sa_session_internal.h"
34
35 #ifndef OMADS_AGENT_LOG
36 #undef LOG_TAG
37 #define LOG_TAG "OMA_DS_SA"
38 #endif
39
40 static command_s *_create_command(session_s * session, command_type_e type);
41
42 static command_s *_create_command(session_s * session, command_type_e type)
43 {
44         _INNER_FUNC_ENTER;
45         sa_error_type_e errorType = SA_INTERNAL_OK;
46
47         if (session == NULL) {
48                 errorType = SA_INTERNAL_NOT_DEFINED;
49                 goto error;
50         }
51
52         if (!type) {
53                 errorType = SA_INTERNAL_NOT_DEFINED;
54                 goto error;
55         }
56
57         command_s *cmd = (command_s *) calloc(1, sizeof(command_s));
58         if (cmd == NULL) {
59                 errorType = SA_INTERNAL_NO_MEMORY;
60                 goto error;
61         }
62
63         cmd->type = type;
64         cmd->msg_id = session->msg_id;
65         cmd->cmd_id = session->cmd_id;
66         cmd->ref_count = 1;
67
68         session->cmd_id++;
69
70         _INNER_FUNC_EXIT;
71         return cmd;
72
73  error:
74         _INNER_FUNC_EXIT;
75         return NULL;
76 }
77
78 void free_commands(GList * commands)
79 {
80         _EXTERN_FUNC_ENTER;
81
82         retm_if(commands == NULL, "List is NULL");
83
84         _DEBUG_INFO("start list length is %d", g_list_length(commands));
85
86         GList *iter = NULL;
87         command_s *pCommand = NULL;
88         for (iter = commands; iter != NULL;) {
89                 pCommand = iter->data;
90                 _DEBUG_INFO("command list length is %d command type is %d\n", g_list_length(commands), pCommand->type);
91
92                 iter = g_list_next(iter);
93                 if (pCommand->type != COMMAND_TYPE_UNKNOWN) {
94                         commands = g_list_remove(commands, pCommand);
95                         free_command(pCommand);
96                 }
97         }
98
99         g_list_free(commands);
100
101         _EXTERN_FUNC_EXIT;
102         return;
103 }
104
105 sa_error_type_e create_alert_command(session_s * session, alert_type_e sync_type, location_s * source, location_s * target, char *last_anchor, char *next_anchor, cred_s * cred, command_s ** command)
106 {
107         _EXTERN_FUNC_ENTER;
108         _DEBUG_INFO("start with syncType =%d", sync_type);
109
110         sa_error_type_e errorType = SA_INTERNAL_OK;
111         anchor_s *pAnchor = NULL;
112
113         if (source == NULL) {
114                 errorType = SA_INTERNAL_NOT_DEFINED;
115                 goto error;
116         }
117
118         if (target == NULL) {
119                 errorType = SA_INTERNAL_NOT_DEFINED;
120                 goto error;
121         }
122
123         *command = _create_command(session, COMMAND_TYPE_ALERT);
124         if (*command == NULL) {
125                 errorType = SA_INTERNAL_NO_MEMORY;
126                 goto error;
127         }
128
129         (*command)->target = target;
130         (*command)->source = source;
131
132         /*TODO  check that sync Type is ALERT_NEXT_MESSAGE(does not need last and next anchor) */
133         /*TODO  check that sync Type is  ALERT_SLOW_SYNC(does not need last anchor) */
134
135         if (next_anchor != NULL) {
136                 errorType = create_anchor(last_anchor, next_anchor, &pAnchor);
137                 if (errorType != SA_INTERNAL_OK)
138                         goto error;
139
140                 (*command)->private.alert.anchor = pAnchor;
141                 pAnchor = NULL;
142         }
143
144         if (cred != NULL)
145                 (*command)->cred = dup_cred(cred);
146
147         (*command)->private.alert.type = sync_type;
148
149         _EXTERN_FUNC_EXIT;
150         return errorType;
151
152  error:
153
154         if (pAnchor != NULL)
155                 free_anchor(pAnchor);
156
157         _EXTERN_FUNC_EXIT;
158         return errorType;
159 }
160
161 sa_error_type_e create_get_command(session_s * session, location_s * target, const char *content_type, command_s ** command)
162 {
163         _EXTERN_FUNC_ENTER;
164         _DEBUG_INFO("start with content type = %s", content_type);
165
166         sa_error_type_e errorType = SA_INTERNAL_OK;
167
168         if (target == NULL) {
169                 errorType = SA_INTERNAL_NOT_DEFINED;
170                 goto error;
171         }
172
173         *command = _create_command(session, COMMAND_TYPE_GET);
174         if (*command == NULL) {
175                 errorType = SA_INTERNAL_NO_MEMORY;
176                 goto error;
177         }
178
179         (*command)->private.access.item = create_item();
180         if ((*command)->private.access.item == NULL) {
181                 errorType = SA_INTERNAL_NO_MEMORY;
182                 goto error;
183         }
184
185         set_item_target((*command)->private.access.item, target);
186
187         if (content_type != NULL)
188                 (*command)->private.access.item->content_type = strdup(content_type);
189
190  error:
191
192         _EXTERN_FUNC_EXIT;
193         return errorType;
194 }
195
196 sa_error_type_e create_put_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command)
197 {
198         _EXTERN_FUNC_ENTER;
199         _DEBUG_INFO("start with content type = %s", content_type);
200
201         sa_error_type_e errorType = SA_INTERNAL_OK;
202
203         if (source == NULL) {
204                 errorType = SA_INTERNAL_NOT_DEFINED;
205                 goto error;
206         }
207
208         *command = _create_command(session, COMMAND_TYPE_PUT);
209         if (*command == NULL) {
210                 errorType = SA_INTERNAL_NO_MEMORY;
211                 goto error;
212         }
213
214         (*command)->private.access.item = create_item_for_devinf(devinf);
215
216         if ((*command)->private.access.item == NULL) {
217                 errorType = SA_INTERNAL_NO_MEMORY;
218                 goto error;
219         }
220
221         set_item_source((*command)->private.access.item, source);
222
223         if (content_type != NULL)
224                 (*command)->private.access.item->content_type = strdup(content_type);
225
226  error:
227
228         _EXTERN_FUNC_EXIT;
229         return errorType;
230 }
231
232 sa_error_type_e create_results_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command)
233 {
234         _EXTERN_FUNC_ENTER;
235         _DEBUG_INFO("start with content type = %s", content_type);
236
237         sa_error_type_e errorType = SA_INTERNAL_OK;
238
239         if (source == NULL) {
240                 errorType = SA_INTERNAL_NOT_DEFINED;
241                 goto error;
242         }
243
244         *command = _create_command(session, COMMAND_TYPE_RESULTS);
245         if (*command == NULL) {
246                 errorType = SA_INTERNAL_NO_MEMORY;
247                 goto error;
248         }
249
250         (*command)->private.results.item = create_item_for_devinf(devinf);
251
252         if ((*command)->private.results.item == NULL) {
253                 errorType = SA_INTERNAL_NO_MEMORY;
254                 goto error;
255         }
256
257         set_item_source((*command)->private.results.item, source);
258
259         if (content_type != NULL)
260                 (*command)->private.results.item->content_type = strdup(content_type);
261
262  error:
263
264         _EXTERN_FUNC_EXIT;
265         return errorType;
266 }
267
268 sa_error_type_e create_sync_start_command(session_s * session, location_s * source, location_s * target, command_s ** command)
269 {
270         _EXTERN_FUNC_ENTER;
271
272         sa_error_type_e errorType = SA_INTERNAL_OK;
273
274         if (source == NULL) {
275                 errorType = SA_INTERNAL_NOT_DEFINED;
276                 goto error;
277         }
278
279         if (target == NULL) {
280                 errorType = SA_INTERNAL_NOT_DEFINED;
281                 goto error;
282         }
283
284         *command = _create_command(session, COMMAND_TYPE_SYNC_START);
285         if (*command == NULL) {
286                 errorType = SA_INTERNAL_NO_MEMORY;
287                 goto error;
288         }
289
290         (*command)->source = source;
291         (*command)->target = target;
292
293  error:
294
295         _EXTERN_FUNC_EXIT;
296         return errorType;
297 }
298
299 sa_error_type_e set_sync_start_command_number_of_changes(command_s * command, unsigned int number_of_changes)
300 {
301         _EXTERN_FUNC_ENTER;
302
303         sa_error_type_e errorType = SA_INTERNAL_OK;
304
305         if (command == NULL) {
306                 errorType = SA_INTERNAL_NOT_DEFINED;
307                 goto error;
308         }
309
310         command->private.sync.has_num_changed = 1;
311         command->private.sync.num_changed = number_of_changes;
312
313  error:
314
315         _EXTERN_FUNC_EXIT;
316         return errorType;
317 }
318
319 sa_error_type_e set_sync_start_command_mem(command_s * command, mem_s * mem)
320 {
321         _EXTERN_FUNC_ENTER;
322
323         sa_error_type_e errorType = SA_INTERNAL_OK;
324
325         if (command == NULL) {
326                 errorType = SA_INTERNAL_NOT_DEFINED;
327                 goto error;
328         }
329
330         command->private.sync.mem = mem;
331
332  error:
333
334         _EXTERN_FUNC_EXIT;
335         return errorType;
336
337 }
338
339 sa_error_type_e create_sync_end_command(command_s ** command)
340 {
341         _EXTERN_FUNC_ENTER;
342
343         sa_error_type_e errorType = SA_INTERNAL_OK;
344
345         *command = (command_s *) calloc(1, sizeof(command_s));
346         if (*command == NULL) {
347                 errorType = SA_INTERNAL_NO_MEMORY;
348                 goto error;
349         }
350
351         (*command)->type = COMMAND_TYPE_SYNC_END;
352
353  error:
354
355         _EXTERN_FUNC_EXIT;
356         return errorType;
357 }
358
359 sa_error_type_e create_add_command(session_s * session, change_type_e type, char *luid, const char *content_type, char *data, unsigned int size, int more_data, command_s ** command)
360 {
361         _EXTERN_FUNC_ENTER;
362         _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type);
363
364         sa_error_type_e errorType = SA_INTERNAL_OK;
365         item_s *temp = NULL;
366         location_s *pLocation = NULL;
367
368         *command = _create_command(session, COMMAND_TYPE_ADD);
369         if (*command == NULL) {
370                 errorType = SA_INTERNAL_NO_MEMORY;
371                 goto error;
372         }
373
374         temp = create_item_for_data(data, size);
375         if (!temp) {
376                 errorType = SA_INTERNAL_NO_MEMORY;
377                 goto error;
378         }
379
380         (*command)->private.change.type = type;
381         if (content_type != NULL)
382                 temp->content_type = strdup(content_type);
383         temp->more_data = more_data;
384
385         errorType = create_location(luid, NULL, &pLocation);
386         if (errorType != SA_INTERNAL_OK)
387                 goto error;
388
389         set_item_source(temp, pLocation);
390         (*command)->private.change.items = g_list_append((*command)->private.change.items, temp);
391         temp = NULL;
392
393  error:
394
395         if (temp != NULL)
396                 free(temp);
397
398         _EXTERN_FUNC_EXIT;
399         return errorType;
400 }
401
402 sa_error_type_e create_replace_command(session_s * session, change_type_e type, char *luid, const char *content_type, const char *data, unsigned int size, int more_data, command_s ** command)
403 {
404         _EXTERN_FUNC_ENTER;
405         _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type);
406
407         sa_error_type_e errorType = SA_INTERNAL_OK;
408         item_s *temp = NULL;
409         location_s *pLocation = NULL;
410
411         *command = _create_command(session, COMMAND_TYPE_REPLACE);
412         if (*command == NULL) {
413                 errorType = SA_INTERNAL_NO_MEMORY;
414                 goto error;
415         }
416
417         temp = create_item_for_data(data, size);
418         if (!temp) {
419                 errorType = SA_INTERNAL_NO_MEMORY;
420                 goto error;
421         }
422
423         (*command)->private.change.type = type;
424         if (content_type != NULL)
425                 temp->content_type = strdup(content_type);
426         temp->more_data = more_data;
427
428         errorType = create_location(luid, NULL, &pLocation);
429         if (errorType != SA_INTERNAL_OK)
430                 goto error;
431
432         set_item_source(temp, pLocation);
433         (*command)->private.change.items = g_list_append((*command)->private.change.items, temp);
434         temp = NULL;
435
436  error:
437
438         if (temp != NULL)
439                 free(temp);
440
441         _EXTERN_FUNC_EXIT;
442         return errorType;
443 }
444
445 sa_error_type_e create_delete_command(session_s * session, change_type_e type, char *luid, const char *content_type, command_s ** command)
446 {
447         _EXTERN_FUNC_ENTER;
448         _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type);
449
450         sa_error_type_e errorType = SA_INTERNAL_OK;
451         item_s *temp = NULL;
452         location_s *pLocation = NULL;
453
454         *command = _create_command(session, COMMAND_TYPE_DELETE);
455         if (*command == NULL) {
456                 errorType = SA_INTERNAL_NO_MEMORY;
457                 goto error;
458         }
459
460         temp = create_item();
461         if (temp == NULL) {
462                 errorType = SA_INTERNAL_NO_MEMORY;
463                 goto error;
464         }
465
466         (*command)->private.change.type = type;
467
468         errorType = create_location(luid, NULL, &pLocation);
469         if (errorType != SA_INTERNAL_OK)
470                 goto error;
471
472         set_item_source(temp, pLocation);
473         if (content_type != NULL)
474                 temp->content_type = strdup(content_type);
475         (*command)->private.change.items = g_list_append((*command)->private.change.items, temp);
476         temp = NULL;
477
478  error:
479
480         if (temp != NULL)
481                 free(temp);
482
483         _EXTERN_FUNC_EXIT;
484         return errorType;
485
486 }
487
488 sa_error_type_e create_map_command(session_s * session, location_s * source, location_s * target, command_s ** command)
489 {
490         _EXTERN_FUNC_ENTER;
491
492         sa_error_type_e errorType = SA_INTERNAL_OK;
493
494         if (source == NULL) {
495                 errorType = SA_INTERNAL_NOT_DEFINED;
496                 goto error;
497         }
498
499         if (target == NULL) {
500                 errorType = SA_INTERNAL_NOT_DEFINED;
501                 goto error;
502         }
503
504         *command = _create_command(session, COMMAND_TYPE_MAP);
505         if (*command == NULL) {
506                 errorType = SA_INTERNAL_NO_MEMORY;
507                 goto error;
508         }
509
510         (*command)->source = source;
511         (*command)->target = target;
512
513  error:
514
515         _EXTERN_FUNC_EXIT;
516         return errorType;
517 }
518
519 sa_error_type_e set_map_command_item(command_s * map_command, item_s * temp)
520 {
521         _EXTERN_FUNC_ENTER;
522
523         sa_error_type_e errorType = SA_INTERNAL_OK;
524
525         if (map_command == NULL) {
526                 errorType = SA_INTERNAL_NOT_DEFINED;
527                 goto error;
528         }
529
530         map_command->private.map.items = g_list_append(map_command->private.map.items, temp);
531
532  error:
533
534         _EXTERN_FUNC_EXIT;
535         return errorType;
536 }
537
538 sa_error_type_e increase_command_ref_count(command_s * command)
539 {
540         _EXTERN_FUNC_ENTER;
541         sa_error_type_e errorType = SA_INTERNAL_OK;
542
543         if (command == NULL) {
544                 errorType = SA_INTERNAL_NOT_DEFINED;
545                 goto error;
546         }
547
548         command->ref_count++;
549
550  error:
551
552         _EXTERN_FUNC_EXIT;
553         return errorType;
554 }
555
556 sa_error_type_e decrease_command_ref_count(command_s * command)
557 {
558         _EXTERN_FUNC_ENTER;
559         sa_error_type_e errorType = SA_INTERNAL_OK;
560
561         if (command == NULL) {
562                 errorType = SA_INTERNAL_NOT_DEFINED;
563                 goto error;
564         }
565
566         command->ref_count--;
567
568  error:
569
570         _EXTERN_FUNC_EXIT;
571         return errorType;
572 }
573
574 sa_error_type_e set_results_command_msg_ref(command_s * command, unsigned int msg_ref)
575 {
576         _EXTERN_FUNC_ENTER;
577         sa_error_type_e errorType = SA_INTERNAL_OK;
578
579         if (command == NULL) {
580                 errorType = SA_INTERNAL_NOT_DEFINED;
581                 goto error;
582         }
583
584         command->private.results.msg_ref = msg_ref;
585
586  error:
587
588         _EXTERN_FUNC_EXIT;
589         return errorType;
590 }
591
592 sa_error_type_e set_results_command_cmd_ref(command_s * command, unsigned int cmd_ref)
593 {
594         _EXTERN_FUNC_ENTER;
595         sa_error_type_e errorType = SA_INTERNAL_OK;
596
597         if (command == NULL) {
598                 errorType = SA_INTERNAL_NOT_DEFINED;
599                 goto error;
600         }
601
602         command->private.results.cmd_ref = cmd_ref;
603
604  error:
605
606         _EXTERN_FUNC_EXIT;
607         return errorType;
608 }
609
610 sa_error_type_e set_results_command_target_ref(command_s * command, location_s * location)
611 {
612         _EXTERN_FUNC_ENTER;
613         sa_error_type_e errorType = SA_INTERNAL_OK;
614
615         if (command == NULL) {
616                 errorType = SA_INTERNAL_NOT_DEFINED;
617                 goto error;
618         }
619
620         _DEBUG_INFO("start with Command Type =%d\n", command->type);
621
622         command->private.results.target_ref = dup_location(location);
623
624  error:
625
626         _EXTERN_FUNC_EXIT;
627         return errorType;
628 }
629
630 void free_command(command_s * command)
631 {
632         _EXTERN_FUNC_ENTER;
633
634         retm_if(command == NULL, "pCommand is NULL");
635
636         _DEBUG_INFO("start with  Command type is %d", command->type);
637
638         GList *iter = NULL;
639
640         if (command->ref_count > 1) {
641                 _DEBUG_INFO("Command's refCount is %d", command->ref_count);
642                 decrease_command_ref_count(command);
643                 return;
644         }
645
646         switch (command->type) {
647         case COMMAND_TYPE_ALERT:
648                 if (command->private.alert.anchor != NULL) {
649                         free_anchor(command->private.alert.anchor);
650                         command->private.alert.anchor = NULL;
651                 }
652
653                 if (command->private.alert.content_type != NULL) {
654                         free(command->private.alert.content_type);
655                         command->private.alert.content_type = NULL;
656                 }
657                 break;
658         case COMMAND_TYPE_SYNC_START:
659                 /*nothing to free */
660                 break;
661         case COMMAND_TYPE_SYNC_END:
662                 /*nothing to free */
663                 break;
664         case COMMAND_TYPE_PUT:
665                 if (command->private.access.type != NULL) {
666                         free(command->private.access.type);
667                         command->private.access.type = NULL;
668                 }
669
670                 if (command->private.access.item != NULL) {
671                         free_item(command->private.access.item);
672                         command->private.access.item = NULL;
673                 }
674                 break;
675         case COMMAND_TYPE_HEADER:
676                 /*COMMAND_TYPE_HEADER doesnot come here */
677                 break;
678         case COMMAND_TYPE_ADD:
679         case COMMAND_TYPE_REPLACE:
680         case COMMAND_TYPE_DELETE:
681                 for (iter = command->private.change.items; iter != NULL; iter = g_list_next(iter))
682                         free_item(iter->data);
683                 break;
684         case COMMAND_TYPE_MAP:
685                 for (iter = command->private.map.items; iter != NULL; iter = g_list_next(iter))
686                         free_item(iter->data);
687                 break;
688         case COMMAND_TYPE_GET:
689                 if (command->private.access.type != NULL) {
690                         free(command->private.access.type);
691                         command->private.access.type = NULL;
692                 }
693
694                 if (command->private.access.item != NULL) {
695                         free_item(command->private.access.item);
696                         command->private.access.item = NULL;
697                 }
698                 break;
699         case COMMAND_TYPE_RESULTS:
700                 if (command->private.results.type != NULL) {
701                         free(command->private.results.type);
702                         command->private.results.type = NULL;
703                 }
704
705                 if (command->private.results.item != NULL) {
706                         free_item(command->private.results.item);
707                         command->private.results.item = NULL;
708                 }
709
710                 if (command->private.results.target_ref != NULL) {
711                         free_location(command->private.results.target_ref);
712                         command->private.results.target_ref = NULL;
713                 }
714
715                 break;
716         case COMMAND_TYPE_UNKNOWN:
717                 break;
718         }
719
720         if (command->source != NULL) {
721                 free_location(command->source);
722                 command->source = NULL;
723         }
724
725         if (command->target != NULL) {
726                 free_location(command->target);
727                 command->target = NULL;
728         }
729
730         if (command->cred != NULL) {
731                 free_cred(command->cred);
732                 command->cred = NULL;
733         }
734
735         free(command);
736
737         _EXTERN_FUNC_EXIT;
738 }
739
740 sa_error_type_e create_new_status_location(session_s * session, oma_status_type_e data, command_s * command, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status)
741 {
742         _EXTERN_FUNC_ENTER;
743         _DEBUG_INFO("start Errortype %d", data);
744
745         sa_error_type_e errorType = SA_INTERNAL_OK;
746
747         errorType = create_status(data, session->cmd_id, session->last_recieved_msg_id, command->cmd_id, source_ref, target_ref, type, status);
748         if (errorType != SA_INTERNAL_OK)
749                 goto error;
750
751         session->cmd_id++;
752
753  error:
754
755         _EXTERN_FUNC_EXIT;
756         return errorType;
757 }
758
759 sa_error_type_e create_new_status(session_s * session, oma_status_type_e data, command_s * command, command_type_e type, status_s ** status)
760 {
761         _EXTERN_FUNC_ENTER;
762         _DEBUG_INFO("start Errortype %d", data);
763
764         sa_error_type_e errorType = SA_INTERNAL_OK;
765
766         errorType = create_status(data, session->cmd_id, session->last_recieved_msg_id, command->cmd_id, command->source, command->target, type, status);
767         if (errorType != SA_INTERNAL_OK)
768                 goto error;
769
770         session->cmd_id++;
771
772  error:
773
774         _EXTERN_FUNC_EXIT;
775         return errorType;
776 }
777
778 sa_error_type_e create_status(oma_status_type_e data, unsigned int cmd_id, unsigned int msg_ref, unsigned int cmd_ref, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status)
779 {
780         _EXTERN_FUNC_ENTER;
781         _DEBUG_INFO("start Errortype %d", data);
782
783         sa_error_type_e errorType = SA_INTERNAL_OK;
784
785         *status = (status_s *) calloc(1, sizeof(status_s));
786         if (*status == NULL) {
787                 errorType = SA_INTERNAL_NO_MEMORY;
788                 goto error;
789         }
790
791         (*status)->cmd_id = cmd_id;
792         (*status)->msg_ref = msg_ref;
793         (*status)->cmd_ref = cmd_ref;
794         (*status)->type = type;
795         (*status)->data = g_strdup_printf("%d", data);
796
797         if (source_ref != NULL)
798                 (*status)->source_ref = dup_location(source_ref);
799
800         if (target_ref != NULL)
801                 (*status)->target_ref = dup_location(target_ref);
802
803  error:
804
805         _EXTERN_FUNC_EXIT;
806         return errorType;
807 }
808
809 void free_statuses(GList * statuses)
810 {
811         _EXTERN_FUNC_ENTER;
812
813         retm_if(statuses == NULL, "List is NULL");
814
815         GList *iter = NULL;
816         status_s *status = NULL;
817         _DEBUG_INFO("count : %d", g_list_length(statuses));
818         for (iter = statuses; iter != NULL; iter = g_list_next(iter)) {
819                 status = (status_s *) iter->data;
820                 free_status(status);
821         }
822
823         g_list_free(statuses);
824
825         _EXTERN_FUNC_EXIT;
826 }
827
828 void free_status(status_s * status)
829 {
830         _EXTERN_FUNC_ENTER;
831
832         retm_if(status == NULL, "pStatus is NULL");
833
834         if (status->data != NULL)
835                 free(status->data);
836
837         if (status->source_ref != NULL)
838                 free_location(status->source_ref);
839
840         if (status->target_ref != NULL)
841                 free_location(status->target_ref);
842
843         if (status->cred != NULL)
844                 free_cred(status->cred);
845
846         if (status->chal != NULL)
847                 free_chal(status->chal);
848
849         free_item(status->item);
850
851         free(status);
852         status = NULL;
853
854         _EXTERN_FUNC_EXIT;
855 }
856
857 oma_status_type_e get_status_code(status_s * status)
858 {
859         _EXTERN_FUNC_ENTER;
860
861         _EXTERN_FUNC_EXIT;
862
863         return atoi(status->data);
864 }
865
866 command_type_e convert_command_type(char *type)
867 {
868         _EXTERN_FUNC_ENTER;
869
870         command_type_e commandType = COMMAND_TYPE_UNKNOWN;
871
872         retvm_if(type == NULL, commandType, "type is NULL");
873
874         if (!strcmp(type, "Alert")) {
875                 commandType = COMMAND_TYPE_ALERT;
876         } else if (!strcmp(type, "Sync")) {
877                 commandType = COMMAND_TYPE_SYNC_START;
878         } else if (!strcmp(type, "Put")) {
879                 commandType = COMMAND_TYPE_PUT;
880         } else if (!strcmp(type, "SyncHdr")) {
881                 commandType = COMMAND_TYPE_HEADER;
882         } else if (!strcmp(type, "Add")) {
883                 commandType = COMMAND_TYPE_ADD;
884         } else if (!strcmp(type, "Replace")) {
885                 commandType = COMMAND_TYPE_REPLACE;
886         } else if (!strcmp(type, "Map")) {
887                 commandType = COMMAND_TYPE_MAP;
888         } else if (!strcmp(type, "Delete")) {
889                 commandType = COMMAND_TYPE_DELETE;
890         } else if (!strcmp(type, "Results")) {
891                 commandType = COMMAND_TYPE_RESULTS;
892         } else if (!strcmp(type, "Get")) {
893                 commandType = COMMAND_TYPE_GET;
894         }
895
896         _EXTERN_FUNC_EXIT;
897         return commandType;
898 }
899
900 change_type_e convert_change_type_command_type(command_type_e type)
901 {
902         _EXTERN_FUNC_ENTER;
903
904         change_type_e changeType = CHANGE_UNKNOWN;
905         switch (type) {
906         case COMMAND_TYPE_UNKNOWN:
907         case COMMAND_TYPE_ALERT:
908         case COMMAND_TYPE_SYNC_START:
909         case COMMAND_TYPE_SYNC_END:
910         case COMMAND_TYPE_PUT:
911         case COMMAND_TYPE_HEADER:
912         case COMMAND_TYPE_MAP:
913         case COMMAND_TYPE_GET:
914         case COMMAND_TYPE_RESULTS:
915                 /*never comes these commands */
916                 break;
917         case COMMAND_TYPE_ADD:
918                 changeType = CHANGE_ADD;
919                 break;
920         case COMMAND_TYPE_REPLACE:
921                 changeType = CHANGE_REPLACE;
922                 break;
923         case COMMAND_TYPE_DELETE:
924                 changeType = CHANGE_DELETE;
925                 break;
926         }
927
928         _EXTERN_FUNC_EXIT;
929         return changeType;
930 }
931
932 command_type_e convert_command_type_change_type(change_type_e type)
933 {
934         _EXTERN_FUNC_ENTER;
935
936         command_type_e commandType = COMMAND_TYPE_UNKNOWN;
937
938         switch (type) {
939         case CHANGE_UNKNOWN:
940                 commandType = COMMAND_TYPE_UNKNOWN;
941                 break;
942         case CHANGE_ADD:
943                 commandType = COMMAND_TYPE_ADD;
944                 break;
945         case CHANGE_REPLACE:
946                 commandType = COMMAND_TYPE_REPLACE;
947                 break;
948         case CHANGE_DELETE:
949                 commandType = COMMAND_TYPE_DELETE;
950                 break;
951         }
952
953         _EXTERN_FUNC_EXIT;
954         return commandType;
955 }
956
957 /*
958 ChangeType convertToChangeType(unsigned int type) {
959
960         ChangeType changeType=CHANGE_UNKNOWN;
961         switch (type) {
962         case 1:
963                 changeType = CHANGE_ADD;
964                 break;
965         case 2:
966                 changeType = CHANGE_REPLACE;
967                 break;
968         case 3:
969                 changeType = CHANGE_DELETE;
970                 break;
971         }
972
973         return changeType;
974 }
975
976 char *convertFromCommandType(CommandType type) {
977         char *commandType=NULL;
978
979         switch (type) {
980         case COMMAND_TYPE_ALERT:
981                 commandType = "Alert";
982                 break;
983         case COMMAND_TYPE_SYNC_START:
984         case COMMAND_TYPE_SYNC_END:
985                 commandType = "Sync";
986                 break;
987         case COMMAND_TYPE_PUT:
988                 commandType = "Put";
989                 break;
990         case COMMAND_TYPE_HEADER:
991                 commandType = "SyncHdr";
992                 break;
993         case COMMAND_TYPE_ADD:
994                 commandType = "Add";
995                 break;
996         case COMMAND_TYPE_REPLACE:
997                 commandType = "Replace";
998                 break;
999         case COMMAND_TYPE_MAP:
1000                 commandType = "Map";
1001                 break;
1002         case COMMAND_TYPE_DELETE:
1003                 commandType = "Delete";
1004                 break;
1005         case COMMAND_TYPE_RESULTS:
1006                 commandType = "Results";
1007                 break;
1008         case COMMAND_TYPE_GET:
1009                 commandType = "Get";
1010                 break;
1011         default:
1012                 commandType="UNKNOWN";
1013         }
1014         return commandType;
1015 }
1016 */