/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/

#include "SctsCommandElements.h"
#include "SctsPlatformLib.h"
#include "SctsErrorLog.h"

#ifdef __SCTS_USING_RTK__
#include "mgrutil.h"

char sctsCommandStrings[SCTS_COMMAND_COUNT][15]=
{
	"Add",
	"Alert",
	"Atomic",
	"End Atomic",
	"Copy",
	"Delete",
	"Exec",
	"Get",
	"Map",
	"Put",
	"Results",
	"Search",
	"Sequence",
	"End Sequence",
	"Status",
	"Sync",
	"End Sync",
	"Replace",
	"SyncHdr",
	"End Message"
};

/*****************************************************************
SctsCommand Definition
******************************************************************/
bool SctsCommand::VerifyDTD(SctsSyncMLProto proto)
{
	return true;
}
	
/*****************************************************************
SctsGeneric Definition
******************************************************************/
SctsPcdata& SctsGeneric::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsGeneric::SetCommandID(int commandID)
{
	SCTSASSERT(rawData);
	if (rawData->cmdID) smlFreePcdata(rawData->cmdID);
	rawData->cmdID=sctsInt2Pcdata(commandID);
}

void SctsGeneric::MakeStub()
{
	SCTSASSERT(rawData);
	SCTSRTKFREEITEMLISTDATA(rawData->itemList);
}

void SctsGeneric::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsGeneric::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsGeneric::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsGeneric::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

void SctsGeneric::SetItemList(SctsItemList *pItemList)
{
	SCTSRTKSETITEMLIST(rawData->itemList,pItemList);
}

SctsItemList& SctsGeneric::GetItemList(SctsItemList& itemList)
{
	SCTSRTKGETITEMLIST(rawData->itemList,itemList);
}

bool SctsGeneric::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsGeneric::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

SctsGeneric::SctsGeneric(SmlGenericCmdPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsGeneric::SctsGeneric(unsigned int cmdID,SctsItemList& itemList)
{
	rawData=(SmlGenericCmdPtr_t)sctsMalloc(sizeof(SmlGenericCmd_t));
	sctsMemset(rawData,0,sizeof(SmlGenericCmd_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->itemList=itemList.rawData;
}

SctsGeneric::~SctsGeneric()
{
	SCTSASSERT(rawData);
	smlFreeGeneric(rawData);
}

/*****************************************************************
SctsAdd Definition
******************************************************************/
void SctsAdd::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlAddCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

SctsCommandType SctsAdd::GetType()
{
	return SCTS_ADD;
}

/*****************************************************************
SctsCopy Definition
******************************************************************/
void SctsCopy::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlCopyCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

SctsCommandType SctsCopy::GetType()
{
	return SCTS_COPY;
}

/*****************************************************************
SctsDelete Definition
******************************************************************/
void SctsDelete::IsSoftDel(bool isSoftDel)
{
	SCTSASSERT(rawData);
	if (isSoftDel)
		((SmlDeletePtr_t)rawData)->flags|=SmlSftDel_f;
	else
		((SmlDeletePtr_t)rawData)->flags&=~SmlSftDel_f;
}


void SctsDelete::IsArchive(bool isArchive)
{
	SCTSASSERT(rawData);
	if (isArchive)
		((SmlDeletePtr_t)rawData)->flags|=SmlArchive_f;
	else
		((SmlDeletePtr_t)rawData)->flags&=~SmlArchive_f;
}

void SctsDelete::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlDeleteCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

SctsCommandType SctsDelete::GetType()
{
	return SCTS_DELETE;
}

/*****************************************************************
SctsReplace Definition
******************************************************************/
void SctsReplace::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlReplaceCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

SctsCommandType SctsReplace::GetType()
{
	return SCTS_REPLACE;
}

/*****************************************************************
SctsGetPut Definition
******************************************************************/
SctsPcdata& SctsGetPut::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsGetPut::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->lang)
	{
		smlFreePcdata(rawData->lang);
		rawData->lang=0;
	}
	if (rawData->cred)
	{
		smlFreeCredPtr(rawData->cred);
		rawData->cred=0;
	}
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
	SCTSRTKFREEITEMLISTDATA(rawData->itemList);
}

void SctsGetPut::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsGetPut::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsGetPut::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsGetPut::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

void SctsGetPut::SetItemList(SctsItemList *pItemList)
{
	SCTSRTKSETITEMLIST(rawData->itemList,pItemList);
}

SctsItemList& SctsGetPut::GetItemList(SctsItemList &itemList)
{
	SCTSRTKGETITEMLIST(rawData->itemList,itemList);
}

void SctsGetPut::SetLang(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->lang,pPcdata);
}

SctsPcdata& SctsGetPut::GetLang(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->lang,pcdata);
}

bool SctsGetPut::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsGetPut::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

SctsGetPut::SctsGetPut(sml_get_put_s * pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}
SctsGetPut::SctsGetPut(unsigned int cmdID,SctsItemList& itemList)
{
	rawData=(sml_get_put_s *)sctsMalloc(sizeof(sml_get_put_s));
	sctsMemset(rawData,0,sizeof(sml_get_put_s));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->itemList=itemList.rawData;
}

SctsGetPut::~SctsGetPut()
{
	SCTSASSERT(rawData);
	smlFreeGetPut(rawData);
}

/*****************************************************************
SctsGet Definition
******************************************************************/
void SctsGet::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlGetCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

SctsCommandType SctsGet::GetType()
{
	return SCTS_GET;
}

/*****************************************************************
SctsPut Definition
******************************************************************/
void SctsPut::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlPutCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

SctsCommandType SctsPut::GetType()
{
	return SCTS_PUT;
}

/*****************************************************************
SctsSearch Definition
******************************************************************/
void SctsSearch::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
	if (rawData->lang)
	{
		smlFreePcdata(rawData->lang);
		rawData->lang=0;
	}
	if (rawData->data)
	{
		smlFreePcdata(rawData->data);
		rawData->data=0;
	}
	if (rawData->cred)
	{
		smlFreeCredPtr(rawData->cred);
		rawData->cred=0;
	}
}

SctsCommandType SctsSearch::GetType()
{
	return SCTS_SEARCH;
}

SctsPcdata& SctsSearch::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsSearch::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlSearchCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsSearch::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsSearch::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

void SctsSearch::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsSearch::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsSearch::SetTarget(char *pLocURI,char *pLocName)
{
	SCTSASSERT(rawData);
	SCTSRTKSETTARGETSOURCE(rawData->target,pLocURI,pLocName);
}

SctsTargetSource& SctsSearch::GetTarget(SctsTargetSource& target)
{
	SCTSASSERT(rawData);
	SCTSRTKGETTARGETSOURCE(rawData->target,target);
}

void SctsSearch::SetSourceList(SctsSourceList *pSourceList)
{
	SCTSASSERT(rawData);
	if (rawData->sourceList) smlFreeSourceList(rawData->sourceList);
	if (pSourceList)
		rawData->sourceList=pSourceList->rawData;
	else
		rawData->sourceList=0;
}

SctsSourceList& SctsSearch::GetSourceList(SctsSourceList& sourceList)
{
	SCTSASSERT(rawData);
	sourceList.rawData=rawData->sourceList;
	return sourceList;
}

void SctsSearch::SetData(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->data,pPcdata);
}

SctsPcdata& SctsSearch::GetData(SctsPcdata &pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->data,pcdata);
}

void SctsSearch::SetLang(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->lang,pPcdata);
}

SctsPcdata& SctsSearch::GetLang(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->lang,pcdata);
}

bool SctsSearch::IsNoResults()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResults_f)==SmlNoResults_f;
}

void SctsSearch::IsNoResults(bool isNoResults)
{
	SCTSASSERT(rawData);
	if (isNoResults)
		rawData->flags|=SmlNoResults_f;
	else
		rawData->flags&=~SmlNoResults_f;
}

bool SctsSearch::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsSearch::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}
	
SctsSearch::SctsSearch(SmlSearchPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsSearch::SctsSearch(unsigned int cmdID,SctsMeta *pMeta,SctsPcdata *pData)
{
	rawData=(SmlSearchPtr_t)sctsMalloc(sizeof(SmlSearch_t));
	sctsMemset(rawData,0,sizeof(SmlSearch_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	if (pMeta) rawData->meta=SctsPcdata(*pMeta).rawData;
	if (pData) rawData->data=pData->rawData;
}

SctsSearch::~SctsSearch()
{
	SCTSASSERT(rawData);
	smlFreeSearch(rawData);
}

/*****************************************************************
SctsResults Definition
******************************************************************/
void SctsResults::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
	SCTSRTKFREEITEMLISTDATA(rawData->itemList);
}	

SctsCommandType SctsResults::GetType()
{
	return SCTS_RESULTS;
}

void SctsResults::SetCommandID(int commandID)
{
	SCTSASSERT(rawData);
	if (rawData->cmdID) smlFreePcdata(rawData->cmdID);
	rawData->cmdID=sctsInt2Pcdata(commandID);
}

SctsPcdata& SctsResults::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsResults::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlResultsCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsResults::SetMsgRef(int msgRef)
{
	SCTSASSERT(rawData);
	SCTSRTKSETINT(rawData->msgRef,msgRef);
}

int SctsResults::GetMsgRef()
{
	SCTSASSERT(rawData);
	if (!rawData->msgRef) return 1;
	SCTSRTKGETINT(rawData->msgRef);
}

void SctsResults::SetCmdRef(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->cmdRef,pPcdata);
}

SctsPcdata& SctsResults::GetCmdRef(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdRef,pcdata);
}

void SctsResults::SetTargetRef(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->targetRef,pPcdata);
}

SctsPcdata& SctsResults::GetTargetRef(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->targetRef,pcdata);
}

void SctsResults::SetSourceRef(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->sourceRef,pPcdata);
}

SctsPcdata& SctsResults::GetSourceRef(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->sourceRef,pcdata);
}

void SctsResults::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsResults::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

void SctsResults::SetItemList(SctsItemList *pItemList)
{
	SCTSRTKSETITEMLIST(rawData->itemList,pItemList);
}

SctsItemList& SctsResults::GetItemList(SctsItemList& itemList)
{
	SCTSRTKGETITEMLIST(rawData->itemList,itemList);
}

SctsResults::SctsResults(SmlResultsPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsResults::SctsResults(unsigned int cmdID,char *pCmdRef,SctsItemList& itemList)
{
	rawData=(SmlResultsPtr_t)sctsMalloc(sizeof(SmlResults_t));
	sctsMemset(rawData,0,sizeof(SmlResults_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->cmdRef=smlString2Pcdata(pCmdRef);
	rawData->itemList=itemList.rawData;
}

SctsResults::~SctsResults()
{
	SCTSASSERT(rawData);
	smlFreeResults(rawData);
}

/*****************************************************************
SctsAtomic Definition
******************************************************************/
void SctsAtomic::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
}

SctsCommandType SctsAtomic::GetType()
{
	return SCTS_ATOMIC_START;
}

SctsPcdata& SctsAtomic::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsAtomic::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlStartAtomic(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsAtomic::BuildClose(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlEndAtomic(sessionContext);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsAtomic::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsAtomic::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

bool SctsAtomic::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsAtomic::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

SctsAtomic::SctsAtomic(SmlAtomicPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsAtomic::SctsAtomic(unsigned int cmdID,SctsMeta *pMeta)
{
	rawData=(SmlAtomicPtr_t)sctsMalloc(sizeof(SmlAtomic_t));
	sctsMemset(rawData,0,sizeof(SmlAtomic_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	if (pMeta) rawData->meta=SctsPcdata(*pMeta).rawData;
}

SctsAtomic::~SctsAtomic()
{
	SCTSASSERT(rawData);
	smlFreeAtomic(rawData);
};

/*****************************************************************
SctsSequence Definition
******************************************************************/
void SctsSequence::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
}

SctsCommandType SctsSequence::GetType()
{
	return SCTS_SEQUENCE_START;
}

SctsPcdata& SctsSequence::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsSequence::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlStartSequence(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsSequence::BuildClose(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlEndSequence(sessionContext);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsSequence::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsSequence::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

bool SctsSequence::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsSequence::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

SctsSequence::SctsSequence(SmlSequencePtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsSequence::SctsSequence(unsigned int cmdID,SctsMeta *pMeta)
{
	rawData=(SmlSequencePtr_t)sctsMalloc(sizeof(SmlSequence_t));
	sctsMemset(rawData,0,sizeof(SmlSequence_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	if (pMeta) rawData->meta=SctsPcdata(*pMeta).rawData;
}

SctsSequence::~SctsSequence()
{
	SCTSASSERT(rawData);
	smlFreeAtomic(rawData);
};

/*****************************************************************
SctsSync Definition
******************************************************************/
void SctsSync::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
	if (rawData->cred)
	{
		smlFreeCredPtr(rawData->cred);
		rawData->cred=0;
	}
}	

SctsCommandType SctsSync::GetType()
{
	return SCTS_SYNC_START;
}

SctsPcdata& SctsSync::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsSync::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlStartSync(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsSync::BuildClose(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlEndSync(sessionContext);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsSync::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsSync::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

void SctsSync::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsSync::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsSync::SetTarget(char *pLocURI,char *pLocName)
{
	SCTSASSERT(rawData);
	SCTSRTKSETTARGETSOURCE(rawData->target,pLocURI,pLocName);
}

SctsTargetSource& SctsSync::GetTarget(SctsTargetSource& target)
{
	SCTSASSERT(rawData);
	SCTSRTKGETTARGETSOURCE(rawData->target,target);
}

void SctsSync::SetSource(char *pLocURI,char *pLocName)
{
	SCTSASSERT(rawData);
	SCTSRTKSETTARGETSOURCE(rawData->source,pLocURI,pLocName);
}

SctsTargetSource& SctsSync::GetSource(SctsTargetSource& source)
{
	SCTSASSERT(rawData);
	SCTSRTKGETTARGETSOURCE(rawData->source,source);
}

bool SctsSync::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

/* SyncML 1.1 : N of M */
void SctsSync::SetNumberOfChanges(int n)
{
	SCTSASSERT(rawData);
	SCTSRTKSETINT(rawData->noc,n);
}

int SctsSync::GetNumberOfChanges()
{
	SCTSASSERT(rawData);
	SCTSRTKGETINT(rawData->noc);
}

void SctsSync::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

SctsSync::SctsSync(SmlSyncPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsSync::SctsSync(unsigned int cmdID,char *pSourceLocURI,char *pSourceLocName,char *pTargetLocURI,char *pTargetLocName)
{
	rawData=(SmlSyncPtr_t)sctsMalloc(sizeof(SmlSync_t));
	sctsMemset(rawData,0,sizeof(SmlSync_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->source=SctsTargetSource(pSourceLocURI,pSourceLocName).rawData;
	rawData->target=SctsTargetSource(pTargetLocURI,pTargetLocName).rawData;
}

SctsSync::~SctsSync()
{
	SCTSASSERT(rawData);
	smlFreeSync(rawData);
}


/*****************************************************************
SctsAlert Definition
******************************************************************/
void SctsAlert::MakeStub()  
{
	SCTSASSERT(rawData);
	if (rawData->cred)
	{
		smlFreeCredPtr(rawData->cred);
		rawData->cred=0;
	}
	if (rawData->data)
	{
		smlFreePcdata(rawData->data);
		rawData->data=0;
	}
	SCTSRTKFREEITEMLISTDATA(rawData->itemList);

    /*
     * Change to support Correlator
     */
	if (rawData->correlator)
	{
		smlFreePcdata(rawData->data);
		rawData->data=0;
	}
}

SctsCommandType SctsAlert::GetType()
{
	return SCTS_ALERT;
}

SctsPcdata& SctsAlert::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsAlert::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlAlertCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsAlert::SetData(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->data,pPcdata);
}

int SctsAlert::GetData()
{
	SCTSASSERT(rawData);
	SCTSRTKGETINT(rawData->data);
}

void SctsAlert::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsAlert::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsAlert::SetItemList(SctsItemList *pItemList)
{
	SCTSRTKSETITEMLIST(rawData->itemList,pItemList);
}

SctsItemList& SctsAlert::GetItemList(SctsItemList& itemList)
{
	SCTSRTKGETITEMLIST(rawData->itemList,itemList);
}

bool SctsAlert::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsAlert::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

/*
 * Get Alert's Correlator Element. 
 */
char * SctsAlert::GetCorrelator()
{
	SCTSASSERT(rawData);
	if(rawData->correlator)
		return (char *)(rawData->correlator->content);
	else
		return 0;
}

/*
 * Set Alert's Correlator Element. 
 */
void SctsAlert::SetCorrelator(char *pCorrelator)
{
	SCTSASSERT(rawData);
	if(rawData->correlator)
		smlFreePcdata(rawData->correlator);
	rawData->correlator=smlString2Pcdata(pCorrelator);
}

SctsAlert::SctsAlert(SmlAlertPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsAlert::SctsAlert(unsigned int cmdID,SctsItemList& itemList,int alertCode)
{
	rawData=(SmlAlertPtr_t)sctsMalloc(sizeof(SmlAlert_t));
	sctsMemset(rawData,0,sizeof(SmlAlert_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->itemList=itemList.rawData;
	rawData->data=sctsInt2Pcdata(alertCode);
}

/*
 * Add correlator support. 
 */
SctsAlert::SctsAlert(unsigned int cmdID,SctsItemList& itemList,int alertCode,char *correlator)
{
	rawData=(SmlAlertPtr_t)sctsMalloc(sizeof(SmlAlert_t));
	sctsMemset(rawData,0,sizeof(SmlAlert_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->itemList=itemList.rawData;
	rawData->data=sctsInt2Pcdata(alertCode);
	rawData->correlator=smlString2Pcdata(correlator);
}

SctsAlert::~SctsAlert()
{
	SCTSASSERT(rawData);
	smlFreeAlert(rawData);
}


/*****************************************************************
SctsSyncHdr Definition
******************************************************************/
void SctsSyncHdr::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
	if (rawData->cred)
	{
		smlFreeCredPtr(rawData->cred);
		rawData->cred=0;
	}
	if (rawData->version)
	{
		smlFreePcdata(rawData->version);
		rawData->version=0;
	}
	if (rawData->proto)
	{
		smlFreePcdata(rawData->proto);
		rawData->version=0;
	}
}

SctsCommandType SctsSyncHdr::GetType()
{
	return SCTS_HEADER;
}

SctsPcdata& SctsSyncHdr::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	pcdata.rawData=0;
	return pcdata;
}

void SctsSyncHdr::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlStartMessage(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsSyncHdr::BuildClose(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlEndMessage(sessionContext,final);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsSyncHdr::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsSyncHdr::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

void SctsSyncHdr::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsSyncHdr::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsSyncHdr::SetTarget(char *pLocURI,char *pLocName)
{
	SCTSASSERT(rawData);
	SCTSRTKSETTARGETSOURCE(rawData->target,pLocURI,pLocName);
}

SctsTargetSource& SctsSyncHdr::GetTarget(SctsTargetSource& target)
{
	SCTSASSERT(rawData);
	SCTSRTKGETTARGETSOURCE(rawData->target,target);
}

void SctsSyncHdr::SetSource(char *pLocURI,char *pLocName)
{
	SCTSASSERT(rawData);
	SCTSRTKSETTARGETSOURCE(rawData->source,pLocURI,pLocName);
}

SctsTargetSource& SctsSyncHdr::GetSource(SctsTargetSource& source)
{
	SCTSASSERT(rawData);
	SCTSRTKGETTARGETSOURCE(rawData->source,source);
}

bool SctsSyncHdr::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsSyncHdr::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

void SctsSyncHdr::SetVersion(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->version,pPcdata);
}

SctsPcdata& SctsSyncHdr::GetVersion(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->version,pcdata);
}

void SctsSyncHdr::SetProto(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->proto,pPcdata);
}

SctsPcdata& SctsSyncHdr::GetProto(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->proto,pcdata);
}

void SctsSyncHdr::SetSessionID(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->sessionID,pPcdata);
}

SctsPcdata& SctsSyncHdr::GetSessionID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->sessionID,pcdata);
}

void SctsSyncHdr::SetMsgID(int msgID)
{
	SCTSASSERT(rawData);
	SCTSRTKSETINT(rawData->msgID,msgID);
}

int SctsSyncHdr::GetMsgID()
{
	SCTSASSERT(rawData);
	SCTSRTKGETINT(rawData->msgID);
}

void SctsSyncHdr::SetRespURI(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->respURI,pPcdata);
}

SctsPcdata& SctsSyncHdr::GetRespURI(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->respURI,pcdata);
}


SctsSyncHdr::SctsSyncHdr(SmlSyncHdrPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsSyncHdr::SctsSyncHdr(SctsCred *pCred,SctsMeta *pMeta,SctsTargetSource *pSource,SctsTargetSource *pTarget,char *pVersion,char *pProto,char *sessionID,int msgID)
{
	rawData=(SmlSyncHdrPtr_t)sctsMalloc(sizeof(SmlSyncHdr_t));
	sctsMemset(rawData,0,sizeof(SmlSyncHdr_t));
	if (pCred) rawData->cred=pCred->rawData;
	if (pMeta) rawData->meta=SctsPcdata(*pMeta).rawData;
	if (pTarget) rawData->target=pTarget->rawData;
	if (pSource) rawData->source=pSource->rawData;
	rawData->sessionID=smlString2Pcdata(sessionID);
	rawData->msgID=sctsInt2Pcdata(msgID);
	rawData->proto=smlString2Pcdata(pProto);
	rawData->version=smlString2Pcdata(pVersion);
}

SctsSyncHdr::~SctsSyncHdr()
{
	SCTSASSERT(rawData);
	smlFreeSyncHdr(rawData);
}

/*****************************************************************
SctsStatus Definition
******************************************************************/
void SctsStatus::MakeStub()
{
}

SctsCommandType SctsStatus::GetType()
{
	return SCTS_STATUS;
}

SctsPcdata& SctsStatus::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsStatus::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlStatusCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsStatus::SetData(int status)
{
	SCTSASSERT(rawData);
	SCTSRTKSETINT(rawData->data,status);
}

int SctsStatus::GetData()
{
	SCTSASSERT(rawData);
	SCTSRTKGETINT(rawData->data);
}

void SctsStatus::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsStatus::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsStatus::SetItemList(SctsItemList *pItemList)
{
	SCTSRTKSETITEMLIST(rawData->itemList,pItemList);
}

SctsItemList& SctsStatus::GetItemList(SctsItemList& itemList)
{
	SCTSRTKGETITEMLIST(rawData->itemList,itemList);
}

void SctsStatus::SetMsgRef(int msgRef)
{
	SCTSASSERT(rawData);
	SCTSRTKSETINT(rawData->msgRef,msgRef);
}

int SctsStatus::GetMsgRef()
{
	SCTSASSERT(rawData);
	SCTSRTKGETINT(rawData->msgRef);
}

void SctsStatus::SetCmdRef(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->cmdRef,pPcdata);
}

SctsPcdata& SctsStatus::GetCmdRef(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdRef,pcdata);
}

void SctsStatus::SetTargetRefList(SctsTargetRefList *targetRefList)
{
	SCTSASSERT(rawData);
	if (rawData->targetRefList) smlFreeTargetRefList(rawData->targetRefList);
	if (targetRefList)
		rawData->targetRefList=targetRefList->rawData;
	else
		rawData->targetRefList=0;
}

SctsTargetRefList& SctsStatus::GetTargetRefList(SctsTargetRefList& targetRefList)
{
	SCTSASSERT(rawData);
	targetRefList.rawData=rawData->targetRefList;
	return targetRefList;
}

void SctsStatus::SetSourceRefList(SctsSourceRefList *sourceRefList)
{
	SCTSASSERT(rawData);
	if (rawData->sourceRefList) smlFreeSourceRefList(rawData->sourceRefList);
	if (sourceRefList)
		rawData->sourceRefList=sourceRefList->rawData;
	else
		rawData->sourceRefList=0;
}

SctsSourceRefList& SctsStatus::GetSourceRefList(SctsSourceRefList& sourceRefList)
{
	SCTSASSERT(rawData);
	sourceRefList.rawData=rawData->sourceRefList;
	return sourceRefList;
}

void SctsStatus::SetCmd(SctsPcdata *pPcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKSETPCDATA(rawData->cmd,pPcdata);
}

SctsPcdata& SctsStatus::GetCmd(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmd,pcdata);
}

void SctsStatus::SetChal(SctsChal *pChal)
{
	SCTSASSERT(rawData);
	if (rawData->chal) 
	{
		smlFreeChalPtr(rawData->chal);
		rawData->chal=0;
	}
	rawData->chal=(SmlChalPtr_t)sctsMalloc(sizeof(SmlChal_t));
	if (pChal)
		rawData->chal->meta=SctsPcdata(*pChal).rawData;
	else
		rawData->chal->meta=0;
}

SctsChal& SctsStatus::GetChal(SctsChal& chal)
{
	SCTSASSERT(rawData);
	if (rawData->chal && rawData->chal->meta && rawData->chal->meta->extension==SML_EXT_METINF)
		chal.rawData=(SmlMetInfMetInfPtr_t)rawData->chal->meta->content;
	else
		chal.rawData=0;
	return chal;
}

SctsStatus::SctsStatus(SmlStatusPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

void SctsStatus::SetCommandID(int commandID)
{
	SCTSASSERT(rawData);
	if (rawData->cmdID) smlFreePcdata(rawData->cmdID);
	rawData->cmdID=sctsInt2Pcdata(commandID);
}

SctsStatus::SctsStatus(unsigned int cmdID,int msgRef,char *pCmdRef,char *pCmd,int status)
{	
	rawData=(SmlStatusPtr_t)sctsMalloc(sizeof(SmlStatus_t));
	sctsMemset(rawData,0,sizeof(SmlStatus_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->msgRef=sctsInt2Pcdata(msgRef);
	rawData->cmdRef=smlString2Pcdata(pCmdRef);
	rawData->cmd=smlString2Pcdata(pCmd);
	rawData->data=sctsInt2Pcdata(status);
}

SctsStatus::~SctsStatus()
{
	SCTSASSERT(rawData);
	smlFreeStatus(rawData);
}

/*****************************************************************
SctsExec Definition
******************************************************************/
void SctsExec::MakeStub()
{
}

SctsCommandType SctsExec::GetType()
{
	return SCTS_EXEC;
}

SctsPcdata& SctsExec::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsExec::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlExecCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsExec::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsExec::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}
void SctsExec::SetItem(SctsItem *pItem)
{
	SCTSASSERT(rawData);
	if (rawData->item) smlFreeItemPtr(rawData->item);
	if (pItem)
		rawData->item=pItem->rawData;
	else
		rawData->item=0;
}

SctsItem& SctsExec::GetItem(SctsItem& item)
{
	SCTSASSERT(rawData);
	item.rawData=rawData->item;
	return item; 
}

bool SctsExec::IsNoResp()
{
	SCTSASSERT(rawData);
	return (rawData->flags&SmlNoResp_f)==SmlNoResp_f;
}

void SctsExec::IsNoResp(bool isNoResp)
{
	SCTSASSERT(rawData);
	if (isNoResp)
		rawData->flags|=SmlNoResp_f;
	else
		rawData->flags&=~SmlNoResp_f;
}

/*
 * Get Correlator of Exec command. 
 */
char * SctsExec::GetCorrelator()
{
	SCTSASSERT(rawData);
	if(rawData->correlator)
		return (char *)(rawData->correlator->content);
	else
		return 0;
}

/*
 * Set Correlator of Exec command. 
 */
void SctsExec::SetCorrelator(char *pCorrelator)
{
	SCTSASSERT(rawData);
	if(rawData->correlator)
		smlFreePcdata(rawData->correlator);
	rawData->correlator=smlString2Pcdata(pCorrelator);
}

SctsExec::SctsExec(SmlExecPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsExec::SctsExec(unsigned int cmdID,SctsItem *pItem)
{
	rawData=(SmlExecPtr_t)sctsMalloc(sizeof(SmlExec_t));
	smlLibMemset( rawData, 0, sizeof(SmlExec_t) );
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->cred=0;
	if (pItem)
		rawData->item=pItem->rawData;
	else
		rawData->item=0;
}

/*
 * Add Correlator support. 
 */
SctsExec::SctsExec(unsigned int cmdID,SctsItem *pItem,char *correlator)
{
	rawData=(SmlExecPtr_t)sctsMalloc(sizeof(SmlExec_t));
	smlLibMemset( rawData, 0, sizeof(SmlExec_t) );
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->cred=0;
	if (pItem)
		rawData->item=pItem->rawData;
	else
		rawData->item=0;
	rawData->correlator=smlString2Pcdata(correlator);
}

SctsExec::~SctsExec()
{
	SCTSASSERT(rawData);
	smlFreeExec(rawData);
}

/*****************************************************************
SctsMap Definition
******************************************************************/
void SctsMap::MakeStub()
{
	SCTSASSERT(rawData);
	if (rawData->meta)
	{
		smlFreePcdata(rawData->meta);
		rawData->meta=0;
	}
	if (rawData->cred)
	{
		smlFreeCredPtr(rawData->cred);
		rawData->cred=0;
	}
}	

SctsCommandType SctsMap::GetType()
{
	return SCTS_MAP;
}

SctsPcdata& SctsMap::GetCommandID(SctsPcdata& pcdata)
{
	SCTSASSERT(rawData);
	SCTSRTKGETPCDATA(rawData->cmdID,pcdata);
}

void SctsMap::SetCommandID(int commandID)
{
	SCTSASSERT(rawData);
	if (rawData->cmdID) smlFreePcdata(rawData->cmdID);
	rawData->cmdID=sctsInt2Pcdata(commandID);
}

void SctsMap::Build(SctsSessionContext sessionContext)
{
	int ret;
	ret=smlMapCmd(sessionContext,rawData);
	SCTSASSERT(ret==SML_ERR_OK);
}

void SctsMap::SetMeta(SctsMeta *pMeta)
{
	SCTSASSERT(rawData);
	SCTSRTKSETMETA(rawData->meta,pMeta);
}

SctsMeta& SctsMap::GetMeta(SctsMeta& meta)
{
	SCTSASSERT(rawData);
	SCTSRTKGETMETA(rawData->meta,meta);
}

void SctsMap::SetCred(SctsCred *pCred)
{
	SCTSRTKSETCRED(rawData->cred,pCred);
}

SctsCred& SctsMap::GetCred(SctsCred& cred)
{
	SCTSASSERT(rawData);
	cred.rawData=rawData->cred;
	return cred;
}

void SctsMap::SetTarget(char *pLocURI,char *pLocName)
{
	SCTSASSERT(rawData);
	SCTSRTKSETTARGETSOURCE(rawData->target,pLocURI,pLocName);
}

SctsTargetSource& SctsMap::GetTarget(SctsTargetSource& target)
{
	SCTSASSERT(rawData);
	SCTSRTKGETTARGETSOURCE(rawData->target,target);
}

void SctsMap::SetSource(char *pLocURI,char *pLocName)
{
	SCTSASSERT(rawData);
	SCTSRTKSETTARGETSOURCE(rawData->source,pLocURI,pLocName);
}

SctsTargetSource& SctsMap::GetSource(SctsTargetSource& source)
{
	SCTSASSERT(rawData);
	SCTSRTKGETTARGETSOURCE(rawData->source,source);
}

void SctsMap::SetMapItemList(SctsMapItemList *pMapItemList)
{
	SCTSASSERT(rawData);
	if (rawData->mapItemList) smlFreeMapItemList(rawData->mapItemList);
	if (pMapItemList)
		rawData->mapItemList=pMapItemList->rawData;
	else
		rawData->mapItemList=0;
}

SctsMapItemList& SctsMap::GetMapItemList(SctsMapItemList& mapItemList)
{
	SCTSASSERT(rawData);
	mapItemList.rawData=rawData->mapItemList;
	return mapItemList;
}

SctsMap::SctsMap(SmlMapPtr_t pCmd)
{
	SCTSASSERT(pCmd);
	rawData=pCmd;
}

SctsMap::SctsMap(unsigned int cmdID,char *pSourceLocURI,char *pSourceLocName,char *pTargetLocURI,char *pTargetLocName,SctsMapItemList *pMapItemList)
{
	rawData=(SmlMapPtr_t)sctsMalloc(sizeof(SmlMap_t));
	sctsMemset(rawData,0,sizeof(SmlMap_t));
	rawData->cmdID=sctsInt2Pcdata(cmdID);
	rawData->source=SctsTargetSource(pSourceLocURI,pSourceLocName).rawData;
	rawData->target=SctsTargetSource(pTargetLocURI,pTargetLocName).rawData;
	rawData->mapItemList=pMapItemList->rawData;
}

SctsMap::~SctsMap()
{
	SCTSASSERT(rawData);
	smlFreeMap(rawData);
}

/*****************************************************************
Verify DTD methods
******************************************************************/

bool SctsAdd::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.1)");verified=false;}
	if(!rawData->itemList || !rawData->itemList->item)
		{SctsErrorLog::AppendError("One or more Item element type MUST be present in the Add Cmd. Representation Protocol(5.5.1)");verified=false;}
	return verified;
}

bool SctsCopy::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.4)");verified=false;}
	if(!rawData->itemList || !rawData->itemList->item)
		{SctsErrorLog::AppendError("One or more Item element type MUST be present in the Copy Cmd. Representation Protocol(5.5.4)");verified=false;}
	return verified;
}

bool SctsDelete::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.5)");verified=false;}
	if(!rawData->itemList || !rawData->itemList->item)
		{SctsErrorLog::AppendError("One or more Item element type MUST be present in the Delete Cmd. Representation Protocol(5.5.5)");verified=false;}
	return verified;
}


bool SctsReplace::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.11)");verified=false;}
	if(!rawData->itemList || !rawData->itemList->item)
		{SctsErrorLog::AppendError("One or more Item element type MUST be specified in the Replace Cmd. Representation Protocol(5.5.11)");verified=false;}
	return verified;
}

bool SctsAlert::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.2)");verified=false;}
	return verified;
}

bool SctsExec::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.6)");verified=false;}
	if(!rawData->item)
		{SctsErrorLog::AppendError("One Item element type MUST be present in the Exec Cmd. Representation Protocol(5.5.6)");verified=false;}
	return verified;
}

bool SctsGet::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.7)");verified=false;}
	if(!rawData->itemList || !rawData->itemList->item)
		{SctsErrorLog::AppendError("One or more Item element type MUST be present in the Get Cmd. Representation Protocol(5.5.7)");verified=false;}
	return verified;
}

bool SctsMap::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.8)");verified=false;}
	if(!rawData->target)
		{SctsErrorLog::AppendError("Target element type MUST be present in the Map Cmd. Representation Protocol(5.5.8)");verified=false;}
	if(!rawData->source)
		{SctsErrorLog::AppendError("Source element type MUST be present in the Map Cmd. Representation Protocol(5.5.8)");verified=false;}
	if(!rawData->mapItemList)
		{SctsErrorLog::AppendError("One or more MapItem MUST be present in the Map Cmd. Representation Protocol(5.5.8)");verified=false;}
	
	SmlMapItemListPtr_t mapItemList = rawData->mapItemList;
	while(mapItemList)
	{
		if(!mapItemList->mapItem)
			{SctsErrorLog::AppendError("One or more MapItem MUST be present in the Map Cmd. Representation Protocol(5.5.8)");verified=false;}
		if(!mapItemList->mapItem->source || !mapItemList->mapItem->target) 
			{SctsErrorLog::AppendError("Source & Target Element MUST be present in the MapItem. Representation Protocol(5.5.9)");verified=false;}
		mapItemList=mapItemList->next;
	}
	return verified;
}


bool SctsPut::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.10)");verified=false;}
	if(!rawData->itemList || !rawData->itemList->item)
		{SctsErrorLog::AppendError("One or more Item element type MUST be present in the Put Cmd. Representation Protocol(5.5.10)");verified=false;}
	return verified;
}

bool SctsResults::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.12)");verified=false;}
	if(!rawData->cmdRef)
		{SctsErrorLog::AppendError("The mandatory CmdRef element missing. Representation Protocol(5.5.12)");verified=false;}
	if(!rawData->itemList || !rawData->itemList->item)
		{SctsErrorLog::AppendError("One or more Item element type MUST be present in the Results Cmd. Representation Protocol(5.5.12)");verified=false;}
	return verified;
}

bool SctsSearch::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.13)");verified=false;}
	if(!rawData->sourceList || !rawData->sourceList->source)
		{SctsErrorLog::AppendError("One or more Source element type MUST be present in the Search Cmd. Representation Protocol(5.5.13)");verified=false;}
	if(!rawData->data)
		{SctsErrorLog::AppendError("The Data element type MUST be present in the Search Cmd. Representation Protocol(5.5.13)");verified=false;}
	if(!rawData->meta)
		{SctsErrorLog::AppendError("The Meta element type MUST be present in the Search Cmd. Representation Protocol(5.5.13)");verified=false;}

	return verified;
}

bool SctsSequence::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.14)");verified=false;}
	return verified;
}

bool SctsSync::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.15)");verified=false;}
	return verified;
}

bool SctsAtomic::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.5.3)");verified=false;}
	return verified;
}


bool SctsStatus::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->cmdID)
		{SctsErrorLog::AppendError("The mandatory CmdID element missing. Representation Protocol(5.4.1)");verified=false;}
	if(!rawData->msgRef)
		{SctsErrorLog::AppendError("The mandatory MsgRef element missing. Representation Protocol(5.4.1)");verified=false;}
	if(!rawData->cmdRef)
		{SctsErrorLog::AppendError("The mandatory CmdRef element missing. Representation Protocol(5.4.1)");verified=false;}
	if(!rawData->cmd)
		{SctsErrorLog::AppendError("The mandatory Cmd element missing. Representation Protocol(5.4.1)");verified=false;}
	if(!rawData->data)
		{SctsErrorLog::AppendError("The mandatory Data element missing. Representation Protocol(5.4.1)");verified=false;}
	return verified;
}
  
bool SctsSyncHdr::VerifyDTD(SctsSyncMLProto proto)
{
	bool verified=true;
	if(!rawData->version)
		{SctsErrorLog::AppendError("VerDTD element missing. Representation Protocol(5.2.2)");verified=false;}
	if(!rawData->proto)
		{SctsErrorLog::AppendError("VerProto element missing. Representation Protocol(5.2.2)");verified=false;}
	if(!rawData->sessionID)
		{SctsErrorLog::AppendError("SessionID element missing. Representation Protocol(5.2.2)");verified=false;}
	if(!rawData->msgID)
		{SctsErrorLog::AppendError("MsgID element missing. Representation Protocol(5.2.2)");verified=false;}
	if(!rawData->target)
		{SctsErrorLog::AppendError("Target element missing. Representation Protocol(5.2.2)");verified=false;}
	if(!rawData->source)
		{SctsErrorLog::AppendError("Source element missing. Representation Protocol(5.2.2)");verified=false;}
	return verified;
}

#endif
