📄 scmpp30operator.cpp
字号:
unsigned long command;
unsigned long state;
int packtplen=0;
if(RecieveSocket(client,LEN_CMPP30_HEADER,head,MAX_RECVTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
memcpy(&templong,head,4);
templong=ntohl(templong);
packetlen=templong-LEN_CMPP30_HEADER;
memcpy(&templong,head+4,4);
templong=ntohl(templong);
command=templong;
cmdstore=command;
memcpy(SequenceID,head+8,4);
switch(command) {
case CMPP30_CONNECT_RESP:
if(RecieveSocket(client,packetlen,logresp,MAX_RECVTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
memcpy(&state,logresp,4);
state=ntohl(state);
if(state!=0)
{
msg.Format("EMPP %d:%u Login Fail",index,state);
ShowMsg(msg);
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
m_ConnList[index]->sock=client;
memcpy(&state,logresp+21,4);
state=ntohl(state);
msg.Format("EMPP %d Login Ok,ability:%u",index,state);
ShowMsg(msg);
break;
case CMPP30_SUBMIT_RESP:
{
if(RecieveSocket(client,packetlen,submitresp,MAX_RECVTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
memcpy(&state,submitresp+10,4);
state=ntohl(state);
unsigned long mt_seq=0;
memcpy(&mt_seq,SequenceID,4);
mt_seq=ntohl(mt_seq);
CString strmsgId;
strmsgId=ConvertToString((BYTE*)submitresp,10);
SetMtResult(mt_seq,(char*)(LPCTSTR)strmsgId,state);
msg.Format("CMPP30 CMPP30_SUBMIT_RESP %d %u %s",index,state,strmsgId);
ShowMsg(msg);
}
break;
case CMPP30_DELIVER:
{
int offset=0;
if(RecieveSocket(client,packetlen,content,MAX_RECVTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
char resp[LEN_CMPP30_HEADER + LEN_CMPP30_DELIVER_RESP];
memset(resp,0,LEN_CMPP30_HEADER + LEN_CMPP30_DELIVER_RESP);
templong=LEN_CMPP30_HEADER + LEN_CMPP30_DELIVER_RESP;
templong=htonl(templong);
memcpy(resp+offset,&templong,4);
offset+=4;
templong=htonl(CMPP30_DELIVER_RESP);
memcpy(resp+offset,&templong,4);
offset+=4;
memcpy(resp+offset,SequenceID,4);
offset+=4;
memcpy(resp+offset,content,10);
offset+=10;
state=0;
state=htonl(state);
memcpy(resp+offset,&state,4);
offset+=4;
if(SendSocket(client,resp,offset,MAX_SENDTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
BYTE isReport=*(content+77);
CString msgId=ConvertToString((BYTE*)content,10);
if(isReport==0)
{
CMPP_Deliver_Body* body=new CMPP_Deliver_Body;
memset(body,0,sizeof(CMPP_Deliver_Body));
unsigned long mo_id=0;
body->telcomid=telcomid;
body->MO_ID=mo_id;
CString rtime=GenStrTime();
strcpy(body->recvtime,(char*)(LPCTSTR)rtime);
memcpy(body->destterminal,content+10,21);
memcpy(body->serviceid,content+31,10);
body->tpPID=*(content+41);
body->tpUDHI=*(content+42);
body->msgformat=*(content+43);
memcpy(body->srcterminal,content+44,32);
body->SrcTerminalIDType=*(content+76);
body->msglength=(BYTE)(*(content+78));
memcpy(body->pMsg,(content+79),body->msglength);
memcpy(body->reserved,(content+79+body->msglength),20);
msg.Format("CMPP30 CMPP30_DELIVER %d, %s,%s,%s",index,body->srcterminal,body->destterminal,body->pMsg);
ShowMsg(msg);
m_molock.Lock();
m_molist.AddTail(body);
m_molock.Unlock();
}else
{
CMPP_Report_Body* body=new CMPP_Report_Body;
memset(body,0,sizeof(CMPP_Report_Body));
unsigned long report_id=0;
body->telcomid=telcomid;
CString rtime=GenStrTime();
strcpy(body->recvtime,(char*)(LPCTSTR)rtime);
memcpy(body->src_terminal_id,content+10,21);
body->report_id=report_id;
memcpy(body->dest_terminal_id,content+44,32);
body->Dest_terminal_Id_Type=*(content+76);
msgId=ConvertToString((BYTE*)(content+79),10);
strcpy(body->msgid,(char*)(LPCTSTR)msgId);
memcpy(body->subtime,content+96,10);
memcpy(body->donetime,content+106,10);
char *tpchar=content+89;
if(strncmp(tpchar,"DELIVRD",7)==0)
{
body->stat=SM_DELIVERED;
}else if(strncmp(tpchar,"EXPIRED",7)==0)
{
body->stat=SM_EXPIRED;
}else if(strncmp(tpchar,"DELETED",7)==0)
{
body->stat=SM_DELETED;
}else if(strncmp(tpchar,"UNDELIV",7)==0)
{
body->stat=SM_UNDELIVERABLE;
}else if(strncmp(tpchar,"ACCEPTD",7)==0)
{
body->stat=SM_ACCEPTED;
}else if(strncmp(tpchar,"UNKNOWN",7)==0)
{
body->stat=SM_UNKNOWN;
}else if(strncmp(tpchar,"REJECTD",7)==0)
{
body->stat=SM_REJECTED;
}else
{
body->stat=SM_UNKNOWN;
}
body->ErrorCode=0;
msg.Format("CMPP30 CMPP30_DELIVER Report %d,%u,%s",index,body->stat,msgId);
ShowMsg(msg);
m_reportlock.Lock();
m_reportlist.AddTail(body);
m_reportlock.Unlock();
}
}
break;
case CMPP30_ACTIVE_TEST:
{
char Active_resp[LEN_CMPP30_HEADER+1];
templong=LEN_CMPP30_HEADER+1;
templong=htonl(templong);
memcpy(Active_resp,&templong,4);
templong=CMPP30_ACTIVE_TEST_RESP;
templong=htonl(templong);
memcpy(Active_resp+4,&templong,4);
memcpy(Active_resp+8,head+8,4);
*(Active_resp+12)=0;
if(SendSocket(client,Active_resp,LEN_CMPP30_HEADER+1,MAX_SENDTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
}
break;
case CMPP30_ACTIVE_TEST_RESP:
{
char Active_resp[2];
if(RecieveSocket(client,packetlen,Active_resp,MAX_RECVTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
msg.Format("CMPP30 CMPP30_ACTIVE_TEST_RESP %d",index);
ShowMsg(msg);
}
break;
default:
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
break;
}
return true;
}
bool CSCmpp30Operator::SendActiveTest(SOCKET &client,int index)
{
char head[LEN_CMPP30_HEADER];
memset(head,0,LEN_CMPP30_HEADER);
unsigned long templong =0;
templong=LEN_CMPP30_HEADER;
templong=htonl(templong);
memcpy(head,&templong,4);
templong=CMPP30_ACTIVE_TEST;
templong=htonl(templong);
memcpy(head+4,&templong,4);
templong=htonl(GenSequence());
memcpy(head+8,&templong,4);
if(SendSocket(client,head,LEN_CMPP30_HEADER,MAX_SENDTIME)<=0)
{
CloseSocket(client);
m_ConnList[index]->sock=client=NULL;
return false;
}
return true;
}
void CSCmpp30Operator::AddMtResultStr(unsigned long seq,HANDLE hevent)
{
m_resultlock.Lock();
cmpp30result* t_obj=NULL;
if(!m_mtobjmap.Lookup((void*)seq,(void*&)t_obj))
{
t_obj=new cmpp30result;
m_mtobjmap.SetAt((void*)seq,t_obj);
t_obj->hevent=NULL;
}
memset(t_obj->msgId,0,21);
strcpy(t_obj->msgId,"-1");
t_obj->state=2000;
t_obj->hevent=hevent;
m_resultlock.Unlock();
}
void CSCmpp30Operator::RemoveMtResult(unsigned long seq)
{
m_resultlock.Lock();
cmpp30result* t_obj=NULL;
if(m_mtobjmap.Lookup((void*)seq,(void*&)t_obj))
{
if(t_obj->hevent)
{
CloseHandle(t_obj->hevent);
t_obj->hevent=NULL;
}
delete t_obj;
}
m_mtobjmap.RemoveKey((void*)seq);
m_resultlock.Unlock();
}
void CSCmpp30Operator::SetMtResult(unsigned long seq,char* msgId,unsigned long state)
{
cmpp30result* t_obj=NULL;
m_resultlock.Lock();
if(m_mtobjmap.Lookup((void*)seq,(void*&)t_obj))
{
strcpy(t_obj->msgId,msgId);
t_obj->state=state;
SetEvent(t_obj->hevent);
}
m_resultlock.Unlock();
}
void CSCmpp30Operator::GetMtResult(unsigned long seq,char* msgId,unsigned long& state)
{
cmpp30result* t_obj=NULL;
m_resultlock.Lock();
if(m_mtobjmap.Lookup((void*)seq,(void*&)t_obj))
{
strcpy(msgId,t_obj->msgId);
state=t_obj->state;
}
m_resultlock.Unlock();
}
void CSCmpp30Operator::RemoveAllMtStr()
{
cmpp30result* t_obj=NULL;
m_resultlock.Lock();
POSITION pos=m_mtobjmap.GetStartPosition();
while(pos)
{
void* key=NULL;
cmpp30result* t_obj=NULL;
m_mtobjmap.GetNextAssoc(pos,key,(void*&)t_obj);
if(t_obj->hevent)
{
SetEvent(t_obj->hevent);
CloseHandle(t_obj->hevent);
t_obj->hevent=NULL;
}
delete t_obj;
}
m_mtobjmap.RemoveAll();
m_resultlock.Unlock();
}
void CSCmpp30Operator::StartMoRecv()
{
m_runrecv=true;
for(int i=0;i<m_mtthread+m_mothread;i++)
{
cmpp30tstr* par=new cmpp30tstr;
par->index=i;
par->p=this;
if(m_mothread==0)
par->mode=2;
else
par->mode=((i<m_mtthread)?0:1);
DWORD tid;
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)RecvThread,par,0,&tid);
}
}
void CSCmpp30Operator::StopMoRecv()
{
m_runrecv=false;
DWORD ret=WaitForMultipleObjects(m_mtthread+m_mothread,m_toevent,TRUE, INFINITE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -