📄 syncsession.cpp
字号:
pItem->meta->content = (SmlMetInfMetInfPtr_t)smlLibMalloc(sizeof(SmlMetInfMetInf_t));
smlLibMemset(pItem->meta->content, 0, sizeof(SmlMetInfMetInf_t));
SmlMetInfMetInfPtr_t pMeta = (SmlMetInfMetInfPtr_t)(pItem->meta->content);
SmlMetInfAnchorPtr_t pAnchor = NULL ;
pAnchor = (SmlMetInfAnchorPtr_t)smlLibMalloc(sizeof(SmlMetInfAnchor_t));
smlLibMemset(pAnchor, 0, sizeof(SmlMetInfAnchor_t));
pMeta->anchor = pAnchor ;
char *serveranchor = _database_get_serveranchor(m_sUser);
char nextanchor[100];
_get_new_anchor(nextanchor);
pMeta->anchor->next = smlString2Pcdata(nextanchor);
pMeta->anchor->last = smlString2Pcdata(serveranchor);
if(alerttype==1)
alert.data = smlString2Pcdata("201");
else
alert.data = smlString2Pcdata(pAlert->data);
//保存信息
m_sServerAnchor = (char *)smlLibMalloc(smlLibStrlen(nextanchor));
smlLibStrcpy(m_sServerAnchor,nextanchor);
m_sClientAnchor = (char *)smlLibMalloc(smlLibStrlen(pAlert->itemList->item->meta->anchor_next));
smlLibStrcpy(m_sClientAnchor,pAlert->itemList->item->meta->anchor_next);
if(m_nSyncType==0)
m_nSyncType=data;
}
smlAlertCmd( id, &alert);
}
if(data==222)//客户端发完了修改信息?不一定,如果这个包中还有同步消息 就不发送自己的修改信息
{
m_nClientSend222 = 1;
}
}
void CSyncSession::HandleStartMessage(InstanceID_t id,CmdSyncHdr_s*pSyncHdr)
{
SmlSyncHdr_t hdr;
SmlSource_t source;
SmlTarget_t target;
char vert[100];
smlLibMemset(&hdr,0,(MemSize_t)sizeof(SmlSyncHdr_t));
smlLibMemset(&source,0,(MemSize_t)sizeof(SmlSource_t));
smlLibMemset(&target,0,(MemSize_t)sizeof(SmlTarget_t));
hdr.elementType = SML_PE_HEADER;
hdr.version = smlString2Pcdata("1.1");
hdr.proto = smlString2Pcdata("SyncML/1.1");
hdr.sessionID = smlString2Pcdata(pSyncHdr->sessionID);
hdr.msgID = smlString2Pcdata(pSyncHdr->msgID);
//hdr.flags = SmlNoResp_f;
target.locURI = smlString2Pcdata(pSyncHdr->source_locURI);
hdr.target = ⌖
source.locURI = smlString2Pcdata(pSyncHdr->target_locURI);
hdr.source = &source;
hdr.respURI = smlString2Pcdata(pSyncHdr->target_locURI);
smlStartMessageExt(id, &hdr, SML_VERS_1_1);
SmlStatus_t status;
smlLibMemset(&status,0,(MemSize_t)sizeof(SmlStatus_t));
status.elementType = SML_PE_STATUS;
sprintf(vert , "%d",m_nCmdID++);
status.cmdID = smlString2Pcdata(vert);
status.msgRef = smlString2Pcdata(pSyncHdr->msgID);
status.cmdRef = smlString2Pcdata("0");
status.cmd = smlString2Pcdata("SyncHdr");
SmlTargetRefListPtr_t pTarget = (SmlTargetRefListPtr_t)smlLibMalloc(sizeof(SmlTargetRefList_t));
smlLibMemset(pTarget, 0, sizeof(SmlTargetRefList_t));
status.targetRefList = pTarget;
pTarget->targetRef = smlString2Pcdata(pSyncHdr->target_locURI);
SmlSourceRefListPtr_t pSource = (SmlSourceRefListPtr_t)smlLibMalloc(sizeof(SmlSourceRefList_t));
smlLibMemset(pSource, 0, sizeof(SmlSourceRefList_t));
status.sourceRefList = pSource;
pSource->sourceRef = smlString2Pcdata(pSyncHdr->source_locURI);
if(m_eCredState==Cred_Offer)
{
char sql [1024];
sprintf(sql,"select count(*) from pim_user where userid='%s' and password='%s'",m_sUser,m_sPwd);
CMySet set;
if(workdb.PrepareSql(sql, set)==FALSE)
{
XPTDEBUG(("sql=%s error=%s\n",sql,workdb.GetSqlError()));
m_eCredState=Cred_Failed;
}
else
{
if(workdb.FetchData())
{
int nCnt = atoi(set.GetFieldValue(0));
XPTDEBUG(("sql=%s Count=%d\n",sql,nCnt));
if(nCnt==0)
{
m_eCredState=Cred_Failed;
}
else
{
m_eCredState=Cred_Success;
}
}
}
}
if(m_eCredState==Cred_NoOffer)
{
SmlChal_t chal ;
smlLibMemset(&chal,0,(MemSize_t)sizeof(SmlChal_t));
status.chal = &chal;
chal.meta = (SmlPcdataPtr_t)smlLibMalloc(sizeof(SmlPcdata_t));
smlLibMemset(chal.meta, 0, sizeof(SmlPcdata_t));
chal.meta->contentType=SML_PCDATA_EXTENSION;
chal.meta->extension=SML_EXT_METINF;
chal.meta->content = (SmlMetInfMetInfPtr_t)smlLibMalloc(sizeof(SmlMetInfMetInf_t));
smlLibMemset(chal.meta->content, 0, sizeof(SmlMetInfMetInf_t));
SmlMetInfMetInfPtr_t pMeta = (SmlMetInfMetInfPtr_t)(chal.meta->content);
pMeta->type = smlString2Pcdata("syncml:auth-basic");
pMeta->format = smlString2Pcdata("b64");
status.data = smlString2Pcdata("407");
}
else if(m_eCredState==Cred_Failed)
{
//无效证书
status.data = smlString2Pcdata("401");
}
else if(m_eCredState==Cred_Success)
{
//接收授权
status.data = smlString2Pcdata("212");
m_eCredState=Cred_Ok;
}
else if(m_eCredState==Cred_Ok)
{
//有效证书 OK
status.data = smlString2Pcdata("200");
}
smlStatusCmd( id, &status);
}
void CSyncSession::DebugCmdItem()
{
SessionCmdItem_t * tmp;
tmp = m_pHead;
while(tmp!=NULL)
{
switch(tmp->ItemType)
{
case SML_PE_UNDEF:
XPTDEBUG(("为定义\n"));
break;
case SML_PE_ERROR:
XPTDEBUG(("Error\n"));
break;
case SML_PE_ADD:
// XPTDEBUG(("Add\n"));
break;
case SML_PE_ALERT:
XPTDEBUG(("Alert\n"));
/*
{
CmdAlert_s* pAlert = (CmdAlert_s*)tmp->CmdItem;
if(pAlert->cmdID!=NULL)
XPTDEBUG(("Alert.CmdID = %s\n",pAlert->cmdID));
if(pAlert->data!=NULL)
XPTDEBUG(("Alert.Data = %s\n",pAlert->data));
if(pAlert->elementType!=NULL)
XPTDEBUG(("Alert.ElementType = %s\n",pAlert->elementType));
if(pAlert->cred_meta!=NULL)
XPTDEBUG(("Alert.Cred.Meta = %s\n",pAlert->cred_meta));
if(pAlert->cred_data!=NULL)
XPTDEBUG(("Alert.Cred.Data = %s\n",pAlert->cred_data));
CmdItemList_s *itemList = pAlert->itemList;
while(itemList!=NULL)
{
if(itemList->item->target_locURI!=NULL)
XPTDEBUG(("Alert.Item.Target.LocURI = %s\n",itemList->item->target_locURI));
if(itemList->item->target_locName!=NULL)
XPTDEBUG(("Alert.Item.Target.LocName = %s\n",itemList->item->target_locName));
if(itemList->item->source_locURI!=NULL)
XPTDEBUG(("Alert.Item.Source.LocURI = %s\n",itemList->item->source_locURI));
if(itemList->item->source_locName!=NULL)
XPTDEBUG(("Alert.Item.Source.LocName = %s\n",itemList->item->source_locName));
if(itemList->item->meta!=NULL)
{
if(itemList->item->meta->maxmsgsize!=NULL)
XPTDEBUG(("Alert.Item.Meta.MaxMsgSize = %s\n",itemList->item->meta->maxmsgsize));
if(itemList->item->meta->format!=NULL)
XPTDEBUG(("Alert.Item.Meta.Format = %s\n",itemList->item->meta->format));
if(itemList->item->meta->type!=NULL)
XPTDEBUG(("Alert.Item.Meta.Type = %s\n",itemList->item->meta->type));
if(itemList->item->meta->version!=NULL)
XPTDEBUG(("Alert.Item.Meta.Version = %s\n",itemList->item->meta->version));
if(itemList->item->meta->anchor_last!=NULL)
XPTDEBUG(("Alert.Item.Meta.Anchor.Last = %s\n",itemList->item->meta->anchor_last));
if(itemList->item->meta->anchor_next!=NULL)
XPTDEBUG(("Alert.Item.Meta.Anchor.Next = %s\n",itemList->item->meta->anchor_next));
if(itemList->item->meta->mark!=NULL)
XPTDEBUG(("Alert.Item.Meta.Mark = %s\n",itemList->item->meta->mark));
if(itemList->item->meta->maxobjsize!=NULL)
XPTDEBUG(("Alert.Item.Meta.MaxObjSize = %s\n",itemList->item->meta->maxobjsize));
if(itemList->item->meta->mem_free!=NULL)
XPTDEBUG(("Alert.Item.Meta.Mem.Free = %s\n",itemList->item->meta->mem_free));
if(itemList->item->meta->mem_freeid!=NULL)
XPTDEBUG(("Alert.Item.Meta.Mem.FreeID = %s\n",itemList->item->meta->mem_freeid));
if(itemList->item->meta->mem_shared!=NULL)
XPTDEBUG(("Alert.Item.Meta.Mem.Shared = %s\n",itemList->item->meta->mem_shared));
if(itemList->item->meta->nextnonce!=NULL)
XPTDEBUG(("Alert.Item.Meta.Mem.NextNonce = %s\n",itemList->item->meta->nextnonce));
if(itemList->item->meta->emi!=NULL)
XPTDEBUG(("Alert.Item.Meta.Emi.Data = %s\n",itemList->item->meta->emi->data));
}
itemList=itemList->next;
}
}
*/
break;
case SML_PE_ATOMIC_START:
XPTDEBUG(("Start\n"));
break;
case SML_PE_ATOMIC_END:
XPTDEBUG(("End\n"));
break;
case SML_PE_COPY:
XPTDEBUG(("Copy\n"));
break;
case SML_PE_DELETE:
XPTDEBUG(("Delete\n"));
break;
case SML_PE_EXEC:
XPTDEBUG(("Exec\n"));
break;
case SML_PE_GET:
XPTDEBUG(("Get\n"));
break;
case SML_PE_MAP:
XPTDEBUG(("Map\n"));
break;
case SML_PE_PUT:
XPTDEBUG(("Put\n"));
/*
{
CmdPut_s* pPut = (CmdPut_s*)tmp->CmdItem;
if(pPut->cmdID!=NULL)
XPTDEBUG(("Put.CmdID = %s\n",pPut->cmdID));
if(pPut->elementType!=NULL)
XPTDEBUG(("Put.ElementType = %s\n",pPut->elementType));
if(pPut->cred_meta!=NULL)
XPTDEBUG(("Put.Cred.Meta = %s\n",pPut->cred_meta));
if(pPut->cred_data!=NULL)
XPTDEBUG(("Put.Cred.Data = %s\n",pPut->cred_data));
//if(pPut->flags!=NULL)
XPTDEBUG(("Put.Flags = %d\n",pPut->flags));
if(pPut->lang!=NULL)
XPTDEBUG(("Put.Lang = %s\n",pPut->lang));
if(pPut->meta!=NULL)
{
if(pPut->meta->maxmsgsize!=NULL)
XPTDEBUG(("Put.Meta.MaxMsgSize = %s\n",pPut->meta->maxmsgsize));
if(pPut->meta->format!=NULL)
XPTDEBUG(("Put.Meta.Format = %s\n",pPut->meta->format));
if(pPut->meta->type!=NULL)
XPTDEBUG(("Put.Meta.Type = %s\n",pPut->meta->type));
if(pPut->meta->version!=NULL)
XPTDEBUG(("Put.Meta.Version = %s\n",pPut->meta->version));
if(pPut->meta->anchor_last!=NULL)
XPTDEBUG(("Put.Meta.Anchor.Last = %s\n",pPut->meta->anchor_last));
if(pPut->meta->anchor_next!=NULL)
XPTDEBUG(("Put.Meta.Anchor.Next = %s\n",pPut->meta->anchor_next));
if(pPut->meta->mark!=NULL)
XPTDEBUG(("Put.Meta.Mark = %s\n",pPut->meta->mark));
if(pPut->meta->maxobjsize!=NULL)
XPTDEBUG(("Put.Meta.MaxObjSize = %s\n",pPut->meta->maxobjsize));
if(pPut->meta->mem_free!=NULL)
XPTDEBUG(("Put.Meta.Mem.Free = %s\n",pPut->meta->mem_free));
if(pPut->meta->mem_freeid!=NULL)
XPTDEBUG(("Put.Meta.Mem.FreeID = %s\n",pPut->meta->mem_freeid));
if(pPut->meta->mem_shared!=NULL)
XPTDEBUG(("Put.Meta.Mem.Shared = %s\n",pPut->meta->mem_shared));
if(pPut->meta->nextnonce!=NULL)
XPTDEBUG(("Put.Meta.Mem.NextNonce = %s\n",pPut->meta->nextnonce));
if(pPut->meta->emi!=NULL)
XPTDEBUG(("Put.Meta.Emi.Data = %s\n",pPut->meta->emi->data));
}
CmdItemList_s *itemList = pPut->itemList;
while(itemList!=NULL)
{
if(itemList->item->target_locURI!=NULL)
XPTDEBUG(("Put.Item.Target.LocURI = %s\n",itemList->item->target_locURI));
if(itemList->item->target_locName!=NULL)
XPTDEBUG(("Put.Item.Target.LocName = %s\n",itemList->item->target_locName));
if(itemList->item->source_locURI!=NULL)
XPTDEBUG(("Put.Item.Source.LocURI = %s\n",itemList->item->source_locURI));
if(itemList->item->source_locName!=NULL)
XPTDEBUG(("Put.Item.Source.LocName = %s\n",itemList->item->source_locName));
if(itemList->item->meta!=NULL)
{
if(itemList->item->meta->maxmsgsize!=NULL)
XPTDEBUG(("Put.Item.Meta.MaxMsgSize = %s\n",itemList->item->meta->maxmsgsize));
if(itemList->item->meta->format!=NULL)
XPTDEBUG(("Put.Item.Meta.Format = %s\n",itemList->item->meta->format));
if(itemList->item->meta->type!=NULL)
XPTDEBUG(("Put.Item.Meta.Type = %s\n",itemList->item->meta->type));
if(itemList->item->meta->version!=NULL)
XPTDEBUG(("Put.Item.Meta.Version = %s\n",itemList->item->meta->version));
if(itemList->item->meta->anchor_last!=NULL)
XPTDEBUG(("Put.Item.Meta.Anchor.Last = %s\n",itemList->item->meta->anchor_last));
if(itemList->item->meta->anchor_next!=NULL)
XPTDEBUG(("Put.Item.Meta.Anchor.Next = %s\n",itemList->item->meta->anchor_next));
if(itemList->item->meta->mark!=NULL)
XPTDEBUG(("Put.Item.Meta.Mark = %s\n",itemList->item->meta->mark));
if(itemList->item->meta->maxobjsize!=NULL)
XPTDEBUG(("Put.Item.Meta.MaxObjSize = %s\n",itemList->item->meta->maxobjsize));
if(itemList->item->meta->mem_free!=NULL)
XPTDEBUG(("Put.Item.Meta.Mem.Free = %s\n",itemList->item->meta->mem_free));
if(itemList->item->meta->mem_freeid!=NULL)
XPTDEBUG(("Put.Item.Meta.Mem.FreeID = %s\n",itemList->item->meta->mem_freeid));
if(itemList->item->meta->mem_shared!=NULL)
XPTDEBUG(("Put.Item.Meta.Mem.Shared = %s\n",itemList->item->meta->mem_shared));
if(itemList->item->meta->nextnonce!=NULL)
XPTDEBUG(("Put.Item.Meta.Mem.NextNonce = %s\n",itemList->item->meta->nextnonce));
if(itemList->item->meta->emi!=NULL)
XPTDEBUG(("Put.Item.Meta.Emi.Data = %s\n",itemList->item->meta->emi->data));
}
//if(itemList->item->data_contentType ==SML_PCDATA_EXTENSION)
//{
// if(itemList->item->data_extension==SML_EXT_DEVINF)
// {
if(itemList->item->data!=NULL)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -