summaryrefslogtreecommitdiff
path: root/src/agent/serviceadapter/sa_command.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/agent/serviceadapter/sa_command.c')
-rw-r--r--src/agent/serviceadapter/sa_command.c944
1 files changed, 944 insertions, 0 deletions
diff --git a/src/agent/serviceadapter/sa_command.c b/src/agent/serviceadapter/sa_command.c
new file mode 100644
index 0000000..47d9b3a
--- /dev/null
+++ b/src/agent/serviceadapter/sa_command.c
@@ -0,0 +1,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;
+
+}