1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
|
/*
* oma-dm-agent
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*sync-agent*/
#include <sync_agent.h>
/*dm-agent*/
#include "common/dm_common.h"
#include "serviceadapter/sa_command.h"
#include "serviceadapter/sa_command_internal.h"
#include "serviceadapter/sa_elements.h"
#include "serviceadapter/sa_elements_internal.h"
#include "serviceadapter/sa_session.h"
#include "serviceadapter/sa_session_internal.h"
#ifndef OMADM_AGENT_LOG
#undef LOG_TAG
#define LOG_TAG "OMA_DM_SA"
#endif
static Command *_create_Cmd(Session * pSession, CommandType type);
static Command *_create_Cmd(Session * pSession, CommandType type)
{
_INNER_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((pSession) == NULL, NULL, "pSession is NULL!!");
retvm_if((type) == COMMAND_TYPE_UNKNOWN, NULL, "type is NULL!!");
_DEBUG_TRACE(" start type : %d msgID : %d cmdID : %d\n", type, pSession->msgID, pSession->cmdID);
Command *cmd = (Command *) calloc(1, sizeof(Command));
if (cmd == NULL) {
ret = COMMON_ERR_ALLOC;
goto error;
}
cmd->type = type;
cmd->msgID = pSession->msgID;
cmd->cmdID = pSession->cmdID;
cmd->refCount = 1;
PendingStatus *temp = NULL;
ret = create_prependingstatus(pSession->msgID, pSession->cmdID, &temp);
if (ret != DM_OK)
goto error;
pSession->pendingStatus = g_list_append(pSession->pendingStatus, temp);
pSession->cmdID++;
_DEBUG_INFO("session cmdId : %d", pSession->cmdID);
_DEBUG_TRACE(" end\n");
_INNER_FUNC_EXIT;
return cmd;
error:
free_command(cmd);
_DEBUG_TRACE(" error : %d\n", ret);
_INNER_FUNC_EXIT;
return NULL;
}
DM_ERROR duplicate_command(Command * source, Command ** target)
{
_EXTERN_FUNC_ENTER;
retvm_if((source) == NULL, COMMON_ERR_IS_NULL, "command is NULL!!");
DM_ERROR ret = DM_OK;
CommandType type = source->type;
switch (type) {
case COMMAND_TYPE_RESULTS:
{
_DEBUG_INFO("dup result command");
*target = (Command *) calloc(1, sizeof(Command));
if (*target == NULL) {
ret = COMMON_ERR_ALLOC;
goto error;
}
(*target)->type = type;
(*target)->msgID = source->msgID;
(*target)->cmdID = source->cmdID;
(*target)->refCount = 1;
if (source->source != NULL) {
_DEBUG_INFO("source location");
(*target)->source = dup_location(source->source);
}
if (source->target) {
_DEBUG_INFO("taget location");
(*target)->target = dup_location(source->target);
}
_DEBUG_INFO("result data cmdRef : %d, msgRef : %d", source->private.results.cmdRef, source->private.results.msgRef);
(*target)->private.results.cmdRef = source->private.results.cmdRef;
(*target)->private.results.msgRef = source->private.results.msgRef;
if (source->private.results.targetRef) {
_DEBUG_INFO("target ref");
(*target)->private.results.targetRef = dup_location(source->private.results.targetRef);
}
if (source->private.results.type) {
_DEBUG_INFO("type");
(*target)->private.results.type = strdup(source->private.results.type);
}
if (source->private.results.items) {
_DEBUG_INFO("result item list");
GList *iter_list = NULL;
Item *temp = NULL;
for (iter_list = source->private.results.items; iter_list != NULL; iter_list = g_list_next(iter_list)) {
_DEBUG_INFO("result item");
temp = (Item *) iter_list->data;
Item *dup_item = NULL;
if (temp->source != NULL) {
if (temp->source->locURI != NULL) {
_DEBUG_INFO("loc uri : %s", temp->source->locURI);
}
ret = construct_Item(temp->source->locURI, temp->format, temp->contenttype, temp->private.data, temp->size, temp->moreData, &dup_item);
_DEBUG_INFO("construct item : %d", ret);
(*target)->private.results.items = g_list_append((*target)->private.results.items, dup_item);
} else {
_DEBUG_INFO("source is null");
}
}
}
}
break;
case COMMAND_TYPE_ALERT:
case COMMAND_TYPE_HEADER:
case COMMAND_TYPE_ADD:
case COMMAND_TYPE_REPLACE:
case COMMAND_TYPE_DELETE:
case COMMAND_TYPE_GET:
case COMMAND_TYPE_EXEC:
case COMMAND_TYPE_SEQUENCE:
case COMMAND_TYPE_ATOMIC:
case COMMAND_TYPE_COPY:
case COMMAND_TYPE_UNKNOWN:
break;
}
_EXTERN_FUNC_EXIT;
return ret;
error:
_EXTERN_FUNC_EXIT;
return ret;
}
void free_commands(GList * commands)
{
_EXTERN_FUNC_ENTER;
if (commands == NULL) {
_EXTERN_FUNC_EXIT;
return;
}
GList *iter = NULL;
Command *pCommand = NULL;
for (iter = commands; iter != NULL;) {
pCommand = iter->data;
_DEBUG_INFO("command type is %d\n", pCommand->type);
iter = g_list_next(iter);
commands = g_list_remove(commands, pCommand);
if (pCommand->type != COMMAND_TYPE_UNKNOWN) {
free_command(pCommand);
_DEBUG_INFO("free command");
}
}
_DEBUG_INFO("free command list");
g_list_free(commands);
_EXTERN_FUNC_EXIT;
return;
}
DM_ERROR set_correlator(Command ** pAlertCommand, char *pCorrelator)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((*pAlertCommand) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "pAlertCommand is NULL!!");
retvm_if((pCorrelator) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "pCorrelator is NULL!!");
(*pAlertCommand)->private.alert.Correlator = g_strdup(pCorrelator);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR create_alert_cmd(Session * session, AlertType syncType, Command ** pCommand)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
*pCommand = _create_Cmd(session, COMMAND_TYPE_ALERT);
if ((*pCommand) == NULL) {
ret = COMMON_ERR_INTERNAL_NO_MEMORY;
goto error;
}
(*pCommand)->private.alert.type = syncType;
_EXTERN_FUNC_EXIT;
return ret;
error:
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR create_replace_cmd(Session * session, Command ** pCommand)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "session is NULL!!");
(*pCommand) = _create_Cmd(session, COMMAND_TYPE_REPLACE);
if ((*pCommand) == NULL) {
ret = COMMON_ERR_INTERNAL_NO_MEMORY;
goto error;
}
(*pCommand)->private.change.type = CHANGE_REPLACE;
_EXTERN_FUNC_EXIT;
return ret;
error:
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR create_results_cmd(Session * session, Command ** pCommand)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "session is NULL!!");
*pCommand = _create_Cmd(session, COMMAND_TYPE_RESULTS);
if ((*pCommand) == NULL) {
ret = COMMON_ERR_INTERNAL_NO_MEMORY;
goto error;
}
_EXTERN_FUNC_EXIT;
return ret;
error:
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR create_add_cmd(Session * session, char *luid, const char *contenttype, char *data, unsigned int size, int moreData, Command ** pCommand)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "session is NULL!!");
retvm_if((luid) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "luid is NULL!!");
retvm_if((contenttype) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "contenttype is NULL!!");
Item *temp = NULL;
Location *pLocation = NULL;
*pCommand = _create_Cmd(session, COMMAND_TYPE_ADD);
if (*pCommand == NULL) {
ret = COMMON_ERR_INTERNAL_NO_MEMORY;
goto error;
}
ret = create_item_data(data, size, &temp);
if (ret != DM_OK) {
ret = COMMON_ERR_INTERNAL_NO_MEMORY;
goto error;
}
(*pCommand)->private.change.type = CHANGE_ADD;
temp->contenttype = g_strdup(contenttype);
temp->moreData = moreData;
ret = create_location(luid, NULL, &pLocation);
if (ret != DM_OK)
goto error;
set_itemsource(temp, pLocation);
(*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
_EXTERN_FUNC_EXIT;
return ret;
error:
free_Item(temp);
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR create_delete_cmd(Session * session, char *luid, const char *contenttype, Command ** pCommand)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "session is NULL!!");
retvm_if((luid) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "luid is NULL!!");
retvm_if((contenttype) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "contenttype is NULL!!");
Item *temp = NULL;
Location *pLocation = NULL;
*pCommand = _create_Cmd(session, COMMAND_TYPE_DELETE);
if (*pCommand == NULL) {
ret = COMMON_ERR_INTERNAL_NO_MEMORY;
goto error;
}
temp = create_Item();
if (temp == NULL) {
ret = COMMON_ERR_INTERNAL_NO_MEMORY;
goto error;
}
(*pCommand)->private.change.type = CHANGE_DELETE;
ret = create_location(luid, NULL, &pLocation);
if (ret != DM_OK)
goto error;
set_itemsource(temp, pLocation);
temp->contenttype = g_strdup(contenttype);
(*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
_EXTERN_FUNC_EXIT;
return ret;
error:
free_Item(temp);
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
void free_command(Command * pCommand)
{
_EXTERN_FUNC_ENTER;
if (pCommand == NULL) {
_EXTERN_FUNC_EXIT;
return;
}
GList *iter = NULL;
_DEBUG_INFO(" Command type is %d", pCommand->type);
if (pCommand->refCount > 1) {
_DEBUG_INFO("Command's refCount is %d\n", pCommand->refCount);
/*decrease_command_refcount(pCommand); */
_EXTERN_FUNC_EXIT;
return;
}
switch (pCommand->type) {
case COMMAND_TYPE_ALERT:
_DEBUG_INFO("alert type : %d", pCommand->private.alert.type);
if ((pCommand->private.alert.type >= DM_ALERT_DISPLAY && pCommand->private.alert.type <= DM_ALERT_MULTIPLE_CHOICE)
&& pCommand->private.alert.items != NULL) {
for (iter = pCommand->private.alert.items; iter != NULL; iter = g_list_next(iter)) {
free_Item((Item *) iter->data);
}
}
_DEBUG_INFO("alert correlator");
if (pCommand->private.alert.Correlator != NULL) {
free(pCommand->private.alert.Correlator);
pCommand->private.alert.Correlator = NULL;
}
break;
case COMMAND_TYPE_HEADER:
_DEBUG_INFO("header type");
//COMMAND_TYPE_HEADER doesnot come here
break;
case COMMAND_TYPE_ADD:
case COMMAND_TYPE_REPLACE:
case COMMAND_TYPE_DELETE:
case COMMAND_TYPE_COPY:
_DEBUG_INFO("add repalce delete type");
if (pCommand->private.change.items != NULL) {
for (iter = pCommand->private.change.items; iter != NULL; iter = g_list_next(iter)) {
free_Item(iter->data);
}
}
break;
case COMMAND_TYPE_GET:
_DEBUG_INFO("get type");
if (pCommand->private.access.type != NULL) {
free(pCommand->private.access.type);
pCommand->private.access.type = NULL;
}
if (pCommand->private.access.items != NULL) {
for (iter = pCommand->private.access.items; iter != NULL; iter = g_list_next(iter)) {
free_Item(iter->data);
}
}
break;
case COMMAND_TYPE_RESULTS:
_DEBUG_INFO("result type");
if (pCommand->private.results.type != NULL) {
free(pCommand->private.results.type);
pCommand->private.results.type = NULL;
}
if (pCommand->private.results.items != NULL) {
for (iter = pCommand->private.results.items; iter != NULL; iter = g_list_next(iter)) {
free_Item(iter->data);
}
}
break;
case COMMAND_TYPE_EXEC:
_DEBUG_INFO("exec type");
if (pCommand->private.exec.correlator != NULL) {
free(pCommand->private.exec.correlator);
pCommand->private.exec.correlator = NULL;
}
if (pCommand->private.exec.item != NULL) {
free_Item(pCommand->private.exec.item);
}
break;
case COMMAND_TYPE_UNKNOWN:
_DEBUG_INFO("unknown type");
break;
case COMMAND_TYPE_SEQUENCE:
case COMMAND_TYPE_ATOMIC:
_DEBUG_INFO("sequence atomic copy type");
if (pCommand->private.sequence_atomic.commands != NULL) {
for (iter = pCommand->private.sequence_atomic.commands; iter != NULL; iter = g_list_next(iter)) {
free_command(iter->data);
}
}
break;
default:
break;
}
_DEBUG_INFO("command source");
if (pCommand->source != NULL) {
free_location(pCommand->source);
pCommand->source = NULL;
}
_DEBUG_INFO("command target");
if (pCommand->target != NULL) {
free_location(pCommand->target);
pCommand->target = NULL;
}
_DEBUG_INFO("free command ");
free(pCommand);
pCommand = NULL;
_DEBUG_INFO("free command end");
_EXTERN_FUNC_EXIT;
}
void free_statuses(GList * status)
{
_EXTERN_FUNC_ENTER;
if (!status) {
_DEBUG_INFO(" List is null\n");
_EXTERN_FUNC_EXIT;
return;
}
GList *iter = NULL;
int i = 0;
_DEBUG_INFO(" count : %d\n", g_list_length(status));
for (iter = status; iter != NULL; iter = g_list_next(iter)) {
_DEBUG_INFO(" count : %d\n", ++i);
free_status(iter->data);
}
g_list_free(status);
_EXTERN_FUNC_EXIT;
}
void free_status(Status * pStatus)
{
_EXTERN_FUNC_ENTER;
if (pStatus == NULL) {
_EXTERN_FUNC_EXIT;
return;
}
if (pStatus->data != NULL)
free(pStatus->data);
if (pStatus->sourceRef != NULL)
free_location(pStatus->sourceRef);
if (pStatus->targetRef != NULL)
free_location(pStatus->targetRef);
/*
if(pStatus->res_chal)
free_chal(pStatus->res_chal);
if(pStatus->cred)
free_cred(pStatus->cred);*/
//free_Item(pStatus->item);
GList *iter = NULL;
for (iter = pStatus->items; iter != NULL; iter = g_list_next(iter))
free_Item(iter->data);
if (pStatus != NULL) {
free(pStatus);
pStatus = NULL;
}
_EXTERN_FUNC_EXIT;
}
DM_ERROR get_statuscode(Status * status)
{
_EXTERN_FUNC_ENTER;
retvm_if((status) == NULL, DM_ERR_FORBIDDEN, "status is NULL!!");
_EXTERN_FUNC_EXIT;
return atoi(status->data);
}
ChangeType converttochangetype(unsigned int type)
{
_EXTERN_FUNC_ENTER;
ChangeType changeType = CHANGE_UNKNOWN;
switch (type) {
case 1:
changeType = CHANGE_ADD;
break;
case 2:
changeType = CHANGE_REPLACE;
break;
case 3:
changeType = CHANGE_DELETE;
break;
case 4:
changeType = CHANGE_COPY;
break;
}
_EXTERN_FUNC_EXIT;
return changeType;
}
unsigned int convertfromchangetype(ChangeType changeType)
{
_EXTERN_FUNC_ENTER;
unsigned int type = 0;
switch (changeType) {
case CHANGE_ADD:
type = 1;
break;
case CHANGE_REPLACE:
type = 2;
break;
case CHANGE_DELETE:
type = 3;
break;
case CHANGE_UNKNOWN:
break;
case CHANGE_COPY:
type = 4;
break;
default:
break;
}
_EXTERN_FUNC_EXIT;
return type;
}
CommandType converttocommandtype(char *type)
{
_EXTERN_FUNC_ENTER;
retvm_if((type) == NULL, COMMAND_TYPE_UNKNOWN, "type is NULL!!");
if (strcmp(type, "Alert") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_ALERT;
} else if (strcmp(type, "SyncHdr") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_HEADER;
} else if (strcmp(type, "Add") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_ADD;
} else if (strcmp(type, "Replace") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_REPLACE;
} else if (strcmp(type, "Delete") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_DELETE;
} else if (strcmp(type, "Results") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_RESULTS;
} else if (strcmp(type, "Get") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_GET;
} else if (strcmp(type, "Exec") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_EXEC;
} else if (strcmp(type, "Sequence") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_SEQUENCE;
} else if (strcmp(type, "Atomic") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_ATOMIC;
} else if (strcmp(type, "Copy") == 0) {
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_COPY;
}
_EXTERN_FUNC_EXIT;
return COMMAND_TYPE_UNKNOWN;
}
char *convertfromcommandtype(CommandType type)
{
_EXTERN_FUNC_ENTER;
char *commandType = NULL;
switch (type) {
case COMMAND_TYPE_ALERT:
commandType = "Alert";
break;
case COMMAND_TYPE_HEADER:
commandType = "SyncHdr";
break;
case COMMAND_TYPE_ADD:
commandType = "Add";
break;
case COMMAND_TYPE_REPLACE:
commandType = "Replace";
break;
case COMMAND_TYPE_DELETE:
commandType = "Delete";
break;
case COMMAND_TYPE_RESULTS:
commandType = "Results";
break;
case COMMAND_TYPE_GET:
commandType = "Get";
break;
case COMMAND_TYPE_EXEC:
commandType = "Exec";
break;
case COMMAND_TYPE_ATOMIC:
commandType = "Atomic";
break;
case COMMAND_TYPE_SEQUENCE:
commandType = "Sequence";
break;
case COMMAND_TYPE_COPY:
commandType = "Copy";
break;
default:
commandType = "UNKNOWN";
}
_EXTERN_FUNC_EXIT;
return commandType;
}
ChangeType convertToChangeTypeFromCommandType(CommandType type)
{
_EXTERN_FUNC_ENTER;
ChangeType changeType = CHANGE_UNKNOWN;
switch (type) {
case COMMAND_TYPE_ADD:
changeType = CHANGE_ADD;
break;
case COMMAND_TYPE_REPLACE:
changeType = CHANGE_REPLACE;
break;
case COMMAND_TYPE_DELETE:
changeType = CHANGE_DELETE;
break;
case COMMAND_TYPE_COPY:
changeType = CHANGE_COPY;
break;
case COMMAND_TYPE_UNKNOWN:
case COMMAND_TYPE_ALERT:
case COMMAND_TYPE_HEADER:
case COMMAND_TYPE_GET:
case COMMAND_TYPE_RESULTS:
case COMMAND_TYPE_EXEC:
case COMMAND_TYPE_SEQUENCE:
case COMMAND_TYPE_ATOMIC:
_DEBUG_INFO("not changetype command");
break;
default:
break;
}
_EXTERN_FUNC_EXIT;
return changeType;
}
CommandType convertToCommandTypeFromChangeType(ChangeType type)
{
_EXTERN_FUNC_ENTER;
CommandType commandType = COMMAND_TYPE_UNKNOWN;
switch (type) {
case CHANGE_UNKNOWN:
commandType = COMMAND_TYPE_UNKNOWN;
break;
case CHANGE_ADD:
commandType = COMMAND_TYPE_ADD;
break;
case CHANGE_REPLACE:
commandType = COMMAND_TYPE_REPLACE;
break;
case CHANGE_DELETE:
commandType = COMMAND_TYPE_DELETE;
break;
case CHANGE_COPY:
commandType = COMMAND_TYPE_COPY;
break;
}
_EXTERN_FUNC_EXIT;
return commandType;
}
DM_ERROR create_newstatuslocation(Session * session, DM_ERROR data, Command * command, Location * sourceref, Location * targetref, CommandType type, Status ** pStatus)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((session) == NULL, COMMON_ERR_IS_NULL, "session is NULL!!");
retvm_if((command) == NULL, COMMON_ERR_IS_NULL, "command is NULL!!");
ret = create_status(data, session->cmdID, session->lastRecievedMsgID, command->cmdID, sourceref, targetref, NULL, type, pStatus);
if (ret != DM_OK)
goto error;
session->cmdID++;
_DEBUG_INFO("session cmdId : %d", session->cmdID);
_DEBUG_INFO(" end %d\n", data);
_EXTERN_FUNC_EXIT;
return ret;
error:
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR create_newstatus(Session * session, DM_ERROR data, Command * command, Location * sourceref, Location * targetref, CommandType type, Status ** pStatus)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((session) == NULL, COMMON_ERR_IS_NULL, "session is NULL!!");
retvm_if((command) == NULL, COMMON_ERR_IS_NULL, "command is NULL!!");
ret = create_status(data, session->cmdID, session->lastRecievedMsgID, command->cmdID, sourceref, targetref, NULL, type, pStatus);
if (ret != DM_OK)
goto error;
session->cmdID++;
_DEBUG_INFO("session cmdId : %d", session->cmdID);
_EXTERN_FUNC_EXIT;
return ret;
error:
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR create_status(DM_ERROR data, unsigned int cmdID, unsigned int msgref, unsigned int cmdref, Location * sourceref, Location * targetref, Chal * pChal, CommandType type, Status ** pStatus)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
_DEBUG_INFO("cmdref : %d msgref : %d", cmdref, msgref);
_DEBUG_INFO("create status : %d", data);
*pStatus = (Status *) calloc(1, sizeof(Status));
if (*pStatus == NULL) {
ret = COMMON_ERR_ALLOC;
goto error;
}
(*pStatus)->cmdID = cmdID;
(*pStatus)->msgRef = msgref;
(*pStatus)->cmdRef = cmdref;
(*pStatus)->type = type;
(*pStatus)->data = g_strdup_printf("%d", data);
if (sourceref != NULL) {
(*pStatus)->sourceRef = dup_location(sourceref);
}
if (targetref != NULL) {
(*pStatus)->targetRef = dup_location(targetref);
if (targetref->locName != NULL) {
_DEBUG_INFO("targetref : %s", targetref->locName);
}
if (targetref->locURI != NULL) {
_DEBUG_INFO("targetref : %s", targetref->locURI);
}
}
if (pChal != NULL)
(*pStatus)->chal = dup_chal(pChal);
_EXTERN_FUNC_EXIT;
return ret;
error:
_DEBUG_INFO(" error : %d\n", ret);
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR set_status_data(Session * session, Command * pCommand, Item * item, DM_ERROR data)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "session is NULL!!");
retvm_if((pCommand) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "pCommand is NULL!!");
retvm_if((item) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "item is NULL!!");
GList *status_iter = NULL;
Status *temp = NULL;
char *target_url = get_location_locuri(item->target);
for (status_iter = session->status; status_iter != NULL; status_iter = g_list_next(status_iter)) {
temp = status_iter->data;
if (pCommand->cmdID == temp->cmdRef && strcmp(temp->targetRef->locURI, target_url) == 0) {
status_iter->data = g_strdup_printf("%d", data);
break;
}
}
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR set_resultscommand_msgref(Command * pCommand, unsigned int msgRef)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((pCommand) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "pCommand is NULL!!");
pCommand->private.results.msgRef = msgRef;
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR set_resultscommand_cmdref(Command * pCommand, unsigned int cmdRef)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((pCommand) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "pCommand is NULL!!");
pCommand->private.results.cmdRef = cmdRef;
_EXTERN_FUNC_EXIT;
return ret;
}
DM_ERROR set_resultscommand_targetref(Command * pCommand, Location * pLocation)
{
_EXTERN_FUNC_ENTER;
DM_ERROR ret = DM_OK;
retvm_if((pCommand) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "pCommand is NULL!!");
retvm_if((pLocation) == NULL, COMMON_ERR_INTERNAL_NO_MEMORY, "pLocation is NULL!!");
pCommand->private.results.targetRef = dup_location(pLocation);
_EXTERN_FUNC_EXIT;
return ret;
}
|